Search in sources :

Example 1 with AdHocFragmentNotFoundException

use of org.jbpm.casemgmt.api.AdHocFragmentNotFoundException in project jbpm by kiegroup.

the class CaseServiceImpl method internalTriggerAdHocFragment.

protected void internalTriggerAdHocFragment(ProcessInstanceDesc pi, String fragmentName, Object data) throws CaseNotFoundException {
    CorrelationKey key = CorrelationKeyXmlAdapter.unmarshalCorrelationKey(pi.getCorrelationKey());
    String caseId = (String) key.getProperties().get(0).getValue();
    authorizationManager.checkAuthorization(caseId);
    CaseDefinition caseDef = caseRuntimeDataService.getCase(pi.getDeploymentId(), pi.getProcessId());
    List<AdHocFragment> allFragments = new ArrayList<>();
    if (caseDef.getAdHocFragments() != null) {
        allFragments.addAll(caseDef.getAdHocFragments());
    }
    caseDef.getCaseStages().forEach(stage -> {
        if (stage.getAdHocFragments() != null) {
            allFragments.addAll(stage.getAdHocFragments());
        }
    });
    allFragments.stream().filter(fragment -> fragment.getName().equals(fragmentName)).findFirst().orElseThrow(() -> new AdHocFragmentNotFoundException("AdHoc fragment '" + fragmentName + "' not found in case " + pi.getCorrelationKey()));
    processService.signalProcessInstance(pi.getId(), fragmentName, data);
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) ArrayList(java.util.ArrayList) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment)

Example 2 with AdHocFragmentNotFoundException

use of org.jbpm.casemgmt.api.AdHocFragmentNotFoundException in project jbpm by kiegroup.

the class CaseServiceImplTest method testTriggerNotExistingAdHocFragment.

@Test
public void testTriggerNotExistingAdHocFragment() {
    String expectedCaseId = "UniqueID-0000000001";
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("patient", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", data, roleAssignments);
    identityProvider.setName("mary");
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", caseFile);
    assertNotNull(caseId);
    assertEquals(expectedCaseId, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(expectedCaseId, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        identityProvider.setName("john");
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(expectedCaseId, "john", Arrays.asList(Status.Reserved), new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        identityProvider.setName("mary");
        try {
            caseService.triggerAdHocFragment(expectedCaseId, "not existing", null);
            fail("There is no ad hoc fragment with name 'not existing'");
        } catch (AdHocFragmentNotFoundException e) {
        // expected
        }
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            identityProvider.setName("mary");
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) 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) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)1 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)1 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)1 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)1 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)1 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)1 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)1 UserImpl (org.jbpm.services.task.impl.model.UserImpl)1 Test (org.junit.Test)1 QueryContext (org.kie.api.runtime.query.QueryContext)1 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)1 TaskSummary (org.kie.api.task.model.TaskSummary)1 CorrelationKey (org.kie.internal.process.CorrelationKey)1