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);
}
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);
}
}
}
Aggregations