@Test(expected = IdeaLabApiException.class) public void createNewPrintJobNullFile() { DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>(); response.setHttpStatus(HttpStatus.BAD_REQUEST); response.setMessage("No file was submitted. Please attach a file to the request"); response.setSuccess(false); Principal principal = null; PrintJobNewRequest request = new PrintJobNewRequest(); request.setColor("RED"); request.setComments("COMMENTS"); request.setCustomerFirstName("test"); request.setCustomerLastName("testLast"); request.setEmail("test@email.com"); request.setFile(null); operations.newPrintJob(request, principal); }
public DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal) { printJobNewRequest.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("File could not be uploaded"); if (printJobNewRequest.getFile() == null) { throw new IdeaLabApiException(DROPBOX_UPLOAD_FILE_ERROR); } String email = printJobNewRequest.getEmail(); String emailHash = emailHashUtil.MD5Hash(email); String customerFirstName = printJobNewRequest.getCustomerFirstName(); String customerLastName = printJobNewRequest.getCustomerLastName(); String color = printJobNewRequest.getColor(); String comments = printJobNewRequest.getComments(); LocalDateTime currentTime = LocalDateTime.now(); CustomerInfo customer = customerInfoRepo.findByEmail(email); if (customer == null) { customer = new CustomerInfo(null, customerFirstName, customerLastName, email); customer = customerInfoRepo.save(customer); } if(customer.getPrintJobs() != null && customer.getPrintJobs().size() > 5) { int countForDay = 0; for(PrintJob p : customer.getPrintJobs()) { if(p.getCreatedAt().plusHours(24).isAfter(LocalDateTime.now())) { countForDay++; } } if(countForDay > 5) { throw new IdeaLabApiException(GENERAL_ERROR, "Customer has already created 5 print jobs in the last 24 hours"); } } ColorType databaseColor = colorTypeRepo.findByColor(color); if (databaseColor == null) { throw new IdeaLabApiException(COLOR_CANT_FIND_BY_TYPE); } Employee databaseEmployee = employeeRepo.findEmployeeByUsername(principal.getName()); PrintJob printJob = new PrintJob(customer, databaseColor, databaseEmployee, Status.PENDING_REVIEW, comments, emailHash); Map<String, String> data = fileService.uploadFile(currentTime.toLocalTime().toNanoOfDay(), printJobNewRequest.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); Set<PrintJob> printJobs; if(customer.getPrintJobs() == null) { printJobs = new HashSet<>(); } else { printJobs = customer.getPrintJobs(); } printJobs.add(printJob); customer.setPrintJobs(printJobs); printJob = printJobRepo.save(printJob); if (printJobRepo.findByCustomerInfo(customer).size() == 1) { Queue queue = new Queue(printJob, queueRepo.getMaximumRank()+1); queue = queueRepo.save(queue); } return getPrintJobResponse(response, printJob, data, "Successfully saved new file to database!"); }
PrintJobOperations { public DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal) { printJobNewRequest.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("File could not be uploaded"); if (printJobNewRequest.getFile() == null) { throw new IdeaLabApiException(DROPBOX_UPLOAD_FILE_ERROR); } String email = printJobNewRequest.getEmail(); String emailHash = emailHashUtil.MD5Hash(email); String customerFirstName = printJobNewRequest.getCustomerFirstName(); String customerLastName = printJobNewRequest.getCustomerLastName(); String color = printJobNewRequest.getColor(); String comments = printJobNewRequest.getComments(); LocalDateTime currentTime = LocalDateTime.now(); CustomerInfo customer = customerInfoRepo.findByEmail(email); if (customer == null) { customer = new CustomerInfo(null, customerFirstName, customerLastName, email); customer = customerInfoRepo.save(customer); } if(customer.getPrintJobs() != null && customer.getPrintJobs().size() > 5) { int countForDay = 0; for(PrintJob p : customer.getPrintJobs()) { if(p.getCreatedAt().plusHours(24).isAfter(LocalDateTime.now())) { countForDay++; } } if(countForDay > 5) { throw new IdeaLabApiException(GENERAL_ERROR, "Customer has already created 5 print jobs in the last 24 hours"); } } ColorType databaseColor = colorTypeRepo.findByColor(color); if (databaseColor == null) { throw new IdeaLabApiException(COLOR_CANT_FIND_BY_TYPE); } Employee databaseEmployee = employeeRepo.findEmployeeByUsername(principal.getName()); PrintJob printJob = new PrintJob(customer, databaseColor, databaseEmployee, Status.PENDING_REVIEW, comments, emailHash); Map<String, String> data = fileService.uploadFile(currentTime.toLocalTime().toNanoOfDay(), printJobNewRequest.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); Set<PrintJob> printJobs; if(customer.getPrintJobs() == null) { printJobs = new HashSet<>(); } else { printJobs = customer.getPrintJobs(); } printJobs.add(printJob); customer.setPrintJobs(printJobs); printJob = printJobRepo.save(printJob); if (printJobRepo.findByCustomerInfo(customer).size() == 1) { Queue queue = new Queue(printJob, queueRepo.getMaximumRank()+1); queue = queueRepo.save(queue); } return getPrintJobResponse(response, printJob, data, "Successfully saved new file to database!"); } }
PrintJobOperations { public DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal) { printJobNewRequest.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("File could not be uploaded"); if (printJobNewRequest.getFile() == null) { throw new IdeaLabApiException(DROPBOX_UPLOAD_FILE_ERROR); } String email = printJobNewRequest.getEmail(); String emailHash = emailHashUtil.MD5Hash(email); String customerFirstName = printJobNewRequest.getCustomerFirstName(); String customerLastName = printJobNewRequest.getCustomerLastName(); String color = printJobNewRequest.getColor(); String comments = printJobNewRequest.getComments(); LocalDateTime currentTime = LocalDateTime.now(); CustomerInfo customer = customerInfoRepo.findByEmail(email); if (customer == null) { customer = new CustomerInfo(null, customerFirstName, customerLastName, email); customer = customerInfoRepo.save(customer); } if(customer.getPrintJobs() != null && customer.getPrintJobs().size() > 5) { int countForDay = 0; for(PrintJob p : customer.getPrintJobs()) { if(p.getCreatedAt().plusHours(24).isAfter(LocalDateTime.now())) { countForDay++; } } if(countForDay > 5) { throw new IdeaLabApiException(GENERAL_ERROR, "Customer has already created 5 print jobs in the last 24 hours"); } } ColorType databaseColor = colorTypeRepo.findByColor(color); if (databaseColor == null) { throw new IdeaLabApiException(COLOR_CANT_FIND_BY_TYPE); } Employee databaseEmployee = employeeRepo.findEmployeeByUsername(principal.getName()); PrintJob printJob = new PrintJob(customer, databaseColor, databaseEmployee, Status.PENDING_REVIEW, comments, emailHash); Map<String, String> data = fileService.uploadFile(currentTime.toLocalTime().toNanoOfDay(), printJobNewRequest.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); Set<PrintJob> printJobs; if(customer.getPrintJobs() == null) { printJobs = new HashSet<>(); } else { printJobs = customer.getPrintJobs(); } printJobs.add(printJob); customer.setPrintJobs(printJobs); printJob = printJobRepo.save(printJob); if (printJobRepo.findByCustomerInfo(customer).size() == 1) { Queue queue = new Queue(printJob, queueRepo.getMaximumRank()+1); queue = queueRepo.save(queue); } return getPrintJobResponse(response, printJob, data, "Successfully saved new file to database!"); } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); }
PrintJobOperations { public DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal) { printJobNewRequest.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("File could not be uploaded"); if (printJobNewRequest.getFile() == null) { throw new IdeaLabApiException(DROPBOX_UPLOAD_FILE_ERROR); } String email = printJobNewRequest.getEmail(); String emailHash = emailHashUtil.MD5Hash(email); String customerFirstName = printJobNewRequest.getCustomerFirstName(); String customerLastName = printJobNewRequest.getCustomerLastName(); String color = printJobNewRequest.getColor(); String comments = printJobNewRequest.getComments(); LocalDateTime currentTime = LocalDateTime.now(); CustomerInfo customer = customerInfoRepo.findByEmail(email); if (customer == null) { customer = new CustomerInfo(null, customerFirstName, customerLastName, email); customer = customerInfoRepo.save(customer); } if(customer.getPrintJobs() != null && customer.getPrintJobs().size() > 5) { int countForDay = 0; for(PrintJob p : customer.getPrintJobs()) { if(p.getCreatedAt().plusHours(24).isAfter(LocalDateTime.now())) { countForDay++; } } if(countForDay > 5) { throw new IdeaLabApiException(GENERAL_ERROR, "Customer has already created 5 print jobs in the last 24 hours"); } } ColorType databaseColor = colorTypeRepo.findByColor(color); if (databaseColor == null) { throw new IdeaLabApiException(COLOR_CANT_FIND_BY_TYPE); } Employee databaseEmployee = employeeRepo.findEmployeeByUsername(principal.getName()); PrintJob printJob = new PrintJob(customer, databaseColor, databaseEmployee, Status.PENDING_REVIEW, comments, emailHash); Map<String, String> data = fileService.uploadFile(currentTime.toLocalTime().toNanoOfDay(), printJobNewRequest.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); Set<PrintJob> printJobs; if(customer.getPrintJobs() == null) { printJobs = new HashSet<>(); } else { printJobs = customer.getPrintJobs(); } printJobs.add(printJob); customer.setPrintJobs(printJobs); printJob = printJobRepo.save(printJob); if (printJobRepo.findByCustomerInfo(customer).size() == 1) { Queue queue = new Queue(printJob, queueRepo.getMaximumRank()+1); queue = queueRepo.save(queue); } return getPrintJobResponse(response, printJob, data, "Successfully saved new file to database!"); } 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> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal) { printJobNewRequest.validate(); DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("File could not be uploaded"); if (printJobNewRequest.getFile() == null) { throw new IdeaLabApiException(DROPBOX_UPLOAD_FILE_ERROR); } String email = printJobNewRequest.getEmail(); String emailHash = emailHashUtil.MD5Hash(email); String customerFirstName = printJobNewRequest.getCustomerFirstName(); String customerLastName = printJobNewRequest.getCustomerLastName(); String color = printJobNewRequest.getColor(); String comments = printJobNewRequest.getComments(); LocalDateTime currentTime = LocalDateTime.now(); CustomerInfo customer = customerInfoRepo.findByEmail(email); if (customer == null) { customer = new CustomerInfo(null, customerFirstName, customerLastName, email); customer = customerInfoRepo.save(customer); } if(customer.getPrintJobs() != null && customer.getPrintJobs().size() > 5) { int countForDay = 0; for(PrintJob p : customer.getPrintJobs()) { if(p.getCreatedAt().plusHours(24).isAfter(LocalDateTime.now())) { countForDay++; } } if(countForDay > 5) { throw new IdeaLabApiException(GENERAL_ERROR, "Customer has already created 5 print jobs in the last 24 hours"); } } ColorType databaseColor = colorTypeRepo.findByColor(color); if (databaseColor == null) { throw new IdeaLabApiException(COLOR_CANT_FIND_BY_TYPE); } Employee databaseEmployee = employeeRepo.findEmployeeByUsername(principal.getName()); PrintJob printJob = new PrintJob(customer, databaseColor, databaseEmployee, Status.PENDING_REVIEW, comments, emailHash); Map<String, String> data = fileService.uploadFile(currentTime.toLocalTime().toNanoOfDay(), printJobNewRequest.getFile()); printJob.setFilePath(data.get("filePath")); printJob.setFileSharableLink(data.get("sharableLink")); Set<PrintJob> printJobs; if(customer.getPrintJobs() == null) { printJobs = new HashSet<>(); } else { printJobs = customer.getPrintJobs(); } printJobs.add(printJob); customer.setPrintJobs(printJobs); printJob = printJobRepo.save(printJob); if (printJobRepo.findByCustomerInfo(customer).size() == 1) { Queue queue = new Queue(printJob, queueRepo.getMaximumRank()+1); queue = queueRepo.save(queue); } return getPrintJobResponse(response, printJob, data, "Successfully saved new file to database!"); } 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);  }