From ba221f51f63b85cb4e7378289f2b85bc764866c2 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Mon, 3 Apr 2023 12:07:39 +0200 Subject: [PATCH] absicherung Mail Adresse im Mahnlauf --- .../CargosoftController.java | 23 +- .../com/alexanderlogistics/InvoiceUtil.java | 19 + .../main/webapp/pages/admin/kreditor.xhtml | 3 + .../com/alexanderlogistics/TestFormat.java | 14 + workflow/mahnlauf-de-1.0.2.bpmn | 1170 +++++++++++++++++ 5 files changed, 1227 insertions(+), 2 deletions(-) create mode 100644 workflow/mahnlauf-de-1.0.2.bpmn diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java index e305d70..53236ac 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/CargosoftController.java @@ -18,7 +18,9 @@ import javax.json.JsonObjectBuilder; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.engine.DocumentService; +import org.imixs.workflow.exceptions.PluginException; import org.imixs.workflow.exceptions.QueryException; +import org.imixs.workflow.faces.util.ErrorHandler; /** * The CargosoftController CDI Bean provides Front-End methods for the cargosoft @@ -311,8 +313,11 @@ public class CargosoftController implements Serializable { /** * Diese Method überträgt die geänderten Daten in das Kreidtoren/Debitoren * Objekt (cdtr.creditperiod,cdtr.iban,cdtr.bic) + * + * Zusätzlich wird geprüft ob die eingegebene Mail Adresse eine gültige SMTP Adresse ist + * @throws PluginException */ - public void updateZahlungsziel() { + public void updateZahlungsziel() throws PluginException { String cdtrNumber = kreditor.getItemValueString("cdtr.number"); logger.fine("Zahlungsziel = " + cdtrNumber); @@ -331,7 +336,15 @@ public class CargosoftController implements Serializable { } catch (NumberFormatException nfe) { // no op } - cargoCreditor.setItemValue("cdtr.mail", kreditor.getItemValueString("cdtr.mail")); + + + String mail= kreditor.getItemValueString("cdtr.mail").trim(); + if (!InvoiceUtil.validateEmail(mail)) { + throw new PluginException(CargosoftController.class.getName(), + "INVALID_EMAIL", "Die Daten konnten nicht aktualisiert werden! Bitte geben Sie eine gültige E-Mail Adresse ein!"); + } + + cargoCreditor.setItemValue("cdtr.mail",mail); cargoCreditor.setItemValue("cdtr.iban", kreditor.getItemValueString("cdtr.iban")); cargoCreditor.setItemValue("cdtr.bic", kreditor.getItemValueString("cdtr.bic")); cargoCreditor.setItemValue("cdtr.iban2", kreditor.getItemValueString("cdtr.iban2")); @@ -344,6 +357,12 @@ public class CargosoftController implements Serializable { } } catch (QueryException e) { logger.severe("Unable to find cargosoft kreditor " + e.getMessage()); + + } catch (PluginException pe) { + + // add a new FacesMessage into the FacesContext + ErrorHandler.handlePluginException(pe); + throw pe; } } diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/InvoiceUtil.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/InvoiceUtil.java index d0acc54..4804cf4 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/InvoiceUtil.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/InvoiceUtil.java @@ -2,6 +2,7 @@ package com.alexanderlogistics; import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.regex.Pattern; /** * Rundungs Methode * @@ -18,6 +19,24 @@ public class InvoiceUtil { return bd.doubleValue(); } + + /** + * Hilfsmethode zum validieren der Mailadresse + * + * @param emailAddress + * @return + */ + public static boolean validateEmail(String emailAddress) { + //String regexPattern = "^(.+)@(\\S+)$"; + + String regexPattern = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@" + + "[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$"; + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + @Deprecated public static double roundConservative(double value) { value = value * 100; diff --git a/office-alexander-logistics-app/src/main/webapp/pages/admin/kreditor.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/admin/kreditor.xhtml index 525ebaa..da8a234 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/admin/kreditor.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/admin/kreditor.xhtml @@ -16,6 +16,9 @@ + + + diff --git a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java index d3876d0..ce4346e 100644 --- a/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java +++ b/office-alexander-logistics-app/src/test/java/com/alexanderlogistics/TestFormat.java @@ -114,5 +114,19 @@ public class TestFormat { System.out.println("Ich bin Kein Held"); } } + + @Test + public void testSMTPMailAddress() { + + Assert.assertTrue(InvoiceUtil.validateEmail("info@imixs.com")); + + Assert.assertFalse(InvoiceUtil.validateEmail("in fo@imixs.com")); + + Assert.assertFalse(InvoiceUtil.validateEmail("SM PSP Queries ")); + + Assert.assertTrue(InvoiceUtil.validateEmail("PSP.Queries@dssmith.com")); + + } + } diff --git a/workflow/mahnlauf-de-1.0.2.bpmn b/workflow/mahnlauf-de-1.0.2.bpmn new file mode 100644 index 0000000..7c31bd3 --- /dev/null +++ b/workflow/mahnlauf-de-1.0.2.bpmn @@ -0,0 +1,1170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<itemvalue>$workflowstatus</itemvalue> + +]]> + + + +]]> + + + + + + + + + + StartEvent_1 + Task_1 + IntermediateCatchEvent_3 + EndEvent_3 + IntermediateCatchEvent_1 + IntermediateCatchEvent_5 + ExclusiveGateway_2 + IntermediateCatchEvent_4 + Task_2 + ExclusiveGateway_1 + IntermediateCatchEvent_2 + IntermediateCatchEvent_8 + IntermediateCatchEvent_7 + Task_3 + IntermediateCatchEvent_9 + IntermediateCatchEvent_6 + + + + SequenceFlow_4 + + + + + $lasteventdate - dbtr.name (dbtr.number)]]> + + + true + + + + + + + + + + + + + + + + + + + + + $workflowgroup - $workflowstatus]]> + SequenceFlow_6 + SequenceFlow_15 + SequenceFlow_10 + SequenceFlow_18 + + + + SequenceFlow_10 + SequenceFlow_13 + + + + + $lasteventdate - dbtr.name (dbtr.number)]]> + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + $workflowgroup - $workflowstatus]]> + SequenceFlow_14 + SequenceFlow_4 + SequenceFlow_1 + SequenceFlow_2 + SequenceFlow_3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + SequenceFlow_6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + 0) { + mail=workitem['dbtr.mail'][0]; + // regex + if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { + // OK + } else { + result.isValid=false; + result.errorMessage='Bitte geben Sie eine gültige E-Mail Adresse ein!'; + } +}]]> + + + + SequenceFlow_14 + + + + + + + + + + + + + + + + + + + +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + home +Mahnwesen]]> + + + + + + + + + + + + false + + + 0) { + mail=workitem['dbtr.mail'][0]; + // regex + if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { + // OK + } else { + result.isValid=false; + result.errorMessage='Bitte geben Sie eine gültige E-Mail Adresse ein!'; + } +}]]> + + + + SequenceFlow_2 + SequenceFlow_16 + + + DataOutput_1 + + + DataOutput_1 + + + + + + SequenceFlow_17 + SequenceFlow_8 + SequenceFlow_9 + + + + + Html-Header +E-Mail - Mahnlauf-dunning.level (DE) +
+description
+
+

+Debitor: dbtr.name (dbtr.number) +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
RechnungsnummerDatumFälligkeitRechnungsbetragSaldoMahnstufe
invoice.numberinvoice.dateinvoice.duedateinvoice.total invoice.currencyinvoice.saldo invoice.currency$workflowstatus
Saldodunning.saldo dunning.currency
+ +E-Mail - Mahnlauf Footer (DE) +Html-Footer +]]>
+
+ + mail.subject_de]]> + + + + + + + + + + + +
+ SequenceFlow_8 + SequenceFlow_11 + +
+ + + + Html-Header +E-Mail - Mahnlauf-dunning.level (EN) +
+description
+
+

