diff --git a/src/main/java/edu/kit/datamanager/pit/web/doip/DoipOverHttp.java b/src/main/java/edu/kit/datamanager/pit/web/doip/DoipOverHttp.java new file mode 100644 index 00000000..e4cef677 --- /dev/null +++ b/src/main/java/edu/kit/datamanager/pit/web/doip/DoipOverHttp.java @@ -0,0 +1,67 @@ +/** + * A lot of code re-used from metadataHub, Apache 2.0 License. + * + * Original Code: https://git.rwth-aachen.de/nfdi4ing/s-3/s-3-3/metadatahub/-/blob/main/src/main/java/edu/kit/metadatahub/rest/controller/Rest4DoipController.java + */ + +package edu.kit.datamanager.pit.web.doip; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; + +/** + * REST controller for DOIP over HTTP. + */ +@RestController +@CrossOrigin(origins = "*", allowedHeaders = "*") +@ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "The request was processed successfully."), + @ApiResponse(responseCode = "400", description = "There was something wrong with the structure or content of the request"), + @ApiResponse(responseCode = "401", description = "The client must authenticate to perform the attempted operation"), + @ApiResponse(responseCode = "403", description = "The client was not permitted to perform the attempted operation"), + @ApiResponse(responseCode = "404", description = "The requested digital object could not be found"), + @ApiResponse(responseCode = "409", description = "There was a conflict preventing the request from being executed"), + @ApiResponse(responseCode = "500", description = "There was an internal server error") }) +public class DoipOverHttp { + + private static final Logger LOGGER = LoggerFactory.getLogger(DoipOverHttp.class); + + /** + * Get all mapping IDs defined in mapping configuration directory. + * + * @param operationId + * @param digitalObject + * @return Array containing all mappingIDs. + * @throws net.dona.doip.client.DoipException + * @throws java.io.IOException + */ + @Operation(summary = "DOIPv2 over HTTP.", description = "DOIPv2 via HTTP as defined by Cordra, as far as applicable.") + @PostMapping(value = { "/doip" }, consumes = { MediaType.APPLICATION_JSON_VALUE }) + @ResponseBody + public ResponseEntity postDoipOperation( + @Parameter(description = "The operationId.", required = true) + @RequestParam(value = "operationId") + final Operations operationId, + + @Parameter(description = "Json representation of the Digital Object.", required = false) + @RequestBody(required = false) + final DoipRequest digitalObject + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/src/main/java/edu/kit/datamanager/pit/web/doip/DoipRequest.java b/src/main/java/edu/kit/datamanager/pit/web/doip/DoipRequest.java new file mode 100644 index 00000000..83c53490 --- /dev/null +++ b/src/main/java/edu/kit/datamanager/pit/web/doip/DoipRequest.java @@ -0,0 +1,87 @@ +/* + * Adapted from: https://git.rwth-aachen.de/nfdi4ing/s-3/s-3-3/metadatahub/-/blob/main/src/main/java/edu/kit/metadatahub/doip/rest/RestDoip.java#L39 + * + * License: Apache 2.0 + */ +package edu.kit.datamanager.pit.web.doip; + +import java.util.ArrayList; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import edu.kit.datamanager.pit.domain.SimplePair; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "id", + "clientId", + "datacite", + "attributes", + "elements", + "header" +}) +public class DoipRequest { + + @JsonProperty("id") + private String id; + @JsonProperty("clientId") + private String clientId; + @JsonProperty("targetId") + private String targetId; + @JsonProperty("token") + private String token; + @JsonProperty("attributes") + private List attributes = new ArrayList<>(); + + @JsonProperty("id") + public String getId() { + return id; + } + + @JsonProperty("id") + public void setId(String id) { + this.id = id; + } + + @JsonProperty("clientId") + public String getClientId() { + return clientId; + } + + @JsonProperty("clientId") + public void setClientId(String clientId) { + this.clientId = clientId; + } + + @JsonProperty("targetId") + public String getTargetId() { + return targetId; + } + + @JsonProperty("targetId") + public void setTargetId(String targetId) { + this.targetId = targetId; + } + + @JsonProperty("token") + public String getToken() { + return token; + } + + @JsonProperty("token") + public void setToken(String token) { + this.token = token; + } + + @JsonProperty("attributes") + public List getAttributes() { + return attributes; + } + + @JsonProperty("attributes") + public void setAttributes(List attributes) { + this.attributes = attributes; + } +} diff --git a/src/main/java/edu/kit/datamanager/pit/web/doip/Operations.java b/src/main/java/edu/kit/datamanager/pit/web/doip/Operations.java new file mode 100644 index 00000000..8eab0dd4 --- /dev/null +++ b/src/main/java/edu/kit/datamanager/pit/web/doip/Operations.java @@ -0,0 +1,39 @@ +/* + * From https://git.rwth-aachen.de/nfdi4ing/s-3/s-3-3/metadatahub/-/blob/main/src/main/java/edu/kit/metadatahub/doip/rest/Operations.java + * + * License: Apache 2.0 + */ + +package edu.kit.datamanager.pit.web.doip; + +/** + * Define valid operations for REST interface of DOIP. + */ +public enum Operations { + OP_CREATE("0.DOIP/Op.Create"), + OP_RETRIEVE("0.DOIP/Op.Retrieve"), + OP_UPDATE("0.DOIP/Op.Update"), + OP_DELETE("0.DOIP/Op.Delete"), + OP_SEARCH("0.DOIP/Op.Search"), + OP_VALIDATE("0.DOIP/Op.Validation"); + + private final String value; + + Operations(String v) { + value = v; + } + + public String value() { + return value; + } + + public static Operations fromValue(String v) { + for (Operations c : Operations.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +}