-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: started DOIP v2.0 over HTTP implementation
- Loading branch information
Showing
3 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/edu/kit/datamanager/pit/web/doip/DoipOverHttp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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); | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/edu/kit/datamanager/pit/web/doip/DoipRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SimplePair> 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<SimplePair> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
@JsonProperty("attributes") | ||
public void setAttributes(List<SimplePair> attributes) { | ||
this.attributes = attributes; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/edu/kit/datamanager/pit/web/doip/Operations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |