Search in sources :

Example 1 with RecordMetadataManager

use of org.folio.oaipmh.helpers.records.RecordMetadataManager in project mod-oai-pmh by folio-org.

the class AbstractGetRecordsHelper method buildRecords.

/**
 * Builds {@link Map} with storage id as key and {@link RecordType} with populated header if there is any,
 * otherwise empty map is returned
 */
private Map<String, RecordType> buildRecords(Context context, Request request, JsonArray instances) {
    final boolean suppressedRecordsProcessingEnabled = getBooleanProperty(request.getRequestId(), REPOSITORY_SUPPRESSED_RECORDS_PROCESSING);
    if (instances != null && !instances.isEmpty()) {
        Map<String, RecordType> records = new HashMap<>();
        RecordMetadataManager metadataManager = RecordMetadataManager.getInstance();
        // Using LinkedHashMap just to rely on order returned by storage service
        String identifierPrefix = request.getIdentifierPrefix();
        instances.stream().map(JsonObject.class::cast).filter(instance -> isNotEmpty(storageHelper.getIdentifierId(instance))).forEach(instance -> {
            String recordId = storageHelper.getRecordId(instance);
            String identifierId = storageHelper.getIdentifierId(instance);
            RecordType record = createRecord(request, identifierPrefix, instance, identifierId);
            // Some repositories like SRS can return record source data along with other info
            String source = storageHelper.getInstanceRecordSource(instance);
            if (source != null && record.getHeader().getStatus() == null) {
                if (suppressedRecordsProcessingEnabled) {
                    source = metadataManager.updateMetadataSourceWithDiscoverySuppressedData(source, instance);
                }
                try {
                    record.withMetadata(buildOaiMetadata(request, source));
                } catch (Exception e) {
                    logger.error("Error occurred while converting record to xml representation. {}.", e.getMessage(), e);
                    logger.debug("Skipping problematic record due the conversion error. Source record id - {}.", recordId);
                    return;
                }
            } else {
                context.put(recordId, instance);
            }
            if (filterInstance(request, instance)) {
                records.put(recordId, record);
            }
        });
        return records;
    }
    return Collections.emptyMap();
}
Also used : HttpResponse(io.vertx.ext.web.client.HttpResponse) SourceStorageSourceRecordsClientWrapper(org.folio.oaipmh.service.SourceStorageSourceRecordsClientWrapper) DecodeException(io.vertx.core.json.DecodeException) Date(java.util.Date) StatusType(org.openarchives.oai._2.StatusType) SEND_REQUEST(org.folio.oaipmh.service.MetricsCollectingService.MetricOperation.SEND_REQUEST) HashMap(java.util.HashMap) REPOSITORY_MAX_RECORDS_PER_RESPONSE(org.folio.oaipmh.Constants.REPOSITORY_MAX_RECORDS_PER_RESPONSE) GENERIC_ERROR_MESSAGE(org.folio.oaipmh.Constants.GENERIC_ERROR_MESSAGE) Context(io.vertx.core.Context) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RepositoryConfigurationUtil.getBooleanProperty(org.folio.oaipmh.helpers.RepositoryConfigurationUtil.getBooleanProperty) Request(org.folio.oaipmh.Request) OAIPMH(org.openarchives.oai._2.OAIPMH) Map(java.util.Map) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) RESUMPTION_TOKEN_FLOW_ERROR(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FLOW_ERROR) Promise(io.vertx.core.Promise) Collection(java.util.Collection) RecordMetadataManager(org.folio.oaipmh.helpers.records.RecordMetadataManager) MetricsCollectingService(org.folio.oaipmh.service.MetricsCollectingService) Future(io.vertx.core.Future) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Buffer(io.vertx.core.buffer.Buffer) Response(javax.ws.rs.core.Response) WebClientProvider(org.folio.oaipmh.WebClientProvider) RecordType(org.openarchives.oai._2.RecordType) RepositoryConfigurationUtil.isDeletedRecordsEnabled(org.folio.oaipmh.helpers.RepositoryConfigurationUtil.isDeletedRecordsEnabled) REPOSITORY_SUPPRESSED_RECORDS_PROCESSING(org.folio.oaipmh.Constants.REPOSITORY_SUPPRESSED_RECORDS_PROCESSING) ListRecordsType(org.openarchives.oai._2.ListRecordsType) Handler(io.vertx.core.Handler) Response.isSuccess(org.folio.rest.tools.client.Response.isSuccess) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) RecordType(org.openarchives.oai._2.RecordType) HashMap(java.util.HashMap) RecordMetadataManager(org.folio.oaipmh.helpers.records.RecordMetadataManager) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException)

Example 2 with RecordMetadataManager

use of org.folio.oaipmh.helpers.records.RecordMetadataManager in project mod-oai-pmh by folio-org.

the class MarcWithHoldingsRequestHelper method buildRecordsList.

private List<RecordType> buildRecordsList(Request request, List<JsonObject> batch, Map<String, JsonObject> srsResponse, boolean deletedRecordSupport) {
    RecordMetadataManager metadataManager = RecordMetadataManager.getInstance();
    final boolean suppressedRecordsProcessing = getBooleanProperty(request.getRequestId(), REPOSITORY_SUPPRESSED_RECORDS_PROCESSING);
    List<RecordType> records = new ArrayList<>();
    batch.stream().filter(instance -> {
        final String instanceId = instance.getString(INSTANCE_ID_FIELD_NAME);
        final JsonObject srsInstance = srsResponse.get(instanceId);
        return Objects.nonNull(srsInstance);
    }).forEach(instance -> {
        final String instanceId = instance.getString(INSTANCE_ID_FIELD_NAME);
        final JsonObject srsInstance = srsResponse.get(instanceId);
        RecordType record = createRecord(request, srsInstance, instanceId);
        JsonObject updatedSrsWithItemsData = metadataManager.populateMetadataWithItemsData(srsInstance, instance, suppressedRecordsProcessing);
        JsonObject updatedSrsInstance = metadataManager.populateMetadataWithHoldingsData(updatedSrsWithItemsData, instance, suppressedRecordsProcessing);
        if (deletedRecordSupport && storageHelper.isRecordMarkAsDeleted(updatedSrsInstance)) {
            record.getHeader().setStatus(StatusType.DELETED);
        }
        String source = storageHelper.getInstanceRecordSource(updatedSrsInstance);
        if (source != null && record.getHeader().getStatus() == null) {
            if (suppressedRecordsProcessing) {
                source = metadataManager.updateMetadataSourceWithDiscoverySuppressedData(source, updatedSrsInstance);
                source = metadataManager.updateElectronicAccessFieldWithDiscoverySuppressedData(source, updatedSrsInstance);
            }
            try {
                record.withMetadata(buildOaiMetadata(request, source));
            } catch (Exception e) {
                logger.error("Error occurred while converting record to xml representation: {}.", e.getMessage(), e);
                logger.debug("Skipping problematic record due the conversion error. Source record id - {}.", storageHelper.getRecordId(srsInstance));
                return;
            }
        }
        if (filterInstance(request, srsInstance)) {
            records.add(record);
        }
    });
    return records;
}
Also used : CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) OFFSET_PARAM(org.folio.oaipmh.Constants.OFFSET_PARAM) DecodeException(io.vertx.core.json.DecodeException) Date(java.util.Date) NEXT_INSTANCE_PK_VALUE(org.folio.oaipmh.Constants.NEXT_INSTANCE_PK_VALUE) StatusType(org.openarchives.oai._2.StatusType) Autowired(org.springframework.beans.factory.annotation.Autowired) NEXT_RECORD_ID_PARAM(org.folio.oaipmh.Constants.NEXT_RECORD_ID_PARAM) SEND_REQUEST(org.folio.oaipmh.service.MetricsCollectingService.MetricOperation.SEND_REQUEST) RESUMPTION_TOKEN_TIMEOUT(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_TIMEOUT) Context(io.vertx.core.Context) WorkerExecutor(io.vertx.core.WorkerExecutor) Tuple(io.vertx.sqlclient.Tuple) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) Request(org.folio.oaipmh.Request) NAME(org.folio.oaipmh.helpers.records.RecordMetadataManager.NAME) OAIPMH(org.openarchives.oai._2.OAIPMH) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) BigInteger(java.math.BigInteger) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) AbstractHelper(org.folio.oaipmh.helpers.AbstractHelper) UNTIL_PARAM(org.folio.oaipmh.Constants.UNTIL_PARAM) EXPIRATION_DATE_RESUMPTION_TOKEN_PARAM(org.folio.oaipmh.Constants.EXPIRATION_DATE_RESUMPTION_TOKEN_PARAM) OKAPI_TENANT(org.folio.oaipmh.Constants.OKAPI_TENANT) InstancesService(org.folio.oaipmh.service.InstancesService) ITEMS(org.folio.oaipmh.helpers.records.RecordMetadataManager.ITEMS) MetricsCollectingService(org.folio.oaipmh.service.MetricsCollectingService) UUID(java.util.UUID) ITEMS_AND_HOLDINGS_FIELDS(org.folio.oaipmh.helpers.records.RecordMetadataManager.ITEMS_AND_HOLDINGS_FIELDS) Instant(java.time.Instant) Future(io.vertx.core.Future) TenantTool(org.folio.rest.tools.utils.TenantTool) Collectors(java.util.stream.Collectors) PostgresClient(org.folio.rest.persist.PostgresClient) ZoneId(java.time.ZoneId) String.format(java.lang.String.format) RepositoryConfigurationUtil(org.folio.oaipmh.helpers.RepositoryConfigurationUtil) REQUEST_ID_PARAM(org.folio.oaipmh.Constants.REQUEST_ID_PARAM) CALL_NUMBER(org.folio.oaipmh.helpers.records.RecordMetadataManager.CALL_NUMBER) Objects(java.util.Objects) List(java.util.List) Logger(org.apache.logging.log4j.Logger) OffsetDateTime(java.time.OffsetDateTime) Buffer(io.vertx.core.buffer.Buffer) Response(javax.ws.rs.core.Response) WebClientProvider(org.folio.oaipmh.WebClientProvider) RETRY_ATTEMPTS(org.folio.oaipmh.Constants.RETRY_ATTEMPTS) STATUS_MESSAGE(org.folio.oaipmh.Constants.STATUS_MESSAGE) ChronoField(java.time.temporal.ChronoField) HttpResponse(io.vertx.ext.web.client.HttpResponse) SourceStorageSourceRecordsClientWrapper(org.folio.oaipmh.service.SourceStorageSourceRecordsClientWrapper) RequestMetadataLb(org.folio.rest.jooq.tables.pojos.RequestMetadataLb) BodyCodec(io.vertx.ext.web.codec.BodyCodec) INSTANCES_PROCESSING(org.folio.oaipmh.service.MetricsCollectingService.MetricOperation.INSTANCES_PROCESSING) HashMap(java.util.HashMap) OKAPI_TOKEN(org.folio.oaipmh.Constants.OKAPI_TOKEN) REPOSITORY_MAX_RECORDS_PER_RESPONSE(org.folio.oaipmh.Constants.REPOSITORY_MAX_RECORDS_PER_RESPONSE) JsonEvent(io.vertx.core.parsetools.JsonEvent) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SpringContextUtil(org.folio.spring.SpringContextUtil) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) RepositoryConfigurationUtil.getBooleanProperty(org.folio.oaipmh.helpers.RepositoryConfigurationUtil.getBooleanProperty) HttpRequestImpl(io.vertx.ext.web.client.impl.HttpRequestImpl) AsyncResult(io.vertx.core.AsyncResult) STATUS_CODE(org.folio.oaipmh.Constants.STATUS_CODE) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Instances(org.folio.rest.jooq.tables.pojos.Instances) RecordMetadataManager(org.folio.oaipmh.helpers.records.RecordMetadataManager) Maps(com.google.common.collect.Maps) HttpRequest(io.vertx.ext.web.client.HttpRequest) JsonArray(io.vertx.core.json.JsonArray) ResponseHelper(org.folio.oaipmh.helpers.response.ResponseHelper) PgConnection(io.vertx.pgclient.PgConnection) Collectors.toList(java.util.stream.Collectors.toList) RecordType(org.openarchives.oai._2.RecordType) REPOSITORY_SRS_HTTP_REQUEST_RETRY_ATTEMPTS(org.folio.oaipmh.Constants.REPOSITORY_SRS_HTTP_REQUEST_RETRY_ATTEMPTS) ACCEPT(javax.ws.rs.core.HttpHeaders.ACCEPT) LOCATION(org.folio.oaipmh.Constants.LOCATION) REPOSITORY_SUPPRESSED_RECORDS_PROCESSING(org.folio.oaipmh.Constants.REPOSITORY_SUPPRESSED_RECORDS_PROCESSING) ListRecordsType(org.openarchives.oai._2.ListRecordsType) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) RecordType(org.openarchives.oai._2.RecordType) RecordMetadataManager(org.folio.oaipmh.helpers.records.RecordMetadataManager) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Promise (io.vertx.core.Promise)2 Buffer (io.vertx.core.buffer.Buffer)2 DecodeException (io.vertx.core.json.DecodeException)2 JsonArray (io.vertx.core.json.JsonArray)2 JsonObject (io.vertx.core.json.JsonObject)2 HttpResponse (io.vertx.ext.web.client.HttpResponse)2 Collections (java.util.Collections)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Maps (com.google.common.collect.Maps)1 Vertx (io.vertx.core.Vertx)1 WorkerExecutor (io.vertx.core.WorkerExecutor)1 JsonEvent (io.vertx.core.parsetools.JsonEvent)1 HttpRequest (io.vertx.ext.web.client.HttpRequest)1