+Debitor: dbtr.name (dbtr.number) +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Invoice No.DateExpiry DateInvoice AmountBalanceDunning Level
invoice.numberinvoice.dateinvoice.duedateinvoice.total invoice.currencyinvoice.saldo invoice.currencyworkflowstatus_en
Saldodunning.saldo dunning.currency
+E-Mail - Mahnlauf Footer (EN) +Html-Footer +]]>
+
+ + mail.subject_en]]> + + + + + + + + + + + +
+ SequenceFlow_9 + SequenceFlow_12 + +
+ + workitem['invoice.language'] && workitem['invoice.language'][0]=="DE" + + + + SequenceFlow_11 + SequenceFlow_12 + SequenceFlow_15 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Mahnwesen]]> + + + + + + + + + + + + false + + + SequenceFlow_1 + + + + + + + $lasteventdate - dbtr.name (dbtr.number)]]> + + + true + + + + + + + + + + + + + + + + + + + + + $workflowgroup - $workflowstatus]]> + SequenceFlow_5 + SequenceFlow_13 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + home]]> + + + + + + + + + + + + false + + + + + + + SequenceFlow_3 + SequenceFlow_5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + SequenceFlow_16 + SequenceFlow_19 + SequenceFlow_17 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + 0) { + mail=workitem['dbtr.mail'][0]; + // regex + if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { + // OK + } else { + result.isValid=false; + result.errorMessage='Bitte geben Sie eine gültige E-Mail Adresse ein!'; + } +}]]> + + + + SequenceFlow_18 + SequenceFlow_19 + + + + + + + + + + + + + + + + + + + +]]> + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file