use of org.jbpm.casemgmt.api.CaseNotFoundException 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.CaseNotFoundException in project jbpm by kiegroup.
the class CaseServiceImpl method reopenCase.
@Override
public void reopenCase(String caseId, String deploymentId, String caseDefinitionId, Map<String, Object> data) throws CaseNotFoundException {
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.REOPEN_CASE);
ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceByCorrelationKey(correlationKeyFactory.newCorrelationKey(caseId));
if (pi != null) {
throw new CaseActiveException("Case with id " + caseId + " is still active and cannot be reopened");
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("caseId", caseId);
params.put("maxResults", 1);
List<Long> caseIdMapping = commandService.execute(new QueryNameCommand<List<Long>>("findCaseIdContextMapping", params));
if (caseIdMapping.isEmpty()) {
throw new CaseNotFoundException("Case with id " + caseId + " was not found");
}
logger.debug("About to reopen case {} by starting process instance {} from deployment {} with additional data {}", caseId, caseDefinitionId, deploymentId, data);
processService.execute(deploymentId, CaseContext.get(caseId), new ReopenCaseCommand(identityProvider, caseId, deploymentId, caseDefinitionId, data, processService));
}
use of org.jbpm.casemgmt.api.CaseNotFoundException in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenCancelRetrieveCaseFile.
@Test
public void testStartThenCancelRetrieveCaseFile() {
try {
caseService.getCaseFileInstance(FIRST_CASE_ID);
fail("There is no case yet started");
} catch (CaseNotFoundException e) {
// expected
}
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("my first case", cInstance.getCaseDescription());
CaseFileInstance caseFileFromCase = caseService.getCaseFileInstance(FIRST_CASE_ID);
assertNotNull(caseFileFromCase);
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseFileFromCase = caseService.getCaseFileInstance(FIRST_CASE_ID);
assertNotNull(caseFileFromCase);
caseService.destroyCase(caseId);
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
caseId = null;
try {
caseService.getCaseFileInstance(FIRST_CASE_ID);
fail("There is no case yet started");
} catch (CaseNotFoundException e) {
// expected
}
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.CaseNotFoundException in project jbpm by kiegroup.
the class StartCaseWorkItemHandler method abortWorkItem.
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
String caseId = (String) workItem.getParameter(CASE_ID);
boolean destroy = true;
if (workItem.getParameter(DESTROY_ON_ABORT) != null) {
destroy = Boolean.parseBoolean((String) workItem.getParameter(DESTROY_ON_ABORT));
}
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
try {
if (destroy) {
logger.debug("Case {} is going to be destroyed", caseId);
caseService.destroyCase(caseId);
} else {
logger.debug("Case {} is going to be canceled", caseId);
caseService.cancelCase(caseId);
}
} catch (CaseNotFoundException e) {
logger.warn("Case instance {} was not found", caseId);
} catch (Exception e) {
logger.error("Unexpected error during canceling case instance {}", caseId, e);
}
}
use of org.jbpm.casemgmt.api.CaseNotFoundException in project jbpm by kiegroup.
the class AbstractCaseServicesBaseTest method assertCaseInstanceNotActive.
public void assertCaseInstanceNotActive(String caseId) {
try {
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
} catch (CaseNotFoundException ex) {
// in case it does not exist at all
}
}
Aggregations