Search in sources :

Example 1 with OAIPMH

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);
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RecordType(org.openarchives.oai._2.RecordType)

Example 2 with OAIPMH

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();
}
Also used : Response(javax.ws.rs.core.Response) OAIPMH(org.openarchives.oai._2.OAIPMH) IdentifyType(org.openarchives.oai._2.IdentifyType) MalformedURLException(java.net.MalformedURLException)

Example 3 with OAIPMH

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;
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) HeaderType(org.openarchives.oai._2.HeaderType) RequestSpecification(io.restassured.specification.RequestSpecification)

Example 4 with OAIPMH

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);
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) RequestSpecification(io.restassured.specification.RequestSpecification) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with OAIPMH

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);
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

OAIPMH (org.openarchives.oai._2.OAIPMH)93 RequestSpecification (io.restassured.specification.RequestSpecification)71 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)71 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)55 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)55 MethodSource (org.junit.jupiter.params.provider.MethodSource)34 Test (org.junit.jupiter.api.Test)32 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)18 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)16 EnumSource (org.junit.jupiter.params.provider.EnumSource)15 Response (javax.ws.rs.core.Response)9 NameValuePair (org.apache.http.NameValuePair)6 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)5 HeaderType (org.openarchives.oai._2.HeaderType)5 SubfieldatafieldType (gov.loc.marc21.slim.SubfieldatafieldType)3 OAIPMHerrorcodeType (org.openarchives.oai._2.OAIPMHerrorcodeType)3 RecordType (org.openarchives.oai._2.RecordType)3 Context (io.vertx.core.Context)2 JsonObject (io.vertx.core.json.JsonObject)2 List (java.util.List)2