- Process the Error of PDF-aggregation. Distinguish between "couldRetry" and "noRetry" cases.

- Update the "RequestParam" for the getUrls endpoints.
- Fix the "assignmentCounter".
- Code cleanup.
This commit is contained in:
Lampros Smyrnaios 2021-08-05 15:43:37 +03:00
parent 25c566bf68
commit d56e988518
4 changed files with 47 additions and 18 deletions

View File

@ -26,18 +26,25 @@ public class UrlController {
private static final Logger logger = LoggerFactory.getLogger(UrlController.class); private static final Logger logger = LoggerFactory.getLogger(UrlController.class);
private static AtomicLong assignmentCounter = new AtomicLong(); // Just for the "getTestUrls"-endpoint. private static AtomicLong assignmentCounter = new AtomicLong(0); // Just for the "getTestUrls"-endpoint.
} }
@GetMapping("") @GetMapping("")
public ResponseEntity<?> getUrls(@RequestParam String workerId, @RequestParam int workerTasksLimit) { public ResponseEntity<?> getUrls(@RequestParam String workerId, @RequestParam int workerAssignmentsLimit) {
List<Task> tasks = new ArrayList<>(); List<Task> tasks = new ArrayList<>();
// TODO - Create the Assignment from the id-urls stored in the database up to the tasks-limit. // TODO - Create the Assignment from the id-urls stored in the database up to the tasks-limit.
Date date = new Date(); // Store it here, in order to have the same date for all current assignments.
// TODO - Make sure the Date is the same for all entries!
Date date = new Date(); // Store it here, in order to have the same for sure.
int assignmentsLimit = ControllerConstants.ASSIGNMENTS_LIMIT;
if ( assignmentsLimit > workerAssignmentsLimit )
assignmentsLimit = workerAssignmentsLimit;
int tasksLimitForAssignment = ControllerConstants.ASSIGNMENTS_LIMIT; int tasksLimitForAssignment = ControllerConstants.ASSIGNMENTS_LIMIT;
@ -50,9 +57,9 @@ public class UrlController {
// TODO - Write the Assignment details to the database and then send it to the worker. // TODO - Write the Assignment details to the database and then send it to the worker.
logger.info("Sending assignment_" + assignmentCounter.get() + " to worker with ID: " + workerId); logger.info("Sending assignment_" + assignmentCounter.incrementAndGet() + " to worker with ID: " + workerId);
return ResponseEntity.status(200).header("Content-Type", "application/json").body(new AssignmentResponse(assignmentCounter.incrementAndGet(), assignments)); return ResponseEntity.status(200).header("Content-Type", "application/json").body(new AssignmentResponse(assignmentCounter.get(), assignments));
} }
@PostMapping("addWorkerReport") @PostMapping("addWorkerReport")
@ -70,7 +77,7 @@ public class UrlController {
@GetMapping("test") @GetMapping("test")
public ResponseEntity<?> getTestUrls(@RequestParam String workerId, @RequestParam int assignmentsLimit) { public ResponseEntity<?> getTestUrls(@RequestParam String workerId, @RequestParam int workerAssignmentsLimit) {
try { try {
new FileUtils(); // Find the input file. new FileUtils(); // Find the input file.
@ -98,7 +105,7 @@ public class UrlController {
for ( Map.Entry<String,String> pair : pairs ) for ( Map.Entry<String,String> pair : pairs )
{ {
if ( assignments.size() >= assignmentsLimit ) { if ( assignments.size() >= workerAssignmentsLimit ) {
assignmentsLimitReached = true; assignmentsLimitReached = true;
break; break;
} }
@ -108,7 +115,7 @@ public class UrlController {
}// end pairs-for-loop }// end pairs-for-loop
if ( assignmentsLimitReached ) { if ( assignmentsLimitReached ) {
logger.debug("Done loading urls from the inputFile as the assignmentsLimit (" + assignmentsLimit + ") was reached."); logger.debug("Done loading urls from the inputFile as the assignmentsLimit (" + workerAssignmentsLimit + ") was reached.");
break; break;
} }
}// end loading-while-loop }// end loading-while-loop
@ -116,9 +123,9 @@ public class UrlController {
if ( FileUtils.inputScanner.get() != null ) // Check if the initial value is null. if ( FileUtils.inputScanner.get() != null ) // Check if the initial value is null.
FileUtils.inputScanner.get().close(); FileUtils.inputScanner.get().close();
logger.info("Sending AssignmentResponse_" + assignmentCounter.get() + " with " + assignments.size() + " assignments (" + FileUtils.duplicateIdUrlEntries.get() + " more assignments were discarded as duplicates), to worker with ID: " + workerId); logger.info("Sending AssignmentResponse_" + assignmentCounter.incrementAndGet() + " with " + assignments.size() + " assignments (" + FileUtils.duplicateIdUrlEntries.get() + " more assignments were discarded as duplicates), to worker with ID: " + workerId);
return ResponseEntity.status(200).header("Content-Type", "application/json").body(new AssignmentResponse(assignmentCounter.incrementAndGet(), assignments)); return ResponseEntity.status(200).header("Content-Type", "application/json").body(new AssignmentResponse(assignmentCounter.get(), assignments));
} }
} }

View File

@ -7,7 +7,6 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
//import javax.persistence.*; //import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List;
//@Entity //@Entity

View File

@ -11,18 +11,27 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
}) })
public class Error { public class Error {
public enum ErrorType {
couldRetry, noRetry
}
@JsonProperty("type") @JsonProperty("type")
private String type; private ErrorType type;
@JsonProperty("message") @JsonProperty("message")
private String message; private String message;
public String getType() { public Error(ErrorType type, String message) {
this.type = type;
this.message = message;
}
public ErrorType getType() {
return type; return type;
} }
public void setType(String type) { public void setType(ErrorType type) {
type = type; this.type = type;
} }
public String getMessage() { public String getMessage() {
@ -36,7 +45,7 @@ public class Error {
@Override @Override
public String toString() { public String toString() {
return "Error{" + return "Error{" +
"type='" + type + '\'' + "type=" + type +
", message='" + message + '\'' + ", message='" + message + '\'' +
'}'; '}';
} }

View File

@ -8,7 +8,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ @JsonPropertyOrder({
"status", "status",
"payload" "payload",
"error"
}) })
public class UrlReport { public class UrlReport {
@ -18,10 +19,14 @@ public class UrlReport {
@JsonProperty("payload") @JsonProperty("payload")
private Payload payload; private Payload payload;
@JsonProperty("error")
private Error error;
public UrlReport(String status, Payload payload) {
public UrlReport(String status, Payload payload, Error error) {
this.status = status; this.status = status;
this.payload = payload; this.payload = payload;
this.error = error;
} }
@ -41,11 +46,20 @@ public class UrlReport {
this.payload = payload; this.payload = payload;
} }
public Error getError() {
return error;
}
public void setError(Error error) {
this.error = error;
}
@Override @Override
public String toString() { public String toString() {
return "UrlReport{" + return "UrlReport{" +
"status='" + status + '\'' + "status='" + status + '\'' +
", payload=" + payload + ", payload=" + payload +
", error=" + error +
'}'; '}';
} }
} }