Browse Source

- Add the "isControllerAlive"-endpoint.

- Change the data-type of the "UrlReport.status" to be "enum StatusType", in order to increase consistency and comparability.
- Change the "Date" datatype in "Payload" to have the SQL's version.
- Fix the project's name inside "settings.gradle".
- Code cleanup.
master
LSmyrnaios 2 months ago
parent
commit
d931315ced
  1. 2
      settings.gradle
  2. 24
      src/main/java/eu/openaire/urls_controller/controllers/GeneralController.java
  3. 16
      src/main/java/eu/openaire/urls_controller/exceptions/BadRequestException.java
  4. 12
      src/main/java/eu/openaire/urls_controller/models/Assignment.java
  5. 83
      src/main/java/eu/openaire/urls_controller/models/DownloadAttempt.java
  6. 45
      src/main/java/eu/openaire/urls_controller/models/FullText.java
  7. 18
      src/main/java/eu/openaire/urls_controller/models/Payload.java
  8. 102
      src/main/java/eu/openaire/urls_controller/models/Publication.java
  9. 14
      src/main/java/eu/openaire/urls_controller/models/UrlReport.java
  10. 3
      src/main/java/eu/openaire/urls_controller/security/SecurityConfiguration.java

2
settings.gradle

@ -3,4 +3,4 @@ pluginManagement {
gradlePluginPortal()
}
}
rootProject.name = 'urls_controller'
rootProject.name = 'UrlsController'

24
src/main/java/eu/openaire/urls_controller/controllers/GeneralController.java

@ -0,0 +1,24 @@
package eu.openaire.urls_controller.controllers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("")
public class GeneralController {
private static final Logger logger = LoggerFactory.getLogger(GeneralController.class);
@GetMapping("isAlive")
public ResponseEntity<?> isControllerAlive() {
logger.info("Received an \"isAlive\" request.");
return ResponseEntity.ok().build();
}
}

16
src/main/java/eu/openaire/urls_controller/exceptions/BadRequestException.java

@ -1,16 +0,0 @@
package eu.openaire.urls_controller.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException {
public BadRequestException(String message) {
super(message);
}
public BadRequestException(String message, Throwable cause) {
super(message, cause);
}
}

12
src/main/java/eu/openaire/urls_controller/models/Assignment.java

@ -4,13 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
//import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
//@Entity
//@Table(name = "assignment")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
@ -19,26 +15,20 @@ import java.util.Date;
"workerId",
"date"
})
public class Assignment implements Serializable {
public class Assignment {
//@Id
//@Column(name = "id")
@JsonProperty("id")
private String id;
//@Id
//@Column(name = "original_url")
@JsonProperty("original_url")
private String originalUrl;
@JsonProperty("datasource")
private Datasource datasource;
//@Column(name = "workerid")
@JsonProperty("workerid")
private String workerId;
//@Column(name = "date")
@JsonProperty("date")
private Date date;

83
src/main/java/eu/openaire/urls_controller/models/DownloadAttempt.java

@ -1,83 +0,0 @@
package eu.openaire.urls_controller.models;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.Date;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
"original_url",
"actual_url",
"date",
"status",
"error"
})
public class DownloadAttempt {
@JsonProperty("id")
private String id;
@JsonProperty("original_url")
private String original_url;
@JsonProperty("date")
private Date date;
@JsonProperty("status")
private String status;
@JsonProperty("error")
private Error error;
public DownloadAttempt(String id, String original_url, Date date, String status, Error error) {
this.id = id;
this.original_url = original_url;
this.date = date;
this.status = status;
this.error = error;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOriginal_url() {
return original_url;
}
public void setOriginal_url(String original_url) {
this.original_url = original_url;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Error getError() {
return error;
}
public void setError(Error error) {
this.error = error;
}
}

45
src/main/java/eu/openaire/urls_controller/models/FullText.java

@ -1,45 +0,0 @@
package eu.openaire.urls_controller.models;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
"link_to_payload"
})
public class FullText {
@JsonProperty("id")
private String id;
@JsonProperty("link_to_payload")
private String link_to_payload;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLink_to_payload() {
return link_to_payload;
}
public void setLink_to_payload(String link_to_payload) {
this.link_to_payload = link_to_payload;
}
@Override
public String toString() {
return "FullText{" +
"id='" + id + '\'' +
", link_to_payload='" + link_to_payload + '\'' +
'}';
}
}

