Search in sources :

Example 16 with Error

use of io.automatiko.engine.workflow.bpmn2.core.Error in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method getErrorIdForErrorCode.

protected String getErrorIdForErrorCode(String errorCode, Node node) {
    org.kie.api.definition.process.NodeContainer parent = node.getParentContainer();
    while (!(parent instanceof RuleFlowProcess) && parent instanceof Node) {
        parent = ((Node) parent).getParentContainer();
    }
    if (!(parent instanceof RuleFlowProcess)) {
        throw new RuntimeException("This should never happen: !(parent instanceof RuleFlowProcess): parent is " + parent.getClass().getSimpleName());
    }
    List<Error> errors = ((Definitions) ((RuleFlowProcess) parent).getMetaData("Definitions")).getErrors();
    Error error = null;
    for (Error listError : errors) {
        if (errorCode.equals(listError.getErrorCode())) {
            error = listError;
            break;
        } else if (errorCode.equals(listError.getId())) {
            error = listError;
            break;
        }
    }
    if (error == null) {
        throw new ProcessParsingValidationException("Could not find error with errorCode " + errorCode);
    }
    return error.getId();
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StateNode(org.jbpm.workflow.core.node.StateNode) CatchLinkNode(org.jbpm.workflow.core.node.CatchLinkNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) Node(org.jbpm.workflow.core.Node) TimerNode(org.jbpm.workflow.core.node.TimerNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Definitions(org.jbpm.bpmn2.core.Definitions) Error(org.jbpm.bpmn2.core.Error)

Example 17 with Error

use of io.automatiko.engine.workflow.bpmn2.core.Error in project kogito-runtimes by kiegroup.

the class BoundaryEventHandler method handleErrorNode.

@SuppressWarnings("unchecked")
protected void handleErrorNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("errorEventDefinition".equals(nodeName)) {
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new ProcessParsingValidationException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new ProcessParsingValidationException("Could not find error " + errorRef);
                }
                String type = error.getErrorCode();
                boolean hasErrorCode = true;
                if (type == null) {
                    type = error.getId();
                    hasErrorCode = false;
                }
                String structureRef = error.getStructureRef();
                if (structureRef != null) {
                    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
                    if (itemDefs.containsKey(structureRef)) {
                        structureRef = itemDefs.get(structureRef).getStructureRef();
                    }
                }
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Error-" + attachedTo + "-" + type);
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("ErrorEvent", type);
                eventNode.setMetaData("HasErrorEvent", hasErrorCode);
                eventNode.setMetaData("ErrorStructureRef", structureRef);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Error(org.jbpm.bpmn2.core.Error) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 18 with Error

use of io.automatiko.engine.workflow.bpmn2.core.Error in project automatiko-engine by automatiko-io.

the class BoundaryEventHandler method handleErrorNode.

@SuppressWarnings("unchecked")
protected void handleErrorNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser, final String attachedTo, final boolean cancelActivity) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    BoundaryEventNode eventNode = (BoundaryEventNode) node;
    eventNode.setMetaData("AttachedTo", attachedTo);
    eventNode.setAttachedToNodeId(attachedTo);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String outputName = ((Element) xmlNode).getAttribute("name");
            dataOutputs.put(id, outputName);
            populateDataOutputs(xmlNode, outputName, parser);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, eventNode, parser);
        } else if ("errorEventDefinition".equals(nodeName)) {
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                String type = error.getErrorCode();
                boolean hasErrorCode = true;
                if (type == null) {
                    type = error.getId();
                    hasErrorCode = false;
                }
                String structureRef = error.getStructureRef();
                if (structureRef != null) {
                    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
                    if (itemDefs.containsKey(structureRef)) {
                        structureRef = itemDefs.get(structureRef).getStructureRef();
                    }
                }
                List<EventFilter> eventFilters = new ArrayList<EventFilter>();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Error-" + attachedTo + "-" + type);
                eventFilters.add(eventFilter);
                eventNode.setEventFilters(eventFilters);
                eventNode.setMetaData("ErrorEvent", type);
                eventNode.setMetaData("HasErrorEvent", hasErrorCode);
                eventNode.setMetaData("ErrorStructureRef", structureRef);
                if (error.getMetaData().get("retry") != null) {
                    eventNode.setMetaData("ErrorRetry", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retry"))).intValue());
                    if (error.getMetaData().get("retryLimit") != null) {
                        eventNode.setMetaData("ErrorRetryLimit", Integer.parseInt((String) error.getMetaData().get("retryLimit")));
                    }
                    if (error.getMetaData().get("retryIncrement") != null) {
                        eventNode.setMetaData("ErrorRetryIncrement", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retryIncrement"))).intValue());
                    }
                    if (error.getMetaData().get("retryMultiplier") != null) {
                        eventNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat((String) error.getMetaData().get("retryMultiplier")));
                    }
                }
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : Element(org.w3c.dom.Element) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Error(io.automatiko.engine.workflow.bpmn2.core.Error) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 19 with Error

use of io.automatiko.engine.workflow.bpmn2.core.Error in project automatiko-engine by automatiko-io.

the class ErrorHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String id = attrs.getValue("id");
    String errorCode = attrs.getValue("errorCode");
    String structureRef = attrs.getValue("structureRef");
    Definitions definitions = (Definitions) parser.getParent();
    List<Error> errors = definitions.getErrors();
    if (errors == null) {
        errors = new ArrayList<Error>();
        definitions.setErrors(errors);
        ((ProcessBuildData) parser.getData()).setMetaData("Errors", errors);
    }
    Error e = new Error(id, errorCode, structureRef);
    errors.add(e);
    return e;
}
Also used : ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) Error(io.automatiko.engine.workflow.bpmn2.core.Error)

Example 20 with Error

use of io.automatiko.engine.workflow.bpmn2.core.Error in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method visitErrors.

protected void visitErrors(Definitions definitions, StringBuilder xmlDump) {
    if (definitions == null) {
        return;
    }
    List<Error> errors = definitions.getErrors();
    if (errors == null || errors.isEmpty()) {
        return;
    }
    for (io.automatiko.engine.workflow.bpmn2.core.Error error : errors) {
        String id = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(error.getId());
        String code = error.getErrorCode();
        xmlDump.append("  <error id=\"" + id + "\"");
        if (error.getErrorCode() != null) {
            code = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(code);
            xmlDump.append(" errorCode=\"" + code + "\"");
        }
        String structureRef = error.getStructureRef();
        if (structureRef != null) {
            structureRef = XmlBPMNProcessDumper.replaceIllegalCharsAttribute(structureRef);
            xmlDump.append(" structureRef=\"" + structureRef + "\"");
        }
        xmlDump.append("/>" + EOL);
    }
}
Also used : Error(io.automatiko.engine.workflow.bpmn2.core.Error) Error(io.automatiko.engine.workflow.bpmn2.core.Error)

Aggregations

Error (org.jbpm.bpmn2.core.Error)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Map (java.util.Map)8 Element (org.w3c.dom.Element)8 Error (io.automatiko.engine.workflow.bpmn2.core.Error)7 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)5 NodeList (org.w3c.dom.NodeList)5 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)4 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)3 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)3 Definitions (io.automatiko.engine.workflow.bpmn2.core.Definitions)3 Escalation (io.automatiko.engine.workflow.bpmn2.core.Escalation)3 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)3 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)3 LinkedHashMap (java.util.LinkedHashMap)3 EventFilter (org.jbpm.process.core.event.EventFilter)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 NonAcceptingEventTypeFilter (org.jbpm.process.core.event.NonAcceptingEventTypeFilter)3 Message (io.automatiko.engine.workflow.bpmn2.core.Message)2