Search in sources :

Example 1 with ListRecordsType

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

the class MarcWithHoldingsRequestHelper method buildRecordsResponse.

private Future<Response> buildRecordsResponse(Request request, String requestId, List<JsonObject> batch, Map<String, JsonObject> srsResponse, boolean firstBatch, String nextInstanceId, boolean deletedRecordSupport) {
    Promise<Response> promise = Promise.promise();
    try {
        List<RecordType> records = buildRecordsList(request, batch, srsResponse, deletedRecordSupport);
        logger.debug("Build records response, instances = {}, instances with srs records = {}.", batch.size(), records.size());
        ResponseHelper responseHelper = getResponseHelper();
        OAIPMH oaipmh = responseHelper.buildBaseOaipmhResponse(request);
        if (records.isEmpty() && nextInstanceId == null && firstBatch) {
            oaipmh.withErrors(createNoRecordsFoundError());
        } else {
            oaipmh.withListRecords(new ListRecordsType().withRecords(records));
        }
        Response response;
        if (oaipmh.getErrors().isEmpty()) {
            if (!firstBatch || nextInstanceId != null) {
                ResumptionTokenType resumptionToken = buildResumptionTokenFromRequest(request, requestId, records.size(), nextInstanceId);
                oaipmh.getListRecords().withResumptionToken(resumptionToken);
            }
            response = responseHelper.buildSuccessResponse(oaipmh);
        } else {
            response = responseHelper.buildFailureResponse(oaipmh, request);
        }
        promise.complete(response);
    } catch (Exception e) {
        handleException(promise, e);
    }
    return promise.future();
}
Also used : Response(javax.ws.rs.core.Response) HttpResponse(io.vertx.ext.web.client.HttpResponse) OAIPMH(org.openarchives.oai._2.OAIPMH) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RecordType(org.openarchives.oai._2.RecordType) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper) DecodeException(io.vertx.core.json.DecodeException) ListRecordsType(org.openarchives.oai._2.ListRecordsType)

Aggregations

DecodeException (io.vertx.core.json.DecodeException)1 HttpResponse (io.vertx.ext.web.client.HttpResponse)1 Response (javax.ws.rs.core.Response)1 ResponseHelper (org.folio.oaipmh.helpers.response.ResponseHelper)1 ListRecordsType (org.openarchives.oai._2.ListRecordsType)1 OAIPMH (org.openarchives.oai._2.OAIPMH)1 RecordType (org.openarchives.oai._2.RecordType)1 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)1