@Test public void testShouldUpdateSevaRequestWithUpdateWorkflowResponseWithDifferentDepartment() { final HashMap<String, Object> complaintRequestMap = new HashMap<>(); final HashMap<String, Object> serviceRequestMap = new HashMap<>(); serviceRequestMap.put("serviceCode", "serviceCode"); serviceRequestMap.put("serviceRequestId", "00015-2016-AP"); serviceRequestMap.put("tenantId", "ap.public"); final ArrayList<HashMap<String, String>> attributeValues = new ArrayList<>(); final HashMap<String, String> stateIdEntry = new HashMap<>(); stateIdEntry.put("key", VALUES_STATE_ID); stateIdEntry.put("name", "6"); attributeValues.add(stateIdEntry); final HashMap<String, String> locationIdEntry = new HashMap<>(); locationIdEntry.put("key", VALUES_LOCATION_ID); locationIdEntry.put("name", "1"); attributeValues.add(locationIdEntry); final HashMap<String, String> commentEntry = new HashMap<>(); commentEntry.put("key", VALUES_APPROVAL_COMMENT); commentEntry.put("name", "Testing complaint update"); attributeValues.add(commentEntry); final HashMap<String, String> assigneeEntry = new HashMap<>(); assigneeEntry.put("key", VALUES_POSITION_ID); assigneeEntry.put("name", "6"); attributeValues.add(assigneeEntry); final HashMap<String, String> registeredEntry = new HashMap<>(); registeredEntry.put("key", STATUS); registeredEntry.put("name", "PROCESSING"); attributeValues.add(registeredEntry); final HashMap<String, String> departmentIdEntry = new HashMap<>(); departmentIdEntry.put("key", VALUES_DEPARTMENT_ID); departmentIdEntry.put("name", "19"); attributeValues.add(departmentIdEntry); serviceRequestMap.put("attribValues", attributeValues); serviceRequestMap.put("attribValues", attributeValues); complaintRequestMap.put("serviceRequest", serviceRequestMap); final RequestInfo requestInfo = RequestInfo.builder().build(); complaintRequestMap.put("RequestInfo", requestInfo); final SevaRequest sevaRequest = new SevaRequest(complaintRequestMap); final WorkflowResponse workflowResponse = new WorkflowResponse(ASSIGNEE, getValuesWithStateId()); when(workflowRepository.update(any(WorkflowRequest.class))).thenReturn(workflowResponse); List<AttributeEntry> responseValues = new ArrayList<>(); responseValues.add(new AttributeEntry("systemLocationId", "1")); responseValues.add(new AttributeEntry("systemDepartmentId", "20")); responseValues.add(new AttributeEntry("systemPositionId", "6")); responseValues.add(new AttributeEntry("systemComplaintStatus", "PROCESSING")); when(complaintRestRepository.getComplaintByCrn("ap.public", serviceRequestMap.get("serviceRequestId") .toString())) .thenReturn(ServiceRequest.builder().attribValues(responseValues).description("Testing complaint update") .complaintTypeCode("serviceCode").build()); final SevaRequest enrichedSevaRequest = workflowService.enrichWorkflow(sevaRequest); assertEquals(ASSIGNEE, enrichedSevaRequest.getDynamicSingleValue("systemPositionId")); assertEquals(STATE_ID, enrichedSevaRequest.getDynamicSingleValue("systemStateId")); }
public SevaRequest enrichWorkflow(SevaRequest sevaRequest) { WorkflowRequest request = sevaRequest.getWorkFlowRequest(); WorkflowResponse workflowResponse = null; if (request.isCreate() && sevaRequest.isCreate()) { workflowResponse = workflowRepository.create(request); } else if (request.isClosed()) { workflowResponse = workflowRepository.close(request); } else { ServiceRequest responseFromDB = complaintRestRepository.getComplaintByCrn(request.getTenantId(), request.getCrn()); String locationId = responseFromDB.getDynamicSingleValue("systemLocationId"); String departmentId = responseFromDB.getDynamicSingleValue("systemDepartmentId"); String positionId = responseFromDB.getDynamicSingleValue("systemPositionId"); String status = responseFromDB.getDynamicSingleValue("systemStatus"); boolean isUpdate = false; if (!responseFromDB.getComplaintTypeCode().equals(request.getValueForKey("complaintTypeCode")) || !locationId.equals(request.getValueForKey("boundaryId")) || !positionId.equals(request.getPositionId().toString())) { isUpdate = true; } else if (!departmentId.equals(request.getValueForKey("systemDepartmentId")) || (!status.equals(request.getStatus()) || !responseFromDB.getDescription().equals(request.getValueForKey("systemApprovalComments"))) && !isUpdate) { isUpdate = true; } if (isUpdate) { workflowResponse = workflowRepository.update(request); } } if (workflowResponse != null) sevaRequest.update(workflowResponse); return sevaRequest; }
WorkflowService { public SevaRequest enrichWorkflow(SevaRequest sevaRequest) { WorkflowRequest request = sevaRequest.getWorkFlowRequest(); WorkflowResponse workflowResponse = null; if (request.isCreate() && sevaRequest.isCreate()) { workflowResponse = workflowRepository.create(request); } else if (request.isClosed()) { workflowResponse = workflowRepository.close(request); } else { ServiceRequest responseFromDB = complaintRestRepository.getComplaintByCrn(request.getTenantId(), request.getCrn()); String locationId = responseFromDB.getDynamicSingleValue("systemLocationId"); String departmentId = responseFromDB.getDynamicSingleValue("systemDepartmentId"); String positionId = responseFromDB.getDynamicSingleValue("systemPositionId"); String status = responseFromDB.getDynamicSingleValue("systemStatus"); boolean isUpdate = false; if (!responseFromDB.getComplaintTypeCode().equals(request.getValueForKey("complaintTypeCode")) || !locationId.equals(request.getValueForKey("boundaryId")) || !positionId.equals(request.getPositionId().toString())) { isUpdate = true; } else if (!departmentId.equals(request.getValueForKey("systemDepartmentId")) || (!status.equals(request.getStatus()) || !responseFromDB.getDescription().equals(request.getValueForKey("systemApprovalComments"))) && !isUpdate) { isUpdate = true; } if (isUpdate) { workflowResponse = workflowRepository.update(request); } } if (workflowResponse != null) sevaRequest.update(workflowResponse); return sevaRequest; } }
WorkflowService { public SevaRequest enrichWorkflow(SevaRequest sevaRequest) { WorkflowRequest request = sevaRequest.getWorkFlowRequest(); WorkflowResponse workflowResponse = null; if (request.isCreate() && sevaRequest.isCreate()) { workflowResponse = workflowRepository.create(request); } else if (request.isClosed()) { workflowResponse = workflowRepository.close(request); } else { ServiceRequest responseFromDB = complaintRestRepository.getComplaintByCrn(request.getTenantId(), request.getCrn()); String locationId = responseFromDB.getDynamicSingleValue("systemLocationId"); String departmentId = responseFromDB.getDynamicSingleValue("systemDepartmentId"); String positionId = responseFromDB.getDynamicSingleValue("systemPositionId"); String status = responseFromDB.getDynamicSingleValue("systemStatus"); boolean isUpdate = false; if (!responseFromDB.getComplaintTypeCode().equals(request.getValueForKey("complaintTypeCode")) || !locationId.equals(request.getValueForKey("boundaryId")) || !positionId.equals(request.getPositionId().toString())) { isUpdate = true; } else if (!departmentId.equals(request.getValueForKey("systemDepartmentId")) || (!status.equals(request.getStatus()) || !responseFromDB.getDescription().equals(request.getValueForKey("systemApprovalComments"))) && !isUpdate) { isUpdate = true; } if (isUpdate) { workflowResponse = workflowRepository.update(request); } } if (workflowResponse != null) sevaRequest.update(workflowResponse); return sevaRequest; } @Autowired  WorkflowService(WorkflowRepository workflowRepository, ComplaintRestRepository complaintRestRepository); }
WorkflowService { public SevaRequest enrichWorkflow(SevaRequest sevaRequest) { WorkflowRequest request = sevaRequest.getWorkFlowRequest(); WorkflowResponse workflowResponse = null; if (request.isCreate() && sevaRequest.isCreate()) { workflowResponse = workflowRepository.create(request); } else if (request.isClosed()) { workflowResponse = workflowRepository.close(request); } else { ServiceRequest responseFromDB = complaintRestRepository.getComplaintByCrn(request.getTenantId(), request.getCrn()); String locationId = responseFromDB.getDynamicSingleValue("systemLocationId"); String departmentId = responseFromDB.getDynamicSingleValue("systemDepartmentId"); String positionId = responseFromDB.getDynamicSingleValue("systemPositionId"); String status = responseFromDB.getDynamicSingleValue("systemStatus"); boolean isUpdate = false; if (!responseFromDB.getComplaintTypeCode().equals(request.getValueForKey("complaintTypeCode")) || !locationId.equals(request.getValueForKey("boundaryId")) || !positionId.equals(request.getPositionId().toString())) { isUpdate = true; } else if (!departmentId.equals(request.getValueForKey("systemDepartmentId")) || (!status.equals(request.getStatus()) || !responseFromDB.getDescription().equals(request.getValueForKey("systemApprovalComments"))) && !isUpdate) { isUpdate = true; } if (isUpdate) { workflowResponse = workflowRepository.update(request); } } if (workflowResponse != null) sevaRequest.update(workflowResponse); return sevaRequest; } @Autowired  WorkflowService(WorkflowRepository workflowRepository, ComplaintRestRepository complaintRestRepository); SevaRequest enrichWorkflow(SevaRequest sevaRequest); }
WorkflowService { public SevaRequest enrichWorkflow(SevaRequest sevaRequest) { WorkflowRequest request = sevaRequest.getWorkFlowRequest(); WorkflowResponse workflowResponse = null; if (request.isCreate() && sevaRequest.isCreate()) { workflowResponse = workflowRepository.create(request); } else if (request.isClosed()) { workflowResponse = workflowRepository.close(request); } else { ServiceRequest responseFromDB = complaintRestRepository.getComplaintByCrn(request.getTenantId(), request.getCrn()); String locationId = responseFromDB.getDynamicSingleValue("systemLocationId"); String departmentId = responseFromDB.getDynamicSingleValue("systemDepartmentId"); String positionId = responseFromDB.getDynamicSingleValue("systemPositionId"); String status = responseFromDB.getDynamicSingleValue("systemStatus"); boolean isUpdate = false; if (!responseFromDB.getComplaintTypeCode().equals(request.getValueForKey("complaintTypeCode")) || !locationId.equals(request.getValueForKey("boundaryId")) || !positionId.equals(request.getPositionId().toString())) { isUpdate = true; } else if (!departmentId.equals(request.getValueForKey("systemDepartmentId")) || (!status.equals(request.getStatus()) || !responseFromDB.getDescription().equals(request.getValueForKey("systemApprovalComments"))) && !isUpdate) { isUpdate = true; } if (isUpdate) { workflowResponse = workflowRepository.update(request); } } if (workflowResponse != null) sevaRequest.update(workflowResponse); return sevaRequest; } @Autowired  WorkflowService(WorkflowRepository workflowRepository, ComplaintRestRepository complaintRestRepository); SevaRequest enrichWorkflow(SevaRequest sevaRequest);  }