package com.alexanderlogistics; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.logging.Logger; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.engine.plugins.AbstractPlugin; import org.imixs.workflow.exceptions.PluginException; /** * Das InvoicePlugin prüft die Eingaben auf gültigkeit, so dass diese problemlos * nach Cargosoft expoertier werden können. *

* Konkret geht es darum, das im Status 5200 in den ChildItems keine leeren * Zeilen vorkommen dürfen. *

* Im Status 5000 muss immer der payment.type ausgewählt werden. Dies wird vom Plugin explizit geprüft * * @author rsoika * @version 1.0 * */ public class InvoicePlugin extends AbstractPlugin { public static final int TASK_ERFASSUNG = 5000; public static final int TASK_SACHPRUEFUNG = 5200; public static final int EVENT_FREIGEBEN = 20; public static final String CHILD_ITEM_PROPERTY = "_ChildItems"; public static final String ERROR_MISSING_DATA = "MISSING_DATA"; // XX-YYY-####-### public static final String REGEX_POSNUMER = "([A-Z]{2}-[A-Z]{3}-[0-9]{4}-[0-9]{3})"; @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(InvoicePlugin.class.getName()); /** * Test childworkitems for empty lines * * @throws PluginException - if data is missing * **/ @Override public ItemCollection run(ItemCollection workitem, ItemCollection documentActivity) throws PluginException { // Payment.type muss immer eingetragne werden! if (workitem.getTaskID() >=TASK_ERFASSUNG) { if (workitem.getItemValueString("payment.type").trim().isEmpty()) { // throw a plugin exception! throw new PluginException(InvoicePlugin.class.getName(), ERROR_MISSING_DATA, "Eingabefehler - Bitte wählen Sie eine Zahlungsart aus!"); } } // die prüfung der positionsnummern und Category erfolgt nur im Status // Sachprüfung (5200) und nur beim Freigeben (20)! if (workitem.getTaskID() == TASK_SACHPRUEFUNG && workitem.getEventID() == EVENT_FREIGEBEN) { List childs = explodeChildList(workitem); for (ItemCollection posItem : childs) { if (posItem.getItemValueString("name").trim().isEmpty()) { // throw a plugin exception - because name is missing! throw new PluginException(InvoicePlugin.class.getName(), ERROR_MISSING_DATA, "Eingabefehler - Die Positionsnummer in Zeile " + posItem.getItemValueString("numpos") + " muss aufgefüllt sein!"); } // validate pos for regex pattern 'XX-YYY-####-###' if (!posItem.getItemValueString("name").matches(REGEX_POSNUMER)) { // throw a plugin exception - because name is missing! throw new PluginException(InvoicePlugin.class.getName(), ERROR_MISSING_DATA, "Eingabefehler - Die Positionsnummer in Zeile " + posItem.getItemValueString("numpos") + " muss im Format 'XX-YYY-####-###' eingeben werden!"); } if (posItem.getItemValueString("category").trim().isEmpty()) { // throw a plugin exception - because name is missing! throw new PluginException(InvoicePlugin.class.getName(), ERROR_MISSING_DATA, "Eingabefehler - Die Leistungsart in Zeile " + posItem.getItemValueString("numpos") + " muss aufgefüllt sein!"); } if (posItem.getItemValueString("tax").trim().isEmpty()) { // throw a plugin exception - because name is missing! throw new PluginException(InvoicePlugin.class.getName(), ERROR_MISSING_DATA, "Eingabefehler - Die Steuer in Zeile " + posItem.getItemValueString("numpos") + " muss aufgefüllt sein!"); } if (posItem.getItemValueFloat("amount") == 0) { // throw a plugin exception - because name is missing! throw new PluginException(InvoicePlugin.class.getName(), ERROR_MISSING_DATA, "Eingabefehler - Der Nettobetrag in in Zeile " + posItem.getItemValueString("numpos") + " darf nicht 0 sein!"); } } } return workitem; } /** * converts the Map List of a workitem into a List of ItemCollectons */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected List explodeChildList(ItemCollection workitem) { // convert current list of childItems into ItemCollection elements ArrayList childItems = new ArrayList(); List mapOrderItems = workitem.getItemValue(CHILD_ITEM_PROPERTY); for (Object mapOderItem : mapOrderItems) { if (mapOderItem instanceof Map) { ItemCollection itemCol = new ItemCollection((Map) mapOderItem); childItems.add(itemCol); } } return childItems; } }