From cde1b2a2ebd39007dd92b3ec7b45def73a9e1d3a Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Fri, 31 Jan 2025 12:29:06 +0100 Subject: [PATCH] import prozess --- .../xml/BusinessPartnerImportService.java | 180 ++++++++++++++++++ workflow/businesspartner-de-1.0.0.bpmn | 135 +++++++++++-- 2 files changed, 298 insertions(+), 17 deletions(-) create mode 100644 office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/BusinessPartnerImportService.java 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 new file mode 100644 index 0000000..84c4974 --- /dev/null +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/xml/BusinessPartnerImportService.java @@ -0,0 +1,180 @@ +/* + * Imixs-Workflow + * + * Copyright (C) 2001-2020 Imixs Software Solutions GmbH, + * http://www.imixs.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can receive a copy of the GNU General Public + * License at http://www.gnu.org/licenses/gpl.html + * + * Project: + * https://www.imixs.org + * https://github.com/imixs/imixs-workflow + * + * Contributors: + * Imixs Software Solutions GmbH - Project Management + * Ralph Soika - Software Developer + */ + +package com.alexanderlogistics.xml; + +import java.util.List; +import java.util.logging.Logger; + +import org.imixs.workflow.ItemCollection; +import org.imixs.workflow.engine.DocumentEvent; +import org.imixs.workflow.engine.DocumentService; +import org.imixs.workflow.engine.ModelService; +import org.imixs.workflow.engine.WorkflowService; +import org.imixs.workflow.exceptions.AccessDeniedException; +import org.imixs.workflow.exceptions.ModelException; +import org.imixs.workflow.exceptions.PluginException; +import org.imixs.workflow.exceptions.ProcessingErrorException; +import org.imixs.workflow.exceptions.QueryException; + +import com.alexanderlogistics.InvoiceUtil; + +import jakarta.ejb.EJB; +import jakarta.ejb.Stateless; +import jakarta.enterprise.event.Observes; + +/** + * Der BusinessPartnerImportService hängt sich an den standard CSVImport Service + * der die Cargosoft Stammdaten aktualisiert. + * Es ist ein simples Observer Pattern das auf das Document Event + * "ON_DOCUMENT_SAVE" reagiert. Hier hängt sich der BusinessPartnerImportService + * ein und prüft ob der Workflow schon existiert oder ggf. aktualisiert werden + * muss. + * + * + * @author rsoika + * + */ +@Stateless +public class BusinessPartnerImportService { + + private static Logger logger = Logger.getLogger(BusinessPartnerImportService.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] .*$"; + + @EJB + WorkflowService workflowService; + + @EJB + DocumentService documentService; + + @EJB + ModelService modelService; + + /** + * Die Methode reagiert auf das CDI DocumentEvent beim Import von cargosoft + * cargosoftkreditor documenten. + * + * + */ + public void onEvent(@Observes DocumentEvent event) { + + if (event == null || event.getDocument() == null) { + return; + } + // check if source is already completed + if (event.getEventType() == DocumentEvent.ON_DOCUMENT_SAVE) { + // check type! + if ("cargosoftkreditor".equals(event.getDocument().getType())) { + logger.info("Verify business partner object...."); + + ItemCollection importDoc = event.getDocument(); + + String name = event.getDocument().getItemValueString("name"); + boolean isCreditor = name.toUpperCase().startsWith("K"); + String partnerID = InvoiceUtil.buildBPID(name); + + // Prüfen ob es diesen partner schon gibt? + ItemCollection businesspartner = lookupBusinessPartner(partnerID); + if (businesspartner == null) { + businesspartner = createBusinessPartner(); + } + ItemCollection oldBussinessPartnerItemColl = (ItemCollection) businesspartner.clone(); + + // Update Fields... + businesspartner.setItemValue("name", partnerID); + businesspartner.setItemValue("partner.id", partnerID); + if (isCreditor) { + businesspartner.setItemValue("cdtr.number", name); + if (businesspartner.isItemEmpty("cdtr.email")) { + businesspartner.setItemValue("cdtr.email", importDoc.getItemValueString("_vendor_email")); + } + } else { + businesspartner.setItemValue("dbtr.number", name); + if (businesspartner.isItemEmpty("dbtr.email")) { + businesspartner.setItemValue("dbtr.email", importDoc.getItemValueString("_vendor_email")); + } + } + businesspartner.setItemValue("partner.country", importDoc.getItemValueString("_vendor_country")); + businesspartner.setItemValue("partner.name", importDoc.getItemValueString("_vendor_name")); + businesspartner.setItemValue("partner.phone", importDoc.getItemValueString("_vendor_phone")); + businesspartner.setItemValue("partner.address", importDoc.getItemValueString("_vendor_str")); + businesspartner.setItemValue("partner.zip", importDoc.getItemValueString("_vendor_zip_code")); + businesspartner.setItemValue("partner.city", importDoc.getItemValueString("_vendor_city")); + + // hat sich das Objekt verändert? + if (!businesspartner.equals(oldBussinessPartnerItemColl)) { + businesspartner.event(201); // update/create + try { + workflowService.processWorkItemByNewTransaction(businesspartner); + } catch (AccessDeniedException | ProcessingErrorException | PluginException | ModelException e) { + logger.warning("Failed to update Business Partner Object " + name + " - " + e.getMessage()); + } + } + } + } + + } + + /** + * Erstellt ein neues leeres Business Partner Object + * + * @return + */ + private ItemCollection createBusinessPartner() { + ItemCollection businessPartner = new ItemCollection(); + businessPartner.setType("workitem"); + businessPartner.setWorkflowGroup("Business Partner"); + businessPartner.task(1000); + + return businessPartner; + } + + /** + * Sucht nach einem Business partner + * + * @param id + * @return + */ + private ItemCollection lookupBusinessPartner(String id) { + String query = "(type:workitem OR type:workitemarchive) AND ($modelversion:businesspartner*) AND (name:" + id + + ")"; + + try { + List result = documentService.find(query, 1, 0, null, false); + if (result.size() > 0) { + return result.get(0); + } + } catch (QueryException e) { + logger.warning("Failed to query businesspartner: " + query + " - Error: " + e.getMessage()); + + } + return null; + } +} diff --git a/workflow/businesspartner-de-1.0.0.bpmn b/workflow/businesspartner-de-1.0.0.bpmn index 8872381..9fc7a62 100644 --- a/workflow/businesspartner-de-1.0.0.bpmn +++ b/workflow/businesspartner-de-1.0.0.bpmn @@ -21,6 +21,8 @@ + + @@ -44,6 +46,9 @@ event_Tr0aug dataObject_UQIXAQ event_vwH0cA + textAnnotation_LyGTCw + event_TuyuwQ + event_h0Kk5g @@ -65,20 +70,47 @@ - + + + + + + partner.name (partner.id)]]> + + sequenceFlow_knUYpQ sequenceFlow_2uNvPw sequenceFlow_NNbMhg sequenceFlow_avahXg + sequenceFlow_9atLFA - + + + partner.name (partner.id)]]> + + + + + sequenceFlow_1mXO8A sequenceFlow_rwdWxw + sequenceFlow_gC0I9w - + + + + + + + + + + Partnermanagement]]> + + sequenceFlow_S9LVXg sequenceFlow_knUYpQ @@ -119,25 +151,26 @@ - + + - + - + @@ -159,13 +192,50 @@ + + + + + + + + + + + + + + + + + + sequenceFlow_9atLFA + + + + + + + + + + + + + + + sequenceFlow_gC0I9w + + + + - + - + @@ -178,13 +248,13 @@ - + - + - + @@ -242,16 +312,15 @@ - + - + - - - - + + + @@ -262,6 +331,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +