@Test public void updatePrintJobColorProp() { UpdatePrintJobPropertiesRequest request = new UpdatePrintJobPropertiesRequest(); request.setColorType("red"); request.setEmployeeId(1); PrintJob printJob = new PrintJob(); printJob.setComments("old comments"); printJob.setStatus(Status.valueOf("FAILED")); ColorType colorType = new ColorType(); colorType.setColor("blue"); printJob.setColorType(colorType); Employee e = new Employee(); e.setId(1); ColorType newColorType = new ColorType(); newColorType.setColor("red"); newColorType.setAvailable(true); when(printJobRepo.findPrintJobById(anyInt())).thenReturn(printJob); when(employeeRepo.findEmployeeById(anyInt())).thenReturn(e); when(colorTypeRepo.findByColor("red")).thenReturn(newColorType); when(printJobRepo.save(printJob)).thenReturn(null); DataResponse<BasicPrintJob> response = operations.updatePrintJobProps(1, request); assertTrue("response is null", response != null); assertTrue("comments are not equal", response.getData().get(0).getComments().equals(printJob.getComments())); assertTrue("status is not equal", response.getData().get(0).getStatus() == printJob.getStatus()); assertTrue("color is not equal", response.getData().get(0).getColorType().getColor().equals(request.getColorType())); }
public DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request) { request.validate(); boolean isChanged = false; PrintJob printJob = printJobRepo.findPrintJobById(printJobId); if(printJob == null) throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); ColorType colorType = null; if(request.getColorType() != null && !request.getColorType().trim().isEmpty()) { colorType = colorTypeRepo.findByColor(request.getColorType()); if (colorType == null) throw new IdeaLabApiException(PRINT_JOB_UPDATE_FAILED, "Color type is invalid"); } if(request.getStatus() != null && !request.getStatus().trim().isEmpty()) { isChanged = true; printJob.setStatus(Status.fromValue(request.getStatus())); } if(request.getComments() != null) { isChanged = true; printJob.setComments(request.getComments()); } if(colorType != null && colorType.getColor() != null && !colorType.getColor().trim().isEmpty()) { isChanged = true; printJob.setColorType(colorType); } if(isChanged) printJobRepo.save(printJob); List<PrintJob> printJobs = new ArrayList<>(); printJobs.add(printJob); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setSuccess(true); response.setMessage("Print job properties updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); response.setData(basicPrintJobs); return response; }
PrintJobOperations { public DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request) { request.validate(); boolean isChanged = false; PrintJob printJob = printJobRepo.findPrintJobById(printJobId); if(printJob == null) throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); ColorType colorType = null; if(request.getColorType() != null && !request.getColorType().trim().isEmpty()) { colorType = colorTypeRepo.findByColor(request.getColorType()); if (colorType == null) throw new IdeaLabApiException(PRINT_JOB_UPDATE_FAILED, "Color type is invalid"); } if(request.getStatus() != null && !request.getStatus().trim().isEmpty()) { isChanged = true; printJob.setStatus(Status.fromValue(request.getStatus())); } if(request.getComments() != null) { isChanged = true; printJob.setComments(request.getComments()); } if(colorType != null && colorType.getColor() != null && !colorType.getColor().trim().isEmpty()) { isChanged = true; printJob.setColorType(colorType); } if(isChanged) printJobRepo.save(printJob); List<PrintJob> printJobs = new ArrayList<>(); printJobs.add(printJob); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setSuccess(true); response.setMessage("Print job properties updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); response.setData(basicPrintJobs); return response; } }
PrintJobOperations { public DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request) { request.validate(); boolean isChanged = false; PrintJob printJob = printJobRepo.findPrintJobById(printJobId); if(printJob == null) throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); ColorType colorType = null; if(request.getColorType() != null && !request.getColorType().trim().isEmpty()) { colorType = colorTypeRepo.findByColor(request.getColorType()); if (colorType == null) throw new IdeaLabApiException(PRINT_JOB_UPDATE_FAILED, "Color type is invalid"); } if(request.getStatus() != null && !request.getStatus().trim().isEmpty()) { isChanged = true; printJob.setStatus(Status.fromValue(request.getStatus())); } if(request.getComments() != null) { isChanged = true; printJob.setComments(request.getComments()); } if(colorType != null && colorType.getColor() != null && !colorType.getColor().trim().isEmpty()) { isChanged = true; printJob.setColorType(colorType); } if(isChanged) printJobRepo.save(printJob); List<PrintJob> printJobs = new ArrayList<>(); printJobs.add(printJob); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setSuccess(true); response.setMessage("Print job properties updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); response.setData(basicPrintJobs); return response; } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); }
PrintJobOperations { public DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request) { request.validate(); boolean isChanged = false; PrintJob printJob = printJobRepo.findPrintJobById(printJobId); if(printJob == null) throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); ColorType colorType = null; if(request.getColorType() != null && !request.getColorType().trim().isEmpty()) { colorType = colorTypeRepo.findByColor(request.getColorType()); if (colorType == null) throw new IdeaLabApiException(PRINT_JOB_UPDATE_FAILED, "Color type is invalid"); } if(request.getStatus() != null && !request.getStatus().trim().isEmpty()) { isChanged = true; printJob.setStatus(Status.fromValue(request.getStatus())); } if(request.getComments() != null) { isChanged = true; printJob.setComments(request.getComments()); } if(colorType != null && colorType.getColor() != null && !colorType.getColor().trim().isEmpty()) { isChanged = true; printJob.setColorType(colorType); } if(isChanged) printJobRepo.save(printJob); List<PrintJob> printJobs = new ArrayList<>(); printJobs.add(printJob); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setSuccess(true); response.setMessage("Print job properties updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); response.setData(basicPrintJobs); return response; } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal); DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model); GenericResponse deleteModel(Integer printId); GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto); GenericResponse deletePrintJob(PrintJobDeleteRequest dto); DataResponse<BasicPrintJob> getAllPrintJobs(String status); DataResponse<BasicPrintJob> getDeletablePrintJobs(); DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request); DataResponse<BasicPrintJob> getPrintJobById(Integer printJobId); }
PrintJobOperations { public DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request) { request.validate(); boolean isChanged = false; PrintJob printJob = printJobRepo.findPrintJobById(printJobId); if(printJob == null) throw new IdeaLabApiException(PRINT_JOB_CANT_FIND_BY_ID); ColorType colorType = null; if(request.getColorType() != null && !request.getColorType().trim().isEmpty()) { colorType = colorTypeRepo.findByColor(request.getColorType()); if (colorType == null) throw new IdeaLabApiException(PRINT_JOB_UPDATE_FAILED, "Color type is invalid"); } if(request.getStatus() != null && !request.getStatus().trim().isEmpty()) { isChanged = true; printJob.setStatus(Status.fromValue(request.getStatus())); } if(request.getComments() != null) { isChanged = true; printJob.setComments(request.getComments()); } if(colorType != null && colorType.getColor() != null && !colorType.getColor().trim().isEmpty()) { isChanged = true; printJob.setColorType(colorType); } if(isChanged) printJobRepo.save(printJob); List<PrintJob> printJobs = new ArrayList<>(); printJobs.add(printJob); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setSuccess(true); response.setMessage("Print job properties updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); response.setData(basicPrintJobs); return response; } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal); DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model); GenericResponse deleteModel(Integer printId); GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto); GenericResponse deletePrintJob(PrintJobDeleteRequest dto); DataResponse<BasicPrintJob> getAllPrintJobs(String status); DataResponse<BasicPrintJob> getDeletablePrintJobs(); DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request); DataResponse<BasicPrintJob> getPrintJobById(Integer printJobId);  }