Skip to content

Commit

Permalink
Merge branch 'master' into sidebarAndTextInputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethoreson authored Jan 5, 2020
2 parents 44dccd7 + ab58366 commit 8e122ac
Show file tree
Hide file tree
Showing 27 changed files with 375 additions and 70 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
.DS_Store
dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import idealab.api.dto.response.PrintJobAuditForLastTwelveMonthsResponse;
import idealab.api.dto.response.AuditPrintJobColorCountResponse;
import idealab.api.dto.response.PrintJobAuditResponse;
import idealab.api.operations.AuditOperations;
Expand Down Expand Up @@ -37,4 +38,10 @@ public ResponseEntity<?> getPrintJobAuditGroupedByColorForPassedYear() {
return new ResponseEntity<>(response, response.getHttpStatus());
}

@GetMapping("/bymonths")
public ResponseEntity<?> getNumberOfAllPrintJobs() {
PrintJobAuditForLastTwelveMonthsResponse response = auditOperations.printNumberOfAllPrintJobsForLastTwelveMonths();
return new ResponseEntity<>(response, response.getHttpStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.security.Principal;

import idealab.api.dto.response.BasicPrintJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -41,22 +42,22 @@ public PrintJobController(PrintJobOperations printJobOperations) {
@GetMapping
public ResponseEntity<?> printJobGetAll(@RequestParam(required = false) String status) {
LOGGER.info("Return all print jobs");
DataResponse<PrintJob> response = printJobOperations.getAllPrintJobs(status);
DataResponse<BasicPrintJob> response = printJobOperations.getAllPrintJobs(status);

return new ResponseEntity<>(response, response.getHttpStatus());
}

// TODO W.E. : add query param or boolean to model to accept mass upload (ignore 5 file max)
@PostMapping
public ResponseEntity<?> printJobNew(@ModelAttribute PrintJobNewRequest model, Principal principal) {
DataResponse<PrintJob> response = printJobOperations.newPrintJob(model, principal);
DataResponse<BasicPrintJob> response = printJobOperations.newPrintJob(model, principal);

return new ResponseEntity<>(response, response.getHttpStatus());
}

@GetMapping("/{print-id}")
public ResponseEntity<?> printJobGetById(@PathVariable("print-id") Integer printId) {
DataResponse<PrintJob> response = printJobOperations.getPrintJobById(printId);
DataResponse<BasicPrintJob> response = printJobOperations.getPrintJobById(printId);
return new ResponseEntity<>(response, response.getHttpStatus());
}

Expand All @@ -65,7 +66,7 @@ public ResponseEntity<?> printJobUpdateModel(@PathVariable("print-id") Integer p
@ModelAttribute PrintModelUpdateRequest model) {

LOGGER.info("PrintJobUpdateModel request is job:" + printId.toString() + "| model: " + model.toString());
DataResponse<PrintJob> response = printJobOperations.updateModel(printId, model);
DataResponse<BasicPrintJob> response = printJobOperations.updateModel(printId, model);

return new ResponseEntity<>(response, response.getHttpStatus());
}
Expand Down Expand Up @@ -101,15 +102,15 @@ public ResponseEntity<?> printJobDelete(@RequestBody PrintJobDeleteRequest dto)
public ResponseEntity<?> getDeletablePrintJobs() {
LOGGER.info("getDeletablePrintJobs ");

DataResponse<PrintJob> response = printJobOperations.getDeletablePrintJobs();
DataResponse<BasicPrintJob> response = printJobOperations.getDeletablePrintJobs();

return new ResponseEntity<>(response, response.getHttpStatus());
}

//Don't include the field in the JSON if you dont want it updated
@PutMapping("/{print-id}")
public ResponseEntity<?> updatePrintJobProperties(@PathVariable("print-id") Integer printId, @RequestBody UpdatePrintJobPropertiesRequest request, Principal principal) {
DataResponse<PrintJob> response = printJobOperations.updatePrintJobProps(printId, request);
DataResponse<BasicPrintJob> response = printJobOperations.updatePrintJobProps(printId, request);
return new ResponseEntity<>(response, response.getHttpStatus());
}
}
161 changes: 161 additions & 0 deletions Backend/src/main/java/idealab/api/dto/response/BasicPrintJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package idealab.api.dto.response;

import idealab.api.model.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class BasicPrintJob {
private Integer id;
private CustomerInfo customerInfo;
private ColorType colorType;
private Status status;
private Queue queueId;
private String comments;
private String fileSharableLink;
private String filePath;
private String emailHash;

public BasicEmployee employee;

private LocalDateTime createdAt;
private LocalDateTime updatedAt;

public BasicPrintJob(){};

public BasicPrintJob(PrintJob printJob){
this.id = printJob.getId();
this.customerInfo = printJob.getCustomerInfo();
this.colorType = printJob.getColorType();
if(printJob.getEmployee() != null){
this.employee = new BasicEmployee(printJob.getEmployee().getUsername(), printJob.getEmployee().getRole(), printJob.getEmployee().getFirstName(), printJob.getEmployee().getLastName());
}
this.status = printJob.getStatus();
this.queueId = printJob.getQueueId();
this.comments = printJob.getComments();
this.fileSharableLink = printJob.getFileSharableLink();
this.filePath = printJob.getFilePath();
this.emailHash = printJob.getEmailHash();
this.createdAt = printJob.getCreatedAt();
this.updatedAt = printJob.getUpdatedAt();
}

public List<BasicPrintJob> ConvertPrintJobs(List<PrintJob> printJobs) {
return printJobs.stream()
.map(printJob -> new BasicPrintJob(printJob)).collect(Collectors.toList());
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public CustomerInfo getCustomerInfo() {
return customerInfo;
}

public void setCustomerInfo(CustomerInfo customerInfo) {
this.customerInfo = customerInfo;
}

public ColorType getColorType() {
return colorType;
}

public void setColorType(ColorType colorType) {
this.colorType = colorType;
}

public Status getStatus() {
return status;
}

public void setStatus(Status status) {
this.status = status;
}

public Queue getQueueId() {
return queueId;
}

public void setQueueId(Queue queueId) {
this.queueId = queueId;
}

public String getComments() {
return comments;
}

public void setComments(String comments) {
this.comments = comments;
}

public String getFileSharableLink() {
return fileSharableLink;
}

public void setFileSharableLink(String fileSharableLink) {
this.fileSharableLink = fileSharableLink;
}

public String getFilePath() {
return filePath;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}

public String getEmailHash() {
return emailHash;
}

public void setEmailHash(String emailHash) {
this.emailHash = emailHash;
}

public BasicEmployee getEmployee() {
return employee;
}

public void setEmployee(BasicEmployee employee) {
this.employee = employee;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}

public LocalDateTime getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BasicPrintJob basicPrintJob = (BasicPrintJob) o;
return Objects.equals(id, basicPrintJob.id) &&
Objects.equals(customerInfo, basicPrintJob.customerInfo) &&
Objects.equals(colorType, basicPrintJob.colorType) &&
Objects.equals(employee, basicPrintJob.employee) &&
status == basicPrintJob.status &&
Objects.equals(queueId, basicPrintJob.queueId) &&
Objects.equals(comments, basicPrintJob.comments) &&
Objects.equals(fileSharableLink, basicPrintJob.fileSharableLink) &&
Objects.equals(filePath, basicPrintJob.filePath) &&
Objects.equals(emailHash, basicPrintJob.emailHash);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package idealab.api.dto.response;

import java.util.Map;

public class PrintJobAuditForLastTwelveMonthsResponse extends GenericResponse {
private Map<String, Integer> data;

public Map<String, Integer> getData() {
return data;
}

public void setData(Map<String, Integer> data) {
this.data = data;
}

@Override
public String toString() {
return "PrintJobAuditForLastTwelveMonthsResponse {"
+"data "+data+
"}";
}
}
37 changes: 37 additions & 0 deletions Backend/src/main/java/idealab/api/operations/AuditOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import idealab.api.dto.response.PrintJobAuditForLastTwelveMonthsResponse;
import idealab.api.dto.response.AuditPrintJobColorCountResponse;
import idealab.api.dto.response.PrintJobAuditModel;
import idealab.api.dto.response.PrintJobAuditResponse;
Expand Down Expand Up @@ -88,4 +89,40 @@ private Map<String, Map<String,Integer>> groupPrintJobsByColorAndMonth(List<Prin
});
return data;
}

//print number of all printing jobs per month
public PrintJobAuditForLastTwelveMonthsResponse printNumberOfAllPrintJobsForLastTwelveMonths() {
//get last twelve months data
LocalDateTime date = LocalDateTime.now().minusMonths(12).withDayOfMonth(1);
long startDate = Timestamp.valueOf(date).getTime();

AuditQuery query = auditService.getPrintJobAuditQuery();
query.addOrder(AuditEntity.revisionNumber().desc());

//add method allows filtering, this is the only difference between getting all print jobs
query.add(AuditEntity.revisionProperty("timestamp").gt(startDate));

//calculating number of all print jobs requested for last 12 months
List<PrintJobAuditModel> auditList = auditService.processPrintJobAuditQuery(query);
Map<String, Integer> counterMap = new HashMap<>();
auditList.forEach((item) -> {
LocalDate listDate = item.getRevisionDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
String thisDate = listDate.getMonth()+" "+listDate.getYear();
Integer count = 0;
if(counterMap.containsKey(thisDate)) {
count = counterMap.get(thisDate) + 1;
counterMap.put(thisDate, count);
}
else {
count++;
counterMap.put(thisDate, count);
}
});
PrintJobAuditForLastTwelveMonthsResponse response = new PrintJobAuditForLastTwelveMonthsResponse();
response.setMessage("Successfully returned print job for last twelve months");
response.setSuccess(true);
response.setHttpStatus(HttpStatus.ACCEPTED);
response.setData(counterMap);
return response;
}
}
Loading

0 comments on commit 8e122ac

Please sign in to comment.