Search in sources :

Example 1 with DynamicNode

use of org.jbpm.workflow.core.node.DynamicNode in project jbpm by kiegroup.

the class RuleFlowProcessValidatorTest method testDynamicNodeValidationInNotDynamicProcess.

@Test
public void testDynamicNodeValidationInNotDynamicProcess() throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process");
    process.setName("Dynamic Node Process");
    process.setPackageName("org.mycomp.myprocess");
    process.setDynamic(false);
    DynamicNode dynamicNode = new DynamicNode();
    dynamicNode.setName("MyDynamicNode");
    dynamicNode.setId(1);
    dynamicNode.setAutoComplete(false);
    // empty completion expression to trigger validation error
    dynamicNode.setCompletionExpression("");
    process.addNode(dynamicNode);
    ProcessValidationError[] errors = validator.validateProcess(process);
    assertNotNull(errors);
    // in non-dynamic processes all check should be triggered
    // they should also include process level checks (start node, end node etc)
    assertEquals(6, errors.length);
    assertEquals("Process has no start node.", errors[0].getMessage());
    assertEquals("Process has no end node.", errors[1].getMessage());
    assertEquals("Node 'MyDynamicNode' [1] Dynamic has no incoming connection", errors[2].getMessage());
    assertEquals("Node 'MyDynamicNode' [1] Dynamic has no outgoing connection", errors[3].getMessage());
    assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors[4].getMessage());
    assertEquals("Node 'MyDynamicNode' [1] Has no connection to the start node.", errors[5].getMessage());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) ProcessValidationError(org.jbpm.process.core.validation.ProcessValidationError) Test(org.junit.Test)

Example 2 with DynamicNode

use of org.jbpm.workflow.core.node.DynamicNode in project jbpm by kiegroup.

the class RuleFlowProcessValidatorTest method testDynamicNodeValidationInDynamicProcess.

@Test
public void testDynamicNodeValidationInDynamicProcess() throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process");
    process.setName("Dynamic Node Process");
    process.setPackageName("org.mycomp.myprocess");
    process.setDynamic(true);
    DynamicNode dynamicNode = new DynamicNode();
    dynamicNode.setName("MyDynamicNode");
    dynamicNode.setId(1);
    dynamicNode.setAutoComplete(false);
    dynamicNode.setCompletionExpression("completion-expression");
    process.addNode(dynamicNode);
    ProcessValidationError[] errors = validator.validateProcess(process);
    assertNotNull(errors);
    // if dynamic process no longer triggering incoming / outgoing connection errors for dynamic nodes
    assertEquals(0, errors.length);
    // empty completion expression to trigger validation error
    process.removeNode(dynamicNode);
    DynamicNode dynamicNode2 = new DynamicNode();
    dynamicNode2.setName("MyDynamicNode");
    dynamicNode2.setId(1);
    dynamicNode2.setAutoComplete(false);
    dynamicNode2.setCompletionExpression("");
    process.addNode(dynamicNode2);
    ProcessValidationError[] errors2 = validator.validateProcess(process);
    assertNotNull(errors2);
    // autocomplete set to false and empty completion condition triggers error
    assertEquals(1, errors2.length);
    assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors2[0].getMessage());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) ProcessValidationError(org.jbpm.process.core.validation.ProcessValidationError) Test(org.junit.Test)

Example 3 with DynamicNode

use of org.jbpm.workflow.core.node.DynamicNode in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method collectCaseStages.

private Collection<CaseStage> collectCaseStages(String deploymentId, String processId, NodeContainer process) {
    Collection<CaseStage> result = new ArrayList<CaseStage>();
    for (Node node : process.getNodes()) {
        if (node instanceof DynamicNode) {
            DynamicNode dynamicNode = (DynamicNode) node;
            Collection<AdHocFragment> adHocFragments = collectAdHocFragments(dynamicNode);
            result.add(new CaseStageImpl((String) ((DynamicNode) node).getMetaData("UniqueId"), node.getName(), adHocFragments));
        }
    }
    return result;
}
Also used : CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) Node(org.kie.api.definition.process.Node) ArrayList(java.util.ArrayList) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment)

Example 4 with DynamicNode

use of org.jbpm.workflow.core.node.DynamicNode in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method internalGetCaseStages.

/*
     * Helper methods to parse process and extract case related information
     */
