public static void indexDescriptiveMetadataFields(ModelService model, String aipId, String representationId,
List<DescriptiveMetadata> metadataList, SolrInputDocument doc)
throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException {
Set<String> usedNonRepeatableFields = new HashSet<>();
for (DescriptiveMetadata metadata : metadataList) {
StoragePath storagePath = ModelUtils.getDescriptiveMetadataStoragePath(aipId, representationId, metadata.getId());
Binary binary = model.getStorage().getBinary(storagePath);
try {
SolrInputDocument fields = getDescriptiveMetadataFields(binary, metadata.getType(), metadata.getVersion());
for (SolrInputField field : fields) {
if (NON_REPEATABLE_FIELDS.contains(field.getName())) {
boolean added = usedNonRepeatableFields.add(field.getName());
if (added) {
doc.addField(field.getName(), field.getValue());
}
} else {
doc.addField(field.getName(), field.getValue());
}
}
} catch (GenericException e) {
LOGGER.warn("Problem processing descriptive metadata: {}", e.getMessage(), e);
} catch (Exception e) {
LOGGER.error("Error processing descriptive metadata: {}", metadata, e);
}
}
}