package com.alexanderlogistics.zoho; import java.util.List; import java.util.logging.Logger; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.imixs.archive.core.SnapshotService; import org.imixs.workflow.FileData; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.SignalAdapter; import org.imixs.workflow.engine.WorkflowService; import org.imixs.workflow.exceptions.AdapterException; import org.imixs.workflow.exceptions.PluginException; import com.alexanderlogistics.InvoicePlugin; import jakarta.inject.Inject; /** * This adapter exports the invoice data to zoho * * @version 1.0 * @author rsoika */ public class ZohoExportAdapter implements SignalAdapter { public static final String CONFIG_ERROR = "CONFIG_ERROR"; public static final String ENV_ZOHO_EXPORT_MAX_ATTACHMENT_SIZE = "zoho.export.maxattachmentsize"; private static Logger logger = Logger.getLogger(ZohoExportAdapter.class.getName()); @Inject ZohoAPIService zohoAPIService; @Inject WorkflowService workflowService; @Inject SnapshotService snapshotService; @Inject @ConfigProperty(name = ENV_ZOHO_EXPORT_MAX_ATTACHMENT_SIZE, defaultValue = "10485760") long maxAttachmentSize; /** * This method calls the zoho api * * @throws PluginException */ @Override public ItemCollection execute(ItemCollection document, ItemCollection event) throws AdapterException, PluginException { logger.info("......starting export..."); // read the cargosoft export options ItemCollection evalItemCollection = workflowService.evalWorkflowResult(event, "zoho", document, false); zohoAPIService.exportInvoice(document); return document; } /** * This method lookups the origin snapshot data and add the content of the $file * to the export document *

* Change 14.10.2021 - Wir senden maximal 5MB and Daten, da die Cargosoft * Schnittstelle größere Datensätze mit großen Dateianhängen einfach verschluckt * ohne eine Fehlermeldugn zu liefern. * * * @param document * @return */ @SuppressWarnings("unchecked") private ItemCollection loadFileDataFromSnapshot(ItemCollection document) { ItemCollection origin = null; ItemCollection result = (ItemCollection) document.clone(); // find the origin document List refs = document.getItemValue(WorkflowService.UNIQUEIDREF); for (String ref : refs) { origin = workflowService.getWorkItem(ref); // "Rechnungseingang".equals(origin.getWorkflowGroup()) if (InvoicePlugin.isCargoRechnung(origin)) { break; } origin = null; } // we should have found the origin... if (origin != null) { ItemCollection snapshot = snapshotService.findSnapshot(origin); // we should have found a snapshot... if (snapshot != null) { List fileDataList = snapshot.getFileData(); // transfer origin file content result.removeItem("$file"); long currentAttachmentSize = 0; // we do only accept .pdf files and a maximum size of 10MB for (FileData filedata : fileDataList) { if (filedata.getName().toLowerCase().endsWith(".pdf")) { // test if the size of the file is below the // "cargosoft.export.ftp.maxattachmentsize" if ((currentAttachmentSize + filedata.getContent().length) > maxAttachmentSize) { long maxSizeInMB = maxAttachmentSize / 1024 / 1024; String message = "Attachment '" + filedata.getName() + "' can not be exported to cargosoft - max file size exeeded (" + maxSizeInMB + "MB)!"; logger.warning(message); // add comment document.setItemValue("txtComment", message); } else { result.addFileData(filedata); currentAttachmentSize = currentAttachmentSize + filedata.getContent().length; } } } } else { logger.warning("...did not found snapshot for origin workitem " + origin.getUniqueID()); } } else { logger.warning("...did not found origin workitem " + document.getUniqueID()); } return result; } }