use of org.jbpm.casemgmt.api.CaseActiveException 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.CaseActiveException in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenReopenActiveCase.
@Test
public void testStartThenReopenActiveCase() {
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());
try {
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
fail("Not allowed to reopen active case");
} catch (CaseActiveException e) {
// expected
}
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations