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());
}
Aggregations