update xml import
This commit is contained in:
parent
2203a41d3b
commit
7a728fc298
2 changed files with 133 additions and 32 deletions
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
# Cargosoft Schnittstelle
|
||||
# Cargosoft Schnittstelle (Bremen - Mandant 001)
|
||||
|
||||
Für den Austasuch von Daten mit Cargosoft verwenden wir einen Subaccount `u248962-sub2` der auf das Verzeichnis `/office-alexander-logistics/cargosoft` zeigt:
|
||||
|
||||
|
|
@ -22,3 +22,38 @@ Technisch wird das über die CDI Bean `com.alexanderlogistics.xml.CargosoftXMLIn
|
|||
|
||||
Die Kreditoren/Debitoren Stammdaten werden von Cargosoft im Verzeichnis `/fromCargosoft/stammdaten/` über die Datei `Vendors.csv` bereitgestellt
|
||||
Über den Document Importer `CSV` werden die Dokumente regelmäßig importiert bzw. aktualisert
|
||||
|
||||
|
||||
|
||||
# Cargosoft Schnittstelle (Bremerhaven Mandant 005)
|
||||
|
||||
Server: u248962.your-storagebox.de
|
||||
Pfad: /office-alexander-logistics/cargosoft-bhv
|
||||
Benutzername: u248962-sub5
|
||||
Passwort: 5hKKzv6TFCKRrAdR
|
||||
|
||||
|
||||
# Cargosoft Schnittstelle (Polen Mandant 003)
|
||||
|
||||
Server: u248962.your-storagebox.de
|
||||
Pfad: /office-alexander-logistics/cargosoft-pl
|
||||
Benutzername: u248962-sub7
|
||||
Passwort: PGPzzqmtZ8BSxkbs
|
||||
|
||||
# Cargosoft Schnittstelle (Dubai Mandant 006)
|
||||
|
||||
Server: u248962.your-storagebox.de
|
||||
Pfad: /office-alexander-logistics/cargosoft-dwc
|
||||
Benutzername: u248962-sub3
|
||||
Passwort: enHjxs9h4nJ6EgsZ
|
||||
|
||||
|
||||
|
||||
|
||||
# Cargosoft Schnittstelle (USA Mandant 004)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Cargosoft Schnittstelle (China Mandant 002 (?))
|
||||
|
|
@ -32,6 +32,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -49,6 +50,11 @@ import javax.inject.Inject;
|
|||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpression;
|
||||
|
|
@ -272,28 +278,29 @@ public class CargosoftXMLInvoiceImportImportService {
|
|||
+ rawData.length);
|
||||
// create new workitem
|
||||
invoice = createWorkitem(event.getSource(), file.getName(), rawData, spacePosMappings);
|
||||
if (invoice == null) {
|
||||
// no new data found
|
||||
continue;
|
||||
if (invoice != null) {
|
||||
// persist workitem only if not exists and with a matching mandant.id
|
||||
if (!invoice.getItemValueString("mandant.id").equals(mandantID)) {
|
||||
throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(),
|
||||
"FTP_ERROR", "Invoice does not match mandantID " + mandantID);
|
||||
}
|
||||
count++;
|
||||
workflowService.processWorkItem(invoice);
|
||||
}
|
||||
} else {
|
||||
logger.warning("...Warning - invalid file content '"
|
||||
+ file.getName() + "' - file will be deleted!");
|
||||
}
|
||||
|
||||
if (invoice != null) {
|
||||
// persist workitem only if not exists and with a matching mandant.id
|
||||
if (!invoice.getItemValueString("mandant.id").equals(mandantID)) {
|
||||
throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(),
|
||||
"FTP_ERROR", "Invoice does not match mandantID " + mandantID);
|
||||
}
|
||||
count++;
|
||||
workflowService.processWorkItem(invoice);
|
||||
}
|
||||
// finally move the file....
|
||||
// ftpClient.deleteFile(file.getName());
|
||||
// finally delete teh file from the transfer folder
|
||||
ftpClient.deleteFile(ftpPath + file.getName());
|
||||
// String sourceFilePath = ftpPath + file.getName();
|
||||
// String destinationFilePath = ftpPath + "processed/" + file.getName();
|
||||
// boolean success = ftpClient.rename(sourceFilePath, destinationFilePath);
|
||||
// if (!success) {
|
||||
// logger.warning("Failed to move file " + file.getName() + " to " + ftpPath +
|
||||
// "processed/");
|
||||
// }
|
||||
|
||||
} catch (AccessDeniedException | ProcessingErrorException | PluginException
|
||||
| ModelException e) {
|
||||
| ModelException | XPathExpressionException | TransformerException e) {
|
||||
throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(),
|
||||
"FTP_ERROR", e.getMessage());
|
||||
}
|
||||
|
|
@ -333,10 +340,13 @@ public class CargosoftXMLInvoiceImportImportService {
|
|||
* @throws PluginException
|
||||
* @throws ProcessingErrorException
|
||||
* @throws AccessDeniedException
|
||||
* @throws TransformerException
|
||||
* @throws XPathExpressionException
|
||||
*/
|
||||
public ItemCollection createWorkitem(ItemCollection source, String fileName, byte[] rawData,
|
||||
Map<String, List<String>> spacePosMappings)
|
||||
throws AccessDeniedException, ProcessingErrorException, PluginException, ModelException {
|
||||
throws AccessDeniedException, ProcessingErrorException, PluginException, ModelException,
|
||||
XPathExpressionException, TransformerException {
|
||||
ItemCollection workitem = new ItemCollection();
|
||||
workitem.model(source.getItemValueString(DocumentImportService.SOURCE_ITEM_MODELVERSION));
|
||||
workitem.task(source.getItemValueInteger(DocumentImportService.SOURCE_ITEM_TASK));
|
||||
|
|
@ -391,6 +401,13 @@ public class CargosoftXMLInvoiceImportImportService {
|
|||
workitem, "invoice.total", Double.class);
|
||||
workitem.setItemValue("invoice.saldo", workitem.getItemValueDouble("invoice.total"));
|
||||
}
|
||||
// Steuer
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/InvoiceAmount/VATInformation/VAT/VATRate",
|
||||
workitem, "invoice.vatrate", Double.class);
|
||||
|
||||
// Booking Period
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/BookingPeriod",
|
||||
workitem, "invoice.bookingperiod", String.class);
|
||||
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/InvoiceCurrency/Codes/Code",
|
||||
workitem, "invoice.currency", String.class);
|
||||
|
|
@ -402,6 +419,10 @@ public class CargosoftXMLInvoiceImportImportService {
|
|||
"/Invoices/Invoice/InvoiceHeader/PaymentConditions/PaymentCondition/Codes/Code[@Type='cs']",
|
||||
workitem, "payment.term", String.class);
|
||||
|
||||
// kostenstelle
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/CostUnit/Description",
|
||||
workitem, "invoice.CostUnit", String.class);
|
||||
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/PaymentConditions/DueDate",
|
||||
workitem, "invoice.duedate", Date.class);
|
||||
|
||||
|
|
@ -427,18 +448,8 @@ public class CargosoftXMLInvoiceImportImportService {
|
|||
// Jetzt noch das Space mapping
|
||||
mahnlaufService.mapInvoiceTextToSpace(workitem, spacePosMappings);
|
||||
|
||||
// read filename
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/Attachments/Attachment/Filename",
|
||||
workitem, "import.filename", String.class);
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/Attachments/Attachment/Content",
|
||||
workitem, "import.filedata", String.class);
|
||||
String fileDataString = workitem.getItemValueString("import.filedata");
|
||||
byte[] decodedData = java.util.Base64.getDecoder().decode(fileDataString);
|
||||
FileData fileData = new FileData(workitem.getItemValueString("import.filename"),
|
||||
decodedData, "application/pdf", null);
|
||||
workitem.addFileData(fileData);
|
||||
workitem.removeItem("import.filename");
|
||||
workitem.removeItem("import.filedata");
|
||||
// Finally we attache the pdf file and the XML conent to the workitem.
|
||||
attacheFiles(doc, workitem);
|
||||
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(),
|
||||
|
|
@ -602,6 +613,61 @@ public class CargosoftXMLInvoiceImportImportService {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method attache the pdf file and the XML file to the workitem.
|
||||
* The method removes the file content first form the xml tree and attache the
|
||||
* XML without the pdf data.
|
||||
*
|
||||
* @throws XPathExpressionException
|
||||
* @throws TransformerException
|
||||
*/
|
||||
private void attacheFiles(Document doc, ItemCollection workitem)
|
||||
throws XPathExpressionException, TransformerException {
|
||||
// create XPath...
|
||||
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
// read filename and content....
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/Attachments/Attachment/Filename",
|
||||
workitem, "import.filename", String.class);
|
||||
readXMLValue(doc, "/Invoices/Invoice/InvoiceHeader/Attachments/Attachment/Content",
|
||||
workitem, "import.filedata", String.class);
|
||||
|
||||
// attache the PDF file content
|
||||
String fileDataString = workitem.getItemValueString("import.filedata");
|
||||
byte[] decodedPDFData = java.util.Base64.getDecoder().decode(fileDataString);
|
||||
FileData fileData = new FileData(workitem.getItemValueString("import.filename"),
|
||||
decodedPDFData, "application/pdf", null);
|
||||
workitem.addFileData(fileData);
|
||||
// remove the temp items..
|
||||
workitem.removeItem("import.filename");
|
||||
workitem.removeItem("import.filedata");
|
||||
|
||||
// next remove the Attachments/AttachmentContent from the dom tree
|
||||
XPathExpression attachmentsExpr = xpath
|
||||
.compile("/Invoices/Invoice/InvoiceHeader/Attachments/Attachment/Content");
|
||||
NodeList contentNodes = (NodeList) attachmentsExpr.evaluate(doc, XPathConstants.NODESET);
|
||||
// Remove the matching nodes
|
||||
for (int i = 0; i < contentNodes.getLength(); i++) {
|
||||
Node contentNode = contentNodes.item(i);
|
||||
Node parentNode = contentNode.getParentNode();
|
||||
parentNode.removeChild(contentNode);
|
||||
}
|
||||
|
||||
// Now attache the XML tree without the file...
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource source = new DOMSource(doc);
|
||||
StreamResult result = new StreamResult(stringWriter);
|
||||
transformer.transform(source, result);
|
||||
// byte[] decodedXMLData =
|
||||
// java.util.Base64.getDecoder().decode(stringWriter.toString().);
|
||||
FileData fileDataXML = new FileData(workitem.getItemValueString("cargosoft.import.filename"),
|
||||
stringWriter.toString().getBytes(), "application/xml", null);
|
||||
workitem.addFileData(fileDataXML);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft ob die Belegnummer schon existiert (importiert wurde)
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue