Permalink
Browse files

JBPM-4646 - Case management - fixed and aligned case stages (#702)

  • Loading branch information...
1 parent 7140207 commit 7123a661de193d1ed4903399a54bdc8efc35e402 @mswiderski mswiderski committed on GitHub Dec 12, 2016
@@ -21,6 +21,7 @@
*/
public enum StageStatus {
+ Available,
Active,
Completed,
Canceled;
@@ -42,6 +42,7 @@
import org.jbpm.casemgmt.api.model.instance.CaseInstance;
import org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance;
import org.jbpm.casemgmt.api.model.instance.CaseStageInstance;
+import org.jbpm.casemgmt.api.model.instance.StageStatus;
import org.jbpm.casemgmt.impl.model.AdHocFragmentImpl;
import org.jbpm.casemgmt.impl.model.CaseDefinitionComparator;
import org.jbpm.casemgmt.impl.model.CaseDefinitionImpl;
@@ -473,21 +474,42 @@ public CaseDefinition getCase(String deploymentId, String caseDefinitionId) {
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) {
- Collection<Long> completedNodes = nodes.stream().filter(n -> ((NodeInstanceDesc)n).getType() == 1).map(n -> n.getId()).collect(toList());
+
filterNodes = n -> ((NodeInstanceDesc)n).getType() == 0 && !completedNodes.contains(((NodeInstanceDesc)n).getId());
} else {
filterNodes = n -> ((NodeInstanceDesc)n).getType() == 0;
}
- Collection<CaseStageInstance> stages = nodes.stream()
+ List<String> triggeredStages = new ArrayList<>();
+ Collection<CaseStageInstance> stages = new ArrayList<>();
+ nodes.stream()
.filter(filterNodes)
- .map(n -> new CaseStageInstanceImpl(n.getNodeId(), n.getName(), stagesByName.get(n.getNodeId()).getAdHocFragments(), Collections.emptyList()))
- .collect(toList());
+ .map(n -> {
+ StageStatus status = StageStatus.Active;
+ if (completedNodes.contains(((NodeInstanceDesc)n).getId())) {
+ status = StageStatus.Completed;
+ }
+ return new CaseStageInstanceImpl(n.getNodeId(), n.getName(), stagesByName.get(n.getNodeId()).getAdHocFragments(), Collections.emptyList(), 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;
}
@@ -51,6 +51,14 @@ public CaseStageInstanceImpl(String id, String name, Collection<AdHocFragment> a
this.activeNodes = activeNodes;
this.status = StageStatus.Active;
}
+
+ public CaseStageInstanceImpl(String id, String name, Collection<AdHocFragment> adHocFragments, Collection<NodeInstanceDesc> activeNodes, StageStatus status) {
+ this.id = id;
+ this.name = name;
+ this.adHocFragments = adHocFragments;
+ this.activeNodes = activeNodes;
+ this.status = status;
+ }
@Override
public String getName() {
@@ -47,6 +47,7 @@
import org.jbpm.casemgmt.api.model.instance.CaseFileInstance;
import org.jbpm.casemgmt.api.model.instance.CaseInstance;
import org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance;
+import org.jbpm.casemgmt.api.model.instance.CaseStageInstance;
import org.jbpm.casemgmt.api.model.instance.CommentInstance;
import org.jbpm.casemgmt.api.model.instance.CommentSortBy;
import org.jbpm.casemgmt.api.model.instance.MilestoneStatus;
@@ -1540,6 +1541,50 @@ public void testStartThenCancelRetrieveCaseFile() {
}
}
+ @Test
+ public void testUserTaskToCaseWithStageComplete() {
+ assertNotNull(deploymentService);
+ DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
+
+ deploymentService.deploy(deploymentUnit);
+ units.add(deploymentUnit);
+ Map<String, Object> data = new HashMap<>();
+ CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data);
+
+ String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
+ assertNotNull(caseId);
+ assertEquals(FIRST_CASE_ID, caseId);
+ try {
+ CaseInstance cInstance = caseService.getCaseInstance(caseId);
+ assertNotNull(cInstance);
+ assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
+ assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
+
+ CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID);
+ assertNotNull(caseDef);
+ assertEquals(1, caseDef.getCaseStages().size());
+ assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
+
+ Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
+ assertNotNull(activeStages);
+ assertEquals(1, activeStages.size());
+
+ caseService.addDataToCaseFile(caseId, "dataComplete", true);
+
+ activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
+ assertNotNull(activeStages);
+ assertEquals(0, activeStages.size());
+
+ } catch (Exception e) {
+ logger.error("Unexpected error {}", e.getMessage(), e);
+ fail("Unexpected exception " + e.getMessage());
+ } finally {
+ if (caseId != null) {
+ caseService.cancelCase(caseId);
+ }
+ }
+ }
+
/*
* Helper methods
*/
@@ -88,7 +88,7 @@
</bpmn2:userTask>
<bpmn2:sequenceFlow id="_59C8EAE4-4B58-4002-8236-5EBA5BB1F423" drools:selectable="true" color:background-color="#000000" color:border-color="#000000" color:color="#000000" sourceRef="_88CD21B4-11DD-41DA-8248-8D7CBC55AB27" targetRef="_D0BEE540-1820-47EB-A88C-D7374BB1562F"/>
<bpmn2:sequenceFlow id="_ADB2DD52-3A32-4D6E-AD90-72528A37DFBE" drools:selectable="true" color:background-color="#000000" color:border-color="#000000" color:color="#000000" sourceRef="_D0BEE540-1820-47EB-A88C-D7374BB1562F" targetRef="_6FED15B1-42A9-46CB-8804-73255F56D4EB"/>
- <bpmn2:completionCondition xsi:type="bpmn2:tFormalExpression" id="_jvALFlAKEeafR5ATvnlHeA"><![CDATA[return dataComplete == true;]]></bpmn2:completionCondition>
+ <bpmn2:completionCondition xsi:type="bpmn2:tFormalExpression" id="_jvALFlAKEeafR5ATvnlHeA" language="http://www.jboss.org/drools/rule"><![CDATA[org.kie.api.runtime.process.CaseData(data.get("dataComplete") == true);]]></bpmn2:completionCondition>
</bpmn2:adHocSubProcess>
<bpmn2:sequenceFlow id="_67625E63-4A05-4B40-8F4A-5823A0130242" drools:selectable="true" color:background-color="#000000" color:border-color="#000000" color:color="#000000" sourceRef="processStartEvent" targetRef="_098AE30C-D548-4082-9F62-26FED6521539"/>
<bpmn2:endEvent id="_7780E1CE-2105-4624-9A33-246862D633C7" drools:selectable="true" color:background-color="#ff6347" color:border-color="#000000" color:color="#000000" name="">
@@ -183,8 +183,8 @@ public void matchCreated(MatchCreatedEvent event) {
String milestoneName = "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getNodeId();
if (milestoneName.equals(ruleName) && checkProcessInstance((Activation) event.getMatch())) {
synchronized(getProcessInstance()) {
- removeEventListeners();
- triggerCompleted();
+ DynamicNodeInstance.this.removeEventListeners();
+ DynamicNodeInstance.this.triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE);
}
}
}

0 comments on commit 7123a66

Please sign in to comment.