- 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.
This commit is contained in:
Lampros Smyrnaios 2021-09-23 15:08:52 +03:00
parent 983b900da7
commit d931315ced
10 changed files with 38 additions and 281 deletions

View File

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

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

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

View File

@ -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;
}
}

View File

@ -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 + '\'' +
'}';
}
}

View File

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

View File

@ -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
}
}

View File

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

View File

@ -2,10 +2,7 @@ package eu.openaire.urls_controller.security;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; 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.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;