From 4b5d007d69c50535ef50ea46f9f569a09251091d Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Wed, 5 Jun 2024 15:48:22 +0200 Subject: [PATCH] xml import - run in one transaction --- ... => CargosoftXMLInvoiceImportService.java} | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) rename office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/{CargosoftXMLInvoiceImportImportService.java => CargosoftXMLInvoiceImportService.java} (97%) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/CargosoftXMLInvoiceImportImportService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/CargosoftXMLInvoiceImportService.java similarity index 97% rename from office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/CargosoftXMLInvoiceImportImportService.java rename to office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/CargosoftXMLInvoiceImportService.java index 3c6433e..2458bee 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/CargosoftXMLInvoiceImportImportService.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/CargosoftXMLInvoiceImportService.java @@ -109,9 +109,9 @@ import com.alexanderlogistics.mahnlauf.MahnlaufService; * */ @Stateless -public class CargosoftXMLInvoiceImportImportService { +public class CargosoftXMLInvoiceImportService { - private static Logger logger = Logger.getLogger(CargosoftXMLInvoiceImportImportService.class.getName()); + private static Logger logger = Logger.getLogger(CargosoftXMLInvoiceImportService.class.getName()); public static final String OPTION_MANDANT_ID = "mandant.id"; public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; public static final String REGEX_IMPORTTEXTPATTERN = "^R[1-8] .*$"; @@ -218,7 +218,7 @@ public class CargosoftXMLInvoiceImportImportService { ftpClient.connect(ftpServer, ftpPort); if (ftpClient.login(ftpUser, ftpPassword) == false) { - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", "FTP file transfer failed: login failed!"); } ftpClient.enterLocalPassiveMode(); @@ -227,7 +227,7 @@ public class CargosoftXMLInvoiceImportImportService { ftpClient.setControlEncoding("UTF-8"); } catch (IOException e) { - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", e.getMessage()); } @@ -252,7 +252,7 @@ public class CargosoftXMLInvoiceImportImportService { // try to enter the working directory and read all files... boolean bWorkingDir = ftpClient.changeWorkingDirectory(ftpPath); if (bWorkingDir == false) { - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", "...failed to change into working directory: "); } @@ -282,11 +282,12 @@ public class CargosoftXMLInvoiceImportImportService { 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(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", "Invoice does not match mandantID " + mandantID); } count++; - workflowService.processWorkItem(invoice); + workflowService.processWorkItemByNewTransaction(invoice); + // .processWorkItem(invoice); } } @@ -302,7 +303,7 @@ public class CargosoftXMLInvoiceImportImportService { } catch (AccessDeniedException | ProcessingErrorException | PluginException | ModelException | XPathExpressionException | TransformerException e) { - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", e.getMessage()); } } @@ -314,7 +315,7 @@ public class CargosoftXMLInvoiceImportImportService { int r = ftpClient.getReplyCode(); logger.severe("FTP ReplyCode=" + r); - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", e.getMessage()); } finally { @@ -325,7 +326,7 @@ public class CargosoftXMLInvoiceImportImportService { ftpClient.disconnect(); } catch (IOException e) { documentImportService.logMessage("...FTP file transfer failed: " + e.getMessage(), event); - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "FTP_ERROR", e.getMessage()); } } @@ -455,11 +456,11 @@ public class CargosoftXMLInvoiceImportImportService { return null; } - // Finally we attache the pdf file and the XML conent to the workitem. + // Finally we attache the pdf file and the XML content to the workitem. attacheFiles(doc, workitem); } catch (ParserConfigurationException | SAXException | IOException e) { - throw new PluginException(CargosoftXMLInvoiceImportImportService.class.getName(), + throw new PluginException(CargosoftXMLInvoiceImportService.class.getName(), "XML_ERROR", e.getMessage()); } return workitem;