partial impementation
This commit is contained in:
parent
44b7be3ba6
commit
8dc134021b
|
@ -1,5 +1,6 @@
|
|||
package eu.dnetlib.app.directindex.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import eu.dnetlib.app.directindex.sword.model.SwordMetadataDocument;
|
||||
|
@ -7,19 +8,25 @@ import eu.dnetlib.app.directindex.sword.model.SwordMetadataDocument;
|
|||
@Service
|
||||
public class DirectIndexService {
|
||||
|
||||
public void prepareMetadataDeletion() {
|
||||
@Autowired
|
||||
private DnetSolrClient dnetSolrClient;
|
||||
|
||||
public void prepareMetadataDeletion(final String id) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void prepareMetadataReplacement() {
|
||||
public void prepareMetadataReplacement(final String id, final SwordMetadataDocument document) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void prepareMetadataInsertion(final SwordMetadataDocument body) {
|
||||
public String prepareMetadataInsertion(final SwordMetadataDocument body) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
final String id = null;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package eu.dnetlib.app.directindex.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import eu.dnetlib.app.directindex.sword.model.SwordMetadataDocument;
|
||||
|
||||
@Service
|
||||
public class DnetSolrClient {
|
||||
|
||||
// TODO: implements an API to change the indexName (TMF / DMF)
|
||||
|
||||
@Value("${dnet.solr.baseurl}")
|
||||
private String baseUrl;
|
||||
|
||||
private String indexName;
|
||||
|
||||
public SwordMetadataDocument findDocument(final String id) {
|
||||
// TODO
|
||||
|
||||
final String solrUrl = currentUrl();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String saveDocument(final String id, final SwordMetadataDocument doc) {
|
||||
// TODO
|
||||
|
||||
final String solrUrl = currentUrl();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteDocument(final String id) {
|
||||
// TODO
|
||||
|
||||
final String solrUrl = currentUrl();
|
||||
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
// TODO
|
||||
|
||||
final String solrUrl = currentUrl();
|
||||
|
||||
}
|
||||
|
||||
private String currentUrl() {
|
||||
return baseUrl + "/" + indexName;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(final String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public synchronized String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
public synchronized void setIndexName(final String indexName) {
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,8 +13,12 @@ public class SwordException extends Exception {
|
|||
}
|
||||
|
||||
public SwordException(final SwordErrorType error) {
|
||||
super();
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return error.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.springframework.http.ResponseEntity;
|
|||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -21,6 +22,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import eu.dnetlib.app.directindex.service.DirectIndexService;
|
||||
import eu.dnetlib.app.directindex.service.DnetSolrClient;
|
||||
import eu.dnetlib.app.directindex.sword.model.SwordError;
|
||||
import eu.dnetlib.app.directindex.sword.model.SwordErrorType;
|
||||
import eu.dnetlib.app.directindex.sword.model.SwordMetadataDocument;
|
||||
|
@ -35,6 +37,9 @@ public class SwordServiceUrlController {
|
|||
@Autowired
|
||||
private DirectIndexService service;
|
||||
|
||||
@Autowired
|
||||
private DnetSolrClient dnetSolrClient;
|
||||
|
||||
@GetMapping("/")
|
||||
public SwordService getServiceDocument() {
|
||||
// TODO
|
||||
|
@ -65,7 +70,6 @@ public class SwordServiceUrlController {
|
|||
|
||||
final HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.setLocation(null);
|
||||
responseHeaders.set("ETag", null);
|
||||
|
||||
try {
|
||||
service.prepareMetadataInsertion(parseMetadata(json));
|
||||
|
@ -77,45 +81,38 @@ public class SwordServiceUrlController {
|
|||
|
||||
}
|
||||
|
||||
@GetMapping("/metadata")
|
||||
public ResponseEntity<SwordMetadataDocument> getMetadata() {
|
||||
@GetMapping("/{id}/metadata")
|
||||
public ResponseEntity<SwordMetadataDocument> getMetadata(@PathVariable final String id) throws SwordException {
|
||||
final SwordMetadataDocument metadata = dnetSolrClient.findDocument(id);
|
||||
|
||||
// TODO
|
||||
if (metadata == null) { throw new SwordException(SwordErrorType.NotFound); }
|
||||
|
||||
final SwordMetadataDocument metadata = null;
|
||||
|
||||
final HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.set("ETag", null);
|
||||
|
||||
return new ResponseEntity<>(metadata, responseHeaders, HttpStatus.OK);
|
||||
return new ResponseEntity<>(metadata, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PutMapping("/metadata")
|
||||
@PutMapping("/{id}/metadata")
|
||||
public ResponseEntity<Void> replaceMetadata(
|
||||
@RequestHeader("Content-Disposition") final String contentDisposition,
|
||||
@RequestHeader("Content-Length") final String contentLength,
|
||||
@RequestHeader("Content-Type") final String contentType,
|
||||
@RequestHeader("Digest") final String digest,
|
||||
@RequestHeader("If-Match") final boolean ifMatch,
|
||||
@RequestHeader(value = "Metadata-Format", defaultValue = "http://purl.org/net/sword/3.0/types/Metadata") final String mdFormat,
|
||||
@RequestBody final SwordMetadataDocument document) {
|
||||
@PathVariable final String id,
|
||||
@RequestBody final SwordMetadataDocument document) throws SwordException {
|
||||
|
||||
service.prepareMetadataReplacement();
|
||||
final SwordMetadataDocument metadata = dnetSolrClient.findDocument(id);
|
||||
|
||||
// TODO
|
||||
final HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.set("ETag", null);
|
||||
if (metadata == null) { throw new SwordException(SwordErrorType.NotFound); }
|
||||
|
||||
return new ResponseEntity<>(responseHeaders, HttpStatus.NO_CONTENT);
|
||||
service.prepareMetadataReplacement(id, document);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@DeleteMapping("/metadata")
|
||||
public ResponseEntity<Void> deleteMetadata(
|
||||
@RequestHeader("Authorization") final String authorization,
|
||||
@RequestHeader("If-Match") final boolean ifMatch,
|
||||
@RequestHeader("On-Behalf-Of") final String onBehalfOf) {
|
||||
public ResponseEntity<Void> deleteMetadata(@PathVariable final String id) {
|
||||
|
||||
service.prepareMetadataDeletion();
|
||||
service.prepareMetadataDeletion(id);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.ACCEPTED);
|
||||
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package eu.dnetlib.app.directindex.sword.model;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
@ -16,7 +12,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
public class SwordError {
|
||||
|
||||
@JsonProperty("@context")
|
||||
private final URL context;
|
||||
private final String context = "https://swordapp.github.io/swordv3/swordv3.jsonld";
|
||||
|
||||
@JsonProperty("@type")
|
||||
private final SwordErrorType type;
|
||||
|
@ -29,27 +25,20 @@ public class SwordError {
|
|||
|
||||
public SwordError(final HttpServletRequest req, final Throwable e) {
|
||||
|
||||
try {
|
||||
// TODO
|
||||
context = new URI("http://").toURL();
|
||||
} catch (final MalformedURLException | URISyntaxException e1) {
|
||||
throw new RuntimeException("Invalid URL");
|
||||
}
|
||||
|
||||
if (e instanceof SwordException) {
|
||||
type = ((SwordException) e).getError();
|
||||
error = ((SwordException) e).getMessage();
|
||||
} else {
|
||||
type = SwordErrorType.BadRequest;
|
||||
error = e.getMessage();
|
||||
}
|
||||
|
||||
error = e.getMessage();
|
||||
|
||||
timestamp = LocalDateTime.now();
|
||||
log = ExceptionUtils.getStackTrace(e);
|
||||
|
||||
}
|
||||
|
||||
public URL getContext() {
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,9 @@ public enum SwordErrorType {
|
|||
PackagingFormatNotAcceptable(415 , "The Packaging header specifies a packaging format for the request which is in a format that the server cannot accept"),
|
||||
SegmentedUploadTimedOut(410 , "The client's segmented upload URL has timed out. Servers MAY respond to this with a 404 and no explanation also."),
|
||||
SegmentLimitExceeded(400 , "During a segmented upload initialisation, the client specified a total number of intended segments which is larger than the limit specified by the server"),
|
||||
UnexpectedSegment(400 , "The client sent a segment that the server was not expecting; in particular the server may have recieved all the segments it was expecting, and this is an extra one");
|
||||
UnexpectedSegment(400 , "The client sent a segment that the server was not expecting; in particular the server may have recieved all the segments it was expecting, and this is an extra one"),
|
||||
NotFound(404, "There is no resource available at the URL you requested");
|
||||
|
||||
// @formatter:on
|
||||
|
||||
private final int httpCode;
|
||||
|
|
Loading…
Reference in New Issue