Search in sources :

Example 1 with Interface

use of org.jbpm.bpmn2.core.Interface in project jbpm by kiegroup.

the class OperationHandler method start.

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 name = attrs.getValue("name");
    String implRef = attrs.getValue("implementationRef");
    Interface i = (Interface) parser.getParent();
    Operation operation = i.addOperation(id, name);
    if (implRef != null) {
        operation.setImplementationRef(implRef);
    }
    return operation;
}
Also used : Operation(org.jbpm.bpmn2.core.Interface.Operation) Interface(org.jbpm.bpmn2.core.Interface)

Example 2 with Interface

use of org.jbpm.bpmn2.core.Interface in project jbpm by kiegroup.

the class DefinitionsHandler method postProcessInterfaces.

private void postProcessInterfaces(NodeContainer nodeContainer, List<Interface> interfaces) {
    for (Node node : nodeContainer.getNodes()) {
        if (node instanceof NodeContainer) {
            postProcessInterfaces((NodeContainer) node, interfaces);
        }
        if (node instanceof WorkItemNode && "Service Task".equals(((WorkItemNode) node).getMetaData("Type"))) {
            WorkItemNode workItemNode = (WorkItemNode) node;
            if (interfaces == null) {
                throw new IllegalArgumentException("No interfaces found");
            }
            String operationRef = (String) workItemNode.getMetaData("OperationRef");
            String implementation = (String) workItemNode.getMetaData("Implementation");
            Operation operation = null;
            for (Interface i : interfaces) {
                operation = i.getOperation(operationRef);
                if (operation != null) {
                    break;
                }
            }
            if (operation == null) {
                throw new IllegalArgumentException("Could not find operation " + operationRef);
            }
            // avoid overriding parameters set by data input associations
            if (workItemNode.getWork().getParameter("Interface") == null) {
                workItemNode.getWork().setParameter("Interface", operation.getInterface().getName());
            }
            if (workItemNode.getWork().getParameter("Operation") == null) {
                workItemNode.getWork().setParameter("Operation", operation.getName());
            }
            if (workItemNode.getWork().getParameter("ParameterType") == null) {
                workItemNode.getWork().setParameter("ParameterType", operation.getMessage().getType());
            }
            // parameters to support web service invocation
            if (implementation != null) {
                workItemNode.getWork().setParameter("interfaceImplementationRef", operation.getInterface().getImplementationRef());
                workItemNode.getWork().setParameter("operationImplementationRef", operation.getImplementationRef());
                workItemNode.getWork().setParameter("implementation", implementation);
            }
        }
    }
}
Also used : ForEachNode(org.jbpm.workflow.core.node.ForEachNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Node(org.kie.api.definition.process.Node) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) Operation(org.jbpm.bpmn2.core.Interface.Operation) Interface(org.jbpm.bpmn2.core.Interface)

Example 3 with Interface

use of org.jbpm.bpmn2.core.Interface in project jbpm by kiegroup.

the class DefinitionsHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Definitions definitions = (Definitions) parser.getCurrent();
    String namespace = element.getAttribute("targetNamespace");
    List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
    Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    for (Process process : processes) {
        RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process;
        ruleFlowProcess.setMetaData("TargetNamespace", namespace);
        postProcessItemDefinitions(ruleFlowProcess, itemDefinitions, parser.getClassLoader());
        postProcessInterfaces(ruleFlowProcess, interfaces);
    }
    definitions.setTargetNamespace(namespace);
    return definitions;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) Element(org.w3c.dom.Element) Definitions(org.jbpm.bpmn2.core.Definitions) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) Map(java.util.Map) Interface(org.jbpm.bpmn2.core.Interface)

Example 4 with Interface

use of org.jbpm.bpmn2.core.Interface in project jbpm by kiegroup.

the class AbstractLogOrThrowWorkItemHandler method handleException.

protected void handleException(Throwable cause, Map<String, Object> handlerInfoMap) {
    String service = (String) handlerInfoMap.get("Interface");
    String operation = (String) handlerInfoMap.get("Operation");
    if (this.logThrownException) {
        String message;
        if (service != null) {
            message = this.getClass().getSimpleName() + " failed when calling " + service + "." + operation;
        } else {
            message = this.getClass().getSimpleName() + " failed while trying to complete the task.";
        }
        logger.error(message, cause);
    } else {
        WorkItemHandlerRuntimeException wihRe = new WorkItemHandlerRuntimeException(cause);
        for (String key : handlerInfoMap.keySet()) {
            wihRe.setInformation(key, handlerInfoMap.get(key));
        }
        wihRe.setInformation(WorkItemHandlerRuntimeException.WORKITEMHANDLERTYPE, this.getClass().getSimpleName());
        throw wihRe;
    }
}
Also used : WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException)

Example 5 with Interface

use of org.jbpm.bpmn2.core.Interface in project jbpm by kiegroup.

the class ServiceTaskHandler method handleNode.

@SuppressWarnings("unchecked")
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    WorkItemNode workItemNode = (WorkItemNode) node;
    String operationRef = element.getAttribute("operationRef");
    String implementation = element.getAttribute("implementation");
    List<Interface> interfaces = (List<Interface>) ((ProcessBuildData) parser.getData()).getMetaData("Interfaces");
    workItemNode.setMetaData("OperationRef", operationRef);
    workItemNode.setMetaData("Implementation", implementation);
    workItemNode.setMetaData("Type", "Service Task");
    if (interfaces != null) {
        // throw new IllegalArgumentException("No interfaces found");
        Operation operation = null;
        for (Interface i : interfaces) {
            operation = i.getOperation(operationRef);
            if (operation != null) {
                break;
            }
        }
        if (operation == null) {
            throw new IllegalArgumentException("Could not find operation " + operationRef);
        }
        // avoid overriding parameters set by data input associations
        if (workItemNode.getWork().getParameter("Interface") == null) {
            workItemNode.getWork().setParameter("Interface", operation.getInterface().getName());
        }
        if (workItemNode.getWork().getParameter("Operation") == null) {
            workItemNode.getWork().setParameter("Operation", operation.getName());
        }
        if (workItemNode.getWork().getParameter("ParameterType") == null) {
            workItemNode.getWork().setParameter("ParameterType", operation.getMessage().getType());
        }
        // parameters to support web service invocation
        if (implementation != null) {
            workItemNode.getWork().setParameter("interfaceImplementationRef", operation.getInterface().getImplementationRef());
            workItemNode.getWork().setParameter("operationImplementationRef", operation.getImplementationRef());
            workItemNode.getWork().setParameter("implementation", implementation);
        }
    }
}
Also used : WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) List(java.util.List) Operation(org.jbpm.bpmn2.core.Interface.Operation) Interface(org.jbpm.bpmn2.core.Interface)

Aggregations

Interface (org.jbpm.bpmn2.core.Interface)4 Operation (org.jbpm.bpmn2.core.Interface.Operation)3 List (java.util.List)2 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)2 Map (java.util.Map)1 Definitions (org.jbpm.bpmn2.core.Definitions)1 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)1 WorkItemHandlerRuntimeException (org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException)1 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)1 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)1 NodeContainer (org.jbpm.workflow.core.NodeContainer)1 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)1 Node (org.kie.api.definition.process.Node)1 Process (org.kie.api.definition.process.Process)1 Element (org.w3c.dom.Element)1