Search in sources :

Example 11 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class OaiPmhImplTest method getOaiListVerbWithNoRecordsFoundFromStorage.

@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithNoRecordsFoundFromStorage(VerbType verb) {
    String metadataPrefix = MetadataPrefix.DC.getName();
    String from = NO_RECORDS_DATE;
    String set = "all";
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, from).param(SET_PARAM, set).param(METADATA_PREFIX_PARAM, metadataPrefix);
    // Unmarshal string to OAIPMH and verify required data presents
    OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 404, 1);
    // The dates are of invalid format so they are not present in request
    assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
    assertThat(oaipmh.getRequest().getFrom(), equalTo(from));
    assertThat(oaipmh.getRequest().getSet(), equalTo(set));
    OAIPMHerrorType error = oaipmh.getErrors().get(0);
    assertThat(error.getCode(), equalTo(NO_RECORDS_MATCH));
    assertThat(error.getValue(), equalTo(NO_RECORD_FOUND_ERROR));
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) RequestSpecification(io.restassured.specification.RequestSpecification) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project openaire-cris-validator by EuroCRIS.

the class OAIPMHEndpoint method checkForErrors.

private void checkForErrors(final OAIPMHtype response) {
    final StringBuilder sb = new StringBuilder();
    for (final OAIPMHerrorType error : response.getError()) {
        if (!OAIPMHerrorcodeType.NO_RECORDS_MATCH.equals(error.getCode())) {
            sb.append(error.getCode().name());
            sb.append(": ");
            sb.append(error.getValue());
            sb.append("; ");
        }
    }
    if (sb.length() > 0) {
        final String errors = sb.substring(0, sb.length() - 2);
        throw new IllegalStateException(errors);
    }
}
Also used : OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType)

Example 13 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class AbstractHelper method buildResponseWithErrors.

protected Future<Response> buildResponseWithErrors(Request request, Promise<Response> promise, List<OAIPMHerrorType> errors) {
    OAIPMH oai;
    if (request.isRestored()) {
        oai = responseHelper.buildOaipmhResponseWithErrors(request, BAD_RESUMPTION_TOKEN, RESUMPTION_TOKEN_FORMAT_ERROR);
    } else {
        oai = responseHelper.buildOaipmhResponseWithErrors(request, errors);
    }
    promise.complete(responseHelper.buildFailureResponse(oai, request));
    return promise.future();
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH)

Example 14 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class GetOaiIdentifiersHelper method handle.

@Override
public Future<javax.ws.rs.core.Response> handle(Request request, Context ctx) {
    Promise<javax.ws.rs.core.Response> promise = Promise.promise();
    try {
        ResponseHelper responseHelper = getResponseHelper();
        List<OAIPMHerrorType> errors = validateRequest(request);
        if (!errors.isEmpty()) {
            OAIPMH oai;
            if (request.isRestored()) {
                oai = responseHelper.buildOaipmhResponseWithErrors(request, BAD_RESUMPTION_TOKEN, RESUMPTION_TOKEN_FORMAT_ERROR);
            } else {
                oai = responseHelper.buildOaipmhResponseWithErrors(request, errors);
            }
            promise.complete(getResponseHelper().buildFailureResponse(oai, request));
            return promise.future();
        }
        requestAndProcessSrsRecords(request, ctx, promise);
    } catch (Exception e) {
        handleException(promise, e);
    }
    return promise.future();
}
Also used : Response(javax.ws.rs.core.Response) OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper)

Example 15 with OAIPMHerrorType

use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.

the class OaiPmhImplTest method getOaiRecordsWithMetadataPrefixMarc21WithHoldingsAndSrsHasNoRecordsForInventoryInstance.

@Test
void getOaiRecordsWithMetadataPrefixMarc21WithHoldingsAndSrsHasNoRecordsForInventoryInstance() {
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, LIST_RECORDS.value()).param(FROM_PARAM, INSTANCE_WITHOUT_SRS_RECORD_DATE).param(METADATA_PREFIX_PARAM, MetadataPrefix.MARC21WITHHOLDINGS.getName());
    OAIPMH oaipmh = verifyResponseWithErrors(request, LIST_RECORDS, 404, 1);
    OAIPMHerrorType error = oaipmh.getErrors().get(0);
    assertEquals(NO_RECORD_FOUND_ERROR, error.getValue());
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) RequestSpecification(io.restassured.specification.RequestSpecification) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)22 OAIPMH (org.openarchives.oai._2.OAIPMH)16 RequestSpecification (io.restassured.specification.RequestSpecification)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)7 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 ArrayList (java.util.ArrayList)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.jupiter.api.Test)4 String.format (java.lang.String.format)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Request (org.folio.oaipmh.Request)3 JsonArray (io.vertx.core.json.JsonArray)2 HashMap (java.util.HashMap)2 Verb (org.folio.oaipmh.domain.Verb)2 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)2