use of org.openarchives.oai._2.OAIPMH in project mod-oai-pmh by folio-org.
the class AbstractGetRecordsHelper method processRecords.
protected Response processRecords(Context ctx, Request request, JsonObject instancesResponseBody) {
JsonArray instances = storageHelper.getItems(instancesResponseBody);
Integer totalRecords = storageHelper.getTotalRecords(instancesResponseBody);
logger.debug("{} entries retrieved out of {}.", instances != null ? instances.size() : 0, totalRecords);
if (request.isRestored() && !canResumeRequestSequence(request, totalRecords, instances)) {
OAIPMH oaipmh = getResponseHelper().buildBaseOaipmhResponse(request).withErrors(new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(RESUMPTION_TOKEN_FLOW_ERROR));
return getResponseHelper().buildFailureResponse(oaipmh, request);
}
ResumptionTokenType resumptionToken = buildResumptionToken(request, instances, totalRecords);
/*
* According to OAI-PMH guidelines: it is recommended that the responseDate reflect the time of the repository's clock at the start
* of any database query or search function necessary to answer the list request, rather than when the output is written.
*/
final OAIPMH oaipmh = getResponseHelper().buildBaseOaipmhResponse(request);
final Map<String, RecordType> recordsMap = buildRecords(ctx, request, instances);
if (recordsMap.isEmpty()) {
return buildNoRecordsFoundOaiResponse(oaipmh, request);
} else {
addRecordsToOaiResponse(oaipmh, recordsMap.values());
addResumptionTokenToOaiResponse(oaipmh, resumptionToken);
return buildResponse(oaipmh, request);
}
}
use of org.openarchives.oai._2.OAIPMH in project mod-oai-pmh by folio-org.
the class GetOaiRepositoryInfoHelper method handle.
@Override
public Future<Response> handle(Request request, Context ctx) {
Promise<Response> promise = Promise.promise();
try {
OAIPMH oai = getResponseHelper().buildBaseOaipmhResponse(request).withIdentify(new IdentifyType().withRepositoryName(getRepositoryName(request.getRequestId())).withBaseURL(request.getOaiRequest().getValue()).withProtocolVersion(REPOSITORY_PROTOCOL_VERSION_2_0).withEarliestDatestamp(getEarliestDatestamp()).withGranularity(GranularityType.fromValue(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_TIME_GRANULARITY))).withDeletedRecord(DeletedRecordType.fromValue(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_DELETED_RECORDS))).withAdminEmails(getEmails(request.getRequestId())).withCompressions(GZIP, DEFLATE).withDescriptions(getDescriptions(request)));
promise.complete(getResponseHelper().buildSuccessResponse(oai));
} catch (Exception e) {
logger.error("Error happened while processing Identify verb request.", e);
promise.fail(e);
}
return promise.future();
}
use of org.openarchives.oai._2.OAIPMH 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.OAIPMH in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method shouldSkipProblematicRecord_whenGetListRecordsAndSrsReturnedInconvertibleToXmlRecord.
@ParameterizedTest
@EnumSource(value = MetadataPrefix.class, names = { "DC", "MARC21XML", "MARC21WITHHOLDINGS" })
void shouldSkipProblematicRecord_whenGetListRecordsAndSrsReturnedInconvertibleToXmlRecord(MetadataPrefix metadataPrefix) {
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, LIST_RECORDS.value()).param(METADATA_PREFIX_PARAM, metadataPrefix.getName()).param(FROM_PARAM, TWO_RECORDS_WITH_ONE_INCONVERTIBLE_TO_XML);
OAIPMH response = verify200WithXml(request, LIST_RECORDS);
verifyListResponse(response, LIST_RECORDS, 1);
}
use of org.openarchives.oai._2.OAIPMH in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method checkSupportDeletedRecordsWhenDeletedConfigIsNoAndSuppressedConfigTrue.
@ParameterizedTest
@MethodSource("metadataPrefixAndVerbProviderExceptMarc21withHoldings")
void checkSupportDeletedRecordsWhenDeletedConfigIsNoAndSuppressedConfigTrue(MetadataPrefix prefix, VerbType verb) {
String repositorySuppressDiscovery = System.getProperty(REPOSITORY_SUPPRESSED_RECORDS_PROCESSING);
String repositoryDeletedRecords = System.getProperty(REPOSITORY_DELETED_RECORDS);
System.setProperty(REPOSITORY_DELETED_RECORDS, "no");
System.setProperty(REPOSITORY_SUPPRESSED_RECORDS_PROCESSING, "true");
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, THREE_INSTANCES_DATE).param(METADATA_PREFIX_PARAM, prefix.getName());
OAIPMH oaipmh = verify200WithXml(request, verb);
verifyListResponse(oaipmh, verb, 3);
System.setProperty(REPOSITORY_SUPPRESSED_RECORDS_PROCESSING, repositorySuppressDiscovery);
System.setProperty(REPOSITORY_DELETED_RECORDS, repositoryDeletedRecords);
}
Aggregations