CaseRuntimeDataServiceImpl implements CaseRuntimeDataService, DeploymentEventListener { @Override public Collection<CaseStageInstance> getCaseInstanceStages(String caseId, boolean activeOnly, QueryContext queryContext) { ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceByCorrelationKey(correlationKeyFactory.newCorrelationKey(caseId)); if (pi == null || !pi.getState().equals(ProcessInstance.STATE_ACTIVE)) { throw new CaseNotFoundException("No case instance found with id " + caseId + " or it's not active anymore"); } CaseDefinition caseDef = getCase(pi.getDeploymentId(), pi.getProcessId()); List<CaseStageInstance> stages = internalGetCaseStages(caseDef, caseId, activeOnly, queryContext); return applyPagination(stages, queryContext); } CaseRuntimeDataServiceImpl(); CaseIdGenerator getCaseIdGenerator(); void setCaseIdGenerator(CaseIdGenerator caseIdGenerator); void setRuntimeDataService(RuntimeDataService runtimeDataService); void setCaseService(CaseService caseService); void setCommandService(TransactionalCommandService commandService); void setIdentityProvider(IdentityProvider identityProvider); void setDeploymentRolesManager(DeploymentRolesManager deploymentRolesManager); @Override void onDeploy(DeploymentEvent event); @Override void onUnDeploy(DeploymentEvent event); @Override void onActivate(DeploymentEvent event); @Override void onDeactivate(DeploymentEvent event); @Override CaseDefinition getCase(String deploymentId, String caseDefinitionId); @Override Collection<CaseDefinition> getCases(QueryContext queryContext); @Override Collection<CaseDefinition> getCases(String filter, QueryContext queryContext); @Override Collection<CaseDefinition> getCasesByDeployment(String deploymentId, QueryContext queryContext); @Override Collection<ProcessDefinition> getProcessDefinitions(QueryContext queryContext); @Override Collection<ProcessDefinition> getProcessDefinitions(String filter, QueryContext queryContext); @Override Collection<ProcessDefinition> getProcessDefinitionsByDeployment(String deploymentId, QueryContext queryContext); @Override Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId, QueryContext queryContext); @Override Collection<ProcessInstanceDesc> getProcessInstancesForCase(String caseId, List<Integer> processStates, QueryContext queryContext); @Override Collection<CaseMilestoneInstance> getCaseInstanceMilestones(String caseId, boolean achievedOnly, QueryContext queryContext); @Override Collection<CaseStageInstance> getCaseInstanceStages(String caseId, boolean activeOnly, QueryContext queryContext); @Override Collection<org.jbpm.services.api.model.NodeInstanceDesc> getActiveNodesForCase(String caseId, QueryContext queryContext); @Override Collection<org.jbpm.services.api.model.NodeInstanceDesc> getCompletedNodesForCase(String caseId, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstances(QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstances(boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstances(List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstances(List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getSubCaseInstancesByParentCaseId(String parentCaseId, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getAllDescendantSubCaseInstancesByParentCaseId(String parentCaseId, List<CaseStatus> statuses); @Override Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDeployment(String deploymentId, List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDefinition(String definitionId, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDefinition(String definitionId, List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesOwnedBy(String owner, List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByRole(String roleName, List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesAnyRole(List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesAnyRole(List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDataItem(String dataItemName, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDataItem(String dataItemName, List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDataItemAndValue(String dataItemName, String dataItemValue, List<CaseStatus> statuses, QueryContext queryContext); @Override Collection<CaseInstance> getCaseInstancesByDataItemAndValue(String dataItemName, String dataItemValue, List<CaseStatus> statuses, boolean withData, QueryContext queryContext); @Override CaseInstance getCaseInstanceById(String caseId); @Override Collection<AdHocFragment> getAdHocFragmentsForCase(String caseId); @Override List<TaskSummary> getCaseTasksAssignedAsPotentialOwner(String caseId, String userId, List<Status> status, QueryContext queryContext); @Override List<TaskSummary> getCaseTasksAssignedAsBusinessAdmin(String caseId, String userId, List<Status> status, QueryContext queryContext); @Override List<TaskSummary> getCaseTasksAssignedAsStakeholder(String caseId, String userId, List<Status> status, QueryContext queryContext); List<CaseStageInstance> internalGetCaseStages(CaseDefinition caseDef, String caseId, boolean activeOnly, QueryContext queryContext); @Override Collection<CaseFileItem> getCaseInstanceDataItems(String caseId, QueryContext queryContext); @Override Collection<CaseFileItem> getCaseInstanceDataItemsByName(String caseId, List<String> names, QueryContext queryContext); @Override Collection<CaseFileItem> getCaseInstanceDataItemsByType(String caseId, List<String> types, QueryContext queryContext);  }
@Test public void testTransitionBetweenStagesInCaseWithActiveElements() { Map<String, OrganizationalEntity> roleAssignments = new HashMap<>(); roleAssignments.put("owner", new UserImpl(USER)); Map<String, Object> data = new HashMap<>(); CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments); String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile); assertNotNull(caseId); try { Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1)); assertNotNull(stage); assertEquals(1, stage.size()); CaseStageInstance stageInstance = stage.iterator().next(); assertEquals("Stage One", stageInstance.getName()); assertEquals(StageStatus.Active, stageInstance.getStatus()); Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes(); assertNotNull(activeNodes); assertEquals(0, activeNodes.size()); caseService.triggerAdHocFragment(caseId, "Task 1", data); stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1)); assertNotNull(stage); assertEquals(1, stage.size()); stageInstance = stage.iterator().next(); assertEquals("Stage One", stageInstance.getName()); assertEquals(StageStatus.Active, stageInstance.getStatus()); activeNodes = stageInstance.getActiveNodes(); assertNotNull(activeNodes); assertEquals(1, activeNodes.size()); assertEquals("Task 1", activeNodes.iterator().next().getName()); caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease"); stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1)); assertNotNull(stage); assertEquals(1, stage.size()); assertEquals("Stage Two", stage.iterator().next().getName()); assertEquals(StageStatus.Active, stage.iterator().next().getStatus()); stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1)); assertNotNull(stage); assertEquals(1, stage.size()); stageInstance = stage.iterator().next(); assertEquals("Stage Two", stageInstance.getName()); assertEquals(StageStatus.Active, stageInstance.getStatus()); activeNodes = stageInstance.getActiveNodes(); assertNotNull(activeNodes); assertEquals(0, activeNodes.size()); caseService.triggerAdHocFragment(caseId, "Task 2", data); stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1)); assertNotNull(stage); assertEquals(1, stage.size()); stageInstance = stage.iterator().next(); assertEquals("Stage Two", stageInstance.getName()); assertEquals(StageStatus.Active, stageInstance.getStatus()); activeNodes = stageInstance.getActiveNodes(); assertNotNull(activeNodes); assertEquals(1, activeNodes.size()); assertEquals("Task 2", activeNodes.iterator().next().getName()); } catch (Exception e) { logger.error("Unexpected error {}", e.getMessage(), e); fail("Unexpected exception " + e.getMessage()); } finally { if (caseId != null) { caseService.cancelCase(caseId); } } }