18
src/main/java/eu/openaire/urls_controller/models/Payload.java

@ -4,13 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
//import javax.persistence.Column;
import java.io.Serializable;
import java.util.Date;
import java.sql.Date;
//@Entity
//@Table(name = "payload")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
@ -23,44 +19,36 @@ import java.util.Date;
"location",
"provenance"
})
public class Payload implements Serializable {
public class Payload {
//@Column(name = "id")
@JsonProperty("id")
private String id;
//@Column(name = "original_url")
@JsonProperty("original_url")
private String original_url;
//@Column(name = "date")
@JsonProperty("actual_url")
private String actual_url;
//@Column(name = "date")
@JsonProperty("date")
private Date date_acquired;
//@Column(name = "mimetype")
@JsonProperty("mime_type")
private String mime_type;
//@Column(name = "size")
@JsonProperty("size")
private Long size; // In bytes.
//@Column(name = "hash")
@JsonProperty("hash")
private String hash;
//@Column(name = "location")
@JsonProperty("location")
private String location;
//@Column(name = "provenance")
@JsonProperty("provenance")
private String provenance; // "crawl:<PluginName>"
public Payload() {}
public Payload(String id, String original_url, String actual_url, Date date_acquired, String mime_type, Long size, String hash, String location, String provenance) {
this.id = id;

102
src/main/java/eu/openaire/urls_controller/models/Publication.java

@ -1,102 +0,0 @@
package eu.openaire.urls_controller.models;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"id",
"dedupid",
"pids",
"urls",
"datasource",
"termsOfReuse"
})
public class Publication {
@JsonProperty("id")
private String id;
@JsonProperty("dedupid")
private String dedupid;
@JsonProperty("pids")
private List<String> pids;
@JsonProperty("urls")
private List<String> urls;
@JsonProperty("datasource")
private Datasource datasource;
@JsonProperty("termsOfReuse")
private String termsOfReuse; // Takes values from the TermsOfReuseEnum.
public Publication(String id, String dedupid, List<String> pids, List<String> urls, Datasource datasource, String termsOfReuse) {
this.id = id;
this.dedupid = dedupid;
this.pids = pids;
this.urls = urls;
this.datasource = datasource;
this.termsOfReuse = termsOfReuse;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDedupid() {
return dedupid;
}
public void setDedupid(String dedupid) {
this.dedupid = dedupid;
}
public List<String> getPids() {
return pids;
}
public void setPids(List<String> pids) {
this.pids = pids;
}
public List<String> getUrls() {
return urls;
}
public void setUrls(List<String> urls) {
this.urls = urls;
}
public Datasource getDatasource() {
return datasource;
}
public void setDatasource(Datasource datasource) {
this.datasource = datasource;
}
public String getTermsOfReuse() {
return termsOfReuse;
}
public void setTermsOfReuse(String termsOfReuse) {
this.termsOfReuse = termsOfReuse;
}
public enum TermsOfReuseEnum {
Full, Mining, Internal
}
}

14
src/main/java/eu/openaire/urls_controller/models/UrlReport.java

@ -13,8 +13,12 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
})
public class UrlReport {
public enum StatusType {
accessible, non_accessible
}
@JsonProperty("status")
private String status;
private StatusType status;
@JsonProperty("payload")
private Payload payload;
@ -23,18 +27,18 @@ public class UrlReport {
private Error error;
public UrlReport(String status, Payload payload, Error error) {
public UrlReport(StatusType status, Payload payload, Error error) {
this.status = status;
this.payload = payload;
this.error = error;
}
public String getStatus() {
public StatusType getStatus() {
return this.status;
}
public void setStatus(String status) {
public void setStatus(StatusType status) {
this.status = status;
}
@ -57,7 +61,7 @@ public class UrlReport {
@Override
public String toString() {
return "UrlReport{" +
"status='" + status + '\'' +
"status=" + status +
", payload=" + payload +
", error=" + error +
'}';

3
src/main/java/eu/openaire/urls_controller/security/SecurityConfiguration.java

@ -2,10 +2,7 @@ package eu.openaire.urls_controller.security;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

Loading…
Cancel
Save