Search in sources :

Example 26 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method buildProcessErrors.

protected ProcessErrors buildProcessErrors() {
    WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
    final List<ExecutionsErrorInfo> errors = pi.errors();
    return new ProcessErrors(errors.stream().map(e -> new ProcessError() {

        @Override
        public String failedNodeId() {
            return e.getFailedNodeId();
        }

        @Override
        public String errorMessage() {
            return e.getErrorMessage();
        }

        @Override
        public String errorId() {
            return e.getErrorId();
        }

        @Override
        public String errorDetails() {
            return e.getErrorDetails();
        }

        @Override
        public void retrigger() {
            WorkflowProcessInstanceImpl pInstance = (WorkflowProcessInstanceImpl) processInstance();
            NodeInstance ni = pInstance.getNodeInstanceByNodeDefinitionId(e.getFailedNodeId(), pInstance.getNodeContainer());
            if (ni == null) {
                throw new IllegalArgumentException("Node with definition id " + e.getFailedNodeId() + " was not found");
            }
            pInstance.setState(STATE_ACTIVE);
            pInstance.resetErrorForNode(e.getFailedNodeId());
            ni.trigger(null, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
            if (pInstance.hasErrors()) {
                pInstance.setState(STATE_ERROR);
            }
            removeOnFinish();
        }

        @Override
        public void skip() {
            WorkflowProcessInstanceImpl pInstance = (WorkflowProcessInstanceImpl) processInstance();
            NodeInstance ni = pInstance.getNodeInstanceByNodeDefinitionId(e.getFailedNodeId(), pInstance.getNodeContainer());
            if (ni == null) {
                throw new IllegalArgumentException("Node with definition id " + e.getFailedNodeId() + " was not found");
            }
            pInstance.setState(STATE_ACTIVE);
            pInstance.resetErrorForNode(e.getFailedNodeId());
            ((NodeInstanceImpl) ni).triggerCompleted(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, true);
            if (pInstance.hasErrors()) {
                pInstance.setState(STATE_ERROR);
            }
            removeOnFinish();
        }
    }).collect(Collectors.toList()));
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) ProcessError(io.automatiko.engine.api.workflow.ProcessError) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)

Example 27 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method image.

