From 90166229bdbdf72ea6100d5c367435070eba4c14 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Thu, 6 Feb 2025 15:44:33 +0100 Subject: [PATCH] changes --- .../BusinessPartnerController.java | 3 +- .../metrics/MetricCreditorRestService.java | 67 +++++++++++++++---- .../metrics/MetricCreditorService.java | 5 ++ .../metrics/MetricDebitorRestService.java | 65 ++++++++++++++---- .../metrics/MetricDebitorService.java | 17 ++--- .../xml/BusinessPartnerImportService.java | 23 ++++++- workflow/dwc/rechnungsausgang-dwc-1.0.2.bpmn | 4 +- workflow/sepa-export-manual-3.0.0.bpmn | 42 ++++++------ 8 files changed, 160 insertions(+), 66 deletions(-) diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/BusinessPartnerController.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/BusinessPartnerController.java index c02a15f..390439f 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/BusinessPartnerController.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/BusinessPartnerController.java @@ -64,8 +64,7 @@ public class BusinessPartnerController implements Serializable { /** * WorkflowEvent listener to convert the IBAN child list embeded HashMaps into - * ItemCollections and - * reconvert them before processing + * ItemCollections and reconvert them before processing * * @param workflowEvent * @throws AccessDeniedException diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorRestService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorRestService.java index a18ba93..bbb0fe3 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorRestService.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorRestService.java @@ -11,6 +11,8 @@ import org.imixs.workflow.exceptions.QueryException; import com.alexanderlogistics.InvoiceUtil; import jakarta.ejb.Stateless; +import jakarta.ejb.TransactionAttribute; +import jakarta.ejb.TransactionAttributeType; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; @@ -86,9 +88,11 @@ public class MetricCreditorRestService { * * @throws QueryException * @throws InterruptedException + * @throws PluginException * */ - public void computeMetrics(StringBuffer messageBuffer) throws QueryException, InterruptedException { + public void computeMetrics(StringBuffer messageBuffer) + throws QueryException, InterruptedException, PluginException { long l = System.currentTimeMillis(); int batchSize = 500; int totalInvoices = 0; @@ -105,20 +109,24 @@ public class MetricCreditorRestService { // Verarbeite Page für Page for (int pageIndex = 0; pageIndex < totalPages; pageIndex++) { - List invoices = documentService.find(query, batchSize, pageIndex); - for (ItemCollection invoice : invoices) { - try { - ItemCollection metricData = metricCreditorService.getMetricByInvoice(invoice); - // Jetzt Rechnung addieren - metricCreditorService.addInvoice(metricData, invoice); - logger.fine("│   │   │   ├── update metric " + InvoiceUtil.getBPId(invoice)); - metricCreditorService.updateMetric(metricData, true); - totalInvoices++; - } catch (PluginException e) { - // invalid invoice - e.g. no dbtr. number - } - } + totalInvoices = totalInvoices + computeInvoiceMetrics(query, batchSize, pageIndex); + // List invoices = documentService.find(query, batchSize, + // pageIndex); + + // for (ItemCollection invoice : invoices) { + // try { + // ItemCollection metricData = + // metricCreditorService.getMetricByInvoice(invoice); + // // Jetzt Rechnung addieren + // metricCreditorService.addInvoice(metricData, invoice); + // logger.fine("│   │   │   ├── update metric " + InvoiceUtil.getBPId(invoice)); + // metricCreditorService.updateMetric(metricData, true); + // totalInvoices++; + // } catch (PluginException e) { + // // invalid invoice - e.g. no dbtr. number + // } + // } // Fortschritt loggen log("│   │ ├── Processed page " + (pageIndex + 1) + " of " + totalPages + @@ -135,6 +143,37 @@ public class MetricCreditorRestService { } + /** + * Helper method runs in new transaction + * + * @param query + * @param batchSize + * @param pageIndex + * @throws PluginException + * @throws QueryException + */ + @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) + public int computeInvoiceMetrics(String query, int batchSize, int pageIndex) + throws PluginException, QueryException { + + int updates = 0; + List invoices = documentService.find(query, batchSize, pageIndex); + + for (ItemCollection invoice : invoices) { + try { + ItemCollection metricData = metricCreditorService.getMetricByInvoice(invoice); + // Jetzt Rechnung addieren + metricCreditorService.addInvoice(metricData, invoice); + logger.fine("│   │   │   ├── update metric " + InvoiceUtil.getBPId(invoice)); + metricCreditorService.updateMetric(metricData, true); + updates++; + } catch (PluginException e) { + // invalid invoice - e.g. no dbtr. number + } + } + return updates; + } + private void log(String message, StringBuffer messageLog) { logger.info(message); messageLog.append(message + "\n"); diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorService.java index 50de7c5..3da4b99 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorService.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricCreditorService.java @@ -12,6 +12,7 @@ import org.eclipse.microprofile.metrics.Metadata; import org.eclipse.microprofile.metrics.MetricRegistry; import org.eclipse.microprofile.metrics.Tag; import org.eclipse.microprofile.metrics.annotation.RegistryScope; +import org.imixs.archive.core.SnapshotService; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.engine.DocumentService; import org.imixs.workflow.engine.ProcessingEvent; @@ -24,6 +25,7 @@ import com.alexanderlogistics.KreditorDebitorService; import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RunAs; +import jakarta.ejb.Singleton; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; @@ -50,6 +52,7 @@ import jakarta.inject.Inject; "org.imixs.ACCESSLEVEL.AUTHORACCESS", "org.imixs.ACCESSLEVEL.EDITORACCESS", "org.imixs.ACCESSLEVEL.MANAGERACCESS" }) @RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS") +@Singleton @ApplicationScoped public class MetricCreditorService { @@ -265,6 +268,7 @@ public class MetricCreditorService { ItemCollection metricData = new ItemCollection(); metricData.setType(TYPE_METRIC_CREDITOR); metricData.setItemValue("name", key); + metricData.setItemValue(SnapshotService.NOSNAPSHOT, true); metricData.setItemValue("bp.id", InvoiceUtil.getBPId(invoice)); metricData.setItemValue("bp.name", InvoiceUtil.getBPName(invoice)); metricData.setItemValue("country", invoice.getItemValueString("invoice.country")); @@ -289,6 +293,7 @@ public class MetricCreditorService { // In Datenbank persistieren if (persist) { + metricData.setItemValue(SnapshotService.NOSNAPSHOT, true); documentService.save(metricData); } diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorRestService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorRestService.java index 4e30fc1..dba54f0 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorRestService.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorRestService.java @@ -11,6 +11,8 @@ import org.imixs.workflow.exceptions.QueryException; import com.alexanderlogistics.InvoiceUtil; import jakarta.ejb.Stateless; +import jakarta.ejb.TransactionAttribute; +import jakarta.ejb.TransactionAttributeType; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; @@ -87,9 +89,11 @@ public class MetricDebitorRestService { * * @throws QueryException * @throws InterruptedException + * @throws PluginException * */ - public void computeMetrics(StringBuffer messageBuffer) throws QueryException, InterruptedException { + public void computeMetrics(StringBuffer messageBuffer) + throws QueryException, InterruptedException, PluginException { long l = System.currentTimeMillis(); int batchSize = 500; int totalInvoices = 0; @@ -105,20 +109,22 @@ public class MetricDebitorRestService { // Verarbeite Page für Page for (int pageIndex = 0; pageIndex < totalPages; pageIndex++) { - List invoices = documentService.find(query, batchSize, pageIndex); + totalInvoices = totalInvoices + computeInvoiceMetrics(query, batchSize, pageIndex); + // List invoices = documentService.find(query, batchSize, + // pageIndex); - for (ItemCollection invoice : invoices) { - try { - ItemCollection metricData = metricDebitorService.getMetricByInvoice(invoice); - // Jetzt Rechnung addieren - metricDebitorService.addInvoice(metricData, invoice); - logger.fine("│   │   │   ├── update metric " + InvoiceUtil.getBPId(invoice)); - metricDebitorService.updateMetric(metricData, true); - totalInvoices++; - } catch (PluginException e) { - // invalid invoice - e.g. no dbtr. number - } - } + // for (ItemCollection invoice : invoices) { + // try { + // ItemCollection metricData = metricDebitorService.getMetricByInvoice(invoice); + // // Jetzt Rechnung addieren + // metricDebitorService.addInvoice(metricData, invoice); + // logger.fine("│   │   │   ├── update metric " + InvoiceUtil.getBPId(invoice)); + // metricDebitorService.updateMetric(metricData, true); + // totalInvoices++; + // } catch (PluginException e) { + // // invalid invoice - e.g. no dbtr. number + // } + // } // Fortschritt loggen log("│   │ ├── Processed page " + (pageIndex + 1) + " of " + totalPages + @@ -135,6 +141,37 @@ public class MetricDebitorRestService { } + /** + * Helper method runs in new transaction + * + * @param query + * @param batchSize + * @param pageIndex + * @throws PluginException + * @throws QueryException + */ + @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW) + public int computeInvoiceMetrics(String query, int batchSize, int pageIndex) + throws PluginException, QueryException { + + int updates = 0; + List invoices = documentService.find(query, batchSize, pageIndex); + + for (ItemCollection invoice : invoices) { + try { + ItemCollection metricData = metricDebitorService.getMetricByInvoice(invoice); + // Jetzt Rechnung addieren + metricDebitorService.addInvoice(metricData, invoice); + logger.fine("│   │   │   ├── update metric " + InvoiceUtil.getBPId(invoice)); + metricDebitorService.updateMetric(metricData, true); + updates++; + } catch (PluginException e) { + // invalid invoice - e.g. no dbtr. number + } + } + return updates; + } + private void log(String message, StringBuffer messageLog) { logger.info(message); messageLog.append(message + "\n"); diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorService.java index 01a97b2..1e18e07 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorService.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/metrics/MetricDebitorService.java @@ -12,6 +12,7 @@ import org.eclipse.microprofile.metrics.Metadata; import org.eclipse.microprofile.metrics.MetricRegistry; import org.eclipse.microprofile.metrics.Tag; import org.eclipse.microprofile.metrics.annotation.RegistryScope; +import org.imixs.archive.core.SnapshotService; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.engine.DocumentService; import org.imixs.workflow.engine.ProcessingEvent; @@ -23,6 +24,7 @@ import com.alexanderlogistics.InvoiceUtil; import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RunAs; +import jakarta.ejb.Singleton; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; @@ -46,6 +48,7 @@ import jakarta.inject.Inject; "org.imixs.ACCESSLEVEL.AUTHORACCESS", "org.imixs.ACCESSLEVEL.EDITORACCESS", "org.imixs.ACCESSLEVEL.MANAGERACCESS" }) @RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS") +@Singleton @ApplicationScoped public class MetricDebitorService { @@ -257,6 +260,7 @@ public class MetricDebitorService { ItemCollection metricData = new ItemCollection(); metricData.setType(TYPE_METRIC_DEBITOR); metricData.setItemValue("name", key); + metricData.setItemValue(SnapshotService.NOSNAPSHOT, true); metricData.setItemValue("bp.id", InvoiceUtil.getBPId(invoice)); metricData.setItemValue("bp.name", InvoiceUtil.getBPName(invoice)); metricData.setItemValue("country", invoice.getItemValueString("invoice.country")); @@ -281,6 +285,7 @@ public class MetricDebitorService { // In Datenbank persistieren if (persist) { + metricData.setItemValue(SnapshotService.NOSNAPSHOT, true); documentService.save(metricData); } @@ -374,16 +379,4 @@ public class MetricDebitorService { } - /** - * Helper Method that refreshes all gauges. The method is called by the - * RestService during a rebuild. - */ - // public void refreshGauges() { - // List keys = getMetricKeys(); - // for (String hashKey : keys) { - // ItemCollection metricData = getMetric(hashKey); - // updateMetric(metricData, false); - // } - // } - } \ No newline at end of file diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/BusinessPartnerImportService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/BusinessPartnerImportService.java index 84c4974..3e0ee27 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/BusinessPartnerImportService.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/BusinessPartnerImportService.java @@ -31,6 +31,7 @@ package com.alexanderlogistics.xml; import java.util.List; import java.util.logging.Logger; +import org.imixs.archive.core.SnapshotService; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.engine.DocumentEvent; import org.imixs.workflow.engine.DocumentService; @@ -44,6 +45,9 @@ import org.imixs.workflow.exceptions.QueryException; import com.alexanderlogistics.InvoiceUtil; +import jakarta.annotation.security.DeclareRoles; +import jakarta.annotation.security.RolesAllowed; +import jakarta.annotation.security.RunAs; import jakarta.ejb.EJB; import jakarta.ejb.Stateless; import jakarta.enterprise.event.Observes; @@ -56,10 +60,19 @@ import jakarta.enterprise.event.Observes; * ein und prüft ob der Workflow schon existiert oder ggf. aktualisiert werden * muss. * + * The service set also the flag NOSNAPSHOT=true for the crgosoftcreditor + * document type. * * @author rsoika * */ +@DeclareRoles({ "org.imixs.ACCESSLEVEL.NOACCESS", "org.imixs.ACCESSLEVEL.READERACCESS", + "org.imixs.ACCESSLEVEL.AUTHORACCESS", "org.imixs.ACCESSLEVEL.EDITORACCESS", + "org.imixs.ACCESSLEVEL.MANAGERACCESS" }) +@RolesAllowed({ "org.imixs.ACCESSLEVEL.NOACCESS", "org.imixs.ACCESSLEVEL.READERACCESS", + "org.imixs.ACCESSLEVEL.AUTHORACCESS", "org.imixs.ACCESSLEVEL.EDITORACCESS", + "org.imixs.ACCESSLEVEL.MANAGERACCESS" }) +@RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS") @Stateless public class BusinessPartnerImportService { @@ -92,8 +105,16 @@ public class BusinessPartnerImportService { if (event.getEventType() == DocumentEvent.ON_DOCUMENT_SAVE) { // check type! if ("cargosoftkreditor".equals(event.getDocument().getType())) { - logger.info("Verify business partner object...."); + // set NOSNAPSHOT=true + event.getDocument().setItemValue(SnapshotService.NOSNAPSHOT, true); + // run only if we have the model 'businesspartner-*'; + if (modelService.findVersionsByRegEx("(businesspartner*)").size() == 0) { + // no business partner workflow found + return; + } + + logger.info("Verify business partner object...."); ItemCollection importDoc = event.getDocument(); String name = event.getDocument().getItemValueString("name"); diff --git a/workflow/dwc/rechnungsausgang-dwc-1.0.2.bpmn b/workflow/dwc/rechnungsausgang-dwc-1.0.2.bpmn index f856ad9..2a3bafe 100644 --- a/workflow/dwc/rechnungsausgang-dwc-1.0.2.bpmn +++ b/workflow/dwc/rechnungsausgang-dwc-1.0.2.bpmn @@ -1291,7 +1291,7 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + @@ -1404,7 +1404,7 @@ Wiedervorlage wird um 7 bzw. 5 Tage erhöht - + diff --git a/workflow/sepa-export-manual-3.0.0.bpmn b/workflow/sepa-export-manual-3.0.0.bpmn index b774774..38fdf5e 100644 --- a/workflow/sepa-export-manual-3.0.0.bpmn +++ b/workflow/sepa-export-manual-3.0.0.bpmn @@ -54,10 +54,10 @@ - + - + IntermediateCatchEvent_6 @@ -800,7 +800,7 @@ result.isValid=true; - + @@ -859,7 +859,7 @@ result.isValid=true; - + @@ -1012,7 +1012,7 @@ result.isValid=true; - + @@ -1073,7 +1073,7 @@ result.isValid=true; - + @@ -1106,7 +1106,7 @@ result.isValid=true; - + @@ -1140,9 +1140,9 @@ result.isValid=true; - - - + + + @@ -1158,21 +1158,21 @@ result.isValid=true; - - - + + + - + - + @@ -1188,19 +1188,19 @@ result.isValid=true; - + - + - + - - - + + +