Search in sources :

Example 1 with CaseNotFoundException

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;
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment)

Example 2 with CaseNotFoundException

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));
}
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 3 with CaseNotFoundException

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

Example 4 with CaseNotFoundException

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);
    }
}
Also used : CaseService(org.jbpm.casemgmt.api.CaseService) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Example 5 with CaseNotFoundException

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
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Aggregations

CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)14 HashMap (java.util.HashMap)6 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)6 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)6 List (java.util.List)5 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)4 QueryContext (org.kie.api.runtime.query.QueryContext)4 Collectors.toList (java.util.stream.Collectors.toList)3 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)3 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)3 CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)3 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 KieInternalServices (org.kie.internal.KieInternalServices)3 IdentityProvider (org.kie.internal.identity.IdentityProvider)3 CorrelationKey (org.kie.internal.process.CorrelationKey)3 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)3