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