Skip to content
Snippets Groups Projects
Unverified Commit 90c0203d authored by Martin Weise's avatar Martin Weise
Browse files

Added ListIdentifiers

parent 467e08c0
No related branches found
No related tags found
1 merge request!86Resolve "OAI-PMH"
Showing
with 262 additions and 54 deletions
package at.tuwien;
import lombok.*;
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Identify {
private String repositoryName;
private String baseURL;
@Builder.Default
private String protocolVersion = "2.0";
private String adminEmail;
private String earliestDatestamp;
private String deletedRecord;
private String granularity;
}
package at.tuwien;
import lombok.Getter;
@Getter
public enum OaiErrorType {
BAD_VERB("badVerb", "Unknown verb"),
ID_DOES_NOT_EXIST("idDoesNotExist", "The value of the identifier argument is unknown or illegal in this repository."),
CANNOT_DISSEMINATE_FORMAT("cannotDisseminateFormat", "The metadata format identified by the value given for the metadataPrefix argument is not supported by the item or by the repository."),
NO_RECORDS_MATCH("noRecordsMatch", "The combination of the values of the from, until, set, and metadataPrefix arguments results in an empty list."),
NO_METADATA_FORMATS("noMetadataFormats", "There are no metadata formats available for the specified item."),
NO_SET_HIERARCHY("noSetHierarchy", "The repository does not support sets."),
BAD_RESUMPTION_TOKEN("badResumptionToken", "The value of the resumptionToken argument is invalid or expired."),
BAD_ARGUMENT("badArgument", "The request includes illegal arguments, is missing required arguments, includes a repeated argument, or values for arguments have an illegal syntax.");
private String errorCode;
private String errorText;
OaiErrorType(String errorCode, String errorText) {
this.errorCode = errorCode;
this.errorText = errorText;
}
}
package at.tuwien;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import java.text.ParseException;
import java.util.Date;
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OaiListIdentifiersParameters extends RequestParameters {
private static final String[] DATE_FORMATS = {"yyyy-MM-dd'T'HH:mm'Z'",
"yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd"};
private String metadataPrefix;
private String from;
private String until;
private String set;
private String resumptionToken;
public Date getFromDate() throws ParseException {
if (StringUtils.isNotEmpty(from)) {
return DateUtils.parseDate(from, DATE_FORMATS);
}
return null;
}
public Date getUntilDate() throws ParseException {
if (StringUtils.isNotEmpty(until)) {
return DateUtils.parseDate(until, DATE_FORMATS);
}
return null;
}
@Override
public String getParametersString() {
StringBuilder builder = new StringBuilder();
appendIfNotEmpty(builder, "metadataPrefix", this.getMetadataPrefix());
appendIfNotEmpty(builder, "from", this.getFrom());
appendIfNotEmpty(builder, "until", this.getUntil());
appendIfNotEmpty(builder, "set", this.getSet());
appendIfNotEmpty(builder, "resumptionToken", this.getResumptionToken());
return builder.toString();
}
}
\ No newline at end of file
package at.tuwien;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import java.text.ParseException;
import java.util.Date;
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OaiListRecordsParameters extends RequestParameters {
private static final String[] DATE_FORMATS = {"yyyy-MM-dd'T'HH:mm'Z'",
"yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd"};
private String metadataPrefix;
private String from;
private String until;
private String set;
private String resumptionToken;
public Date getFromDate() throws ParseException {
if (StringUtils.isNotEmpty(from)) {
return DateUtils.parseDate(from, DATE_FORMATS);
}
return null;
}
public Date getUntilDate() throws ParseException {
if (StringUtils.isNotEmpty(until)) {
return DateUtils.parseDate(until, DATE_FORMATS);
}
return null;
}
@Override
public String getParametersString() {
StringBuilder builder = new StringBuilder();
appendIfNotEmpty(builder, "metadataPrefix", this.getMetadataPrefix());
appendIfNotEmpty(builder, "from", this.getFrom());
appendIfNotEmpty(builder, "until", this.getUntil());
appendIfNotEmpty(builder, "set", this.getSet());
appendIfNotEmpty(builder, "resumptionToken", this.getResumptionToken());
return builder.toString();
}
}
\ No newline at end of file
package at.tuwien;
import org.apache.commons.lang3.StringUtils;
public abstract class RequestParameters {
public abstract String getParametersString();
protected void appendIfNotEmpty(StringBuilder builder, String name, String value) {
if (StringUtils.isNotEmpty(value)) {
builder.append(name).append("=").append("\"").append(value).append("\" ");
}
}
}
...@@ -25,6 +25,7 @@ ENV METADATA_DB=fda ...@@ -25,6 +25,7 @@ ENV METADATA_DB=fda
ENV METADATA_USERNAME=postgres ENV METADATA_USERNAME=postgres
ENV METADATA_PASSWORD=postgres ENV METADATA_PASSWORD=postgres
ENV GATEWAY_ENDPOINT=http://gateway-service:9095 ENV GATEWAY_ENDPOINT=http://gateway-service:9095
ENV PID_BASE="https://example.com/pid/"
ENV REPOSITORY_NAME="Example Repository" ENV REPOSITORY_NAME="Example Repository"
ENV BASE_URL="https://example.com" ENV BASE_URL="https://example.com"
ENV ADMIN_MAIL="noreply@example.com" ENV ADMIN_MAIL="noreply@example.com"
......
...@@ -74,6 +74,12 @@ ...@@ -74,6 +74,12 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>at.tuwien</groupId>
<artifactId>fda-metadata-db-querystore</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<!-- IDE --> <!-- IDE -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
......
package at.tuwien.endpoints; package at.tuwien.endpoints;
import at.tuwien.OaiErrorType;
import at.tuwien.OaiListIdentifiersParameters;
import at.tuwien.OaiListRecordsParameters;
import at.tuwien.service.MetadataService; import at.tuwien.service.MetadataService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI; import javax.ws.rs.core.Response;
@Log4j2 @Log4j2
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
...@@ -23,15 +27,25 @@ public class MetadataEndpoint extends AbstractEndpoint { ...@@ -23,15 +27,25 @@ public class MetadataEndpoint extends AbstractEndpoint {
this.metadataService = metadataService; this.metadataService = metadataService;
} }
@GetMapping @GetMapping(produces = "text/xml;charset=UTF-8")
@Operation(summary = "Identify the repository") @Operation(summary = "Identify the repository")
public ResponseEntity<?> identify(UriComponentsBuilder uriComponentsBuilder) { public ResponseEntity<?> identify() {
final URI uri = uriComponentsBuilder return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.replacePath(null) .body(metadataService.error(OaiErrorType.BAD_VERB));
.replaceQuery(null) }
.build().toUri();
final String document = metadataService.identify(uri.toString()); @GetMapping(params = "verb=Identify", produces = "text/xml;charset=UTF-8")
return ResponseEntity.ok(document); @Operation(summary = "Identify the repository")
@Parameter(name = "verb", example = "Identify")
public ResponseEntity<?> identifyAlt() {
return ResponseEntity.ok(metadataService.identify());
}
@GetMapping(params = "verb=ListIdentifiers", produces = "text/xml;charset=UTF-8")
@Operation(summary = "List the identifiers")
@Parameter(name = "verb", example = "ListIdentifiers")
public ResponseEntity<?> listRecords(OaiListIdentifiersParameters parameters) {
return ResponseEntity.ok(metadataService.listIdentifiers(parameters));
} }
} }
...@@ -35,6 +35,7 @@ eureka: ...@@ -35,6 +35,7 @@ eureka:
client.serviceUrl.defaultZone: http://discovery-service:9090/eureka/ client.serviceUrl.defaultZone: http://discovery-service:9090/eureka/
fda: fda:
ready.path: ./ready ready.path: ./ready
pid.base: "${PID_BASE}"
gateway.endpoint: "${GATEWAY_ENDPOINT}" gateway.endpoint: "${GATEWAY_ENDPOINT}"
dbrepo: dbrepo:
repository-name: "${REPOSITORY_NAME}" repository-name: "${REPOSITORY_NAME}"
......
...@@ -35,10 +35,11 @@ eureka: ...@@ -35,10 +35,11 @@ eureka:
client.serviceUrl.defaultZone: http://localhost:9090/eureka/ client.serviceUrl.defaultZone: http://localhost:9090/eureka/
fda: fda:
ready.path: ./ready ready.path: ./ready
pid.base: https://example.com/pid/
gateway.endpoint: http://localhost:9095 gateway.endpoint: http://localhost:9095
dbrepo: dbrepo:
repository-name: TU Wien Database Repository repository-name: TU Wien Database Repository
base-url: https://dbrepo.ossdip.at base-url: https://dbrepo.ossdip.at/api/oai
admin-email: noreply@example.com admin-email: noreply@example.com
earliest-datestamp: 2022-09-17T16:09:00Z earliest-datestamp: 2022-09-17T16:09:00Z
deleted-record: persistent deleted-record: persistent
......
...@@ -39,6 +39,7 @@ eureka: ...@@ -39,6 +39,7 @@ eureka:
client.serviceUrl.defaultZone: http://discovery-service:9090/eureka/ client.serviceUrl.defaultZone: http://discovery-service:9090/eureka/
fda: fda:
ready.path: ./ready ready.path: ./ready
pid.base: "${PID_BASE}"
gateway.endpoint: "${GATEWAY_ENDPOINT}" gateway.endpoint: "${GATEWAY_ENDPOINT}"
dbrepo: dbrepo:
repository-name: "${REPOSITORY_NAME}" repository-name: "${REPOSITORY_NAME}"
......
<?xml version='1.0' encoding='UTF-8'?>
<OAI-PMH xmlns='http://www.openarchives.org/OAI/2.0/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd'>
<responseDate>[[${responseDate}]]</responseDate>
[(${request})]
[(${body})]
</OAI-PMH>
\ No newline at end of file
<error th:attr="code=${code}">[[${message}]]</error>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<OAI-PMH xmlns='http://www.openarchives.org/OAI/2.0/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd'>
<responseDate>[[${responseDate}]]</responseDate>
<request verb="Identify">[[${request}]]</request>
<Identify> <Identify>
<repositoryName>[[${repositoryName}]]</repositoryName> <repositoryName>[[${repositoryName}]]</repositoryName>
<baseURL>[[${baseURL}]]</baseURL> <baseURL>[[${baseURL}]]</baseURL>
...@@ -12,4 +7,3 @@ ...@@ -12,4 +7,3 @@
<deletedRecord>[[${deletedRecord}]]</deletedRecord> <deletedRecord>[[${deletedRecord}]]</deletedRecord>
<granularity>[[${granularity}]]</granularity> <granularity>[[${granularity}]]</granularity>
</Identify> </Identify>
\ No newline at end of file
</OAI-PMH>
\ No newline at end of file
<header>
<identifier>[[${identifier}]]</identifier>
<datestamp>[[${datestamp}]]</datestamp>
</header>
\ No newline at end of file
...@@ -26,4 +26,7 @@ public class MetadataConfig { ...@@ -26,4 +26,7 @@ public class MetadataConfig {
@Value("${dbrepo.granularity}") @Value("${dbrepo.granularity}")
private String granularity; private String granularity;
@Value("${fda.pid.base}")
private String pidBase;
} }
package at.tuwien.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public class InvalidPrefixException extends Exception {
public InvalidPrefixException(String msg) {
super(msg);
}
public InvalidPrefixException(String msg, Throwable thr) {
super(msg, thr);
}
public InvalidPrefixException(Throwable thr) {
super(thr);
}
}
package at.tuwien.mapper;
import org.mapstruct.Mapper;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@Mapper(componentModel = "spring")
public interface MetadataMapper {
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MetadataMapper.class);
default String instantToDatestamp(Instant data) {
return DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
.withZone(ZoneId.systemDefault())
.format(data);
}
}
package at.tuwien.repository.jpa;
import at.tuwien.entities.identifier.Identifier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IdentifierRepository extends JpaRepository<Identifier, Long> {
}
package at.tuwien.service;
import at.tuwien.entities.identifier.Identifier;
import java.util.List;
public interface IdentifierService {
List<Identifier> findAll();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment