use of org.jbpm.casemgmt.api.model.CaseRole 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.CaseRole in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method collectCaseRoles.
private Collection<CaseRole> collectCaseRoles(Process process) {
String roles = (String) process.getMetaData().get("customCaseRoles");
if (roles == null) {
return Collections.emptyList();
}
List<CaseRole> result = new ArrayList<CaseRole>();
String[] roleStrings = roles.split(",");
for (String roleString : roleStrings) {
String[] elements = roleString.split(":");
CaseRoleImpl role = new CaseRoleImpl(elements[0]);
result.add(role);
if (elements.length > 1) {
role.setCardinality(Integer.parseInt(elements[1]));
}
}
return result;
}
use of org.jbpm.casemgmt.api.model.CaseRole in project jbpm by kiegroup.
the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionByIdWithBoundaryEvent.
@Test
public void testGetCaseDefinitionByIdWithBoundaryEvent() {
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskCaseBoundary");
// UserTaskWithStageCase asserts
assertNotNull(caseDef);
assertEquals("UserTaskCaseBoundary", caseDef.getId());
assertEquals("Simple Case with User Tasks and Boundary", caseDef.getName());
assertEquals("1.0", caseDef.getVersion());
assertEquals("HR", caseDef.getIdentifierPrefix());
assertEquals(2, caseDef.getCaseMilestones().size());
assertEquals(0, caseDef.getCaseStages().size());
assertEquals(3, caseDef.getAdHocFragments().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
Map<String, CaseMilestone> mappedMilestones = mapMilestones(caseDef.getCaseMilestones());
assertTrue(mappedMilestones.containsKey("Milestone1"));
assertTrue(mappedMilestones.containsKey("Milestone2"));
Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseDef.getAdHocFragments());
assertTrue(mappedFragments.containsKey("Hello2"));
assertEquals("HumanTaskNode", mappedFragments.get("Hello2").getType());
assertTrue(mappedFragments.containsKey("Milestone1"));
assertEquals("MilestoneNode", mappedFragments.get("Milestone1").getType());
assertTrue(mappedFragments.containsKey("Milestone2"));
assertEquals("MilestoneNode", mappedFragments.get("Milestone2").getType());
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());
}
use of org.jbpm.casemgmt.api.model.CaseRole 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.CaseRole in project jbpm by kiegroup.
the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionById.
@Test
public void testGetCaseDefinitionById() {
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskWithStageCase");
// UserTaskWithStageCase asserts
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());
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());
}
Aggregations