RemoteCaseManagementServiceImpl implements CaseManagementService { @Override public Actions getCaseActions(String container, String caseId, String userId) { final Actions actions = new Actions(); final List<CaseActionSummary> adHocActions = getAdHocActions(container, caseId); final List<CaseActionSummary> inProgressActions = getInProgressActions(container, caseId); final List<CaseActionSummary> completedActions = getCompletedActions(container, caseId); actions.setInProgressAction(inProgressActions); actions.setCompleteActions(completedActions); actions.setAvailableActions( adHocActions.stream() .filter(action -> { if (new MilestoneNodePredicate().negate().test(action.getType())) { return true; } if (findMilestone(inProgressActions, action.getName())) { return false; } if (findMilestone(completedActions, action.getName())) { return false; } return true; }) .filter(action -> new InProgressHumanTaskPredicate().negate().test(action, inProgressActions)) .collect(toList())); return actions; }  @Override List<CaseDefinitionSummary> getCaseDefinitions(); @Override CaseDefinitionSummary getCaseDefinition(final String containerId, final String caseDefinitionId); @Override List<CaseInstanceSummary> getCaseInstances(final CaseInstanceSearchRequest request); @Override String startCaseInstance(final String containerId,
                                    final String caseDefinitionId,
                                    final String owner,
                                    final List<CaseRoleAssignmentSummary> roleAssignments); @Override void cancelCaseInstance(final String containerId, final String caseId); @Override void closeCaseInstance(final String containerId, final String caseId, final String comment); @Override CaseInstanceSummary getCaseInstance(final String containerId, final String caseId); @Override void assignUserToRole(final String containerId,
                                 final String caseId,
                                 final String roleName,
                                 final String user); @Override void assignGroupToRole(final String containerId,
                                  final String caseId,
                                  final String roleName,
                                  final String group); @Override void removeUserFromRole(final String containerId,
                                   final String caseId,
                                   final String roleName,
                                   final String user); @Override void removeGroupFromRole(final String containerId,
                                    final String caseId,
                                    final String roleName,
                                    final String group); @Override List<CaseCommentSummary> getComments(final String containerId,
                                                final String caseId,
                                                final Integer page,
                                                final Integer pageSize); @Override void addComment(final String containerId,
                           final String caseId,
                           final String author,
                           final String text); @Override void updateComment(final String containerId,
                              final String caseId,
                              final String commentId,
                              final String author,
                              final String text); @Override void removeComment(final String containerId,
                              final String caseId,
                              final String commentId); @Override List<CaseMilestoneSummary> getCaseMilestones(final String containerId,
                                                        final String caseId,
                                                        final CaseMilestoneSearchRequest request); @Override List<CaseStageSummary> getCaseStages(final String containerId, final String caseId); @Override Actions getCaseActions(String container, String caseId, String userId); List<CaseActionSummary> getInProgressActions(String containerId,
                                                        String caseId); List<NodeInstance> getCaseCompletedNodes(String containerId, String caseId); List<CaseActionSummary> getCompletedActions(String containerId, String caseId); List<CaseActionSummary> getAdHocFragments(String containerId, String caseId); List<CaseActionSummary> getAdHocActions(String containerId, String caseId); void addDynamicUserTask(String containerId,
                                   String caseId,
                                   String name,
                                   String description,
                                   String actors,
                                   String groups,
                                   Map<String, Object> data); void addDynamicUserTaskToStage(String containerId,
                                          String caseId,
                                          String stageId,
                                          String name,
                                          String description,
                                          String actors,
                                          String groups,
                                          Map<String, Object> data); void addDynamicSubProcess(String containerId,
                                     String caseId,
                                     String processId,
                                     Map<String, Object> data); void addDynamicSubProcessToStage(String containerId,
                                            String caseId,
                                            String stageId,
                                            String processId,
                                            Map<String, Object> data); @Override void triggerAdHocActionInStage(String containerId,
                                          String caseId,
                                          String stageId,
                                          String adHocName,
                                          Map<String, Object> data); @Override void triggerAdHocAction(String containerId,
                                   String caseId,
                                   String adHocName,
                                   Map<String, Object> data); @Override List<ProcessDefinitionSummary> getProcessDefinitions(String containerId); static final int PAGE_SIZE_UNLIMITED; static final String CASE_OWNER_ROLE; }
@Test public void getCaseActionsTest() { final CaseInstance ci = createTestInstance(caseId); CaseStage stage1 = createTestCaseStage("stage1", "stage1-name", CaseStageStatus.ACTIVE.getStatus()); CaseAdHocFragment cAHF1_stage1 = createTestCaseAdHocFragment("stage1-adHoc-1", "adHocFragment-type-1"); CaseAdHocFragment cAHF2_stage1 = createTestCaseAdHocFragment("stage1-adHoc-2", "adHocFragment-type-2"); CaseStage stage2 = createTestCaseStage("stage2", "stage2-name", CaseStageStatus.COMPLETED.getStatus()); CaseAdHocFragment cAHF1_stage2 = createTestCaseAdHocFragment("stage2-adHoc-1", "adHocFragment-type-1"); CaseAdHocFragment cAHF2_stage2 = createTestCaseAdHocFragment("stage2-adHoc-2", "adHocFragment-type-2"); stage1.setAdHocFragments(Arrays.asList(cAHF1_stage1, cAHF2_stage1)); stage2.setAdHocFragments(Arrays.asList(cAHF1_stage2, cAHF2_stage2)); ci.setStages(Arrays.asList(stage1, stage2)); when(clientMock.getCaseInstance(ci.getContainerId(), ci.getCaseId(), false, true, true, true)) .thenReturn(ci); CaseAdHocFragment cAHF1 = createTestCaseAdHocFragment("adHocFragment-name-1", "adHocFragment-type-1"); CaseAdHocFragment cAHF2 = createTestCaseAdHocFragment("adHocFragment-name-2", "adHocFragment-type-2"); CaseAdHocFragment cAHF3 = createTestCaseAdHocFragment("active1", "Human Task"); CaseAdHocFragment cAHF4 = createTestCaseAdHocFragment("active2", "HumanTaskNode"); CaseAdHocFragment cAHF5 = createTestCaseAdHocFragment("Milestone 1", "MilestoneNode"); CaseAdHocFragment cAHF6 = createTestCaseAdHocFragment("Milestone 2", "MilestoneNode"); when(clientMock.getAdHocFragments(containerId, caseId)).thenReturn(Arrays.asList(cAHF1, cAHF2, cAHF3, cAHF4, cAHF5, cAHF6)); Long nodeWorkItemId = 0L; NodeInstance node1 = createTestNodeInstance("active1", "Human Task", nodeWorkItemId++); NodeInstance node2 = createTestNodeInstance("active2", "Service Task", nodeWorkItemId++); NodeInstance node3 = createTestNodeInstance("active2", "HumanTaskNode", nodeWorkItemId++); NodeInstance node4 = createTestNodeInstance("Milestone 1", "MilestoneNode", nodeWorkItemId++); when(clientMock.getActiveNodes(eq(containerId), eq(caseId), anyInt(), anyInt())).thenReturn(Arrays.asList(node1, node2, node3, node4)); NodeInstance node5 = createTestNodeInstance("complete1", "Human Task", nodeWorkItemId++); NodeInstance node6 = createTestNodeInstance("complete2", "Service Task", nodeWorkItemId++); when(clientMock.getCompletedNodes(eq(containerId), eq(caseId), anyInt(), anyInt())).thenReturn(Arrays.asList(node5, node6)); TaskInstance t1 = TaskInstance.builder() .actualOwner("Koe") .build(); when(userTaskServicesClient.findTaskByWorkItemId(node1.getWorkItemId())).thenReturn(t1); when(userTaskServicesClient.findTaskByWorkItemId(node3.getWorkItemId())).thenReturn(t1); when(userTaskServicesClient.findTaskByWorkItemId(node5.getWorkItemId())).thenReturn(t1); Actions actions = testedService.getCaseActions(containerId, caseId, userId); assertEquals(5, actions.getAvailableActions().size()); assertCaseActionAdHocFragment(cAHF1, actions.getAvailableActions().get(0)); assertCaseActionAdHocFragment(cAHF2, actions.getAvailableActions().get(1)); assertCaseActionAdHocFragment(cAHF6, actions.getAvailableActions().get(2)); assertCaseActionAdHocFragmentWithStage(cAHF1_stage1, actions.getAvailableActions().get(3)); assertCaseActionAdHocFragmentWithStage(cAHF2_stage1, actions.getAvailableActions().get(4)); assertEquals(4, actions.getInProgressAction().size()); assertCaseActionNodeInstance(node1, actions.getInProgressAction().get(0)); assertCaseActionNodeInstance(node2, actions.getInProgressAction().get(1)); assertCaseActionNodeInstance(node3, actions.getInProgressAction().get(2)); assertCaseActionNodeInstance(node4, actions.getInProgressAction().get(3)); assertEquals(2, actions.getCompleteActions().size()); assertCaseActionNodeInstance(node5, actions.getCompleteActions().get(0)); assertCaseActionNodeInstance(node6, actions.getCompleteActions().get(1)); verify(clientMock).getAdHocFragments(containerId, caseId); verify(clientMock).getActiveNodes(eq(containerId), eq(caseId), eq(0), anyInt()); verify(clientMock).getCompletedNodes(eq(containerId), eq(caseId), eq(0), anyInt()); verify(userTaskServicesClient).findTaskByWorkItemId(node1.getWorkItemId()); verify(userTaskServicesClient, never()).findTaskByWorkItemId(node2.getWorkItemId()); verify(userTaskServicesClient).findTaskByWorkItemId(node3.getWorkItemId()); verify(userTaskServicesClient, never()).findTaskByWorkItemId(node4.getWorkItemId()); verify(userTaskServicesClient).findTaskByWorkItemId(node5.getWorkItemId()); verify(userTaskServicesClient, never()).findTaskByWorkItemId(node6.getWorkItemId()); }