use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class StageCompletionConditionTest method testAutoCompleteNoAutoStartTaskNotExistingAdHocInStage.
@Test
public void testAutoCompleteNoAutoStartTaskNotExistingAdHocInStage() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
Collection<CaseStage> stages = caseDef.getCaseStages();
assertThat(stages).hasSize(1);
String stageId = stages.iterator().next().getId();
assertThatExceptionOfType(AdHocFragmentNotFoundException.class).isThrownBy(() -> {
caseService.triggerAdHocFragment(caseId, stageId, "not existing", null);
}).withMessageContaining("AdHoc fragment 'not existing' not found in case " + caseId + " and stage " + stageId);
assertCaseInstanceActive(caseId);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(0);
caseService.cancelCase(caseId);
assertCaseInstanceNotActive(caseId);
}
use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method getCaseInstanceStages.
@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);
}
use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method getCaseInstanceMilestones.
@Override
public Collection<CaseMilestoneInstance> getCaseInstanceMilestones(String caseId, boolean achievedOnly, 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");
}
CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
Collection<org.jbpm.services.api.model.NodeInstanceDesc> nodes = runtimeDataService.getNodeInstancesByCorrelationKeyNodeType(correlationKey, Arrays.asList(ProcessInstance.STATE_ACTIVE), Arrays.asList("MilestoneNode"), queryContext);
Collection<Long> completedNodes = nodes.stream().filter(n -> ((NodeInstanceDesc) n).getType() == 1).map(n -> n.getId()).collect(toList());
Predicate<org.jbpm.services.api.model.NodeInstanceDesc> filterNodes = null;
if (achievedOnly) {
filterNodes = n -> ((NodeInstanceDesc) n).getType() == 1;
} else {
filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0;
}
List<String> foundMilestones = new ArrayList<>();
List<CaseMilestoneInstance> milestones = nodes.stream().filter(filterNodes).map(n -> {
foundMilestones.add(n.getName());
return new CaseMilestoneInstanceImpl(String.valueOf(n.getId()), n.getName(), completedNodes.contains(n.getId()), n.getDataTimeStamp());
}).collect(toList());
if (!achievedOnly) {
// add other milestones that are present in the definition
CaseDefinition caseDef = getCase(pi.getDeploymentId(), pi.getProcessId());
caseDef.getCaseMilestones().stream().filter(cm -> !foundMilestones.contains(cm.getName())).map(cm -> new CaseMilestoneInstanceImpl(cm.getId(), cm.getName(), false, null)).forEach(cmi -> milestones.add(cmi));
}
return applyPagination(milestones, queryContext);
}
use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseServiceImpl method newCaseFileInstanceWithRestrictions.
@Override
public CaseFileInstance newCaseFileInstanceWithRestrictions(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, List<String>> accessRestrictions) {
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());
Map<String, List<String>> combinedAccessRestrictions = def.getDataAccessRestrictions();
if (accessRestrictions != null) {
combinedAccessRestrictions.putAll(accessRestrictions);
}
caseFile.setAccessRestrictions(combinedAccessRestrictions);
return caseFile;
}
use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.
the class CaseServiceImpl method newCaseFileInstanceWithRestrictions.
@Override
public CaseFileInstance newCaseFileInstanceWithRestrictions(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, OrganizationalEntity> rolesAssignment, Map<String, List<String>> accessRestrictions) {
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());
Map<String, List<String>> combinedAccessRestrictions = def.getDataAccessRestrictions();
if (accessRestrictions != null) {
combinedAccessRestrictions.putAll(accessRestrictions);
}
caseFile.setAccessRestrictions(combinedAccessRestrictions);
rolesAssignment.entrySet().stream().forEach(entry -> caseFile.assign(entry.getKey(), entry.getValue()));
return caseFile;
}
Aggregations