public List<CaseStageInstance> internalGetCaseStages(CaseDefinition caseDef, String caseId, boolean activeOnly, QueryContext queryContext) {
    CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
    Collection<org.jbpm.services.api.model.NodeInstanceDesc> nodes = runtimeDataService.getNodeInstancesByCorrelationKeyNodeType(correlationKey, Arrays.asList(ProcessInstance.STATE_ACTIVE), Arrays.asList("DynamicNode"), queryContext);
    Collection<Long> completedNodes = nodes.stream().filter(n -> ((NodeInstanceDesc) n).getType() == 1).map(n -> n.getId()).collect(toList());
    Map<String, CaseStage> stagesByName = caseDef.getCaseStages().stream().collect(toMap(CaseStage::getId, c -> c));
    Predicate<org.jbpm.services.api.model.NodeInstanceDesc> filterNodes = null;
    if (activeOnly) {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0 && !completedNodes.contains(((NodeInstanceDesc) n).getId());
    } else {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0;
    }
    List<String> triggeredStages = new ArrayList<>();
    List<CaseStageInstance> stages = new ArrayList<>();
    nodes.stream().filter(filterNodes).map(n -> {
        StageStatus status = StageStatus.Active;
        if (completedNodes.contains(((NodeInstanceDesc) n).getId())) {
            status = StageStatus.Completed;
        }
        Collection<org.jbpm.services.api.model.NodeInstanceDesc> activeNodes = getActiveNodesForCaseAndStage(caseId, n.getNodeId(), new QueryContext(0, 100));
        return new CaseStageInstanceImpl(n.getNodeId(), n.getName(), stagesByName.get(n.getNodeId()).getAdHocFragments(), activeNodes, status);
    }).forEach(csi -> {
        stages.add(csi);
        triggeredStages.add(csi.getName());
    });
    if (!activeOnly) {
        // add other stages that are present in the definition
        caseDef.getCaseStages().stream().filter(cs -> !triggeredStages.contains(cs.getName())).map(cs -> new CaseStageInstanceImpl(cs.getId(), cs.getName(), cs.getAdHocFragments(), Collections.emptyList(), StageStatus.Available)).forEach(csi -> stages.add(csi));
    }
    return stages;
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CaseDefinitionComparator(org.jbpm.casemgmt.impl.model.CaseDefinitionComparator) Collectors.toMap(java.util.stream.Collectors.toMap) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) FILTER(org.kie.internal.query.QueryParameterIdentifiers.FILTER) Set(java.util.Set) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) NodeContainer(org.kie.api.definition.process.NodeContainer) AdHocFragmentImpl(org.jbpm.casemgmt.impl.model.AdHocFragmentImpl) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ArrayList(java.util.ArrayList) ProcessDefinitionComparator(org.jbpm.casemgmt.impl.model.ProcessDefinitionComparator) HashSet(java.util.HashSet) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) KieBase(org.kie.api.KieBase) IdentityProvider(org.kie.internal.identity.IdentityProvider) QueryManager(org.jbpm.shared.services.impl.QueryManager) CorrelationKey(org.kie.internal.process.CorrelationKey) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) CaseIdGenerator(org.jbpm.casemgmt.api.generator.CaseIdGenerator) Collectors.toList(java.util.stream.Collectors.toList) Node(org.kie.api.definition.process.Node) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) CaseMilestoneImpl(org.jbpm.casemgmt.impl.model.CaseMilestoneImpl) CommonUtils.getAuthenticatedUserRoles(org.jbpm.kie.services.impl.CommonUtils.getAuthenticatedUserRoles) Collections(java.util.Collections) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CorrelationKey(org.kie.internal.process.CorrelationKey) Collection(java.util.Collection) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl)

Example 5 with DynamicNode

use of org.jbpm.workflow.core.node.DynamicNode in project jbpm by kiegroup.

the class AdHocSubProcessHandler 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);
    DynamicNode dynamicNode = (DynamicNode) node;
    String cancelRemainingInstances = element.getAttribute("cancelRemainingInstances");
    if ("false".equals(cancelRemainingInstances)) {
        dynamicNode.setCancelRemainingInstances(false);
    }
    // by default it should not autocomplete as it's adhoc
    dynamicNode.setAutoComplete(false);
    dynamicNode.setActivationExpression((String) dynamicNode.getMetaData("customActivationCondition"));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("completionCondition".equals(nodeName)) {
            String expression = xmlNode.getTextContent();
            if (AUTOCOMPLETE_EXPRESSIONS.contains(expression)) {
                dynamicNode.setAutoComplete(true);
            } else {
                dynamicNode.setCompletionExpression(expression == null ? "" : expression);
            }
            org.w3c.dom.Node languageNode = xmlNode.getAttributes().getNamedItem("language");
            if (languageNode != null) {
                String language = languageNode.getNodeValue();
                if (XmlBPMNProcessDumper.MVEL_LANGUAGE.equals(language)) {
                    dynamicNode.setLanguage("mvel");
                } else if (XmlBPMNProcessDumper.RULE_LANGUAGE.equals(language)) {
                    dynamicNode.setLanguage("rule");
                } else {
                    throw new IllegalArgumentException("Unknown language " + language);
                }
            } else {
                dynamicNode.setLanguage("mvel");
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
    List<SequenceFlow> connections = (List<SequenceFlow>) dynamicNode.getMetaData(ProcessHandler.CONNECTIONS);
    ProcessHandler.linkConnections(dynamicNode, connections);
    ProcessHandler.linkBoundaryEvents(dynamicNode);
    handleScript(dynamicNode, element, "onEntry");
    handleScript(dynamicNode, element, "onExit");
}
Also used : SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) List(java.util.List)

Aggregations

DynamicNode (org.jbpm.workflow.core.node.DynamicNode)12 ArrayList (java.util.ArrayList)6 MilestoneNode (org.jbpm.workflow.core.node.MilestoneNode)6 StartNode (org.jbpm.workflow.core.node.StartNode)6 EventNode (org.jbpm.workflow.core.node.EventNode)5 Node (org.kie.api.definition.process.Node)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)4 EndNode (org.jbpm.workflow.core.node.EndNode)4 StateNode (org.jbpm.workflow.core.node.StateNode)4 Map (java.util.Map)3 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)3 FaultNode (org.jbpm.workflow.core.node.FaultNode)3 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)3 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)3 Split (org.jbpm.workflow.core.node.Split)3 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)3 TimerNode (org.jbpm.workflow.core.node.TimerNode)3