use of org.openarchives.oai._2.GranularityType in project mod-oai-pmh by folio-org.
the class AbstractHelper method validateDateRange.
private void validateDateRange(Request request, List<OAIPMHerrorType> errors) {
Pair<GranularityType, LocalDateTime> from = null;
Pair<GranularityType, LocalDateTime> until = null;
// Get repository supported granularity
boolean isDateOnly = isDateOnlyGranularity(request);
if (request.getFrom() != null) {
ImmutablePair<String, String> date = new ImmutablePair<>(FROM_PARAM, request.getFrom());
from = isDateOnly ? parseDate(date, errors) : parseDateTime(date, errors);
if (from == null) {
// In case the 'from' date is invalid, it cannot be sent in OAI-PMH/request@from because it contradicts schema definition
request.getOaiRequest().setFrom(null);
}
}
if (request.getUntil() != null) {
ImmutablePair<String, String> date = new ImmutablePair<>(UNTIL_PARAM, request.getUntil());
until = isDateOnly ? parseDate(date, errors) : parseDateTime(date, errors);
if (until == null) {
// In case the 'until' date is invalid, it cannot be sent in OAI-PMH/request@until because it contradicts schema definition
request.getOaiRequest().setUntil(null);
}
}
if (from != null && until != null) {
// Both arguments must have the same granularity.
if (from.getLeft() != until.getLeft()) {
errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue("Invalid date range: 'from' must have the same granularity as 'until'."));
} else if (from.getRight().isAfter(until.getRight())) {
// The from argument must be less than or equal to the until argument.
errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue("Invalid date range: 'from' must be less than or equal to 'until'."));
}
}
}
use of org.openarchives.oai._2.GranularityType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method shouldReturnCorrectHeaderDate_whenGetListRecords.
@ParameterizedTest
@MethodSource("metadataPrefixAndVerbAndGranularityType")
void shouldReturnCorrectHeaderDate_whenGetListRecords(MetadataPrefix metadataPrefix, VerbType verb, GranularityType granularityType) {
String timeGranularity = System.getProperty(REPOSITORY_TIME_GRANULARITY);
System.setProperty(REPOSITORY_TIME_GRANULARITY, granularityType.value());
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, DEFAULT_RECORD_DATE).param(METADATA_PREFIX_PARAM, metadataPrefix.getName());
OAIPMH oaipmh = verify200WithXml(request, verb);
String expectedDate = granularityType.equals(GranularityType.YYYY_MM_DD) ? "2021-03-31" : "2021-03-31T07:23:11Z";
verifyHeaderDate(expectedDate, oaipmh, verb);
System.setProperty(REPOSITORY_TIME_GRANULARITY, timeGranularity);
}
use of org.openarchives.oai._2.GranularityType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method headerDatestampOfGetRecordVerbShouldCorrespondToGranularitySetting.
@ParameterizedTest
@MethodSource("allMetadataPrefixesAndGranularityTypesProvider")
void headerDatestampOfGetRecordVerbShouldCorrespondToGranularitySetting(MetadataPrefix prefix, GranularityType granularityType) {
String timeGranularity = System.getProperty(REPOSITORY_TIME_GRANULARITY);
System.setProperty(REPOSITORY_TIME_GRANULARITY, granularityType.value());
String identifier = IDENTIFIER_PREFIX + OkapiMockServer.EXISTING_IDENTIFIER;
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, GET_RECORD.value()).param(IDENTIFIER_PARAM, identifier).param(METADATA_PREFIX_PARAM, prefix.getName());
OAIPMH oaipmh = verify200WithXml(request, GET_RECORD);
verifyHeaderDateStamp(oaipmh, GET_RECORD, granularityType.value());
System.setProperty(REPOSITORY_TIME_GRANULARITY, timeGranularity);
}
Aggregations