use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method getAdHocFragmentsForCase.
@Override
public Collection<AdHocFragment> getAdHocFragmentsForCase(String caseId) {
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<AdHocFragment> adHocFragments = new ArrayList<>();
adHocFragments.addAll(caseDef.getAdHocFragments());
Collection<CaseStageInstance> activeStages = internalGetCaseStages(caseDef, caseId, true, new QueryContext(0, 100));
activeStages.forEach(stage -> adHocFragments.addAll(stage.getAdHocFragments()));
return adHocFragments;
}
use of org.jbpm.casemgmt.api.model.CaseDefinition 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.CaseDefinition in project jbpm by kiegroup.
the class CaseServiceImpl method internalTriggerAdHocFragment.
protected void internalTriggerAdHocFragment(ProcessInstanceDesc pi, String fragmentName, Object data) throws CaseNotFoundException {
CorrelationKey key = CorrelationKeyXmlAdapter.unmarshalCorrelationKey(pi.getCorrelationKey());
String caseId = (String) key.getProperties().get(0).getValue();
authorizationManager.checkAuthorization(caseId);
CaseDefinition caseDef = caseRuntimeDataService.getCase(pi.getDeploymentId(), pi.getProcessId());
List<AdHocFragment> allFragments = new ArrayList<>();
if (caseDef.getAdHocFragments() != null) {
allFragments.addAll(caseDef.getAdHocFragments());
}
caseDef.getCaseStages().forEach(stage -> {
if (stage.getAdHocFragments() != null) {
allFragments.addAll(stage.getAdHocFragments());
}
});
allFragments.stream().filter(fragment -> fragment.getName().equals(fragmentName)).findFirst().orElseThrow(() -> new AdHocFragmentNotFoundException("AdHoc fragment '" + fragmentName + "' not found in case " + pi.getCorrelationKey()));
processService.signalProcessInstance(pi.getId(), fragmentName, data);
}
use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseServiceImpl method newCaseFileInstance.
/*
* new instances methods
*/
@Override
public CaseFileInstance newCaseFileInstance(String deploymentId, String caseDefinition, Map<String, Object> data) {
CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
if (def == null) {
throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
}
CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
caseFile.setupRoles(def.getCaseRoles());
caseFile.setAccessRestrictions(def.getDataAccessRestrictions());
return caseFile;
}
use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionsSorted.
@Test
public void testGetCaseDefinitionsSorted() {
Collection<CaseDefinition> cases = caseRuntimeDataService.getCases(new QueryContext(0, 1, SORT_BY_CASE_DEFINITION_NAME, true));
assertNotNull(cases);
assertEquals(1, cases.size());
assertEquals("CaseWithTwoStages", cases.iterator().next().getId());
cases = caseRuntimeDataService.getCases(new QueryContext(1, 1, SORT_BY_CASE_DEFINITION_NAME, true));
assertNotNull(cases);
assertEquals(1, cases.size());
assertEquals("EmptyCase", cases.iterator().next().getId());
cases = caseRuntimeDataService.getCases(new QueryContext(2, 1, SORT_BY_CASE_DEFINITION_NAME, true));
assertNotNull(cases);
assertEquals(1, cases.size());
assertEquals("UserTaskCase", cases.iterator().next().getId());
cases = caseRuntimeDataService.getCases(new QueryContext(SORT_BY_CASE_DEFINITION_NAME, false));
assertNotNull(cases);
assertEquals(5, cases.size());
List<CaseDefinition> sortedCases = new ArrayList<>(cases);
assertEquals("UserTaskWithStageCase", sortedCases.get(0).getId());
assertEquals("UserTaskCaseBoundary", sortedCases.get(1).getId());
assertEquals("UserTaskCase", sortedCases.get(2).getId());
assertEquals("EmptyCase", sortedCases.get(3).getId());
}
Aggregations