@Override
public String image(String path) {
    if (process().image() == null) {
        return null;
    }
    StringBuilder script = new StringBuilder();
    String image = process().image();
    List<String> completedNodes = ((WorkflowProcessInstanceImpl) processInstance()).getCompletedNodeIds();
    Collection<NodeInstance> activeInstances = ((WorkflowProcessInstanceImpl) processInstance()).getNodeInstances(true);
    if (!activeInstances.isEmpty() || !completedNodes.isEmpty() || status == STATE_ERROR) {
        script.append("<script>");
        script.append("function remove(item) {if (item != null) {var parent = item.parentNode; parent.removeChild(item);}}");
        script.append("function linkSet(item, link) {if (item != null) {item.setAttribute('xlink:href', link);}}");
        script.append("function urlSet(item, url) {if (item != null) {item.onclick=function (e) {openInNewTab(url);};}}");
        script.append("function fill(item, rgb) {if (item != null) {item.style['fill']=rgb;}}");
        script.append("function highlight(item) {if (item != null) {item.style['stroke']='rgb(255, 0, 0)';item.style['stroke-width']='2';}}");
        script.append("var warnIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABz0lEQVQ4y2NgoBAwYhNsK7HVdbOWCpCX5FJjYGRgePzi+63dR59tKO86dBmvAQlB2kJT6ixncLN+CWH4/xvVcEbW/9//8q4taDuZPmvFpXcYBsQFagktaDM7zPj3sxZM7Or93wwMDAwM2oqscHP+M/Ney2g8aztrxeV3KAZ8Phe/moftSwiypfVzPjEwMDAwNKbwoTjm+x/e1VwGC8IYGBgYWBgYGBga88x1edi+BhMbcJwsX0I6S610y7uPXWZhYGBgcLUUDmBg+M9IfNj/Z3SxEA5gYGCAGCArzqpGavTJSUD0sDAwMDC8ef+VUUaMnyQDXr/9wgg34Oi5N3cM1DENkBfH7avDZ1/fgceCpb6Q8dElDqcZGRlRdPz//x8S16jCDP////9vF3/Q9Mi5t2dZGBgYGI5ffHd2475nWwOcpX2QFTbO+8zAwMDA0JCMGo2b9j/feuTc27Mo6UBUkE3q0EKHQxpKvMowsZNXvzMwMDAwmGtzwjXfuP/5rn38QbtX734+w0jKwgJsMjPrjWYHuUi5Y/HO/3V7nu3MaDyX+ubDryf4MhOzvjq/lb+TVIC6Ao86AwMDw80HX25u3Pds48WbH48xMDD8YaAmAAAYL5tXiXxXawAAAABJRU5ErkJggg==';");
        script.append("var errorIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAC80lEQVR42m2TD0yMYRzHP897d65y0akzUTYjVEKnMNQw2RqbzVrzd2wopkwrFrMw//8sDBtbNmZj5k9tDYXMbEYRM8oiSwqp6E53qbvu8uuG5c+zvXv37v09n+f3+36/j+I/azkERsJsM4zVg74D3tfC3ePw4e9a1fdjLvgnQJ5Z0zKGx8ebQqKi0BkM2OrqqH/wwGPr6LjaDDmHoeEfQDxY5kNJZHi4NTYzE1NY2B90l8NBVUEBNRUVLe9g3lF4/BswWNpcAWXxZnNibMZadCYjOk1D9Sh6usHrgW6PB6UUtZcuUVVd3XwPYovhow8wB1YthoKY5NkYJ0czKi2HugsnMdqbUN0aNqdi9IYt1F+5iquykprCQso9nnPHYKXqB1oWVEzVaZNGpE6he1oS1vU7cDu+Ub43DVfLJ2JzTzNoVCS114tp2LUbd81r3thsXUdgmDJBiMzzOdwfLTTBiNMcgHtaOjMy99L5zUZ78wcGR4zjVUkRb/LWYGn5juO9kyYvnIEFahhMPADPhgaJipPBbyi+n/bxeczL3ukT8EXZLar2zCfaz01XIzhExeZ2OA8ZSgSMFn9fWgIhOA76CfGVaxBx224THmP1AZxtX7mRlcSYzqfSq8CroUX8PAXpSoOBZ8XXED2BQePhi0U2599mSJSV+ofXaH1bjnXpfhmnjfubkghueIr9kUBssBUSe10wbITLM2UezQKhm3OJy9nHR9nceHERpgFu9DHZRKQe4vPjUp5nJtP1RBrx0rhWkuqzcTjMOgGl4pjBG6oYmbYaW8VZgkLcGPpLiCQL/Scso6msmLYyO3o7nJRE3oT8X2EzLoTt6ZBrV5IfuQT+oSKovHsBvXN2tkK7zB7gBGmgdAek9IiefdM6IEUA6yDbIVo6ZZNHQqJ0EhSXwNwgvJ47UHQQ1rl9cv51mWQFhMH0JVIghiRIRoLlFCUTOOTwyitifaUApK79v7fx59J6QfKY/QQgDeikaxmANnmkObx9i38AhmwGt8LiZCUAAAAASUVORK5CYII=';");
        script.append("function openInNewTab(url) {var win = window.open(url, '_blank');win.focus();}");
        for (NodeInstance nodeInstance : activeInstances) {
            if (((NodeInstanceImpl) nodeInstance).getNode().getMetaData().containsKey("hidden_node") || nodeInstance.getNodeDefinitionId().startsWith("_jbpm-unique")) {
                continue;
            }
            script.append("highlight(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("'));\n");
            if (nodeInstance instanceof LambdaSubProcessNodeInstance) {
                // add links for call activity
                LambdaSubProcessNodeInstance subprocess = (LambdaSubProcessNodeInstance) nodeInstance;
                String url = path + "/" + ((SubProcessNode) subprocess.getNode()).getProcessId() + "/" + subprocess.getProcessInstanceId() + "/image";
                script.append("urlSet(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_image'), '" + url + "');\n");
            }
            if (nodeInstance instanceof EventSubProcessNodeInstance) {
                if (((EventSubProcessNodeInstance) nodeInstance).getTimerInstances() != null && !((EventSubProcessNodeInstance) nodeInstance).getTimerInstances().isEmpty()) {
                    String nodeDefId = (String) ((EventSubProcessNode) ((EventSubProcessNodeInstance) nodeInstance).getEventBasedNode()).findStartNode().getMetaData("UniqueId");
                    if (nodeDefId != null) {
                        script.append("highlight(document.getElementById('").append(nodeDefId).append("'));\n");
                    }
                }
            }
            if (nodeInstance.getNodeInstanceState().equals(NodeInstanceState.Retrying)) {
                script.append("linkSet(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_warn_image'), warnIcon);\n");
            } else if (nodeInstance.getNodeInstanceState().equals(NodeInstanceState.Failed)) {
                script.append("linkSet(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_warn_image'), errorIcon);\n");
            } else {
                script.append("remove(document.getElementById('").append(nodeInstance.getNodeDefinitionId()).append("_warn_image'));\n");
            }
        }
        for (String nodeInstanceId : completedNodes) {
            script.append("remove(document.getElementById('").append(nodeInstanceId).append("_warn_image'));\n");
            script.append("fill(document.getElementById('").append(nodeInstanceId).append("'), 'rgb(160, 160, 160)');\n");
        }
        if (status == STATE_ERROR) {
            for (ProcessError error : errors().get().errors()) {
                String failedNodeId = error.failedNodeId();
                script.append("highlight(document.getElementById('").append(failedNodeId).append("'));\n");
                script.append("linkSet(document.getElementById('").append(failedNodeId).append("_warn_image'), errorIcon);\n");
            }
        }
        script.append("</script></svg>");
        image = image.replaceAll("</svg>", script.toString());
    }
    return image;
}
Also used : LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ProcessError(io.automatiko.engine.api.workflow.ProcessError) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)

