use of org.openarchives.oai._2.HeaderType in project mod-oai-pmh by folio-org.
the class AbstractHelper method createHeader.
/**
* Creates {@link HeaderType} and Datestamp and Set
*
* @param instance the instance item returned by storage service
* @param request oai-pmh request
* @return populated {@link HeaderType}
*/
protected HeaderType createHeader(JsonObject instance, Request request) {
HeaderType headerType = new HeaderType().withSetSpecs("all");
Instant instant = getInstanceDate(instance);
String date;
if (isDateOnlyGranularity(request)) {
instant = instant.truncatedTo(ChronoUnit.DAYS);
LocalDate time = LocalDate.ofInstant(instant, ZoneId.of("UTC"));
date = ISO_UTC_DATE_ONLY.format(time);
} else {
LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("UTC"));
date = ISO_UTC_DATE_TIME.format(time);
}
return headerType.withDatestamp(date);
}
use of org.openarchives.oai._2.HeaderType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method makeResumptionTokenRequestsAndVerifyCount.
private ResumptionTokenType makeResumptionTokenRequestsAndVerifyCount(List<HeaderType> totalRecords, ResumptionTokenType resumptionToken, VerbType verb, int desiredCount, int expectedCursor) {
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(RESUMPTION_TOKEN_PARAM, resumptionToken.getValue());
OAIPMH oaipmh;
List<HeaderType> records;
oaipmh = verify200WithXml(request, verb);
verifyListResponse(oaipmh, verb, desiredCount);
resumptionToken = getResumptionToken(oaipmh, verb);
assertThat(resumptionToken, is(notNullValue()));
assertEquals(expectedCursor, resumptionToken.getCursor().intValue());
records = getHeadersListDependOnVerbType(verb, oaipmh);
totalRecords.addAll(records);
return resumptionToken;
}
use of org.openarchives.oai._2.HeaderType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method verifyResumptionTokenFlowForMarc21AndOaiDcMetadataPrefixes.
@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void verifyResumptionTokenFlowForMarc21AndOaiDcMetadataPrefixes(MetadataPrefix prefix, VerbType verb) {
String maxRecordsPerResponse = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "4");
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, prefix.getName()).param(FROM_PARAM, DATE_FOR_INSTANCES_10_PARTIALLY);
OAIPMH oaipmh = verify200WithXml(request, verb);
verifyListResponse(oaipmh, verb, 4);
ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
assertThat(resumptionToken, is(notNullValue()));
assertThat(resumptionToken.getValue(), is(notNullValue()));
assertEquals(BigInteger.TEN, resumptionToken.getCompleteListSize());
assertEquals(BigInteger.ZERO, resumptionToken.getCursor());
List<HeaderType> totalRecords = getHeadersListDependOnVerbType(verb, oaipmh);
resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 4, 4);
resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 2, 8);
assertThat(resumptionToken.getValue(), isEmptyString());
System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, maxRecordsPerResponse);
}
use of org.openarchives.oai._2.HeaderType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method verifyHeaderDateStamp.
private void verifyHeaderDateStamp(OAIPMH oaipmh, VerbType verbType, String timeGranularity) {
String verb = verbType.value();
if (verb.equals(LIST_RECORDS.value())) {
oaipmh.getListRecords().getRecords().stream().map(RecordType::getHeader).map(HeaderType::getDatestamp).forEach(headerDateStamp -> verifyHeaderDateStamp(headerDateStamp, timeGranularity));
} else if (verb.equals(LIST_IDENTIFIERS.value())) {
oaipmh.getListIdentifiers().getHeaders().stream().map(HeaderType::getDatestamp).forEach(headerDateStamp -> verifyHeaderDateStamp(headerDateStamp, timeGranularity));
} else if (verb.equals(GET_RECORD.value())) {
String datestamp = oaipmh.getGetRecord().getRecord().getHeader().getDatestamp();
verifyHeaderDateStamp(datestamp, timeGranularity);
}
}
use of org.openarchives.oai._2.HeaderType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method verifyResumptionTokenFlow_whenVerbListRecordsAndMetadataPrefixMarc21WithHoldings.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_RECORDS" })
void verifyResumptionTokenFlow_whenVerbListRecordsAndMetadataPrefixMarc21WithHoldings(VerbType verb) {
final String currentValue = System.getProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE);
System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, "4");
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, DATE_INVENTORY_10_INSTANCE_IDS).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
OAIPMH oaipmh = verify200WithXml(request, verb);
verifyListResponse(oaipmh, verb, 4);
ResumptionTokenType resumptionToken = getResumptionToken(oaipmh, verb);
assertThat(resumptionToken, is(notNullValue()));
assertThat(resumptionToken.getValue(), is(notNullValue()));
assertEquals(0, resumptionToken.getCursor().intValue());
List<HeaderType> totalRecords = getHeadersListDependOnVerbType(verb, oaipmh);
resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 4, 4);
resumptionToken = makeResumptionTokenRequestsAndVerifyCount(totalRecords, resumptionToken, verb, 2, 8);
assertThat(resumptionToken.getValue(), is(isEmptyString()));
assertThat(totalRecords.size(), is(10));
System.setProperty(REPOSITORY_MAX_RECORDS_PER_RESPONSE, currentValue);
}
Aggregations