partial implementation

This commit is contained in:
Michele Artini 2024-11-06 15:41:13 +01:00
parent 03fb10dd60
commit a125798e1a
9 changed files with 118 additions and 39 deletions

View File

@ -1,5 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -8,8 +21,8 @@
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
@ -23,18 +36,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -0,0 +1,18 @@
package eu.dnetlib.app.directindex.service;
import org.springframework.stereotype.Service;
@Service
public class DirectIndexService {
public void prepareMetadataDeletion() {
// TODO Auto-generated method stub
}
public void prepareMetadataReplacement() {
// TODO Auto-generated method stub
}
}

View File

@ -1,42 +1,69 @@
package eu.dnetlib.app.directindex.sword; package eu.dnetlib.app.directindex.sword;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.app.directindex.service.DirectIndexService;
import eu.dnetlib.app.directindex.sword.model.SwordMetadataDocument;
@RestController("/api/directindex/metadata") @RestController("/api/directindex/metadata")
public class SwordMetadataUrlController { public class SwordMetadataUrlController {
@Autowired
private DirectIndexService service;
@GetMapping("/") @GetMapping("/")
public @ResponseBody Object getMetadata( public ResponseEntity<SwordMetadataDocument> getMetadata(
@RequestHeader("Authorization") final String authorization, @RequestHeader("Authorization") final String authorization,
@RequestHeader("On-Behalf-Of") final String onBehalfOf) { @RequestHeader("On-Behalf-Of") final String onBehalfOf) {
// TODO // TODO
return null;
final SwordMetadataDocument metadata = null;
final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("ETag", null);
return new ResponseEntity<>(metadata, responseHeaders, HttpStatus.OK);
} }
@PutMapping("/") @PutMapping("/")
public @ResponseBody Object replaceMetadata(@RequestHeader("Authorization") final String authorization, public ResponseEntity<Void> replaceMetadata(@RequestHeader("Authorization") final String authorization,
@RequestHeader("Content-Disposition") final String contentDisposition, @RequestHeader("Content-Disposition") final String contentDisposition,
@RequestHeader("Content-Length") final String contentLength, @RequestHeader("Content-Length") final String contentLength,
@RequestHeader("Content-Type") final String contentType, @RequestHeader("Content-Type") final String contentType,
@RequestHeader("Digest") final String digest, @RequestHeader("Digest") final String digest,
@RequestHeader("If-Match") final boolean ifMatch, @RequestHeader("If-Match") final boolean ifMatch,
@RequestHeader("On-Behalf-Of") final String onBehalfOf, @RequestHeader("On-Behalf-Of") final String onBehalfOf,
@RequestHeader(value = "Metadata-Format", defaultValue = "http://purl.org/net/sword/3.0/types/Metadata") final String mdFormat) { @RequestHeader(value = "Metadata-Format", defaultValue = "http://purl.org/net/sword/3.0/types/Metadata") final String mdFormat,
@RequestBody final SwordMetadataDocument document) {
service.prepareMetadataReplacement();
// TODO // TODO
return null; final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("ETag", null);
return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT);
} }
@DeleteMapping("/") @DeleteMapping("/")
public @ResponseBody Object deleteMetadata( public ResponseEntity<Void> deleteMetadata(
@RequestHeader("Authorization") final String authorization, @RequestHeader("Authorization") final String authorization,
@RequestHeader("If-Match") final boolean ifMatch, @RequestHeader("If-Match") final boolean ifMatch,
@RequestHeader("On-Behalf-Of") final String onBehalfOf) { @RequestHeader("On-Behalf-Of") final String onBehalfOf) {
// TODO
return null; service.prepareMetadataDeletion();
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} }
} }

View File

