@Test public void testForUpdateWorkflowWithState() { Task task = getTask(); State state = prepareState(); when(stateService.update(new State())).thenReturn(state); when(stateService.getStateByIdAndTenantId(2l,TENANT_ID)).thenReturn(state); Task actualResponse = pgrWorkflow.update("ap.public", task); assertEquals(actualResponse.getId(), state.getId().toString()); }
@Override public Task update(final String tenantId, final Task task) { final Long stateId = Long.valueOf(task.getValueForKey(STATE_ID)); final State state = stateService.getStateByIdAndTenantId(stateId, tenantId); if (Objects.nonNull(state)) { state.addStateHistory(new StateHistory(state)); state.setValue(task.getStatus()); state.setComments(task.getValueForKey("systemApprovalComments")); state.setSenderName(task.getSender()); if (null == task.getAssignee()) { Long newAssignee = getAssignee(null, task.getComplaintTypeCode(), task.getPreviousAssignee(), tenantId).getId(); Long previousAssignee = task.getPreviousAssignee(); if (newAssignee == previousAssignee) { task.setAssignee(String.valueOf(newAssignee)); return task; } else { state.setOwnerPosition(newAssignee); state.setPreviousOwner(task.getPreviousAssignee()); state.setValue(ESCALATED); } } else state.setOwnerPosition(Long.valueOf(task.getAssignee())); state.setExtraInfo(task.getValueForKey(STATE_DETAILS)); state.setDateInfo(task.getCreatedDate()); state.setTenantId(tenantId); setAuditableFields(state, Long.valueOf(task.getRequestInfo().getUserInfo().getId())); stateService.update(state); if (state.getId() != null) { task.setId(state.getId().toString()); task.setAssignee(state.getOwnerPosition().toString()); } } return task; }
PgrWorkflow implements Workflow { @Override public Task update(final String tenantId, final Task task) { final Long stateId = Long.valueOf(task.getValueForKey(STATE_ID)); final State state = stateService.getStateByIdAndTenantId(stateId, tenantId); if (Objects.nonNull(state)) { state.addStateHistory(new StateHistory(state)); state.setValue(task.getStatus()); state.setComments(task.getValueForKey("systemApprovalComments")); state.setSenderName(task.getSender()); if (null == task.getAssignee()) { Long newAssignee = getAssignee(null, task.getComplaintTypeCode(), task.getPreviousAssignee(), tenantId).getId(); Long previousAssignee = task.getPreviousAssignee(); if (newAssignee == previousAssignee) { task.setAssignee(String.valueOf(newAssignee)); return task; } else { state.setOwnerPosition(newAssignee); state.setPreviousOwner(task.getPreviousAssignee()); state.setValue(ESCALATED); } } else state.setOwnerPosition(Long.valueOf(task.getAssignee())); state.setExtraInfo(task.getValueForKey(STATE_DETAILS)); state.setDateInfo(task.getCreatedDate()); state.setTenantId(tenantId); setAuditableFields(state, Long.valueOf(task.getRequestInfo().getUserInfo().getId())); stateService.update(state); if (state.getId() != null) { task.setId(state.getId().toString()); task.setAssignee(state.getOwnerPosition().toString()); } } return task; } }
PgrWorkflow implements Workflow { @Override public Task update(final String tenantId, final Task task) { final Long stateId = Long.valueOf(task.getValueForKey(STATE_ID)); final State state = stateService.getStateByIdAndTenantId(stateId, tenantId); if (Objects.nonNull(state)) { state.addStateHistory(new StateHistory(state)); state.setValue(task.getStatus()); state.setComments(task.getValueForKey("systemApprovalComments")); state.setSenderName(task.getSender()); if (null == task.getAssignee()) { Long newAssignee = getAssignee(null, task.getComplaintTypeCode(), task.getPreviousAssignee(), tenantId).getId(); Long previousAssignee = task.getPreviousAssignee(); if (newAssignee == previousAssignee) { task.setAssignee(String.valueOf(newAssignee)); return task; } else { state.setOwnerPosition(newAssignee); state.setPreviousOwner(task.getPreviousAssignee()); state.setValue(ESCALATED); } } else state.setOwnerPosition(Long.valueOf(task.getAssignee())); state.setExtraInfo(task.getValueForKey(STATE_DETAILS)); state.setDateInfo(task.getCreatedDate()); state.setTenantId(tenantId); setAuditableFields(state, Long.valueOf(task.getRequestInfo().getUserInfo().getId())); stateService.update(state); if (state.getId() != null) { task.setId(state.getId().toString()); task.setAssignee(state.getOwnerPosition().toString()); } } return task; } @Autowired  PgrWorkflow(final ComplaintRouterService complaintRouterService, final StateService stateService,
                       final EmployeeRepository employeeRepository, final UserRepository userRepository, final DepartmentRestRepository departmentRestRepository); }
PgrWorkflow implements Workflow { @Override public Task update(final String tenantId, final Task task) { final Long stateId = Long.valueOf(task.getValueForKey(STATE_ID)); final State state = stateService.getStateByIdAndTenantId(stateId, tenantId); if (Objects.nonNull(state)) { state.addStateHistory(new StateHistory(state)); state.setValue(task.getStatus()); state.setComments(task.getValueForKey("systemApprovalComments")); state.setSenderName(task.getSender()); if (null == task.getAssignee()) { Long newAssignee = getAssignee(null, task.getComplaintTypeCode(), task.getPreviousAssignee(), tenantId).getId(); Long previousAssignee = task.getPreviousAssignee(); if (newAssignee == previousAssignee) { task.setAssignee(String.valueOf(newAssignee)); return task; } else { state.setOwnerPosition(newAssignee); state.setPreviousOwner(task.getPreviousAssignee()); state.setValue(ESCALATED); } } else state.setOwnerPosition(Long.valueOf(task.getAssignee())); state.setExtraInfo(task.getValueForKey(STATE_DETAILS)); state.setDateInfo(task.getCreatedDate()); state.setTenantId(tenantId); setAuditableFields(state, Long.valueOf(task.getRequestInfo().getUserInfo().getId())); stateService.update(state); if (state.getId() != null) { task.setId(state.getId().toString()); task.setAssignee(state.getOwnerPosition().toString()); } } return task; } @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 Task update(final String tenantId, final Task task) { final Long stateId = Long.valueOf(task.getValueForKey(STATE_ID)); final State state = stateService.getStateByIdAndTenantId(stateId, tenantId); if (Objects.nonNull(state)) { state.addStateHistory(new StateHistory(state)); state.setValue(task.getStatus()); state.setComments(task.getValueForKey("systemApprovalComments")); state.setSenderName(task.getSender()); if (null == task.getAssignee()) { Long newAssignee = getAssignee(null, task.getComplaintTypeCode(), task.getPreviousAssignee(), tenantId).getId(); Long previousAssignee = task.getPreviousAssignee(); if (newAssignee == previousAssignee) { task.setAssignee(String.valueOf(newAssignee)); return task; } else { state.setOwnerPosition(newAssignee); state.setPreviousOwner(task.getPreviousAssignee()); state.setValue(ESCALATED); } } else state.setOwnerPosition(Long.valueOf(task.getAssignee())); state.setExtraInfo(task.getValueForKey(STATE_DETAILS)); state.setDateInfo(task.getCreatedDate()); state.setTenantId(tenantId); setAuditableFields(state, Long.valueOf(task.getRequestInfo().getUserInfo().getId())); stateService.update(state); if (state.getId() != null) { task.setId(state.getId().toString()); task.setAssignee(state.getOwnerPosition().toString()); } } return task; } @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; }