Example 28 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method cancelNodeInstance.

@Override
public void cancelNodeInstance(String nodeInstanceId) {
    lock();
    NodeInstance nodeInstance = ((WorkflowProcessInstanceImpl) processInstance()).getNodeInstances(true).stream().filter(ni -> ni.getId().equals(nodeInstanceId)).findFirst().orElseThrow(() -> new NodeInstanceNotFoundException(this.id, nodeInstanceId));
    nodeInstance.cancel();
    removeOnFinish();
}
Also used : NodeInstanceNotFoundException(io.automatiko.engine.api.workflow.NodeInstanceNotFoundException) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)

Example 29 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method retriggerNodeInstance.

@Override
public void retriggerNodeInstance(String nodeInstanceId) {
    lock();
    NodeInstance nodeInstance = ((WorkflowProcessInstanceImpl) processInstance()).getNodeInstances(true).stream().filter(ni -> ni.getId().equals(nodeInstanceId)).findFirst().orElseThrow(() -> new NodeInstanceNotFoundException(this.id, nodeInstanceId));
    ((NodeInstanceImpl) nodeInstance).retrigger(true);
    removeOnFinish();
}
Also used : NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) NodeInstanceNotFoundException(io.automatiko.engine.api.workflow.NodeInstanceNotFoundException) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)

Example 30 with WorkflowProcessInstanceImpl

use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.

the class AbstractProcessInstance method triggerNode.

@Override
public void triggerNode(String nodeId) {
    lock();
    WorkflowProcessInstanceImpl wfpi = ((WorkflowProcessInstanceImpl) processInstance());
    ExecutableProcess rfp = ((ExecutableProcess) wfpi.getProcess());
    Node node = rfp.getNodesRecursively().stream().filter(ni -> nodeId.equals(ni.getMetaData().get("UniqueId"))).findFirst().orElseThrow(() -> new NodeNotFoundException(this.id, nodeId));
    Node parentNode = rfp.getParentNode(node.getId());
    NodeInstanceContainer nodeInstanceContainerNode = parentNode == null ? wfpi : ((NodeInstanceContainer) wfpi.getNodeInstance(parentNode));
    if (nodeInstanceContainerNode.getNodeInstances().isEmpty() && nodeInstanceContainerNode instanceof CompositeContextNodeInstance) {
        ((CompositeContextNodeInstance) nodeInstanceContainerNode).internalTriggerOnlyParent(null, nodeId);
    }
    nodeInstanceContainerNode.getNodeInstance(node).trigger(null, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
}
Also used : NodeNotFoundException(io.automatiko.engine.api.workflow.NodeNotFoundException) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Node(io.automatiko.engine.api.definition.process.Node) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Aggregations

WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)36 ArrayList (java.util.ArrayList)10 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)8 Node (io.automatiko.engine.api.definition.process.Node)7 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)7 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)7 Process (io.automatiko.engine.api.definition.process.Process)6 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)6 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)5 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)5 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)5 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)5 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)5 Date (java.util.Date)5 ExpirationTime (io.automatiko.engine.api.jobs.ExpirationTime)4 JobsService (io.automatiko.engine.api.jobs.JobsService)4