Search in sources :

Example 6 with WorkflowProcess

use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.

the class DefaultChecklistManager method getTasks.

@SuppressWarnings("unchecked")
public List<ChecklistItem> getTasks(long processInstanceId) {
    RuntimeEngine runtime = getRuntime();
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    Map<String, ChecklistItem> orderingIds = new HashMap<String, ChecklistItem>();
    if (processInstance != null) {
        WorkflowProcess process = (WorkflowProcess) ksession.getKieBase().getProcess(processInstance.getProcessId());
        Collection<ChecklistItem> result = ChecklistItemFactory.getPendingChecklistItems(process);
        result.addAll(ChecklistItemFactory.getLoggedChecklistItems(process, (List<NodeInstanceLog>) runtime.getAuditService().findNodeInstances(processInstance.getId())));
        for (ChecklistItem item : result) {
            if (item.getOrderingNb() != null && item.getOrderingNb().trim().length() > 0) {
                orderingIds.put(item.getOrderingNb(), item);
            }
        }
    }
    TaskService taskService = runtime.getTaskService();
    List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstanceId);
    List<ChecklistItem> result = new ArrayList<ChecklistItem>();
    for (Long taskId : taskIds) {
        Task task = taskService.getTaskById(taskId);
        if (task != null) {
            ChecklistItem item = ChecklistItemFactory.createChecklistItem(task);
            if (item.getOrderingNb() != null) {
                orderingIds.put(item.getOrderingNb(), item);
            } else {
                result.add(item);
            }
        }
    }
    for (ChecklistItem item : orderingIds.values()) {
        result.add(item);
    }
    Collections.sort(result, new Comparator<ChecklistItem>() {

        public int compare(ChecklistItem o1, ChecklistItem o2) {
            if (o1.getOrderingNb() != null && o2.getOrderingNb() != null) {
                return o1.getOrderingNb().compareTo(o2.getOrderingNb());
            } else if (o1.getTaskId() != null && o2.getTaskId() != null) {
                return o1.getTaskId().compareTo(o2.getTaskId());
            } else {
                throw new IllegalArgumentException();
            }
        }
    });
    manager.disposeRuntimeEngine(runtime);
    return result;
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess)

Example 7 with WorkflowProcess

use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitHeader.

protected void visitHeader(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    Map<String, Object> metaData = getMetaData(process.getMetaData());
    Set<String> imports = ((org.jbpm.process.core.Process) process).getImports();
    Map<String, String> globals = ((org.jbpm.process.core.Process) process).getGlobals();
    if ((imports != null && !imports.isEmpty()) || (globals != null && globals.size() > 0) || !metaData.isEmpty()) {
        xmlDump.append("    <extensionElements>" + EOL);
        if (imports != null) {
            for (String s : imports) {
                xmlDump.append("     <tns:import name=\"" + s + "\" />" + EOL);
            }
        }
        if (globals != null) {
            for (Map.Entry<String, String> global : globals.entrySet()) {
                xmlDump.append("     <tns:global identifier=\"" + global.getKey() + "\" type=\"" + global.getValue() + "\" />" + EOL);
            }
        }
        writeMetaData(getMetaData(process.getMetaData()), xmlDump);
        xmlDump.append("    </extensionElements>" + EOL);
    }
    // TODO: function imports
    // TODO: exception handlers
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null) {
        visitVariables(variableScope.getVariables(), xmlDump);
    }
    visitLanes(process, xmlDump);
}
Also used : Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 8 with WorkflowProcess

use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitProcess.

protected void visitProcess(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    String targetNamespace = (String) process.getMetaData().get("TargetNamespace");
    if (targetNamespace == null) {
        targetNamespace = "http://www.jboss.org/drools";
    }
    xmlDump.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + EOL + "<definitions id=\"Definition\"" + EOL + "             targetNamespace=\"" + targetNamespace + "\"" + EOL + "             typeLanguage=\"http://www.java.com/javaTypes\"" + EOL + "             expressionLanguage=\"http://www.mvel.org/2.0\"" + EOL + "             xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"" + EOL + "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + EOL + "             xsi:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"" + EOL + "             xmlns:g=\"http://www.jboss.org/drools/flow/gpd\"" + EOL + (metaDataType == META_DATA_USING_DI ? "             xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"" + EOL + "             xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"" + EOL + "             xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"" + EOL : "") + "             xmlns:tns=\"http://www.jboss.org/drools\">" + EOL + EOL);
    // item definitions
    this.visitedVariables = new HashSet<String>();
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    Set<String> dumpedItemDefs = new HashSet<String>();
    Map<String, ItemDefinition> itemDefs = (Map<String, ItemDefinition>) process.getMetaData().get("ItemDefinitions");
    if (itemDefs != null) {
        for (ItemDefinition def : itemDefs.values()) {
            xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getId()) + "\" ");
            if (def.getStructureRef() != null && !"java.lang.Object".equals(def.getStructureRef())) {
                xmlDump.append("structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(def.getStructureRef()) + "\" ");
            }
            xmlDump.append("/>" + EOL);
            dumpedItemDefs.add(def.getId().intern());
        }
    }
    visitVariableScope(variableScope, "_", xmlDump, dumpedItemDefs);
    visitSubVariableScopes(process.getNodes(), xmlDump, dumpedItemDefs);
    visitInterfaces(process.getNodes(), xmlDump);
    visitEscalations(process.getNodes(), xmlDump, new ArrayList<String>());
    Definitions def = (Definitions) process.getMetaData().get("Definitions");
    visitErrors(def, xmlDump);
    // data stores
    if (def != null && def.getDataStores() != null) {
        for (DataStore dataStore : def.getDataStores()) {
            visitDataStore(dataStore, xmlDump);
        }
    }
    // the process itself
    xmlDump.append("  <process processType=\"Private\" isExecutable=\"true\" ");
    if (process.getId() == null || process.getId().trim().length() == 0) {
        ((ProcessImpl) process).setId("com.sample.bpmn2");
    }
    xmlDump.append("id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" ");
    if (process.getName() != null) {
        xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getName()) + "\" ");
    }
    String packageName = process.getPackageName();
    if (packageName != null && !"org.drools.bpmn2".equals(packageName)) {
        xmlDump.append("tns:packageName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(packageName) + "\" ");
    }
    if (((org.jbpm.workflow.core.WorkflowProcess) process).isDynamic()) {
        xmlDump.append("tns:adHoc=\"true\" ");
    }
    String version = process.getVersion();
    if (version != null && !"".equals(version)) {
        xmlDump.append("tns:version=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(version) + "\" ");
    }
    // TODO: package, version
    xmlDump.append(">" + EOL + EOL);
    visitHeader(process, xmlDump, metaDataType);
    List<org.jbpm.workflow.core.Node> processNodes = new ArrayList<org.jbpm.workflow.core.Node>();
    for (Node procNode : process.getNodes()) {
        processNodes.add((org.jbpm.workflow.core.Node) procNode);
    }
    visitNodes(processNodes, xmlDump, metaDataType);
    visitConnections(process.getNodes(), xmlDump, metaDataType);
    // add associations
    List<Association> associations = (List<Association>) process.getMetaData().get(ProcessHandler.ASSOCIATIONS);
    if (associations != null) {
        for (Association association : associations) {
            visitAssociation(association, xmlDump);
        }
    }
    xmlDump.append("  </process>" + EOL + EOL);
    if (metaDataType == META_DATA_USING_DI) {
        xmlDump.append("  <bpmndi:BPMNDiagram>" + EOL + "    <bpmndi:BPMNPlane bpmnElement=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(process.getId()) + "\" >" + EOL);
        visitNodesDi(process.getNodes(), xmlDump);
        visitConnectionsDi(process.getNodes(), xmlDump);
        xmlDump.append("    </bpmndi:BPMNPlane>" + EOL + "  </bpmndi:BPMNDiagram>" + EOL + EOL);
    }
    xmlDump.append("</definitions>");
}
Also used : Definitions(org.jbpm.bpmn2.core.Definitions) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ArrayList(java.util.ArrayList) Association(org.jbpm.bpmn2.core.Association) DataStore(org.jbpm.bpmn2.core.DataStore) ProcessImpl(org.jbpm.process.core.impl.ProcessImpl) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) VariableScope(org.jbpm.process.core.context.variable.VariableScope) HashSet(java.util.HashSet)

Example 9 with WorkflowProcess

use of org.kie.api.definition.process.WorkflowProcess in project jbpm by kiegroup.

the class MigrationManager method upgradeProcessInstance.

private void upgradeProcessInstance(KieRuntime oldkruntime, KieRuntime kruntime, long processInstanceId, String processId, Map<String, String> nodeMapping, EntityManager em, String deploymentId) {
    if (nodeMapping == null) {
        nodeMapping = new HashMap<String, String>();
    }
    WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) oldkruntime.getProcessInstance(processInstanceId);
    if (processInstance == null) {
        report.addEntry(Type.ERROR, "Could not find process instance " + processInstanceId);
    }
    if (processId == null) {
        report.addEntry(Type.ERROR, "Null process id");
    }
    WorkflowProcess process = (WorkflowProcess) kruntime.getKieBase().getProcess(processId);
    if (process == null) {
        report.addEntry(Type.ERROR, "Could not find process " + processId);
    }
    if (processInstance.getProcessId().equals(processId)) {
        report.addEntry(Type.WARN, "Source and target process id is exactly the same (" + processId + ") it's recommended to use unique process ids");
    }
    synchronized (processInstance) {
        org.kie.api.definition.process.Process oldProcess = processInstance.getProcess();
        processInstance.disconnect();
        processInstance.setProcess(oldProcess);
        updateNodeInstances(processInstance, nodeMapping, (NodeContainer) process, em);
        processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) extractIfNeeded(kruntime));
        processInstance.setDeploymentId(deploymentId);
        processInstance.setProcess(process);
        processInstance.reconnect();
    }
}
Also used : WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess)

Aggregations

WorkflowProcess (org.kie.api.definition.process.WorkflowProcess)9 HashMap (java.util.HashMap)4 Process (org.kie.api.definition.process.Process)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)3 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)3 VariableScope (org.jbpm.process.core.context.variable.VariableScope)2 KieSession (org.kie.api.runtime.KieSession)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 Dialect (org.drools.compiler.compiler.Dialect)1 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)1 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)1 DuplicateProcess (org.drools.compiler.compiler.DuplicateProcess)1 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 ParserError (org.drools.compiler.compiler.ParserError)1 ProcessDescr (org.drools.compiler.lang.descr.ProcessDescr)1