@Test public void updatePrintJobSuccess() { PrintJobUpdateRequest request = new PrintJobUpdateRequest(); request.setEmployeeId(1); request.setStatus("Completed"); Employee employee = new Employee(); employee.setId(1); PrintJob printJob = new PrintJob(); printJob.setEmployee(employee); printJob.setId(2); printJob.setStatus(Status.COMPLETED); when(employeeRepo.findEmployeeById(anyInt())).thenReturn(employee); when(printJobRepo.findPrintJobById(anyInt())).thenReturn(printJob); when(printJobRepo.save(printJob)).thenReturn(printJob); GenericResponse response = operations.updatePrintJobStatus(2, request); assertTrue("response is not true", response.isSuccess() == true); assertTrue("print job was not updated", response.getMessage().equalsIgnoreCase("Print Job Updated")); }
public GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto) { dto.validate(); Status requestStatus = Status.fromValue(dto.getStatus()); if(requestStatus == null || !requestStatus.isValid()){ ErrorType.REQUEST_STATUS_IS_NOT_VALID.throwException(); } Employee employee = employeeRepo.findEmployeeById(dto.getEmployeeId()); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(employee == null || printJob == null){ ErrorType.PRINT_JOB_UPDATE_FAILED.throwException(); } if (requestStatus == Status.REJECTED || requestStatus == Status.COMPLETED) { Queue deleteQueue = queueRepo.findByPrintJobId(printJob); queueRepo.delete(deleteQueue); CustomerInfo customer = printJob.getCustomerInfo(); List<PrintJob> printJobs = printJobRepo.findByCustomerInfo(customer); printJobs.removeIf(job -> (job.getStatus() == Status.REJECTED || job.getStatus() == Status.COMPLETED)); if (printJobs.size() > 1) { Collections.sort(printJobs); } if (printJobs.size() > 0) { Queue newQueue = new Queue(printJobs.get(0), queueRepo.getMaximumRank()+1); newQueue = queueRepo.save(newQueue); } } GenericResponse response = new GenericResponse(); printJob.setStatus(requestStatus); printJobRepo.save(printJob); response.setSuccess(true); response.setMessage("Print Job Updated"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; }
PrintJobOperations { public GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto) { dto.validate(); Status requestStatus = Status.fromValue(dto.getStatus()); if(requestStatus == null || !requestStatus.isValid()){ ErrorType.REQUEST_STATUS_IS_NOT_VALID.throwException(); } Employee employee = employeeRepo.findEmployeeById(dto.getEmployeeId()); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(employee == null || printJob == null){ ErrorType.PRINT_JOB_UPDATE_FAILED.throwException(); } if (requestStatus == Status.REJECTED || requestStatus == Status.COMPLETED) { Queue deleteQueue = queueRepo.findByPrintJobId(printJob); queueRepo.delete(deleteQueue); CustomerInfo customer = printJob.getCustomerInfo(); List<PrintJob> printJobs = printJobRepo.findByCustomerInfo(customer); printJobs.removeIf(job -> (job.getStatus() == Status.REJECTED || job.getStatus() == Status.COMPLETED)); if (printJobs.size() > 1) { Collections.sort(printJobs); } if (printJobs.size() > 0) { Queue newQueue = new Queue(printJobs.get(0), queueRepo.getMaximumRank()+1); newQueue = queueRepo.save(newQueue); } } GenericResponse response = new GenericResponse(); printJob.setStatus(requestStatus); printJobRepo.save(printJob); response.setSuccess(true); response.setMessage("Print Job Updated"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } }
PrintJobOperations { public GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto) { dto.validate(); Status requestStatus = Status.fromValue(dto.getStatus()); if(requestStatus == null || !requestStatus.isValid()){ ErrorType.REQUEST_STATUS_IS_NOT_VALID.throwException(); } Employee employee = employeeRepo.findEmployeeById(dto.getEmployeeId()); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(employee == null || printJob == null){ ErrorType.PRINT_JOB_UPDATE_FAILED.throwException(); } if (requestStatus == Status.REJECTED || requestStatus == Status.COMPLETED) { Queue deleteQueue = queueRepo.findByPrintJobId(printJob); queueRepo.delete(deleteQueue); CustomerInfo customer = printJob.getCustomerInfo(); List<PrintJob> printJobs = printJobRepo.findByCustomerInfo(customer); printJobs.removeIf(job -> (job.getStatus() == Status.REJECTED || job.getStatus() == Status.COMPLETED)); if (printJobs.size() > 1) { Collections.sort(printJobs); } if (printJobs.size() > 0) { Queue newQueue = new Queue(printJobs.get(0), queueRepo.getMaximumRank()+1); newQueue = queueRepo.save(newQueue); } } GenericResponse response = new GenericResponse(); printJob.setStatus(requestStatus); printJobRepo.save(printJob); response.setSuccess(true); response.setMessage("Print Job Updated"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); }
PrintJobOperations { public GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto) { dto.validate(); Status requestStatus = Status.fromValue(dto.getStatus()); if(requestStatus == null || !requestStatus.isValid()){ ErrorType.REQUEST_STATUS_IS_NOT_VALID.throwException(); } Employee employee = employeeRepo.findEmployeeById(dto.getEmployeeId()); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(employee == null || printJob == null){ ErrorType.PRINT_JOB_UPDATE_FAILED.throwException(); } if (requestStatus == Status.REJECTED || requestStatus == Status.COMPLETED) { Queue deleteQueue = queueRepo.findByPrintJobId(printJob); queueRepo.delete(deleteQueue); CustomerInfo customer = printJob.getCustomerInfo(); List<PrintJob> printJobs = printJobRepo.findByCustomerInfo(customer); printJobs.removeIf(job -> (job.getStatus() == Status.REJECTED || job.getStatus() == Status.COMPLETED)); if (printJobs.size() > 1) { Collections.sort(printJobs); } if (printJobs.size() > 0) { Queue newQueue = new Queue(printJobs.get(0), queueRepo.getMaximumRank()+1); newQueue = queueRepo.save(newQueue); } } GenericResponse response = new GenericResponse(); printJob.setStatus(requestStatus); printJobRepo.save(printJob); response.setSuccess(true); response.setMessage("Print Job Updated"); response.setHttpStatus(HttpStatus.ACCEPTED); 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 GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto) { dto.validate(); Status requestStatus = Status.fromValue(dto.getStatus()); if(requestStatus == null || !requestStatus.isValid()){ ErrorType.REQUEST_STATUS_IS_NOT_VALID.throwException(); } Employee employee = employeeRepo.findEmployeeById(dto.getEmployeeId()); PrintJob printJob = printJobRepo.findPrintJobById(printId); if(employee == null || printJob == null){ ErrorType.PRINT_JOB_UPDATE_FAILED.throwException(); } if (requestStatus == Status.REJECTED || requestStatus == Status.COMPLETED) { Queue deleteQueue = queueRepo.findByPrintJobId(printJob); queueRepo.delete(deleteQueue); CustomerInfo customer = printJob.getCustomerInfo(); List<PrintJob> printJobs = printJobRepo.findByCustomerInfo(customer); printJobs.removeIf(job -> (job.getStatus() == Status.REJECTED || job.getStatus() == Status.COMPLETED)); if (printJobs.size() > 1) { Collections.sort(printJobs); } if (printJobs.size() > 0) { Queue newQueue = new Queue(printJobs.get(0), queueRepo.getMaximumRank()+1); newQueue = queueRepo.save(newQueue); } } GenericResponse response = new GenericResponse(); printJob.setStatus(requestStatus); printJobRepo.save(printJob); response.setSuccess(true); response.setMessage("Print Job Updated"); response.setHttpStatus(HttpStatus.ACCEPTED); 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);  }