use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.
the class CaseManagementServiceBase method startCase.
public String startCase(String containerId, String caseDefinitionId, String payload, String marshallingType) {
containerId = context.getContainerId(containerId, ContainerLocatorProvider.get().getLocator());
CaseDefinition caseDef = caseRuntimeDataService.getCase(containerId, caseDefinitionId);
if (caseDef == null) {
throw new CaseDefinitionNotFoundException("Unable to find case '" + caseDefinitionId + "' in container " + containerId);
}
logger.debug("About to unmarshal case file from payload: '{}'", payload);
CaseFile caseFile = marshallerHelper.unmarshal(containerId, payload, marshallingType, CaseFile.class);
String caseId;
if (caseFile == null) {
logger.debug("Case file not given, starting case without case file");
caseId = caseService.startCase(containerId, caseDefinitionId);
} else {
logger.debug("Case file provided {}", caseFile);
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
if (caseFile.getUserAssignments() != null) {
caseFile.getUserAssignments().entrySet().stream().filter(entry -> entry.getValue() != null && !entry.getValue().isEmpty()).forEach(entry -> roleAssignments.put(entry.getKey(), taskModelFactory.newUser(entry.getValue())));
}
if (caseFile.getGroupAssignments() != null) {
caseFile.getGroupAssignments().entrySet().stream().filter(entry -> entry.getValue() != null && !entry.getValue().isEmpty()).forEach(entry -> roleAssignments.put(entry.getKey(), taskModelFactory.newGroup(entry.getValue())));
}
Map<String, List<String>> accessRestrictions = null;
if (caseFile.getAccessRestrictions() != null) {
accessRestrictions = new HashMap<>();
for (Entry<String, String[]> entry : caseFile.getAccessRestrictions().entrySet()) {
accessRestrictions.put(entry.getKey(), Arrays.asList(entry.getValue()));
}
}
CaseFileInstance caseFileInstance = caseService.newCaseFileInstanceWithRestrictions(containerId, caseDefinitionId, caseFile.getData(), roleAssignments, accessRestrictions);
caseId = caseService.startCase(containerId, caseDefinitionId, caseFileInstance);
}
logger.debug("New case instance started with case id {} for case definition {}", caseId, caseDefinitionId);
// return response
return marshallerHelper.marshal(containerId, marshallingType, caseId);
}
use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.
the class CaseRuntimeDataServiceIntegrationTest method testFindCaseTasksAssignedAsBusinessAdminByPassAuth.
@Test
public void testFindCaseTasksAssignedAsBusinessAdminByPassAuth() throws Exception {
CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_OWNER_ROLE, USER_YODA).addUserAssignments(CASE_CONTACT_ROLE, USER_JOHN).addGroupAssignments(CASE_PARTICIPANT_ROLE, CASE_ADMIN_GROUP).build();
String caseId = startUserTaskCase(caseFile);
assertNotNull(caseId);
assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
assertTaskListAsBusinessAdmin(caseId, USER_YODA, USER_YODA);
caseClient.destroyCaseInstance(CONTAINER_ID, caseId);
caseId = startUserTaskCase(caseFile);
assertNotNull(caseId);
assertTrue(caseId.startsWith(CASE_HR_ID_PREFIX));
assertTaskListAsBusinessAdmin(caseId, USER_YODA, USER_ADMINISTRATOR);
changeUser(USER_YODA);
caseClient.destroyCaseInstance(CONTAINER_ID, caseId);
}
use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.
the class CaseRuntimeDataServiceIntegrationTest method testAddDynamicProcessToCaseNotExistingProcessDefinition.
@Test
public void testAddDynamicProcessToCaseNotExistingProcessDefinition() {
String invalidProcessId = "not-existing-process-id";
Map<String, Object> data = new HashMap<>();
data.put("s", "first case started");
CaseFile caseFile = CaseFile.builder().data(data).addUserAssignments(CASE_INSURED_ROLE, USER_YODA).addUserAssignments(CASE_INS_REP_ROLE, USER_JOHN).build();
String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
assertNotNull(caseId);
assertClientException(() -> caseClient.addDynamicSubProcess(CONTAINER_ID, caseId, invalidProcessId, null), 404, "Could not find process definition \"" + invalidProcessId + "\" in container \"" + CONTAINER_ID + "\"", "No process definition found with id: " + invalidProcessId);
}
use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.
the class CaseSLAComplianceIntegrationTest method testStartCaseWithSLAEscalation.
@Test
public void testStartCaseWithSLAEscalation() throws Exception {
Map<String, Object> data = new HashMap<>();
data.put("s", "with SLA");
CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_SLA_OWNER_ROLE, USER_JOHN).addUserAssignments(CASE_SLA_ADMIN_ROLE, USER_MARY).data(data).build();
changeUser(USER_JOHN);
String caseId = caseClient.startCase(CONTAINER_ID, SLA_CASE_DEF_ID, caseFile);
CaseInstance caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
List<org.kie.server.api.model.instance.ProcessInstance> instances = caseClient.getActiveProcessInstances(CONTAINER_ID, caseId, 0, 10);
assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
assertThat(caseInstance.getCaseDefinitionId()).isEqualTo(SLA_CASE_DEF_ID);
assertThat(caseInstance.getContainerId()).isEqualTo(CONTAINER_ID);
assertThat(caseInstance.getCaseDescription()).isEqualTo("Case with SLA");
assertThat(caseInstance.getSlaCompliance()).isEqualTo(ProcessInstance.SLA_PENDING);
assertThat(caseInstance.getSlaDueDate()).isCloseTo(new Date(), 30_000L);
List<TaskSummary> johnTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_JOHN, 0, 10);
TaskSummary johnTask = johnTasks.get(0);
assertThat(johnTasks).hasSize(1);
assertThat(johnTask.getName()).isEqualTo("Hello1");
assertThat(johnTask.getProcessType()).isEqualTo(WorkflowProcess.CASE_TYPE);
AbstractStringAssert<?> corKeyAssert = assertThat(johnTask.getCorrelationKey());
if (!instances.isEmpty()) {
corKeyAssert.isEqualTo(instances.get(0).getCorrelationKey());
} else {
corKeyAssert.isNull();
}
changeUser(USER_MARY);
List<TaskSummary> maryTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_MARY, 0, 10);
// No SLA escalation tasks for Mary yet
assertThat(maryTasks).isEmpty();
Long caseProcessInstanceId = johnTask.getProcessInstanceId();
// Wait for SLA to expire
KieServerSynchronization.waitForProcessInstanceSLAViolated(queryClient, caseProcessInstanceId, 8_000L);
caseInstance = caseClient.getCaseInstance(CONTAINER_ID, caseId);
assertThat(caseInstance.getCaseId()).isEqualTo(caseId);
assertThat(caseInstance.getSlaCompliance()).isEqualTo(ProcessInstance.SLA_VIOLATED);
assertThat(caseInstance.getSlaDueDate()).isCloseTo(new Date(), 30_000L);
maryTasks = taskClient.findTasksAssignedAsPotentialOwner(USER_MARY, 0, 10);
// SLA Escalation task for Mary should be created
assertThat(maryTasks).hasSize(1);
TaskSummary escalationTask = maryTasks.get(0);
assertThat(escalationTask.getName()).isEqualTo("SLA violation for case " + caseId);
assertThat(escalationTask.getDescription()).isEqualTo("Service Level Agreement has been violated for case " + caseId);
}
use of org.kie.server.api.model.cases.CaseFile in project droolsjbpm-integration by kiegroup.
the class CarInsuranceClaimCaseIntegrationTest method startCarInsuranceClaimCase.
private String startCarInsuranceClaimCase(String insured, String insuranceRep) {
CaseFile caseFile = CaseFile.builder().addUserAssignments(CASE_INSURED_ROLE, insured).addUserAssignments(CASE_INS_REP_ROLE, insuranceRep).addUserAssignments(CASE_INS_ASSESSOR_ROLE, insuranceRep).build();
String caseId = caseClient.startCase(CONTAINER_ID, CLAIM_CASE_DEF_ID, caseFile);
assertNotNull(caseId);
return caseId;
}
Aggregations