Search in sources :

Example 1 with CaseActiveException

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));
}
Also used : HashMap(java.util.HashMap) ReopenCaseCommand(org.jbpm.casemgmt.impl.command.ReopenCaseCommand) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) List(java.util.List) ArrayList(java.util.ArrayList) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException)

Example 2 with CaseActiveException

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);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)2 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)1 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)1 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)1 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)1 ReopenCaseCommand (org.jbpm.casemgmt.impl.command.ReopenCaseCommand)1 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)1 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)1 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)1 Test (org.junit.Test)1