Search in sources :

Example 1 with BAD_VERB

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

the class VerbValidator method validate.

/**
 * Validates request parameters except 'from' and 'until' against particular verb.
 *
 * @param object        - name of verb against witch parameters are validated
 * @param requestParams - map with request parameters
 * @return list of errors.
 */
public List<OAIPMHerrorType> validate(Object object, Map<String, String> requestParams, Request request) {
    List<OAIPMHerrorType> errors = new ArrayList<>();
    String verbName = Objects.nonNull(object) ? object.toString() : "empty";
    Verb verb = Verb.fromName(verbName);
    if (Objects.nonNull(verb)) {
        validateRequiredParams(requestParams, verb, errors);
        validateExclusiveParam(verb, requestParams, request, errors);
        validateIllegalParams(verb, requestParams, errors);
    } else {
        errors.add(new OAIPMHerrorType().withCode(BAD_VERB).withValue(format(VERB_NOT_IMPLEMENTED_ERROR_MESSAGE, verbName)));
    }
    return errors;
}
Also used : OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) Verb(org.folio.oaipmh.domain.Verb) ArrayList(java.util.ArrayList)

Example 2 with BAD_VERB

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

the class ResponseHelperTest method shouldBuildOaipmhResponseWithErrorCodeAndValue.

@Test
void shouldBuildOaipmhResponseWithErrorCodeAndValue() {
    OAIPMH oaipmh = responseHelper.buildOaipmhResponseWithErrors(request, BAD_VERB, TEST_ERROR_MESSAGE);
    boolean isErrorPresented = oaipmh.getErrors().stream().anyMatch(error -> error.getCode().equals(BAD_VERB) && error.getValue().equals(TEST_ERROR_MESSAGE));
    assertTrue(isErrorPresented);
    assertNotNull(oaipmh.getResponseDate());
    assertEquals(oaipmh.getRequest(), request.getOaiRequest());
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Verb (org.folio.oaipmh.domain.Verb)1 Test (org.junit.jupiter.api.Test)1 OAIPMH (org.openarchives.oai._2.OAIPMH)1 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)1