Search in sources :

Example 1 with RESUMPTION_TOKEN_FLOW_ERROR

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

the class GetOaiIdentifiersHelper method buildListIdentifiers.

/**
 * Builds {@link ListIdentifiersType} with headers if there is any item or {@code null}
 *
 * @param request           request
 * @param srsRecords the response from the storage which contains items
 * @return {@link ListIdentifiersType} with headers if there is any or {@code null}
 */
private OAIPMH buildListIdentifiers(Request request, JsonObject srsRecords) {
    ResponseHelper responseHelper = getResponseHelper();
    JsonArray instances = storageHelper.getItems(srsRecords);
    Integer totalRecords = storageHelper.getTotalRecords(srsRecords);
    if (request.isRestored() && !canResumeRequestSequence(request, totalRecords, instances)) {
        return responseHelper.buildOaipmhResponseWithErrors(request, BAD_RESUMPTION_TOKEN, RESUMPTION_TOKEN_FLOW_ERROR);
    }
    if (instances != null && !instances.isEmpty()) {
        logger.debug("{} entries retrieved out of {}.", instances.size(), totalRecords);
        ListIdentifiersType identifiers = new ListIdentifiersType().withResumptionToken(buildResumptionToken(request, instances, totalRecords));
        String identifierPrefix = request.getIdentifierPrefix();
        instances.stream().map(object -> (JsonObject) object).filter(instance -> StringUtils.isNotEmpty(storageHelper.getIdentifierId(instance))).filter(instance -> filterInstance(request, instance)).map(instance -> addHeader(identifierPrefix, request, instance)).forEach(identifiers::withHeaders);
        if (identifiers.getHeaders().isEmpty()) {
            OAIPMH oaipmh = responseHelper.buildBaseOaipmhResponse(request);
            return oaipmh.withErrors(createNoRecordsFoundError());
        }
        ResumptionTokenType resumptionToken = buildResumptionToken(request, instances, totalRecords);
        OAIPMH oaipmh = responseHelper.buildBaseOaipmhResponse(request).withListIdentifiers(identifiers);
        addResumptionTokenToOaiResponse(oaipmh, resumptionToken);
        return oaipmh;
    }
    return responseHelper.buildOaipmhResponseWithErrors(request, createNoRecordsFoundError());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) RESUMPTION_TOKEN_FLOW_ERROR(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FLOW_ERROR) Promise(io.vertx.core.Promise) ListIdentifiersType(org.openarchives.oai._2.ListIdentifiersType) Context(io.vertx.core.Context) Future(io.vertx.core.Future) StringUtils(org.apache.commons.lang3.StringUtils) JsonArray(io.vertx.core.json.JsonArray) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Request(org.folio.oaipmh.Request) Response(javax.ws.rs.core.Response) OAIPMH(org.openarchives.oai._2.OAIPMH) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) RESUMPTION_TOKEN_FORMAT_ERROR(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FORMAT_ERROR) JsonObject(io.vertx.core.json.JsonObject) LogManager(org.apache.logging.log4j.LogManager) ListIdentifiersType(org.openarchives.oai._2.ListIdentifiersType) OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper)

Aggregations

Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 List (java.util.List)1 Response (javax.ws.rs.core.Response)1 StringUtils (org.apache.commons.lang3.StringUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 RESUMPTION_TOKEN_FLOW_ERROR (org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FLOW_ERROR)1 RESUMPTION_TOKEN_FORMAT_ERROR (org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FORMAT_ERROR)1 Request (org.folio.oaipmh.Request)1 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)1 ListIdentifiersType (org.openarchives.oai._2.ListIdentifiersType)1 OAIPMH (org.openarchives.oai._2.OAIPMH)1 OAIPMHerrorType (org.openarchives.oai._2.OAIPMHerrorType)1 BAD_RESUMPTION_TOKEN (org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN)1 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)1