Search in sources :

Example 1 with EXPIRED_RESUMPTION_TOKEN

use of org.folio.oaipmh.Constants.EXPIRED_RESUMPTION_TOKEN in project mod-oai-pmh by folio-org.

the class VerbValidator method validateExclusiveParam.

/**
 * In case of resumption token param presence verifies if there any other parameters were specified too. If they were then error
 * will be added to error list.
 *
 * @param verb          - verb
 * @param requestParams - request parameters
 * @param request       - oai-pmh request
 * @param errors        - list of errors
 */
private void validateExclusiveParam(Verb verb, Map<String, String> requestParams, Request request, List<OAIPMHerrorType> errors) {
    String resumptionToken = requestParams.get(verb.getExclusiveParam());
    if (verb.getExclusiveParam() != null && resumptionToken != null) {
        requestParams.keySet().stream().filter(p -> !verb.getExcludedParams().contains(p)).filter(p -> !verb.getExclusiveParam().equals(p)).findAny().ifPresent(param -> {
            if (!param.equals(VERB_PARAM)) {
                errors.add(new OAIPMHerrorType().withCode(BAD_ARGUMENT).withValue(format(EXCLUSIVE_PARAM_ERROR_MESSAGE, verb.name(), verb.getExclusiveParam())));
            }
        });
        if (!request.isResumptionTokenParsableAndValid()) {
            OAIPMHerrorType error = new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(format(INVALID_RESUMPTION_TOKEN, verb.name()));
            errors.add(error);
            return;
        }
        if (request.isResumptionTokenTimeExpired()) {
            OAIPMHerrorType errorByExpiredTime = new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(EXPIRED_RESUMPTION_TOKEN);
            errors.add(errorByExpiredTime);
        }
    }
}
Also used : INVALID_RESUMPTION_TOKEN(org.folio.oaipmh.Constants.INVALID_RESUMPTION_TOKEN) EXPIRED_RESUMPTION_TOKEN(org.folio.oaipmh.Constants.EXPIRED_RESUMPTION_TOKEN) Set(java.util.Set) VERB_PARAM(org.folio.oaipmh.Constants.VERB_PARAM) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) BAD_ARGUMENT(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects(java.util.Objects) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) Component(org.springframework.stereotype.Component) List(java.util.List) Request(org.folio.oaipmh.Request) Verb(org.folio.oaipmh.domain.Verb) Map(java.util.Map) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) BAD_VERB(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_VERB) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType)

Aggregations

String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 EXPIRED_RESUMPTION_TOKEN (org.folio.oaipmh.Constants.EXPIRED_RESUMPTION_TOKEN)1 INVALID_RESUMPTION_TOKEN (org.folio.oaipmh.Constants.INVALID_RESUMPTION_TOKEN)1 VERB_PARAM (org.folio.oaipmh.Constants.VERB_PARAM)1 Request (org.folio.oaipmh.Request)1 Verb (org.folio.oaipmh.domain.Verb)1 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)1 BAD_ARGUMENT (org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_ARGUMENT)1 BAD_RESUMPTION_TOKEN (org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN)1 BAD_VERB (org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_VERB)1 Component (org.springframework.stereotype.Component)1