@Test public void testForGetWorkflowHistoryByWorkFlowId() { final State state = prepareState(); final EmployeeRes employeeRes = getEmployee(); final UserResponse userResponse = getUserResponse(); final DepartmentRes departmentRes=getDepartment(); when(stateService.getStateByIdAndTenantId(2l,"tenantId")).thenReturn(state); when(employeeRepository.getEmployeeForUserIdAndTenantId(1l,"tenantId")).thenReturn(employeeRes); when(userRepository.findUserByIdAndTenantId(1L,"tenantId")).thenReturn(userResponse); when(employeeRepository.getEmployeeForPositionAndTenantId(3l, new LocalDate(),"tenantId")).thenReturn(employeeRes); when(departmentRestRepository.getDepartmentById(1L,"tenantId")).thenReturn(departmentRes); final List<Task> actualHistory = pgrWorkflow.getHistoryDetail(TENANT_ID, "2"); assertEquals(3, actualHistory.size()); }
@Override public List<Task> getHistoryDetail(final String tenantId, final String workflowId) { final List<Task> tasks = new ArrayList<Task>(); Task t; final State state = stateService.getStateByIdAndTenantId(Long.valueOf(workflowId), tenantId); final Set<StateHistory> history = state.getHistory(); for (final StateHistory stateHistory : history) { t = stateHistory.map(); Employee user; User sender = null; if (stateHistory.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(stateHistory.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (stateHistory.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(stateHistory.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(stateHistory.getNatureOfTask()); tasks.add(t); } t = state.map(); Employee user; User sender = null; if (state.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(state.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (state.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(state.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(state.getNatureOfTask()); tasks.add(t); return tasks; }
PgrWorkflow implements Workflow { @Override public List<Task> getHistoryDetail(final String tenantId, final String workflowId) { final List<Task> tasks = new ArrayList<Task>(); Task t; final State state = stateService.getStateByIdAndTenantId(Long.valueOf(workflowId), tenantId); final Set<StateHistory> history = state.getHistory(); for (final StateHistory stateHistory : history) { t = stateHistory.map(); Employee user; User sender = null; if (stateHistory.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(stateHistory.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (stateHistory.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(stateHistory.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(stateHistory.getNatureOfTask()); tasks.add(t); } t = state.map(); Employee user; User sender = null; if (state.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(state.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (state.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(state.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(state.getNatureOfTask()); tasks.add(t); return tasks; } }
PgrWorkflow implements Workflow { @Override public List<Task> getHistoryDetail(final String tenantId, final String workflowId) { final List<Task> tasks = new ArrayList<Task>(); Task t; final State state = stateService.getStateByIdAndTenantId(Long.valueOf(workflowId), tenantId); final Set<StateHistory> history = state.getHistory(); for (final StateHistory stateHistory : history) { t = stateHistory.map(); Employee user; User sender = null; if (stateHistory.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(stateHistory.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (stateHistory.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(stateHistory.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(stateHistory.getNatureOfTask()); tasks.add(t); } t = state.map(); Employee user; User sender = null; if (state.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(state.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (state.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(state.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(state.getNatureOfTask()); tasks.add(t); return tasks; } @Autowired  PgrWorkflow(final ComplaintRouterService complaintRouterService, final StateService stateService,
                       final EmployeeRepository employeeRepository, final UserRepository userRepository, final DepartmentRestRepository departmentRestRepository); }
PgrWorkflow implements Workflow { @Override public List<Task> getHistoryDetail(final String tenantId, final String workflowId) { final List<Task> tasks = new ArrayList<Task>(); Task t; final State state = stateService.getStateByIdAndTenantId(Long.valueOf(workflowId), tenantId); final Set<StateHistory> history = state.getHistory(); for (final StateHistory stateHistory : history) { t = stateHistory.map(); Employee user; User sender = null; if (stateHistory.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(stateHistory.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (stateHistory.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(stateHistory.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(stateHistory.getNatureOfTask()); tasks.add(t); } t = state.map(); Employee user; User sender = null; if (state.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(state.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (state.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(state.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(state.getNatureOfTask()); tasks.add(t); return tasks; } @Autowired  PgrWorkflow(final ComplaintRouterService complaintRouterService, final StateService stateService,
                       final EmployeeRepository employeeRepository, final UserRepository userRepository, final DepartmentRestRepository departmentRestRepository); @Override ProcessInstance start(final String jurisdiction, final ProcessInstance processInstance); @Override ProcessInstance end(final String jurisdiction, final ProcessInstance processInstance); @Override PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId); @Override List<Task> getHistoryDetail(final String tenantId, final String workflowId); @Override Task update(final String tenantId, final Task task); }
PgrWorkflow implements Workflow { @Override public List<Task> getHistoryDetail(final String tenantId, final String workflowId) { final List<Task> tasks = new ArrayList<Task>(); Task t; final State state = stateService.getStateByIdAndTenantId(Long.valueOf(workflowId), tenantId); final Set<StateHistory> history = state.getHistory(); for (final StateHistory stateHistory : history) { t = stateHistory.map(); Employee user; User sender = null; if (stateHistory.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(stateHistory.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (stateHistory.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(stateHistory.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(stateHistory.getNatureOfTask()); tasks.add(t); } t = state.map(); Employee user; User sender = null; if (state.getLastModifiedBy() > 0){ UserResponse userResponse = userRepository.findUserByIdAndTenantId(state.getLastModifiedBy(), tenantId); if(userResponse != null && userResponse.getUser() != null && userResponse.getUser().size() > 0) sender = userResponse.getUser().get(0); } if (sender != null) t.setSender(sender.getUserName() + "::" + sender.getName()); else t.setSender(""); if (state.getOwnerUser() != null) { user = employeeRepository.getEmployeeForUserIdAndTenantId(state.getOwnerUser(), tenantId).getEmployees().get(0); t.setOwner(user.getUsername() + "::" + user.getName()); final Long dept = user.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else { final List<Employee> employeeList = employeeRepository .getEmployeeForPositionAndTenantId(state.getOwnerPosition(), new LocalDate(), tenantId).getEmployees(); if(!employeeList.isEmpty()){ Employee employee = employeeList.get(0); t.setOwner(employee.getUsername() + "::" + employee.getName()); final Long dept = employee.getAssignments().get(0).getDepartment(); DepartmentRes departmentRes = departmentRestRepository.getDepartmentById(dept, tenantId); t.getAttributes().put(DEPARTMENT, putDepartmentValues(departmentRes.getDepartment().get(0).getName())); } else{ t.setOwner("NO EMPLOYEE Assigned"); t.getAttributes().put(DEPARTMENT, putDepartmentValues("NO DEPARTMENT")); } } t.setNatureOfTask(state.getNatureOfTask()); tasks.add(t); return tasks; } @Autowired  PgrWorkflow(final ComplaintRouterService complaintRouterService, final StateService stateService,
                       final EmployeeRepository employeeRepository, final UserRepository userRepository, final DepartmentRestRepository departmentRestRepository); @Override ProcessInstance start(final String jurisdiction, final ProcessInstance processInstance); @Override ProcessInstance end(final String jurisdiction, final ProcessInstance processInstance); @Override PositionResponse getAssignee(final Long boundaryId, final String complaintTypeCode, final Long assigneeId, final String tenantId); @Override List<Task> getHistoryDetail(final String tenantId, final String workflowId); @Override Task update(final String tenantId, final Task task); static final String STATE_ID; static final String DEPARTMENT; static final String ESCALATED; static final String COMPLAINT; static final String SYSTEM_KEYWORD; static final String DELIVERABLE_SERVICE; static final String STATE_DETAILS; }