diff --git a/imixs-workflow-core/src/main/java/org/imixs/workflow/ModelManager.java b/imixs-workflow-core/src/main/java/org/imixs/workflow/ModelManager.java index dfd57cfa9..a6762ab0e 100644 --- a/imixs-workflow-core/src/main/java/org/imixs/workflow/ModelManager.java +++ b/imixs-workflow-core/src/main/java/org/imixs/workflow/ModelManager.java @@ -19,9 +19,11 @@ import org.imixs.workflow.exceptions.PluginException; import org.openbpmn.bpmn.BPMNModel; import org.openbpmn.bpmn.BPMNNS; +import org.openbpmn.bpmn.BPMNTypes; import org.openbpmn.bpmn.elements.Activity; import org.openbpmn.bpmn.elements.BPMNProcess; import org.openbpmn.bpmn.elements.Event; +import org.openbpmn.bpmn.elements.Participant; import org.openbpmn.bpmn.elements.core.BPMNElement; import org.openbpmn.bpmn.elements.core.BPMNElementNode; import org.openbpmn.bpmn.exceptions.BPMNModelException; @@ -348,7 +350,7 @@ public BPMNModel findModelByWorkitem(ItemCollection workitem) throws ModelExcept // Still no match, try to find model version by group if (!workitem.getWorkflowGroup().isEmpty()) { - List versions = findVersionsByGroup(workitem.getWorkflowGroup()); + List versions = findAllVersionsByGroup(workitem.getWorkflowGroup()); if (!versions.isEmpty()) { String newVersion = versions.get(0); if (!newVersion.isEmpty()) { @@ -371,14 +373,54 @@ public BPMNModel findModelByWorkitem(ItemCollection workitem) throws ModelExcept } /** - * This method returns a sorted list of model versions containing the requested - * workflow group. The result is sorted in reverse order, so the highest version - * number is the first in the result list. + * This method returns a sorted list of all workflow groups contained in a BPMN + * model. + *