@ -1,16 +1,22 @@
package eu.dnetlib.app.directindex.sword; package eu.dnetlib.app.directindex.sword;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.app.directindex.sword.model.SwordService;
import eu.dnetlib.app.directindex.sword.model.SwordStatusDocument;
@RestController("/api/directindex/") @RestController("/api/directindex/")
public class SwordServiceUrlController { public class SwordServiceUrlController {
@GetMapping("/") @GetMapping("/")
public @ResponseBody Object getServiceDocument( public SwordService getServiceDocument(
@RequestHeader("Authorization") final String authorization, @RequestHeader("Authorization") final String authorization,
@RequestHeader("On-Behalf-Of") final String onBehalfOf) { @RequestHeader("On-Behalf-Of") final String onBehalfOf) {
// TODO // TODO
@ -18,7 +24,7 @@ public class SwordServiceUrlController {
} }
@PostMapping("/") @PostMapping("/")
public @ResponseBody Object makeNewObject( public ResponseEntity<SwordStatusDocument> makeNewObject(
@RequestHeader("Authorization") final String authorization, @RequestHeader("Authorization") final String authorization,
@RequestHeader("Content-Disposition") final String contentDisposition, @RequestHeader("Content-Disposition") final String contentDisposition,
@RequestHeader("Content-Length") final String contentLength, @RequestHeader("Content-Length") final String contentLength,
@ -28,9 +34,25 @@ public class SwordServiceUrlController {
@RequestHeader(value = "Metadata-Format", defaultValue = "http://purl.org/net/sword/3.0/types/Metadata") final String mdFormat, @RequestHeader(value = "Metadata-Format", defaultValue = "http://purl.org/net/sword/3.0/types/Metadata") final String mdFormat,
@RequestHeader("On-Behalf-Of") final String onBehalfOf, @RequestHeader("On-Behalf-Of") final String onBehalfOf,
@RequestHeader(value = "Packaging", defaultValue = "http://purl.org/net/sword/3.0/package/Binary") final String packaging, @RequestHeader(value = "Packaging", defaultValue = "http://purl.org/net/sword/3.0/package/Binary") final String packaging,
@RequestHeader("Slug") final String slug) { @RequestHeader("Slug") final String slug,
// Content used to create new Object. This can be one of: Metadata, By-Reference, Metadata+By-Reference, Binary File, Packaged
// Content, Empty Body
@RequestBody final Object content) {
// TODO // TODO
return null; final SwordStatusDocument status = null;
final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(null);
responseHeaders.set("ETag", null);
return new ResponseEntity<>(status, responseHeaders, isCreated() ? HttpStatus.CREATED : HttpStatus.ACCEPTED);
}
private boolean isCreated() {
// TODO Auto-generated method stub
return false;
} }
} }

View File

@ -2,7 +2,7 @@ package eu.dnetlib.app.directindex.sword.model;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
public class BaseInfo { public class SwordCommonInfo {
@JsonProperty("@id") @JsonProperty("@id")
private String id; private String id;

View File

@ -5,7 +5,7 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
public class Link { public class SwordLink {
@JsonProperty("@id") @JsonProperty("@id")
private String id; private String id;

View File

@ -0,0 +1,6 @@
package eu.dnetlib.app.directindex.sword.model;
public class SwordMetadataDocument {
}

View File

@ -6,7 +6,7 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
public class ServiceInfo extends BaseInfo { public class SwordService extends SwordCommonInfo {
@JsonProperty("@context") @JsonProperty("@context")
private static final String context = "https://swordapp.github.io/swordv3/swordv3.jsonld"; private static final String context = "https://swordapp.github.io/swordv3/swordv3.jsonld";
@ -14,9 +14,9 @@ public class ServiceInfo extends BaseInfo {
@JsonProperty("@type") @JsonProperty("@type")
private final String type = "Status"; private final String type = "Status";
private BaseInfo metadata; private SwordCommonInfo metadata;
private BaseInfo fileSet; private SwordCommonInfo fileSet;
private String service; private String service;
@ -26,17 +26,17 @@ public class ServiceInfo extends BaseInfo {
static { static {
actions.put("getMetadata", true); actions.put("getMetadata", true);
actions.put("getFiles", true); actions.put("getFiles", false);
actions.put("appendMetadata", true); actions.put("appendMetadata", true);
actions.put("appendFiles", true); actions.put("appendFiles", false);
actions.put("replaceMetadata", true); actions.put("replaceMetadata", true);
actions.put("replaceFiles", true); actions.put("replaceFiles", false);
actions.put("deleteMetadata", true); actions.put("deleteMetadata", true);
actions.put("deleteFiles", true); actions.put("deleteFiles", false);
actions.put("deleteObject", true); actions.put("deleteObject", false);
} }
private final List<Link> links = new ArrayList<>(); private final List<SwordLink> links = new ArrayList<>();
// @formatter:off // @formatter:off

View File

@ -0,0 +1,6 @@
package eu.dnetlib.app.directindex.sword.model;
public class SwordStatusDocument {
}