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

- Update the "RequestParam" for the getUrls endpoints.
- Fix the "assignmentCounter".
- Code cleanup.
springify_project
Lampros Smyrnaios 3 years ago
parent 25c566bf68
commit d56e988518

@ -26,18 +26,25 @@ public class UrlController {
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("")
public ResponseEntity<?> getUrls(@RequestParam String workerId, @RequestParam int workerTasksLimit) {
public ResponseEntity<?> getUrls(@RequestParam String workerId, @RequestParam int workerAssignmentsLimit) {
List<Task> tasks = new ArrayList<>();
// 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;
@ -50,9 +57,9 @@ public class UrlController {
// 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")
@ -70,7 +77,7 @@ public class UrlController {
@GetMapping("test")
public ResponseEntity<?> getTestUrls(@RequestParam String workerId, @RequestParam int assignmentsLimit) {
public ResponseEntity<?> getTestUrls(@RequestParam String workerId, @RequestParam int workerAssignmentsLimit) {
try {
new FileUtils(); // Find the input file.
@ -98,7 +105,7 @@ public class UrlController {
for ( Map.Entry<String,String> pair : pairs )
{
if ( assignments.size() >= assignmentsLimit ) {
if ( assignments.size() >= workerAssignmentsLimit ) {
assignmentsLimitReached = true;
break;
}
@ -108,7 +115,7 @@ public class UrlController {
}// end pairs-for-loop
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;
}
}// end loading-while-loop
@ -116,9 +123,9 @@ public class UrlController {
if ( FileUtils.inputScanner.get() != null ) // Check if the initial value is null.
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));
}
}

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

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

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

Loading…
Cancel
Save