+ * In case the model is a collaboration diagram, the method returns only group + * names from private process instances (Pools)! * * @param group * @return */ - public List findVersionsByGroup(String group) { + public Set findAllGroups(BPMNModel _model) { + Set result = new LinkedHashSet<>(); + + Set processList = _model.getProcesses(); + for (BPMNProcess _process : processList) { + String groupName = _process.getName(); + if (_model.isCollaborationDiagram()) { + // collaboration diagram - only add private processes (Pools) + if (BPMNTypes.PROCESS_TYPE_PRIVATE.equals(_process.getProcessType())) { + // add only private process types + result.add(groupName); + } + } else { + // if it is not a collaboration diagram we return the name of the first Public + // Process + if (BPMNTypes.PROCESS_TYPE_PUBLIC.equals(_process.getProcessType())) { + result.add(groupName); + break; + } + } + } + + if (result.size() == 0) { + logger.warning("Model " + BPMNUtil.getVersion(_model) + + " does not contain valid process elements! Please check your model file!"); + } + + return result; + } + + /** + * Returns a sorted list of all model versions containing the requested + * workflow group. The result is sorted in reverse order, so the highest version + * number is the first in the result list. + * + * @param group - name of the workflow group + * @return list of matching model versions + */ + public List findAllVersionsByGroup(String group) { boolean debug = logger.isLoggable(Level.FINE); List result = new ArrayList(); if (debug) { @@ -387,12 +429,9 @@ public List findVersionsByGroup(String group) { // try to find matching model version by group Collection models = modelStore.values(); for (BPMNModel _model : models) { - - Set processList = _model.getProcesses(); - for (BPMNProcess _process : processList) { - if (group.equals(_process.getName())) { - result.add(BPMNUtil.getVersion(_model)); - } + Set allGroups = findAllGroups(_model); + if (allGroups.contains(group)) { + result.add(BPMNUtil.getVersion(_model)); } } // sort result @@ -400,6 +439,27 @@ public List findVersionsByGroup(String group) { return result; } + /** + * Returns the first matching model version by a given workflow group. + *

+ * If multiple models are containing the same group the latest version will be + * returned. + *

+ * In case the model is a collaboration diagram, the method compares the given + * group name only with private process instances (Pools)! + * + * @param group + * @return + */ + public String findVersionByGroup(String group) { + String result = null; + List versions = findAllVersionsByGroup(group); + if (versions.size() > 0) { + result = versions.get(0); + } + return result; + } + /** * This method returns a sorted list of model versions matching a given regex * for a model version. The result is sorted in reverse order, so the highest @@ -427,22 +487,6 @@ public List findVersionsByRegEx(String modelRegex) { return result; } - /** - * This method returns a sorted list of all workflow groups contained in a BPMN - * model - * - * @param group - * @return - */ - public Set findAllGroups(BPMNModel _model) { - Set result = new LinkedHashSet<>(); - Set processList = _model.getProcesses(); - for (BPMNProcess _process : processList) { - result.add(_process.getName()); - } - return result; - } - /** * This method finds a Imixs task element by its ID (imixs:activityid). * The method returns a cloned Instance of the model entity to avoid @@ -494,14 +538,41 @@ public ItemCollection findEventByID(final BPMNModel model, int taskID, int event /** * Returns a list of start Tasks of a given Process Group + *

+ * In case of a collaboration diagram only Pool names are compared. The default + * process (Public Process) will be ignored. * - * @param processGroup - * @return + * @param model - the BPMN model + * @param processGroup - the name of the process group to match + * @return list of all Start Task entities or null if not process with the given + * name was found. * @throws BPMNModelException */ public List findStartTasks(final BPMNModel model, String processGroup) throws BPMNModelException { List result = new ArrayList<>(); - BPMNProcess process = model.findProcessByName(processGroup); + BPMNProcess process = null; + + if (processGroup == null || processGroup.isEmpty()) { + logger.warning("findEndTasks processGroup is empty!"); + return result; + } + // find Process containing matching the process group + if (model.isCollaborationDiagram()) { + Set poolList = model.getParticipants(); + for (Participant pool : poolList) { + process = pool.openProcess(); + if (processGroup.equals(process.getName())) { + break; + } + } + } else { + process = model.openDefaultProces(); + if (!processGroup.equals(process.getName())) { + // no match! + process = null; + } + } + // test start task.... BPMNStartElementIterator startElements = new BPMNStartElementIterator<>(process, node -> (node instanceof Activity)); @@ -513,20 +584,52 @@ public List findStartTasks(final BPMNModel model, String process /** * Returns a list of End Tasks of a given Process Group + *

+ * In case of a collaboration diagram only Pool names are compared. The default + * process (Public Process) will be ignored. * - * @param processGroup - * @return + * @param model - the BPMN model + * @param processGroup - the name of the process group to match + * @return list of all End Task entities or null if not process with the given + * name was found. * @throws BPMNModelException */ public List findEndTasks(final BPMNModel model, String processGroup) throws BPMNModelException { List result = new ArrayList<>(); - BPMNProcess process = model.findProcessByName(processGroup); - // test End task.... - BPMNEndElementIterator endElements = new BPMNEndElementIterator<>(process, - node -> (node instanceof Activity)); - while (endElements.hasNext()) { - result.add(BPMNEntityBuilder.build(endElements.next())); + BPMNProcess process = null; + + if (processGroup == null || processGroup.isEmpty()) { + logger.warning("findEndTasks processGroup is empty!"); + return result; + } + + // find Process containing matching the process group + if (model.isCollaborationDiagram()) { + Set poolList = model.getParticipants(); + for (Participant pool : poolList) { + process = pool.openProcess(); + if (processGroup.equals(process.getName())) { + break; + } + } + } else { + process = model.openDefaultProces(); + if (!processGroup.equals(process.getName())) { + // no match! + process = null; + } } + + // now get the End task ... + if (process != null) { + // test End task.... + BPMNEndElementIterator endElements = new BPMNEndElementIterator<>(process, + node -> (node instanceof Activity)); + while (endElements.hasNext()) { + result.add(BPMNEntityBuilder.build(endElements.next())); + } + } + return result; } diff --git a/imixs-workflow-core/src/test/java/org/imixs/workflow/bpmn/TestBPMNParserGroups.java b/imixs-workflow-core/src/test/java/org/imixs/workflow/bpmn/TestBPMNParserGroups.java index dc01b280e..68ede51a4 100644 --- a/imixs-workflow-core/src/test/java/org/imixs/workflow/bpmn/TestBPMNParserGroups.java +++ b/imixs-workflow-core/src/test/java/org/imixs/workflow/bpmn/TestBPMNParserGroups.java @@ -64,6 +64,9 @@ public void testSingleGroup() { /** * This test tests the resolution of multiple groups in a collaboration diagram * + * The method findAllGroups should return only the group names from the Pools + * but not the default process name. + * * @throws ParseException * @throws ParserConfigurationException * @throws SAXException @@ -85,10 +88,10 @@ public void testMultiGroups() // Test Groups Set groups = openBPMNModelManager.findAllGroups(model); - Assert.assertEquals(3, groups.size()); + Assert.assertEquals(2, groups.size()); Assert.assertTrue(groups.contains("Protokoll")); Assert.assertTrue(groups.contains("Protokollpunkt")); - Assert.assertTrue(groups.contains("Default Process")); + Assert.assertFalse(groups.contains("Default Process")); // Test tasks per group BPMNProcess process = null; @@ -107,6 +110,11 @@ public void testMultiGroups() } activities = process.getActivities(); Assert.assertEquals(4, activities.size()); + + // test the Default Group (Public Process) + BPMNProcess defaultProcess = model.openDefaultProces(); + Assert.assertEquals("Default Process", defaultProcess.getName()); + } } diff --git a/imixs-workflow-engine/src/main/java/org/imixs/workflow/engine/SetupService.java b/imixs-workflow-engine/src/main/java/org/imixs/workflow/engine/SetupService.java index 54c40559c..a74cfec64 100644 --- a/imixs-workflow-engine/src/main/java/org/imixs/workflow/engine/SetupService.java +++ b/imixs-workflow-engine/src/main/java/org/imixs/workflow/engine/SetupService.java @@ -157,7 +157,7 @@ public void startup() { logger.info("...initializing models..."); // first we scan for default models - List models = modelService.getVersions(); + List models = modelService.getModelManager().getVersions(); if (models.isEmpty() || modelDefaultDataOverwrite == true) { scanDefaultModels(); } else { @@ -179,7 +179,7 @@ public void startup() { migrateWorkflowScheduler(); // Finally start optional schedulers - logger.info("...initalizing schedulers..."); + logger.info("...initializing schedulers..."); schedulerService.startAllSchedulers(); } @@ -190,7 +190,7 @@ public void startup() { * @return */ public int getModelVersionCount() { - return modelService.getVersions().size(); + return modelService.getModelManager().getVersions().size(); } /**