Search in sources :

Example 1 with ProcessError

use of io.automatiko.engine.api.workflow.ProcessError in project automatiko-engine by automatiko-io.

the class BaseProcessInstanceManagementResource method doGetInstanceInError.

public T doGetInstanceInError(String processId, String processInstanceId) {
    return executeOnInstanceInError(processId, processInstanceId, processInstance -> {
        ProcessErrors errors = processInstance.errors().get();
        List<Map<String, String>> errorsData = new ArrayList<>();
        for (ProcessError error : errors.errors()) {
            Map<String, String> data = new HashMap<>();
            data.put("id", processInstance.id());
            data.put("failedNodeId", error.failedNodeId());
            data.put("message", error.errorMessage());
            errorsData.add(data);
        }
        return buildOkResponse(errorsData);
    });
}
Also used : ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) ProcessError(io.automatiko.engine.api.workflow.ProcessError) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with ProcessError

use of io.automatiko.engine.api.workflow.ProcessError in project automatiko-engine by automatiko-io.

the class ServiceTaskTest method testServiceProcessDifferentOperationsParallelTaskRetriggerIndividually.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testServiceProcessDifferentOperationsParallelTaskRetriggerIndividually() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceProcessDifferentOperationsParallel.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("ServiceProcessDifferentOperations_1_0");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    // parameters.put("s", "john");
    m.fromMap(parameters);
    ProcessInstance processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.startDate()).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
    assertThat(processInstance.errors()).isPresent();
    assertThat(((ProcessErrors) processInstance.errors().get()).errors()).hasSize(2);
    parameters.put("s", "john");
    m.fromMap(parameters);
    processInstance.updateVariables(m);
    ProcessErrors errors = (ProcessErrors) processInstance.errors().get();
    for (ProcessError error : errors.errors()) {
        errors.retrigger(error.failedNodeId());
    }
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("s");
    assertThat(result.toMap().get("s")).isNotNull().asString().contains("Goodbye").contains("Hello");
}
Also used : ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) HashMap(java.util.HashMap) ProcessError(io.automatiko.engine.api.workflow.ProcessError) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessError

use of io.automatiko.engine.api.workflow.ProcessError 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 4 with ProcessError

use of io.automatiko.engine.api.workflow.ProcessError 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)

Aggregations

ProcessError (io.automatiko.engine.api.workflow.ProcessError)4 ProcessErrors (io.automatiko.engine.api.workflow.ProcessErrors)3 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)2 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)2 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)2 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)2 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)2 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)2 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)2 HashMap (java.util.HashMap)2 Application (io.automatiko.engine.api.Application)1 Model (io.automatiko.engine.api.Model)1 ExecutionsErrorInfo (io.automatiko.engine.api.workflow.ExecutionsErrorInfo)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)1 SubProcessNode (io.automatiko.engine.workflow.process.core.node.SubProcessNode)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1