use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class NotifyParentCaseEventListener method getCaseFile.
protected CaseFileInstance getCaseFile(KieSession ksession) {
Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
if (caseFiles.size() == 0) {
return null;
}
CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
return caseFile;
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class AuthorizationManagerImpl method checkCommentAuthorization.
@Override
public void checkCommentAuthorization(String caseId, CaseFileInstance caseFileInstance, CommentInstance commentInstance) {
CommentInstanceImpl comment = ((CommentInstanceImpl) commentInstance);
if (comment.getRestrictedTo() == null || comment.getRestrictedTo().isEmpty()) {
return;
}
List<String> callerAuthorization = collectUserAuthInfo();
logger.debug("Caller {} authorization set is {}", identityProvider.getName(), callerAuthorization);
List<String> callerCaseRoles = getCallerRoles(caseFileInstance, callerAuthorization);
logger.debug("Caller {} case role set is {}", identityProvider.getName(), callerCaseRoles);
List<String> requiredRoles = comment.getRestrictedTo();
if (requiredRoles.isEmpty() || requiredRoles.stream().anyMatch(role -> callerCaseRoles.contains(role))) {
logger.debug("Caller has access to comment {}", comment.getId());
return;
}
logger.warn("User {} does not have access to comment {} in case {}, required roles are {} and user has {}", identityProvider.getName(), comment.getId(), caseId, requiredRoles, callerCaseRoles);
throw new SecurityException(MessageFormat.format(NO_AUTH_TO_COMMENT, identityProvider.getName(), comment.getId(), caseId));
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class AuthorizationManagerImpl method filterByCommentAuthorization.
@Override
public List<CommentInstance> filterByCommentAuthorization(String caseId, CaseFileInstance caseFileInstance, List<CommentInstance> comments) {
if (comments == null || comments.isEmpty()) {
logger.debug("No comments to be filtered");
return comments;
}
List<String> callerAuthorization = collectUserAuthInfo();
logger.debug("Caller {} authorization set is {}", identityProvider.getName(), callerAuthorization);
List<String> callerCaseRoles = getCallerRoles(caseFileInstance, callerAuthorization);
logger.debug("Caller {} case role set is {}", identityProvider.getName(), callerCaseRoles);
List<CommentInstance> filteredComments = new ArrayList<>(comments);
for (CommentInstance commentInstance : comments) {
CommentInstanceImpl comment = ((CommentInstanceImpl) commentInstance);
List<String> requiredRoles = comment.getRestrictedTo();
if (requiredRoles == null || requiredRoles.isEmpty()) {
continue;
}
if (requiredRoles.isEmpty() || requiredRoles.stream().anyMatch(role -> callerCaseRoles.contains(role))) {
logger.debug("Caller {} has access to comment {}", identityProvider.getName(), comment.getId());
continue;
}
logger.debug("Caller {} does not have access to comment {}", identityProvider.getName(), comment.getId());
filteredComments.remove(comment);
}
return filteredComments;
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testAddSubprocessToEmptyCaseCheckCaseNodes.
@Test
public void testAddSubprocessToEmptyCaseCheckCaseNodes() {
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(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
Collection<NodeInstanceDesc> completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(0, completedNodes.size());
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocess(caseId, "UserTask", parameters);
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(2, activeNodes.size());
Map<String, NodeInstanceDesc> mappedNodes = mapNodeInstances(activeNodes);
assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(0, completedNodes.size());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertEquals(1, tasks.size());
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(2, completedNodes.size());
assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCaseWithActiveElements.
@Test
public void testTransitionBetweenStagesInCaseWithActiveElements() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
assertNotNull(caseId);
try {
Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
CaseStageInstance stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 1", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 1", activeNodes.iterator().next().getName());
caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
assertEquals("Stage Two", stage.iterator().next().getName());
assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 2", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 2", activeNodes.iterator().next().getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations