use of org.jbpm.casemgmt.api.model.CaseStage in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method onDeploy.
/*
* Deploy and undeploy handling
*/
@Override
public void onDeploy(DeploymentEvent event) {
AbstractRuntimeManager runtimeManager = (AbstractRuntimeManager) event.getDeployedUnit().getRuntimeManager();
KieBase kieBase = runtimeManager.getEnvironment().getKieBase();
Collection<Process> processes = kieBase.getProcesses();
Map<String, DeployedAsset> mapProcessById = event.getDeployedUnit().getDeployedAssets().stream().collect(toMap(DeployedAsset::getId, asset -> asset));
for (Process process : processes) {
if (((WorkflowProcess) process).isDynamic()) {
String caseIdPrefix = collectCaseIdPrefix(process);
Collection<CaseMilestone> caseMilestones = collectMilestoness(process);
Collection<CaseStage> caseStages = collectCaseStages(event.getDeploymentId(), process.getId(), ((WorkflowProcess) process));
Collection<CaseRole> caseRoles = collectCaseRoles(process);
Collection<AdHocFragment> adHocFragments = collectAdHocFragments((WorkflowProcess) process);
Map<String, List<String>> dataAccessRestrictions = collectDataAccessRestrictions(process);
CaseDefinitionImpl caseDef = new CaseDefinitionImpl((ProcessAssetDesc) mapProcessById.get(process.getId()), caseIdPrefix, caseStages, caseMilestones, caseRoles, adHocFragments, dataAccessRestrictions);
availableCases.add(caseDef);
caseIdGenerator.register(caseIdPrefix);
}
}
// collect role information
Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
List<String> roles = null;
for (DeployedAsset asset : assets) {
if (asset instanceof ProcessAssetDesc) {
// if it's not dynamic it's considered as not case definition
if (!((ProcessAssetDesc) asset).isDynamic()) {
availableProcesses.add((ProcessAssetDesc) asset);
}
if (roles == null) {
roles = ((ProcessAssetDesc) asset).getRoles();
}
}
}
if (roles == null) {
roles = Collections.emptyList();
}
deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);
}
use of org.jbpm.casemgmt.api.model.CaseStage 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;
}
use of org.jbpm.casemgmt.api.model.CaseStage 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;
}
use of org.jbpm.casemgmt.api.model.CaseStage in project jbpm by kiegroup.
the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitions.
@Test
public void testGetCaseDefinitions() {
Collection<CaseDefinition> cases = caseRuntimeDataService.getCases(new QueryContext());
assertNotNull(cases);
assertEquals(5, cases.size());
Map<String, CaseDefinition> mappedCases = mapCases(cases);
assertTrue(mappedCases.containsKey("EmptyCase"));
assertTrue(mappedCases.containsKey("UserTaskCase"));
assertTrue(mappedCases.containsKey("UserTaskCaseBoundary"));
assertTrue(mappedCases.containsKey("UserTaskWithStageCase"));
// EmptyCase asserts
CaseDefinition caseDef = mappedCases.get("EmptyCase");
assertNotNull(caseDef);
assertEquals("EmptyCase", caseDef.getId());
assertEquals("New Case", caseDef.getName());
assertEquals("", caseDef.getVersion());
assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
assertNotNull(caseDef.getCaseMilestones());
assertTrue(caseDef.getCaseMilestones().isEmpty());
assertNotNull(caseDef.getCaseStages());
assertTrue(caseDef.getCaseStages().isEmpty());
assertNotNull(caseDef.getCaseRoles());
assertTrue(caseDef.getCaseRoles().isEmpty());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
// UserTaskCase asserts
caseDef = mappedCases.get("UserTaskCase");
assertNotNull(caseDef);
assertEquals("UserTaskCase", caseDef.getId());
assertEquals("Simple Case with User Tasks", caseDef.getName());
assertEquals("1.0", caseDef.getVersion());
assertEquals("HR", caseDef.getIdentifierPrefix());
assertNotNull(caseDef.getCaseMilestones());
assertEquals(2, caseDef.getCaseMilestones().size());
Map<String, CaseMilestone> mappedMilestones = mapMilestones(caseDef.getCaseMilestones());
assertTrue(mappedMilestones.containsKey("Milestone1"));
assertTrue(mappedMilestones.containsKey("Milestone2"));
CaseMilestone milestone = mappedMilestones.get("Milestone1");
assertEquals("_SomeID4", milestone.getId());
assertEquals("Milestone1", milestone.getName());
assertEquals("", milestone.getAchievementCondition());
assertEquals(false, milestone.isMandatory());
milestone = mappedMilestones.get("Milestone2");
assertEquals("_5", milestone.getId());
assertEquals("Milestone2", milestone.getName());
assertEquals("org.kie.api.runtime.process.CaseData(data.get(\"dataComplete\") == true)", milestone.getAchievementCondition());
assertEquals(false, milestone.isMandatory());
assertNotNull(caseDef.getCaseStages());
assertEquals(0, caseDef.getCaseStages().size());
assertNotNull(caseDef.getCaseRoles());
assertEquals(3, caseDef.getCaseRoles().size());
Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
assertTrue(mappedRoles.containsKey("owner"));
assertTrue(mappedRoles.containsKey("contact"));
assertTrue(mappedRoles.containsKey("participant"));
assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
// UserTaskWithStageCase asserts
caseDef = mappedCases.get("UserTaskWithStageCase");
assertNotNull(caseDef);
assertEquals("UserTaskWithStageCase", caseDef.getId());
assertEquals("UserTaskWithStageCase", caseDef.getName());
assertEquals("1.0", caseDef.getVersion());
assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
assertNotNull(caseDef.getCaseMilestones());
assertEquals(0, caseDef.getCaseMilestones().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
assertNotNull(caseDef.getCaseStages());
assertEquals(1, caseDef.getCaseStages().size());
Map<String, CaseStage> mappedStages = mapStages(caseDef.getCaseStages());
assertTrue(mappedStages.containsKey("Collect input"));
CaseStage caseStage = mappedStages.get("Collect input");
assertNotNull(caseStage);
assertEquals("Collect input", caseStage.getName());
assertEquals(2, caseStage.getAdHocFragments().size());
Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseStage.getAdHocFragments());
assertTrue(mappedFragments.containsKey("Missing data"));
assertEquals("HumanTaskNode", mappedFragments.get("Missing data").getType());
assertTrue(mappedFragments.containsKey("Verification of data"));
assertEquals("SubProcessNode", mappedFragments.get("Verification of data").getType());
assertNotNull(caseDef.getCaseRoles());
assertEquals(3, caseDef.getCaseRoles().size());
mappedRoles = mapRoles(caseDef.getCaseRoles());
assertTrue(mappedRoles.containsKey("owner"));
assertTrue(mappedRoles.containsKey("contact"));
assertTrue(mappedRoles.containsKey("participant"));
assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
use of org.jbpm.casemgmt.api.model.CaseStage in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddDynamicSubprocessToNotActiveStage.
@Test
public void testAddDynamicSubprocessToNotActiveStage() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseDefinition caseDefinition = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
assertThat(caseDefinition).isNotNull();
assertThat(caseDefinition.getCaseStages()).hasSize(2);
Iterator<CaseStage> caseStageIterator = caseDefinition.getCaseStages().iterator();
caseStageIterator.next();
String stageId = caseStageIterator.next().getId();
assertThatThrownBy(() -> caseService.addDynamicSubprocessToStage(caseId, stageId, SUBPROCESS, Collections.emptyMap())).isInstanceOf(StageNotFoundException.class);
}
Aggregations