diff --git a/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java b/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java index cfd8c53f79a..65d0f25c306 100644 --- a/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java +++ b/dspace-api/src/main/java/org/dspace/content/authority/DSpaceControlledVocabulary.java @@ -93,6 +93,7 @@ public boolean isPublic() { @Override public boolean storeAuthorityInMetadata() { + init(); return storeAuthority; } diff --git a/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java b/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java index f17e36ee90a..7a6f2927092 100644 --- a/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java +++ b/dspace-api/src/main/java/org/dspace/content/enhancer/impl/RelatedEntityItemEnhancer.java @@ -11,10 +11,14 @@ import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -import java.util.Objects; +import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; +import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.dspace.content.Item; @@ -45,11 +49,20 @@ public class RelatedEntityItemEnhancer extends AbstractItemEnhancer { @Autowired private ItemService itemService; + /** + * the entity that can be extended by this enhancer, i.e. Publication + */ private String sourceEntityType; - private String sourceItemMetadataField; + /** + * the metadata used to navigate the relation, i.e. dc.contributor.author + */ + private List sourceItemMetadataFields; - private String relatedItemMetadataField; + /** + * the metadata that is copied from the linked entity, i.e. person.identifier.orcid + */ + private List relatedItemMetadataFields; @Override public boolean canEnhance(Context context, Item item) { @@ -62,18 +75,17 @@ public boolean enhance(Context context, Item item, boolean deepMode) { if (!deepMode) { try { result = cleanObsoleteVirtualFields(context, item); - result = updateVirtualFieldsPlaces(context, item) || result; result = performEnhancement(context, item) || result; } catch (SQLException e) { LOGGER.error("An error occurs enhancing item with id {}: {}", item.getID(), e.getMessage(), e); throw new SQLRuntimeException(e); } } else { - List currMetadataValues = getCurrentVirtualMetadata(context, item); - List toBeMetadataValues = getToBeVirtualMetadata(context, item); + Map> currMetadataValues = getCurrentVirtualsMap(item); + Map> toBeMetadataValues = getToBeVirtualMetadata(context, item); if (!equivalent(currMetadataValues, toBeMetadataValues)) { try { - itemService.removeMetadataValues(context, item, currMetadataValues); + clearAllVirtualMetadata(context, item); addMetadata(context, item, toBeMetadataValues); } catch (SQLException e) { throw new SQLRuntimeException(e); @@ -84,20 +96,44 @@ public boolean enhance(Context context, Item item, boolean deepMode) { return result; } - private void addMetadata(Context context, Item item, List toBeMetadataValues) + private void clearAllVirtualMetadata(Context context, Item item) throws SQLException { + itemService.clearMetadata(context, item, VIRTUAL_METADATA_SCHEMA, VIRTUAL_SOURCE_METADATA_ELEMENT, + getVirtualQualifier(), Item.ANY); + itemService.clearMetadata(context, item, VIRTUAL_METADATA_SCHEMA, VIRTUAL_METADATA_ELEMENT, + getVirtualQualifier(), Item.ANY); + } + + private void addMetadata(Context context, Item item, Map> toBeMetadataValues) throws SQLException { - for (MetadataValueDTO dto : toBeMetadataValues) { - itemService.addMetadata(context, item, dto.getSchema(), dto.getElement(), dto.getQualifier(), null, - dto.getValue(), dto.getAuthority(), dto.getConfidence()); + for (Entry> metadataValues : toBeMetadataValues.entrySet()) { + addVirtualSourceField(context, item, metadataValues.getKey()); + for (MetadataValueDTO dto : metadataValues.getValue()) { + addVirtualField(context, item, dto.getValue(), dto.getAuthority(), dto.getLanguage(), + dto.getConfidence()); + } } } - private boolean equivalent(List currMetadataValues, List toBeMetadataValues) { + private boolean equivalent(Map> currMetadataValues, + Map> toBeMetadataValues) { if (currMetadataValues.size() != toBeMetadataValues.size()) { return false; } else { - for (int idx = 0; idx < currMetadataValues.size(); idx++) { - if (!equivalent(currMetadataValues.get(idx), toBeMetadataValues.get(idx))) { + for (String key : currMetadataValues.keySet()) { + if (!equivalent(currMetadataValues.get(key), toBeMetadataValues.get(key))) { + return false; + } + } + } + return true; + } + + private boolean equivalent(List metadataValue, List metadataValueDTO) { + if (metadataValue.size() != metadataValueDTO.size()) { + return false; + } else { + for (int i = 0; i < metadataValue.size(); i++) { + if (!equivalent(metadataValue.get(i), metadataValueDTO.get(i))) { return false; } } @@ -114,23 +150,14 @@ private boolean equivalent(MetadataValue metadataValue, MetadataValueDTO metadat && StringUtils.equals(metadataValue.getAuthority(), metadataValueDTO.getAuthority()); } - private List getToBeVirtualMetadata(Context context, Item item) { - List tobeVirtualMetadata = new ArrayList<>(); - List virtualSourceFields = getEnhanceableMetadataValue(item); - for (MetadataValue virtualSourceField : virtualSourceFields) { - MetadataValueDTO mv = new MetadataValueDTO(); - mv.setSchema(VIRTUAL_METADATA_SCHEMA); - mv.setElement(VIRTUAL_SOURCE_METADATA_ELEMENT); - mv.setQualifier(getVirtualQualifier()); - String authority = virtualSourceField.getAuthority(); + private Map> getToBeVirtualMetadata(Context context, Item item) { + Map> tobeVirtualMetadataMap = new HashMap>(); + + Set virtualSources = getVirtualSources(item); + for (String authority : virtualSources) { + List tobeVirtualMetadata = new ArrayList<>(); Item relatedItem = null; - if (StringUtils.isNotBlank(authority)) { - mv.setValue(authority); - relatedItem = findRelatedEntityItem(context, virtualSourceField); - } else { - mv.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); - } - tobeVirtualMetadata.add(mv); + relatedItem = findRelatedEntityItem(context, authority); if (relatedItem == null) { MetadataValueDTO mvRelated = new MetadataValueDTO(); mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); @@ -138,44 +165,38 @@ private List getToBeVirtualMetadata(Context context, Item item mvRelated.setQualifier(getVirtualQualifier()); mvRelated.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); tobeVirtualMetadata.add(mvRelated); - continue; - } - - List relatedItemMetadataValues = getMetadataValues(relatedItem, relatedItemMetadataField); - if (relatedItemMetadataValues.isEmpty()) { - MetadataValueDTO mvRelated = new MetadataValueDTO(); - mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); - mvRelated.setElement(VIRTUAL_METADATA_ELEMENT); - mvRelated.setQualifier(getVirtualQualifier()); - mvRelated.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); - tobeVirtualMetadata.add(mvRelated); - continue; - } - for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { - MetadataValueDTO mvRelated = new MetadataValueDTO(); - mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); - mvRelated.setElement(VIRTUAL_METADATA_ELEMENT); - mvRelated.setQualifier(getVirtualQualifier()); - mvRelated.setValue(relatedItemMetadataValue.getValue()); - String authorityRelated = relatedItemMetadataValue.getAuthority(); - if (StringUtils.isNotBlank(authorityRelated)) { - mvRelated.setAuthority(authorityRelated); - mvRelated.setConfidence(Choices.CF_ACCEPTED); + } else { + boolean foundAtLeastOneValue = false; + for (String relatedItemMetadataField : relatedItemMetadataFields) { + List relatedItemMetadataValues = getMetadataValues(relatedItem, + relatedItemMetadataField); + for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { + MetadataValueDTO mvRelated = new MetadataValueDTO(); + mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); + mvRelated.setElement(VIRTUAL_METADATA_ELEMENT); + mvRelated.setQualifier(getVirtualQualifier()); + mvRelated.setValue(relatedItemMetadataValue.getValue()); + String authorityRelated = relatedItemMetadataValue.getAuthority(); + if (StringUtils.isNotBlank(authorityRelated)) { + mvRelated.setAuthority(authorityRelated); + mvRelated.setConfidence(Choices.CF_ACCEPTED); + } + tobeVirtualMetadata.add(mvRelated); + foundAtLeastOneValue = true; + } + } + if (!foundAtLeastOneValue) { + MetadataValueDTO mvRelated = new MetadataValueDTO(); + mvRelated.setSchema(VIRTUAL_METADATA_SCHEMA); + mvRelated.setElement(VIRTUAL_METADATA_ELEMENT); + mvRelated.setQualifier(getVirtualQualifier()); + mvRelated.setValue(PLACEHOLDER_PARENT_METADATA_VALUE); + tobeVirtualMetadata.add(mvRelated); } - tobeVirtualMetadata.add(mvRelated); } + tobeVirtualMetadataMap.put(authority, tobeVirtualMetadata); } - return tobeVirtualMetadata; - } - - private List getCurrentVirtualMetadata(Context context, Item item) { - List currentVirtualMetadata = new ArrayList<>(); - List virtualSourceFields = getVirtualSourceFields(item); - for (MetadataValue virtualSourceField : virtualSourceFields) { - currentVirtualMetadata.add(virtualSourceField); - getRelatedVirtualField(item, virtualSourceField).ifPresent(currentVirtualMetadata::add); - } - return currentVirtualMetadata; + return tobeVirtualMetadataMap; } private boolean cleanObsoleteVirtualFields(Context context, Item item) throws SQLException { @@ -188,66 +209,17 @@ private boolean cleanObsoleteVirtualFields(Context context, Item item) throws SQ return result; } - private boolean updateVirtualFieldsPlaces(Context context, Item item) { - boolean result = false; - List virtualSourceFields = getVirtualSourceFields(item); - List enhanceableMetadataValue = getEnhanceableMetadataValue(item); - for (MetadataValue virtualSourceField : virtualSourceFields) { - Optional metadataWithPlaceToUpdate = metadataWithPlaceToUpdate(item, - enhanceableMetadataValue, virtualSourceField); - if (metadataWithPlaceToUpdate.isPresent()) { - updatePlaces(item, metadataWithPlaceToUpdate.get(), virtualSourceField); - result = true; - } - } - return result; - } - - private Optional metadataWithPlaceToUpdate(Item item, List enhanceableMetadataValue, - MetadataValue virtualSourceField) { - return findMetadataValueToUpdatePlace(enhanceableMetadataValue, virtualSourceField, - item); - } - - private boolean hasToUpdatePlace(MetadataValue metadataValue, MetadataValue virtualSourceField) { - return metadataValue.getPlace() != virtualSourceField.getPlace(); - } - - private void updatePlaces(Item item, MetadataValue mv, MetadataValue virtualSourceField) { - virtualSourceField.setPlace(mv.getPlace()); - getRelatedVirtualField(item, mv) - .ifPresent(relatedMv -> relatedMv.setPlace(mv.getPlace())); - } - - private Optional findMetadataValueToUpdatePlace(List enhanceableMetadataValue, - MetadataValue virtualSourceField, Item item) { - Optional exactMatch = enhanceableMetadataValue.stream() - .filter(metadataValue -> hasAuthorityEqualsTo(metadataValue, - virtualSourceField.getValue()) && !hasToUpdatePlace(metadataValue, virtualSourceField)) - .findFirst(); - if (exactMatch.isPresent()) { - enhanceableMetadataValue.remove(exactMatch.get()); - return Optional.empty(); - } else { - Optional authorityOnlyMatch = enhanceableMetadataValue.stream() - .filter(metadataValue -> hasAuthorityEqualsTo(metadataValue, - virtualSourceField.getValue()) && hasToUpdatePlace(metadataValue, virtualSourceField)) - .findFirst(); - enhanceableMetadataValue.remove(authorityOnlyMatch.get()); - return authorityOnlyMatch; - } - } - private List getObsoleteVirtualFields(Item item) { List obsoleteVirtualFields = new ArrayList<>(); - - List virtualSourceFields = getVirtualSourceFields(item); - List enhanceableMetadata = getEnhanceableMetadataValue(item); - for (MetadataValue virtualSourceField : virtualSourceFields) { - if (isRelatedSourceNoMorePresent(item, enhanceableMetadata, virtualSourceField)) { - obsoleteVirtualFields.add(virtualSourceField); - getRelatedVirtualField(item, virtualSourceField).ifPresent(obsoleteVirtualFields::add); + Map> currentVirtualsMap = getCurrentVirtualsMap(item); + Set virtualSources = getVirtualSources(item); + for (String authority : currentVirtualsMap.keySet()) { + if (!virtualSources.contains(authority)) { + for (MetadataValue mv : getVirtualSourceFields(item, authority)) { + obsoleteVirtualFields.add(mv); + getRelatedVirtualField(item, mv.getPlace()).ifPresent(obsoleteVirtualFields::add); + } } } @@ -255,142 +227,117 @@ private List getObsoleteVirtualFields(Item item) { } - /** - * This method will look in the enhanceableMetadata if the source metadata is still present. If so, it will remove - * form the list as it would not be used to validate other potential duplicate source metadata - * - * @param item - * @param enhanceableMetadata - * @param virtualSourceField - * @return true if the metadata containing a source of enhancement is still present in the list of the metadata to - * use to enhance the item - */ - private boolean isRelatedSourceNoMorePresent(Item item, List enhanceableMetadata, - MetadataValue virtualSourceField) { - Optional mv = enhanceableMetadata.stream() - .filter(metadataValue -> hasAuthorityEqualsTo(metadataValue, virtualSourceField.getValue())) - .findFirst(); - if (mv.isPresent()) { - enhanceableMetadata.remove(mv.get()); - return false; - } - return true; + private Set getVirtualSources(Item item) { + return sourceItemMetadataFields.stream() + .flatMap(field -> itemService.getMetadataByMetadataString(item, field).stream()) + .filter(mv -> UUIDUtils.fromString(mv.getAuthority()) != null) + .map(mv -> mv.getAuthority()) + .collect(Collectors.toSet()); } - private Optional getRelatedVirtualField(Item item, MetadataValue virtualSourceField) { - return getVirtualFields(item).stream() - .filter(metadataValue -> metadataValue.getPlace() == virtualSourceField.getPlace()) - .findFirst(); - } + private Map> getCurrentVirtualsMap(Item item) { + Map> currentVirtualsMap = new HashMap>(); + List sources = itemService.getMetadata(item, VIRTUAL_METADATA_SCHEMA, + VIRTUAL_SOURCE_METADATA_ELEMENT, getVirtualQualifier(), Item.ANY); + List generated = itemService.getMetadata(item, VIRTUAL_METADATA_SCHEMA, VIRTUAL_METADATA_ELEMENT, + getVirtualQualifier(), Item.ANY); - private boolean performEnhancement(Context context, Item item) throws SQLException { - boolean result = false; - if (noEnhanceableMetadata(context, item)) { - return false; + if (sources.size() != generated.size()) { + LOGGER.error( + "inconsistent virtual metadata for the item {} got {} sources and {} generated virtual metadata", + item.getID().toString(), sources.size(), generated.size()); } - for (MetadataValue metadataValue : getEnhanceableMetadataValue(item)) { - - if (wasValueAlreadyUsedForEnhancement(item, metadataValue)) { - continue; - } - - Item relatedItem = findRelatedEntityItem(context, metadataValue); - if (relatedItem == null) { - addVirtualField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE); - addVirtualSourceField(context, item, metadataValue); - continue; + for (int i = 0; i < Integer.max(sources.size(), generated.size()); i++) { + String authority; + if (i < sources.size()) { + authority = sources.get(i).getValue(); + } else { + // we have less source than virtual metadata let's generate a random uuid to + // associate with these extra metadata so that they will be managed as obsolete + // value + authority = UUID.randomUUID().toString(); } - - List relatedItemMetadataValues = getMetadataValues(relatedItem, relatedItemMetadataField); - if (relatedItemMetadataValues.isEmpty()) { - addVirtualField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE); - addVirtualSourceField(context, item, metadataValue); - continue; + List mvalues = currentVirtualsMap.get(authority); + if (mvalues == null) { + mvalues = new ArrayList(); } - for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { - addVirtualField(context, item, relatedItemMetadataValue.getValue()); - addVirtualSourceField(context, item, metadataValue); + if (i < generated.size()) { + mvalues.add(generated.get(i)); } - result = true; + currentVirtualsMap.put(authority, mvalues); } - return result; - } - - private boolean noEnhanceableMetadata(Context context, Item item) { - - return getEnhanceableMetadataValue(item) - .stream() - .noneMatch(metadataValue -> validAuthority(context, metadataValue)); - } - - private boolean validAuthority(Context context, MetadataValue metadataValue) { - Item relatedItem = findRelatedEntityItem(context, metadataValue); - return Objects.nonNull(relatedItem); + return currentVirtualsMap; } - private List getEnhanceableMetadataValue(Item item) { - return getMetadataValues(item, sourceItemMetadataField); + private Optional getRelatedVirtualField(Item item, int pos) { + return getVirtualFields(item).stream() + .skip(pos) + .findFirst(); } - private boolean wasValueAlreadyUsedForEnhancement(Item item, MetadataValue metadataValue) { + private boolean performEnhancement(Context context, Item item) throws SQLException { + boolean result = false; + Map> currentVirtualsMap = getCurrentVirtualsMap(item); + Set virtualSources = getVirtualSources(item); + for (String authority : virtualSources) { + boolean foundAtLeastOne = false; + if (!currentVirtualsMap.containsKey(authority)) { + result = true; + Item relatedItem = findRelatedEntityItem(context, authority); + if (relatedItem == null) { + addVirtualField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE, null, null, Choices.CF_UNSET); + addVirtualSourceField(context, item, authority); + continue; + } - if (isPlaceholderAtPlace(getVirtualFields(item), metadataValue.getPlace())) { - return true; + for (String relatedItemMetadataField : relatedItemMetadataFields) { + List relatedItemMetadataValues = getMetadataValues(relatedItem, + relatedItemMetadataField); + for (MetadataValue relatedItemMetadataValue : relatedItemMetadataValues) { + foundAtLeastOne = true; + addVirtualField(context, item, relatedItemMetadataValue.getValue(), + relatedItemMetadataValue.getAuthority(), relatedItemMetadataValue.getLanguage(), + relatedItemMetadataValue.getConfidence()); + addVirtualSourceField(context, item, authority); + } + } + if (!foundAtLeastOne) { + addVirtualField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE, null, null, Choices.CF_UNSET); + addVirtualSourceField(context, item, authority); + continue; + } + } } - - return getVirtualSourceFields(item).stream() - .anyMatch(virtualSourceField -> virtualSourceField.getPlace() == metadataValue.getPlace() - && hasAuthorityEqualsTo(metadataValue, virtualSourceField.getValue())); - - } - - private boolean isPlaceholderAtPlace(List metadataValues, int place) { - return place < metadataValues.size() ? isPlaceholder(metadataValues.get(place)) : false; - } - - private boolean hasAuthorityEqualsTo(MetadataValue metadataValue, String authority) { - return Objects.equals(metadataValue.getAuthority(), authority) - || (StringUtils.isBlank(metadataValue.getAuthority()) - && Objects.equals(PLACEHOLDER_PARENT_METADATA_VALUE, authority)); + return result; } - private Item findRelatedEntityItem(Context context, MetadataValue metadataValue) { + private Item findRelatedEntityItem(Context context, String authority) { try { - UUID relatedItemUUID = UUIDUtils.fromString(metadataValue.getAuthority()); + UUID relatedItemUUID = UUIDUtils.fromString(authority); return relatedItemUUID != null ? itemService.find(context, relatedItemUUID) : null; } catch (SQLException e) { throw new SQLRuntimeException(e); } } - private boolean isPlaceholder(MetadataValue metadataValue) { - return PLACEHOLDER_PARENT_METADATA_VALUE.equals(metadataValue.getValue()); - } - private List getMetadataValues(Item item, String metadataField) { return itemService.getMetadataByMetadataString(item, metadataField); } - private List getVirtualSourceFields(Item item) { - return getMetadataValues(item, getVirtualSourceMetadataField()); + private List getVirtualSourceFields(Item item, String authority) { + return getMetadataValues(item, getVirtualSourceMetadataField()).stream() + .filter(mv -> StringUtils.equals(authority, mv.getValue())).collect(Collectors.toList()); } private List getVirtualFields(Item item) { return getMetadataValues(item, getVirtualMetadataField()); } - private void addVirtualField(Context context, Item item, String value) throws SQLException { - itemService.addMetadata(context, item, VIRTUAL_METADATA_SCHEMA, VIRTUAL_METADATA_ELEMENT, - getVirtualQualifier(), null, value); - } - - private void addVirtualSourceField(Context context, Item item, MetadataValue sourceValue) throws SQLException { - if (StringUtils.isNotBlank(sourceValue.getAuthority())) { - addVirtualSourceField(context, item, sourceValue.getAuthority()); - } else { - addVirtualSourceField(context, item, PLACEHOLDER_PARENT_METADATA_VALUE); - } + private void addVirtualField(Context context, Item item, String value, String authority, String lang, + int confidence) throws SQLException { + itemService.addMetadata(context, item, VIRTUAL_METADATA_SCHEMA, VIRTUAL_METADATA_ELEMENT, getVirtualQualifier(), + lang, value, authority, confidence); } private void addVirtualSourceField(Context context, Item item, String sourceValueAuthority) throws SQLException { @@ -402,12 +349,28 @@ public void setSourceEntityType(String sourceEntityType) { this.sourceEntityType = sourceEntityType; } + @Deprecated public void setSourceItemMetadataField(String sourceItemMetadataField) { - this.sourceItemMetadataField = sourceItemMetadataField; + LOGGER.warn( + "RelatedEntityItemEnhancer configured using the old single source item metadata field, " + + "please update the configuration to use the list"); + this.sourceItemMetadataFields = List.of(sourceItemMetadataField); } + @Deprecated public void setRelatedItemMetadataField(String relatedItemMetadataField) { - this.relatedItemMetadataField = relatedItemMetadataField; + LOGGER.warn( + "RelatedEntityItemEnhancer configured using the old single related item metadata field, " + + "please update the configuration to use the list"); + this.relatedItemMetadataFields = List.of(relatedItemMetadataField); + } + + public void setRelatedItemMetadataFields(List relatedItemMetadataFields) { + this.relatedItemMetadataFields = relatedItemMetadataFields; + } + + public void setSourceItemMetadataFields(List sourceItemMetadataFields) { + this.sourceItemMetadataFields = sourceItemMetadataFields; } } diff --git a/dspace-api/src/test/data/dspaceFolder/config/local.cfg b/dspace-api/src/test/data/dspaceFolder/config/local.cfg index 2f3a64218db..b02b9fd1550 100644 --- a/dspace-api/src/test/data/dspaceFolder/config/local.cfg +++ b/dspace-api/src/test/data/dspaceFolder/config/local.cfg @@ -226,4 +226,5 @@ choices.presentation.dspace.object.owner = suggest authority.controlled.dspace.object.owner = true # force the event system to work synchronously during test -system-event.thread.size = 0 \ No newline at end of file +system-event.thread.size = 0 +vocabulary.plugin.srsc-noauthority.authority.store = false \ No newline at end of file diff --git a/dspace-api/src/test/data/dspaceFolder/config/spring/api/extra-metadata-enhancers-for-test.xml b/dspace-api/src/test/data/dspaceFolder/config/spring/api/extra-metadata-enhancers-for-test.xml new file mode 100644 index 00000000000..0311d8a26aa --- /dev/null +++ b/dspace-api/src/test/data/dspaceFolder/config/spring/api/extra-metadata-enhancers-for-test.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + dc.contributor.author + dc.contributor.editor + + + + + person.affiliation.name + person.identifier.orcid + + + + + + diff --git a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java index bef8ca45c09..4d4af87ddaa 100644 --- a/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java +++ b/dspace-api/src/test/java/org/dspace/app/bulkimport/service/BulkImportWorkbookBuilderIT.java @@ -221,7 +221,7 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { with("dc.contributor.author", "White, Walter", authorId, 600), with("oairecerif.author.affiliation", PLACEHOLDER_PARENT_METADATA_VALUE), with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(getItemBitstreamsByBundle(firstItem, "ORIGINAL"), contains( bitstreamWith("Bitstream 1", "First bitstream content"), @@ -242,8 +242,8 @@ public void testWorkbookBuildingFromItemDtos() throws Exception { with("oairecerif.author.affiliation", "Company", 1), with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE) + with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE), + with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE) )); assertThat(getItemBitstreamsByBundle(secondItem, "ORIGINAL"), contains( diff --git a/dspace-api/src/test/java/org/dspace/app/matcher/MetadataValueMatcher.java b/dspace-api/src/test/java/org/dspace/app/matcher/MetadataValueMatcher.java index 1439c9c37fa..55ceb779ba0 100644 --- a/dspace-api/src/test/java/org/dspace/app/matcher/MetadataValueMatcher.java +++ b/dspace-api/src/test/java/org/dspace/app/matcher/MetadataValueMatcher.java @@ -72,7 +72,8 @@ protected boolean matchesSafely(MetadataValue metadataValue) { Objects.equals(metadataValue.getMetadataField().toString('.'), field) && Objects.equals(metadataValue.getLanguage(), language) && Objects.equals(metadataValue.getAuthority(), authority) && - Objects.equals(metadataValue.getPlace(), place) && + (Objects.isNull(place) + || Objects.equals(metadataValue.getPlace(), place)) && Objects.equals(metadataValue.getConfidence(), confidence) && Objects.equals(metadataValue.getSecurityLevel(), securityLevel); } @@ -91,6 +92,10 @@ public static MetadataValueMatcher with(String field, String value) { return with(field, value, null, null, 0, -1); } + public static MetadataValueMatcher withNoPlace(String field, String value) { + return with(field, value, null, null, null, -1); + } + public static MetadataValueMatcher withSecurity(String field, String value, Integer securityLevel) { return with(field, value, null, null, 0, -1, securityLevel); } diff --git a/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java b/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java index 176f055a446..b2b34c1074f 100644 --- a/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java +++ b/dspace-api/src/test/java/org/dspace/content/enhancer/consumer/ItemEnhancerConsumerIT.java @@ -8,6 +8,7 @@ package org.dspace.content.enhancer.consumer; import static org.dspace.app.matcher.MetadataValueMatcher.with; +import static org.dspace.app.matcher.MetadataValueMatcher.withNoPlace; import static org.dspace.core.CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -18,15 +19,19 @@ import java.sql.SQLException; import java.util.List; +import java.util.stream.Collectors; +import org.apache.commons.codec.binary.StringUtils; import org.dspace.AbstractIntegrationTestWithDatabase; import org.dspace.authorize.AuthorizeException; import org.dspace.builder.CollectionBuilder; import org.dspace.builder.CommunityBuilder; import org.dspace.builder.ItemBuilder; +import org.dspace.builder.MetadataFieldBuilder; import org.dspace.builder.WorkspaceItemBuilder; import org.dspace.content.Collection; import org.dspace.content.Item; +import org.dspace.content.MetadataSchema; import org.dspace.content.MetadataValue; import org.dspace.content.WorkspaceItem; import org.dspace.content.factory.ContentServiceFactory; @@ -83,8 +88,8 @@ public void testSingleMetadataValueEnhancement() throws Exception { assertThat(metadataValues, hasSize(11)); assertThat(metadataValues, hasItem(with("cris.virtual.department", "4Science"))); assertThat(metadataValues, hasItem(with("cris.virtualsource.department", personId))); - assertThat(metadataValues, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(metadataValues, hasItem(with("cris.virtualsource.author-orcid", personId))); + assertThat(metadataValues, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(metadataValues, hasItem(with("cris.virtualsource.orcid", personId))); MetadataValue virtualField = getFirstMetadataValue(publication, "cris.virtual.department"); @@ -101,8 +106,8 @@ public void testSingleMetadataValueEnhancement() throws Exception { assertThat(metadataValues, hasItem(with("dc.contributor.author", "Walter White", personId, 600))); assertThat(metadataValues, hasItem(with("cris.virtual.department", "4Science"))); assertThat(metadataValues, hasItem(with("cris.virtualsource.department", personId))); - assertThat(metadataValues, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(metadataValues, hasItem(with("cris.virtualsource.author-orcid", personId))); + assertThat(metadataValues, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(metadataValues, hasItem(with("cris.virtualsource.orcid", personId))); assertThat(virtualField, equalTo(getFirstMetadataValue(publication, "cris.virtual.department"))); assertThat(virtualSourceField, equalTo(getFirstMetadataValue(publication, "cris.virtualsource.department"))); @@ -134,38 +139,36 @@ public void testManyMetadataValuesEnhancement() throws Exception { .withAuthor("Red Smith") .withAuthor("Walter White", person1.getID().toString()) .withAuthor("John Smith", person2.getID().toString()) - .withAuthor("Jesse Pinkman", person3.getID().toString()) + .withEditor("Jesse Pinkman", person3.getID().toString()) .build(); context.restoreAuthSystemState(); publication = commitAndReload(publication); List values = publication.getMetadata(); - assertThat(values, hasSize(26)); + assertThat(values, hasSize(22)); assertThat(values, hasItem(with("dc.contributor.author", "Red Smith"))); assertThat(values, hasItem(with("dc.contributor.author", "Walter White", person1.getID().toString(), 1, 600))); assertThat(values, hasItem(with("dc.contributor.author", "John Smith", person2.getID().toString(), 2, 600))); - assertThat(values, hasItem(with("dc.contributor.author", "Jesse Pinkman", person3.getID().toString(), 3, 600))); - assertThat(values, hasItem(with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtualsource.department", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtual.department", "4Science", 1))); - assertThat(values, hasItem(with("cris.virtualsource.department", person1.getID().toString(), 1))); - assertThat(values, hasItem(with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); - assertThat(values, hasItem(with("cris.virtualsource.department", person2.getID().toString(), 2))); - assertThat(values, hasItem(with("cris.virtual.department", "University of Rome", 3))); - assertThat(values, hasItem(with("cris.virtualsource.department", person3.getID().toString(), 3))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person1.getID().toString(), 1))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person2.getID().toString(), 2))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person3.getID().toString(), 3))); - assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(4)); - assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(4)); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), hasSize(4)); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), hasSize(4)); + assertThat(values, hasItem(with("dc.contributor.editor", "Jesse Pinkman", person3.getID().toString(), 0, 600))); + // virtual source and virtual metadata are not required to respect the order of the source metadata + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person2.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person3.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "4Science"))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "University of Rome"))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person2.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person3.getID().toString()))); + // we can check with the position as all the values are expected to be placeholder + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); + assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), hasSize(3)); } @@ -246,22 +249,28 @@ public void testEnhancementWithMetadataRemoval() throws Exception { assertThat(values, hasItem(with("dc.contributor.author", "Walter White", person1.getID().toString(), 0, 600))); assertThat(values, hasItem(with("dc.contributor.author", "John Smith", person2.getID().toString(), 1, 600))); assertThat(values, hasItem(with("dc.contributor.author", "Jesse Pinkman", person3.getID().toString(), 2, 600))); - assertThat(values, hasItem(with("cris.virtual.department", "4Science"))); - assertThat(values, hasItem(with("cris.virtualsource.department", person1.getID().toString()))); - assertThat(values, hasItem(with("cris.virtual.department", "Company", 1))); - assertThat(values, hasItem(with("cris.virtualsource.department", person2.getID().toString(), 1))); - assertThat(values, hasItem(with("cris.virtual.department", "University of Rome", 2))); - assertThat(values, hasItem(with("cris.virtualsource.department", person3.getID().toString(), 2))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person1.getID().toString()))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person2.getID().toString(), 1))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person3.getID().toString(), 2))); + // virtual source and virtual metadata are not required to respect the order of the source metadata + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person2.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person3.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "4Science"))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "Company"))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "University of Rome"))); assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(3)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(3)); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person2.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person3.getID().toString()))); + // we can check with the position as all the values are expected to be placeholder + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 2))); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), hasSize(3)); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), hasSize(3)); + + MetadataValue authorToRemove = getMetadataValues(publication, "dc.contributor.author").get(1); context.turnOffAuthorisationSystem(); @@ -274,18 +283,20 @@ public void testEnhancementWithMetadataRemoval() throws Exception { assertThat(values, hasSize(16)); assertThat(values, hasItem(with("dc.contributor.author", "Walter White", person1.getID().toString(), 0, 600))); assertThat(values, hasItem(with("dc.contributor.author", "Jesse Pinkman", person3.getID().toString(), 1, 600))); - assertThat(values, hasItem(with("cris.virtual.department", "4Science"))); - assertThat(values, hasItem(with("cris.virtualsource.department", person1.getID().toString()))); - assertThat(values, hasItem(with("cris.virtual.department", "University of Rome", 1))); - assertThat(values, hasItem(with("cris.virtualsource.department", person3.getID().toString(), 1))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person1.getID().toString(), 0))); - assertThat(values, hasItem(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); - assertThat(values, hasItem(with("cris.virtualsource.author-orcid", person3.getID().toString(), 1))); + // virtual source and virtual metadata are not required to respect the order of the source metadata + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.department", person3.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "4Science"))); + assertThat(values, hasItem(withNoPlace("cris.virtual.department", "University of Rome"))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person1.getID().toString()))); + assertThat(values, hasItem(withNoPlace("cris.virtualsource.orcid", person3.getID().toString()))); + // we can check with the position as all the values are expected to be placeholder + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 0))); + assertThat(values, hasItem(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1))); assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2)); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), hasSize(2)); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), hasSize(2)); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), hasSize(2)); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), hasSize(2)); } @@ -347,17 +358,11 @@ public void testEnhancementAfterItemUpdate() throws Exception { with("dc.contributor.author", "Walter White", personId, 2, 600), with("dc.contributor.author", "Gus Fring", 3))); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), contains( - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1), - with("cris.virtual.author-orcid", "0000-0000-1111-2222", 2), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3))); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), contains( + with("cris.virtual.orcid", "0000-0000-1111-2222"))); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), contains( - with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1), - with("cris.virtualsource.author-orcid", personId, 2), - with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3))); + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), contains( + with("cris.virtualsource.orcid", personId))); context.turnOffAuthorisationSystem(); itemService.addMetadata(context, publication, "dc", "title", "alternative", null, "Other name"); @@ -371,18 +376,89 @@ public void testEnhancementAfterItemUpdate() throws Exception { with("dc.contributor.author", "Walter White", personId, 2, 600), with("dc.contributor.author", "Gus Fring", 3))); - assertThat(getMetadataValues(publication, "cris.virtual.author-orcid"), contains( - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1), - with("cris.virtual.author-orcid", "0000-0000-1111-2222", 2), - with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3))); + assertThat(getMetadataValues(publication, "cris.virtual.orcid"), contains( + with("cris.virtual.orcid", "0000-0000-1111-2222"))); + + assertThat(getMetadataValues(publication, "cris.virtualsource.orcid"), contains( + with("cris.virtualsource.orcid", personId))); + + } + + @Test + public void testMultipleRelatedItemValuesEnhancement() throws Exception { + + context.turnOffAuthorisationSystem(); + MetadataSchema schema = ContentServiceFactory.getInstance() + .getMetadataSchemaService().find(context, "cris"); + MetadataFieldBuilder.createMetadataField(context, schema, "virtual", "testmultival", null); + MetadataFieldBuilder.createMetadataField(context, schema, "virtualsource", "testmultival", null); + + Item person1 = ItemBuilder.createItem(context, collection) + .withTitle("Walter White") + .withPersonMainAffiliation("4Science") + .withPersonMainAffiliation("DSpace") + .withOrcidIdentifier("orcid1") + .build(); - assertThat(getMetadataValues(publication, "cris.virtualsource.author-orcid"), contains( - with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE), - with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 1), - with("cris.virtualsource.author-orcid", personId, 2), - with("cris.virtualsource.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE, 3))); + Item person2 = ItemBuilder.createItem(context, collection) + .withTitle("John Smith") + .build(); + + Item person3 = ItemBuilder.createItem(context, collection) + .withTitle("Jesse Pinkman") + .withPersonMainAffiliation("University of Rome") + .build(); + + Item testEntity = ItemBuilder.createItem(context, collection) + .withTitle("Test publication") + // let's use our custom entity for test purpose, see extra-metadata-enhancers-for-test.xml + .withEntityType("TestEntity") + .withAuthor("Red Smith") + .withAuthor("Walter White", person1.getID().toString()) + .withAuthor("John Smith", person2.getID().toString()) + .withEditor("Jesse Pinkman", person3.getID().toString()) + .build(); + + context.restoreAuthSystemState(); + testEntity = commitAndReload(testEntity); + + List values = testEntity.getMetadata(); + assertThat(values, hasItem(with("dc.contributor.author", "Red Smith"))); + assertThat(values, hasItem(with("dc.contributor.author", "Walter White", person1.getID().toString(), 1, 600))); + assertThat(values, hasItem(with("dc.contributor.author", "John Smith", person2.getID().toString(), 2, 600))); + assertThat(values, hasItem(with("dc.contributor.editor", "Jesse Pinkman", person3.getID().toString(), 0, 600))); + // virtual source and virtual metadata are not required to respect the order of the source metadata + List posPerson1 = getPlacesAsVirtualSource(person1, testEntity, "cris.virtualsource.testmultival"); + List posPerson2 = getPlacesAsVirtualSource(person2, testEntity, "cris.virtualsource.testmultival"); + List posPerson3 = getPlacesAsVirtualSource(person3, testEntity, "cris.virtualsource.testmultival"); + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person1.getID().toString(), posPerson1.get(0)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "4Science", posPerson1.get(0)))); + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person1.getID().toString(), posPerson1.get(1)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "DSpace", posPerson1.get(1)))); + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person1.getID().toString(), posPerson1.get(2)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "orcid1", posPerson1.get(2)))); + + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person2.getID().toString(), posPerson2.get(0)))); + assertThat(values, + hasItem(with("cris.virtual.testmultival", PLACEHOLDER_PARENT_METADATA_VALUE, posPerson2.get(0)))); + + assertThat(values, + hasItem(with("cris.virtualsource.testmultival", person3.getID().toString(), posPerson3.get(0)))); + assertThat(values, hasItem(with("cris.virtual.testmultival", "University of Rome", posPerson3.get(0)))); + + assertThat(getMetadataValues(testEntity, "cris.virtualsource.testmultival"), hasSize(5)); + assertThat(getMetadataValues(testEntity, "cris.virtual.testmultival"), hasSize(5)); + + } + private List getPlacesAsVirtualSource(Item person1, Item publication, String metadata) { + return getMetadataValues(publication, metadata).stream() + .filter(mv -> StringUtils.equals(mv.getValue(), person1.getID().toString())).map(mv -> mv.getPlace()) + .collect(Collectors.toList()); } private MetadataValue getFirstMetadataValue(Item item, String metadataField) { diff --git a/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java b/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java index 33913368b0a..6d67c67a10b 100644 --- a/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java +++ b/dspace-api/src/test/java/org/dspace/content/enhancer/script/ItemEnhancerScriptIT.java @@ -8,11 +8,13 @@ package org.dspace.content.enhancer.script; import static org.dspace.app.matcher.MetadataValueMatcher.with; +import static org.dspace.app.matcher.MetadataValueMatcher.withNoPlace; import static org.dspace.content.Item.ANY; import static org.dspace.content.enhancer.consumer.ItemEnhancerConsumer.ITEMENHANCER_ENABLED; import static org.dspace.core.CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; @@ -22,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.UUID; import org.dspace.AbstractIntegrationTestWithDatabase; import org.dspace.app.launcher.ScriptLauncher; @@ -37,6 +40,7 @@ import org.dspace.content.WorkspaceItem; import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.service.ItemService; +import org.dspace.core.CrisConstants; import org.dspace.core.ReloadableEntity; import org.dspace.event.factory.EventServiceFactory; import org.dspace.event.service.EventService; @@ -136,24 +140,38 @@ public void testItemsEnhancement() throws Exception { .withAuthor("Jesse Pinkman", secondAuthorId) .build(); - WorkspaceItem thirdPublication = WorkspaceItemBuilder.createWorkspaceItem(context, collection) - .withTitle("Test publication 3") + final String randomUUID = UUID.randomUUID().toString(); + Item thirdPublication = ItemBuilder.createItem(context, collection) + .withTitle("Test publication 3") + .withEntityType("Publication") + .withAuthor("Walter White", firstAuthorId) + .withAuthor("Jesse Pinkman", secondAuthorId) + // same author multiple time + .withAuthor("Walter White", firstAuthorId) + // an author is also an editor + .withEditor("Jesse Pinkman", secondAuthorId) + .withEditor("Editor WithExternaAuthority", "external-authority") + .withEditor("Editor WithExternaUUIDAuthority", randomUUID) + .build(); + + WorkspaceItem wsPublication = WorkspaceItemBuilder.createWorkspaceItem(context, collection) + .withTitle("Test workspace publication") .withEntityType("Publication") - .withAuthor("Jesse Pinkman", secondAuthorId) + .withEditor("Jesse Pinkman", secondAuthorId) .build(); context.commit(); firstPublication = reload(firstPublication); secondPublication = reload(secondPublication); - thirdPublication = reload(thirdPublication); + wsPublication = reload(wsPublication); assertThat(getMetadataValues(firstPublication, "cris.virtual.department"), empty()); assertThat(getMetadataValues(firstPublication, "cris.virtualsource.department"), empty()); assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), empty()); assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), empty()); - assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), empty()); - assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), empty()); + assertThat(getMetadataValues(wsPublication, "cris.virtual.department"), empty()); + assertThat(getMetadataValues(wsPublication, "cris.virtualsource.department"), empty()); TestDSpaceRunnableHandler runnableHandler = runScript(false); @@ -162,22 +180,40 @@ public void testItemsEnhancement() throws Exception { firstPublication = reload(firstPublication); secondPublication = reload(secondPublication); + thirdPublication = reload(thirdPublication); + wsPublication = reload(wsPublication); assertThat(getMetadataValues(firstPublication, "cris.virtual.department"), hasSize(1)); assertThat(getMetadataValues(firstPublication, "cris.virtualsource.department"), hasSize(1)); - - assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), hasSize(2)); - assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), hasSize(2)); - assertThat(firstPublication.getMetadata(), hasItem(with("cris.virtual.department", "4Science"))); assertThat(firstPublication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId))); - assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtual.department", "4Science"))); - assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId))); - assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 1))); - assertThat(secondPublication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId, 1))); - assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), empty()); - assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), empty()); + assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), hasSize(2)); + assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), hasSize(2)); + assertThat(getMetadataValues(secondPublication, "cris.virtual.department"), + containsInAnyOrder( + withNoPlace("cris.virtual.department", "4Science"), + withNoPlace("cris.virtual.department", "Company"))); + assertThat(getMetadataValues(secondPublication, "cris.virtualsource.department"), + containsInAnyOrder( + withNoPlace("cris.virtualsource.department", firstAuthorId), + withNoPlace("cris.virtualsource.department", secondAuthorId))); + + assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), hasSize(3)); + assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), hasSize(3)); + assertThat(getMetadataValues(thirdPublication, "cris.virtual.department"), + containsInAnyOrder( + withNoPlace("cris.virtual.department", "4Science"), + withNoPlace("cris.virtual.department", CrisConstants.PLACEHOLDER_PARENT_METADATA_VALUE), + withNoPlace("cris.virtual.department", "Company"))); + assertThat(getMetadataValues(thirdPublication, "cris.virtualsource.department"), + containsInAnyOrder( + withNoPlace("cris.virtualsource.department", randomUUID), + withNoPlace("cris.virtualsource.department", firstAuthorId), + withNoPlace("cris.virtualsource.department", secondAuthorId))); + + assertThat(getMetadataValues(wsPublication, "cris.virtual.department"), empty()); + assertThat(getMetadataValues(wsPublication, "cris.virtualsource.department"), empty()); } @@ -223,10 +259,13 @@ public void testItemEnhancementWithoutForce() throws Exception { assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2)); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science"))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 1))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId, 1))); + assertThat(getMetadataValues(publication, "cris.virtual.department"), containsInAnyOrder( + withNoPlace("cris.virtual.department", "4Science"), + withNoPlace("cris.virtual.department", "Company"))); + + assertThat(getMetadataValues(publication, "cris.virtualsource.department"), containsInAnyOrder( + withNoPlace("cris.virtualsource.department", firstAuthorId), + withNoPlace("cris.virtualsource.department", secondAuthorId))); context.turnOffAuthorisationSystem(); @@ -273,7 +312,7 @@ public void testItemEnhancementWithForce() throws Exception { Item publication = ItemBuilder.createItem(context, collection) .withTitle("Test publication 2 ") .withEntityType("Publication") - .withAuthor("Walter White", firstAuthorId) + .withEditor("Walter White", firstAuthorId) .withAuthor("Jesse Pinkman", secondAuthorId) .build(); @@ -293,14 +332,16 @@ public void testItemEnhancementWithForce() throws Exception { assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2)); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science"))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 1))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId, 1))); + assertThat(getMetadataValues(publication, "cris.virtual.department"), containsInAnyOrder( + withNoPlace("cris.virtual.department", "4Science"), + withNoPlace("cris.virtual.department", "Company"))); + assertThat(getMetadataValues(publication, "cris.virtualsource.department"), containsInAnyOrder( + withNoPlace("cris.virtualsource.department", firstAuthorId), + withNoPlace("cris.virtualsource.department", secondAuthorId))); context.turnOffAuthorisationSystem(); - MetadataValue authorToRemove = getMetadataValues(publication, "dc.contributor.author").get(1); + MetadataValue authorToRemove = getMetadataValues(publication, "dc.contributor.author").get(0); itemService.removeMetadataValues(context, publication, List.of(authorToRemove)); replaceMetadata(firstAuthor, "person", "affiliation", "name", "University"); @@ -375,17 +416,16 @@ public void testItemEnhancementMetadataPositions() throws Exception { assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(4)); assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(4)); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", - PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", firstAuthorId,0))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science", 1))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId,1))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "Company", 2))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", thirdAuthorId, 2))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", - PLACEHOLDER_PARENT_METADATA_VALUE, 3))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", fourthAuthorId,3))); - + assertThat(getMetadataValues(publication, "cris.virtual.department"), containsInAnyOrder( + withNoPlace("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE), + withNoPlace("cris.virtual.department", "4Science"), + withNoPlace("cris.virtual.department", "Company"), + withNoPlace("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(getMetadataValues(publication, "cris.virtualsource.department"), containsInAnyOrder( + withNoPlace("cris.virtualsource.department", firstAuthorId), + withNoPlace("cris.virtualsource.department", secondAuthorId), + withNoPlace("cris.virtualsource.department", thirdAuthorId), + withNoPlace("cris.virtualsource.department", fourthAuthorId))); } @Test @@ -404,7 +444,7 @@ public void testItemEnhancementSourceWithoutAuthority() throws Exception { .withTitle("Test publication 2 ") .withEntityType("Publication") .withAuthor("Jesse Pinkman") - .withAuthor("Jesse Smith", secondAuthorId) + .withEditor("Jesse Smith", secondAuthorId) .build(); context.commit(); @@ -420,15 +460,11 @@ public void testItemEnhancementSourceWithoutAuthority() throws Exception { publication = reload(publication); - assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(2)); - assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(2)); + assertThat(getMetadataValues(publication, "cris.virtual.department"), hasSize(1)); + assertThat(getMetadataValues(publication, "cris.virtualsource.department"), hasSize(1)); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", - PLACEHOLDER_PARENT_METADATA_VALUE, 0))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", - PLACEHOLDER_PARENT_METADATA_VALUE,0))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science", 1))); - assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId,1))); + assertThat(publication.getMetadata(), hasItem(with("cris.virtual.department", "4Science", 0))); + assertThat(publication.getMetadata(), hasItem(with("cris.virtualsource.department", secondAuthorId,0))); } diff --git a/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java b/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java index b305ccc1806..9c402b4e3a0 100644 --- a/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java +++ b/dspace-api/src/test/java/org/dspace/harvest/OAIHarvesterIT.java @@ -781,7 +781,7 @@ public void testRunHarvestWithPublicationAndThenPerson() throws Exception { assertThat(values, hasItems(with("dc.identifier.doi", "10.1007/978-3-642-35233-1_18"))); assertThat(values, hasItems(with("oairecerif.author.affiliation", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItems(with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); - assertThat(values, hasItems(with("cris.virtual.author-orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); + assertThat(values, hasItems(with("cris.virtual.orcid", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItems(with("cris.sourceId", "test-harvest::3"))); assertThat(values, hasItems(with("dspace.entity.type", "Publication"))); @@ -889,8 +889,8 @@ public void testRunHarvestWithPersonAndThenPublication() throws Exception { assertThat(values, hasItems(with("dspace.entity.type", "Publication"))); assertThat(values, hasItems(with("cris.virtual.department", PLACEHOLDER_PARENT_METADATA_VALUE))); assertThat(values, hasItems(with("cris.virtualsource.department", UUIDUtils.toString(person.getID())))); - assertThat(values, hasItems(with("cris.virtual.author-orcid", "0000-0002-9079-5932"))); - assertThat(values, hasItems(with("cris.virtualsource.author-orcid", + assertThat(values, hasItems(with("cris.virtual.orcid", "0000-0002-9079-5932"))); + assertThat(values, hasItems(with("cris.virtualsource.orcid", UUIDUtils.toString(person.getID())))); MetadataValue author = itemService.getMetadata(publication, "dc", "contributor", "author", Item.ANY).get(0); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/EditItemConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/EditItemConverter.java index f19ce63d6b5..8a2135e032b 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/EditItemConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/EditItemConverter.java @@ -7,6 +7,7 @@ */ package org.dspace.app.rest.converter; +import java.util.Objects; import javax.servlet.http.HttpServletRequest; import org.apache.logging.log4j.Logger; @@ -138,7 +139,9 @@ protected void fillFromModel(EditItem obj, EditItemRest rest, Projection project } rest.setCollection(collection != null ? converter.toRest(collection, projection) : null); rest.setItem(converter.toRest(item, projection)); - rest.setSubmitter(converter.toRest(submitter, projection)); + if (Objects.nonNull(submitter)) { + rest.setSubmitter(converter.toRest(submitter, projection)); + } } private void addValidationErrorsToItem(EditItem obj, EditItemRest rest) { diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/VocabularyEntryDetailsRest.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/VocabularyEntryDetailsRest.java index fc37e537722..a3471c92921 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/VocabularyEntryDetailsRest.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/VocabularyEntryDetailsRest.java @@ -10,6 +10,8 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import org.dspace.app.rest.RestResourceController; /** @@ -28,6 +30,8 @@ public class VocabularyEntryDetailsRest extends BaseObjectRest { public static final String CHILDREN = "children"; private String display; private String value; + @JsonInclude(Include.NON_NULL) + private String authority; private Map otherInformation; private String source; private boolean selectable; @@ -61,6 +65,14 @@ public void setValue(String value) { this.value = value; } + public void setAuthority(String authority) { + this.authority = authority; + } + + public String getAuthority() { + return authority; + } + public static String getName() { return NAME; } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java index d96e43c79aa..4a256cab644 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsChildrenLinkRepository.java @@ -72,7 +72,7 @@ public Page getChildren(@Nullable HttpServletRequest pageable.getPageSize(), context.getCurrentLocale().toString()); for (Choice value : choices.values) { results.add(authorityUtils.convertEntryDetails(fix, value, vocabularyName, authority.isHierarchical(), - utils.obtainProjection())); + authority.storeAuthorityInMetadata(), utils.obtainProjection())); } Page resources = new PageImpl(results, pageable, choices.total); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java index 0b91b3ecf68..37b62f857dc 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsParentLinkRepository.java @@ -67,6 +67,6 @@ public VocabularyEntryDetailsRest getParent(@Nullable HttpServletRequest request throw new NotFoundException(); } return authorityUtils.convertEntryDetails(fix, choice, vocabularyName, authority.isHierarchical(), - utils.obtainProjection()); + authority.storeAuthorityInMetadata(), utils.obtainProjection()); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java index 31e8d7d3b92..0ddf0bdcae8 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/VocabularyEntryDetailsRestRepository.java @@ -85,7 +85,7 @@ public VocabularyEntryDetailsRest findOne(Context context, String name) { fix = true; } VocabularyEntryDetailsRest entryDetails = authorityUtils.convertEntryDetails(fix, choice, vocabularyName, - source.isHierarchical(), utils.obtainProjection()); + source.isHierarchical(), source.storeAuthorityInMetadata(), utils.obtainProjection()); //FIXME hack to deal with an improper use on the angular side of the node id (otherinformation.id) to // build a vocabulary entry details ID if (source instanceof DSpaceControlledVocabulary && !StringUtils.startsWith(vocabularyId, vocabularyName) @@ -114,7 +114,7 @@ public Page findAllTop(@Parameter(value = "vocabular } for (Choice value : choices.values) { results.add(authorityUtils.convertEntryDetails(fix, value, vocabularyId, source.isHierarchical(), - utils.obtainProjection())); + source.storeAuthorityInMetadata(), utils.obtainProjection())); } Page resources = new PageImpl(results, pageable, choices.total); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/AuthorityUtils.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/AuthorityUtils.java index aa92e71f437..5d121b60788 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/AuthorityUtils.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/utils/AuthorityUtils.java @@ -75,21 +75,26 @@ public String getPresentation(String schema, String element, String qualifier) { /** * TODO the authorityName MUST be a part of Choice model * - * @param fix if true mean that we need to deal with a - * DSpaceControlledVocabulary that requires to have the - * vocabulary name in both the authority than in the entry - * id. An entry id with a double vocabulary name would cause issue to angular - * if the vocabulary entry was requested using just one occurrence of the name - * FIXME hack to deal with an improper use on the angular side of the node id - * (otherinformation.id) to build a vocabulary entry details ID - - * @param choice - * @param authorityName - * @param projection the name of the projection to use, or {@code null}. + * @param fix if true mean that we need to deal with a + * DSpaceControlledVocabulary that requires to have the + * vocabulary name in both the authority than in the entry + * id. An entry id with a double vocabulary name would + * cause issue to angular if the vocabulary entry was + * requested using just one occurrence of the name FIXME + * hack to deal with an improper use on the angular side + * of the node id (otherinformation.id) to build a + * vocabulary entry details ID + * @param choice the choice to convert + * @param authorityName the name of the authority to which the choice belongs + * @param isHierarchical true if it is an hierarchical vocabulary + * @param storeAuthority true if the authority is configured to store the + * authority in the metadata + * {@link ChoiceAuthority#storeAuthorityInMetadata()} + * @param projection the name of the projection to use, or {@code null}. * @return */ public VocabularyEntryDetailsRest convertEntryDetails(boolean fix, Choice choice, String authorityName, - boolean isHierarchical, Projection projection) { + boolean isHierarchical, boolean storeAuthority, Projection projection) { if (choice == null) { return null; } @@ -98,6 +103,9 @@ public VocabularyEntryDetailsRest convertEntryDetails(boolean fix, Choice choice if (!fix) { entry.setId(authorityName + ":" + entry.getId()); } + if (storeAuthority) { + entry.setAuthority(choice.authority); + } entry.setInHierarchicalVocabulary(isHierarchical); return entry; } diff --git a/dspace-server-webapp/src/test/data/dspaceFolder/config/controlled-vocabularies/srsc-noauthority.xml b/dspace-server-webapp/src/test/data/dspaceFolder/config/controlled-vocabularies/srsc-noauthority.xml new file mode 100644 index 00000000000..f37dda70f10 --- /dev/null +++ b/dspace-server-webapp/src/test/data/dspaceFolder/config/controlled-vocabularies/srsc-noauthority.xml @@ -0,0 +1,2256 @@ + + + + + + + + + + Religionshistoria + + + Kyrkovetenskap + + + Missionsvetenskap + + + Systematisk teologi + + + Islamologi + + + Tros- och livsåskådningsvetenskap + + + Religionssociologi + + + Religionspsykologi + + + Religionsfilosofi + + + Nya testamentets exegetik + + + Gamla testamentets exegetik + + + Dogmatik med symbolik + + + Religionsvetenskap/Teologi + + + + + + + Logik + + + Praktisk filosofi + + + Teoretisk filosofi + + + Vetenskapsteori + + + Filosofiämnen + + + + + Arkeologi + + + Arkeologi, klassisk + + + Arkeologi, medeltid + + + Arkeologi, nordeuropeisk + + + Arkeologi, utomeuropeisk + + + Afrikansk och jämförande arkeologi + + + Historisk osteologi + + + Arkeologiämnen + + + + + Historia + + + Idé- o lärdomshistoria + + + Ekonomisk historia + + + Kyrkohistoria + + + Teknikhistoria + + + Teknik och kultur + + + Teknik- och industrihistoria + + + Vetenskapshistoria + + + Rättshistoria + + + Medicinens historia + + + Agrarhistoria + + + Bok- och bibliotekshistoria + + + Historieämnen + + + + + Humanekologi + + + Kulturantropologi + + + Etnologi + + + + + Antikens kultur och samhälle + + + Bysantinologi + + + Historiska kulturer + + + Historisk-filosofiska ämnen + + + + + Estetik + + + Filmvetenskap + + + Konstvetenskap + + + Litteraturvetenskap + + + Musikvetenskap + + + Retorik + + + Teatervetenskap + + + Bebyggelseforskning + + + Estetiska ämnen + + + + + + + Svenska språket + + + Samiska + + + Norska språket + + + Danska språket + + + Nordiska språk + + + + + Germanistik + + + Engelska språket + + + Tyska språket + + + Nederländska + + + Övriga germanska språk + + + + + Franska språket + + + Italienska språket + + + Spanska språket + + + Portugisiska + + + Rumänska + + + Romanska språk + + + + + Finska språket + + + Estniska språket + + + Finsk-ugriska språk + + + + + Ryska språket + + + Polska språket + + + Slaviska språk + + + + + Latin + + + Klassisk grekiska + + + Nygrekiska + + + Klassiska språk + + + + + Sanskrit med indoeuropeisk språkforskning + + + Keltiska språk + + + Baltiska språk + + + Östasiatiska språk + + + Turkiska språk + + + Iranska språk + + + Arabiska + + + Kinesiska + + + Egyptologi + + + Indonesiska + + + Afrikanska språk + + + Bantuistik + + + Kaukasiska språk + + + Semitiska språk + + + Altaistik + + + Assyriologi + + + Indologi + + + Japanologi + + + Koreanologi + + + Övriga språk + + + Teckenspråk + + + + + Lingvistik + + + Fonetik + + + Barnspråk + + + Tvåspråkighet + + + Språkteknologi + + + Datorlingvistik + + + Lingvistikämnen + + + Språkvetenskap + + + Övrig humaniora och religionsvetenskap + + + HUMANIORA och RELIGIONSVETENSKAP + + + + + + + Förvaltningsrätt + + + Konstitutionell rätt + + + Socialrätt + + + Offentlig rätt + + + + + Civilprocess + + + Straffprocess + + + Förvaltningsprocess + + + Skiljemannarätt + + + Processrätt + + + Straffrätt + + + Finansrätt + + + + + Allmän avtalsrätt + + + Arbetsrätt + + + Affärsrätt + + + Bolagsrätt + + + Försäkringsrätt + + + Immaterialrätt + + + Sakrätt + + + Skadeståndsrätt + + + Speciell avtalsrätt + + + Civilrätt + + + + + Allmän rättslära + + + EU-rätt + + + Folkrätt + + + Internationell privat- och processrätt + + + Komparativ rätt + + + Marknads- och konkurrensrätt + + + Miljörätt + + + Övrig rätt + + + RÄTTSVETENSKAP/JURIDIK + + + + + + + + + Ämnesdidaktik + + + Vårdpedagogik + + + Musikpedagogik + + + Internationell pedagogik + + + Pedagogik + + + + + Tillämpad psykologi + + + Miljöpsykologi + + + Kognitionsforskning + + + Psykologi + + + + + Socialantropologi + + + Etnografi + + + Socialantrolopologi/etnografi + + + + + Familjeforskning + + + Ungdomsforskning + + + Handikappsforskning + + + Idrottsforskning + + + Socialt arbete + + + + + Kriminalvetenskap + + + Kriminologi + + + + + Rättssociologi + + + Sociologi + + + Demografi + + + + + Freds- och konfliktforskning + + + Freds- och utvecklingsforskning + + + Empirisk konfliktforskning + + + Forskning om Europa + + + Statsvetenskap + + + Pedagogiskt arbete + + + Socialvetenskap + + + + + Företagsekonomi + + + + + Kulturgeografi + + + Ekonomisk geografi + + + Kulturgeografi, ekonomisk geografi + + + + + Ekonometri + + + Nationalekonomi + + + Ekonomi + + + + + + + Informatik + + + Informatik och systemvetenskap + + + ADB + + + Data- och systemvetenskap + + + Databaser + + + Databehandling + + + Informations- och språkteknologi + + + Informationsbehandling + + + Informationsteknologi + + + Informatik, data- och systemvetenskap + + + + + Biostatistik + + + Statistik + + + Statistik, data- och systemvetenskap + + + + + Masskommunikation + + + Medie- och kommunikationsvetenskap + + + Biblioteks- och informationsvetenskap + + + Arbetsmarknadsforskning + + + Europeiskt forskningssamarbete + + + Forskning om offentlig sektor + + + Forskningspolitik + + + Militär underrättelse- och säkerhetstjänst + + + Övrig samhällsvetenskap + + + SAMHÄLLSVETENSKAP + + + + + + + Algebra och geometri + + + Analys + + + Matematisk logik + + + Diskret matematik + + + Algebra, geometri och analys + + + + + Numerisk analys + + + Matematisk statistik + + + Optimeringslära, systemteori + + + Teoretisk datalogi + + + Tillämpad matematik + + + Övrig matematik + + + MATEMATIK + + + + + + + + + Astropartikelfysik + + + Jonfysik + + + Elementarpartikelfysik + + + + + Tungjonsfysik + + + Mellanenergifysik + + + Lågenergifysik + + + Kärnfysik + + + + + Atomfysik + + + Molekylfysik + + + Kemisk fysik + + + Atom- och molekylfysik + + + + + Magnetism + + + Ytor och mellanytor + + + Halvledarfysik + + + Elektronstruktur + + + Supraledning + + + Defekter och diffusion + + + Struktur- och vibrationsfysik + + + Kritiska fenomen (fasövergångar) + + + Vätskefysik + + + Lågtemperaturfysik + + + Makromolekylfysik + + + Mesoskopisk fysik + + + Biologisk fysik + + + Kondenserade materiens fysik + + + + + Astronomi + + + Astropartikelfysik + + + Högenergiastrofysik + + + Solfysik + + + Planetsystemet + + + Galaktisk astronomi + + + Extragalaktisk astronomi + + + Stjärnors bildning och utveckling + + + Kosmologi + + + Astronomi och astrofysik + + + + + Rymdfysik + + + Plasmafysik + + + Fusion + + + Geokosmofysik och plasmafysik + + + + + Optik + + + Geofysik + + + Matematisk fysik + + + Beräkningsfysik + + + Relativitetsteori, gravitation + + + Statistisk fysik + + + Icke-linjär dynamik, kaos + + + Övrig fysik + + + Fysik + + + + + + + Kvantkemi + + + Statistisk mekanik + + + Bioinformatik + + + Teoretisk kemi + + + + + Biofysikalisk kemi + + + Kinetik + + + Spektroskopi + + + Yt- och kolloidkemi + + + Kemisk fysik + + + Fysikalisk kemi + + + + + Separationsmetoder + + + Elektrokemi + + + Spektroskopi + + + Analytisk kemi + + + Molekylär biofysik + + + + + Koordinationskemi + + + Lösningskemi + + + Fasta tillståndets kemi + + + Bio-oorganisk kemi + + + Oorganisk kemi + + + + + Organisk syntes + + + Fysikalisk organisk kemi + + + Bioorganisk kemi + + + Polymerkemi + + + Läkemedelskemi + + + Organisk kemi + + + + + Molekylärbiologi + + + Toxikologi + + + Strukturbiologi + + + Funktionsgenomik + + + Biokemi + + + + + Persistenta organiska föreningar + + + Tungmetaller och övriga metaller + + + Miljötoxikologi + + + Miljökemi + + + Övrig kemi + + + Kemi + + + + + + + Terrestisk ekologi + + + Limnisk ekologi + + + Marin ekologi + + + Etologi och beteendeekologi + + + Terrestisk, limnisk och marin ekologi + + + + + Mikrobiologi + + + Morfologi + + + Systematik och fylogeni + + + Växtfysiologi + + + Zoofysiologi + + + Utvecklingsbiologi + + + Organismbiologi + + + + + Cellbiologi + + + Molekylärbiologi + + + Immunologi + + + Toxikologi + + + Neurobiologi + + + Genetik + + + Cell- och molekylärbiologi + + + + + Bioinformatik + + + Funktionsgenomik + + + Övrig biologi + + + Biologi + + + + + + + Berggrundsgeologi och petrologi + + + Mineralvetenskap + + + Fasta jordens fysik + + + Endogen geovetenskap + + + + + Historisk geologi och paleontologi + + + Kvartärgeologi + + + Naturgeografi + + + Exogen geokemi + + + Sedimentologi + + + Exogen geovetenskap + + + + + Meteorologi + + + Hydrologi + + + Oceanografi + + + Klimatologi + + + Atmosfärs- och hydrosfärsvetenskap + + + Övrig geovetenskap + + + Geovetenskap + + + NATURVETENSKAP + + + + + + + + + Datalogi + + + Programvaruteknik + + + Kognitionsvetenskap + + + Datavetenskap + + + Reglerteknik + + + + + Telekommunikationsteori + + + Teletransmissionsteori + + + Teletrafiksystem + + + Datatransmission + + + Telekommunikation + + + Signalbehandling + + + Bildanalys + + + Datorteknik + + + Systemteknik + + + Övrig informationsteknik + + + Informationsteknik + + + + + Optisk fysik + + + Akustik + + + Materialfysik med ytfysik + + + Plasmafysik med fusion + + + Biofysik + + + Övrig teknisk fysik + + + Teknisk fysik + + + + + Elektroteknik + + + Elektronik + + + Elektrofysik + + + Fotonik + + + Elektronisk mät- och apparatteknik + + + Elkraftteknik + + + Övrig elektroteknik, elektronik och fotonik + + + Elektroteknik, elektronik och fotonik + + + + + + + Processkemi + + + Katalys + + + Molekylära transportprocesser i kemisk processteknik + + + Kemisk energiteknik + + + Cellulosa- och pappersteknik + + + Materialkemi + + + Elektrokemi + + + Yt- och kolloidkemi + + + Kärnkemi + + + Kemisk apparatteknik + + + Kemisk produktionsteknik + + + Kemisk process- och produktionsteknik + + + + + Metallurgisk processteknik + + + Metallurgisk produktionsteknik + + + Metallurgisk process- och produktionsteknik + + + Livsmedelsteknik + + + Övrig kemiteknik + + + Kemiteknik + + + + + Genteknik inkl. funktionsgenomik + + + Strukturbiokemi + + + Biokemisk och bioteknisk processteknik + + + Enzymteknik + + + Immunteknik + + + Bioteknisk separation + + + Bioanalytisk teknik + + + Bioorganisk syntes + + + Växtbioteknik + + + Bioinformatik + + + Övrig bioteknik + + + Bioteknik + + + + + Fastkroppsmekanik + + + Strömningsmekanik + + + Konstruktionsteknik + + + Mekanisk tillverkningsteknik + + + + + Mekanisk energiteknik + + + Termisk energiteknik + + + Mekanisk och termisk energiteknik + + + Farkostteknik + + + Övrig teknisk mekanik + + + Teknisk mekanik + + + + + Funktionella material + + + Konstruktionsmaterial + + + Ytbehandlingsteknik + + + Övrig bearbetning/sammanfogning + + + Övrig teknisk materialvetenskap + + + Teknisk materialvetenskap + + + + + + + Geoteknik + + + Gruvteknik + + + Geoteknik och gruvteknik + + + Byggnadsteknik + + + Byggproduktionsteknik + + + Vattenteknik + + + Lantmäteri + + + + + Arkitektur + + + Bebyggelsevård + + + Arkitektur och bebyggelsevård + + + Övrig samhällsbyggnadsteknik och arkitektur + + + Samhällsbyggnadsteknik och arkitektur + + + + + + + Produktionsteknik + + + Arbetsvetenskap och ergonomi + + + Produktion och arbetsvetenskap + + + Industriell organisation, administration och ekonomi + + + Fysisk planläggning + + + Övrig industriell teknik och ekonomi + + + Industriell teknik och ekonomi + + + + + Medicinsk teknik + + + Miljöteknik + + + Rymdteknik + + + Övriga teknikvetenskaper + + + TEKNIKVETENSKAP + + + + + + + Markfysik + + + Markkemi + + + Markbiologi + + + Jordmånslära + + + Markvetenskap + + + + + Växtförädling + + + Trädgårdsväxtodling + + + Jordbruksväxtodling + + + Skogsskötsel + + + Växt- och skogsskydd + + + Växtproduktion + + + + + Husdjursförädling + + + Husdjurens utfodring och vård + + + Vattenbruk + + + Fiske + + + Animalieproduktion + + + + + Livsmedelsvetenskap + + + Träfiber- och virkeslära + + + Fytokemi inklusive alger och industribioråvaror + + + Produktforskning + + + + + Landskapsarkitektur + + + Vegetationsbyggnad + + + Natur- och landskapsvård + + + Översiktlig planering + + + Landskapsplanering + + + + + Jordbruksteknik + + + Jordbrukets byggnadsteknik + + + Skogsteknik + + + Fjärranalys + + + Areell teknik + + + + + Jordbruksekonomi + + + Skogsekonomi + + + Skogsuppskattning och skogsindelning + + + Informationslära + + + Areell ekonomi + + + SKOGS- och JORDBRUKSVETENSKAP samt LANDSKAPSPLANERING + + + + + + + + + Anestesiologi + + + Intensivvård + + + Katastrofmedicin + + + Traumatologi + + + Anestesiologi och intensivvård + + + + + Endokrin kirurgi + + + Handkirurgi + + + Kirurgi + + + Kärlkirurgi + + + Neurokirurgi + + + Ortopedi + + + Otoneurologi + + + Pediatrisk kirurgi + + + Plastikkirurgi + + + Thoraxkirurgi + + + Transplantationskirurgi + + + Urologi och andrologi + + + Kirurgisk forskning + + + + + Obstetrik och gynekologi + + + Reproduktiv hälsa + + + Reproduktiv och perinatal omvårdnad + + + Obstetrik och kvinnosjukdomar + + + Onkologi + + + + + Audiologi + + + Logopedi och foniatrik + + + Otorhinolaryngologi + + + Kirurgi + + + + + + + Neurovetenskap + + + Neurobiologi + + + Medicinsk cellbiologi + + + Cellbiologi + + + + + Anatomi + + + Biomaterial + + + Histologi + + + Tumörbiologi + + + Morfologi + + + + + Rättsmedicin + + + Molekylär medicin + + + Patologi + + + Morfologi, cellbiologi, patologi + + + + + Dermatologi och venerologi + + + + + Medicinsk genetik + + + Rättsgenetik + + + Molekylärbiologi + + + Molekykär ekogenetik + + + Klinisk genetik + + + + + Barnkardiologi + + + Diabetologi + + + Endokrinologi + + + Gastroenterologi + + + Geriatrik och medicinsk gerontologi + + + Hematologi + + + Kardiologi + + + Kardiovaskulär medicin + + + Lungsjukdomar + + + Molekylär medicin (genetik och patologi) + + + Neurologi + + + Njursjukdomar + + + Palliativ medicin + + + Pediatrisk medicin + + + Prenatal- och perinatalforskning + + + Reumatologi + + + Transfusionsmedicin + + + Invärtesmedicin + + + Dermatologi och venerologi, klinisk genetik, invärtesmedicin + + + + + + + Farmakologi + + + Klinisk farmakologi + + + Toxikologi + + + Farmakologisk forskning + + + + + Experimentell hjärnforskning + + + Försöksdjursvetenskap + + + Klinisk fysiologi + + + Klinisk neurofysiologi + + + Medicinsk informatik + + + Medicinsk teknik + + + Molekylär neurobiologi + + + Neurobiologi + + + Neurofysiologi + + + Näringslära + + + Fysiologi + + + + + Oftalmiatrik + + + Optometri + + + Oftalmologi + + + + + Radiologi + + + Diagnostisk radiologi + + + Radiofysik + + + Strålningsbiologi + + + Radiologisk forskning + + + Fysiologi och farmakologi + + + + + + + Allmänmedicin + + + Arbetsfysiologi + + + Epidemiologi + + + Folkhälsovetenskap + + + Miljömedicin + + + Samhällsmedicin + + + Yrkesmedicin + + + Folkhälsomedicinska forskningsområden + + + Socialmedicin + + + + + + + Allergologi + + + Immungenetik + + + Immunbiologi + + + Klinisk immunologi + + + Tumörimmunologi + + + Immunologi + + + + + Bakteriologi + + + Klinisk bakteriologi + + + Klinisk virologi + + + Medicinsk mikrobiologi + + + Virologi + + + Mikrobiologi + + + Infektionssjukdomar + + + Mikrobiologi, immunologi, infektionssjukdomar + + + + + Biokemi + + + Klinisk kemi + + + Neurokemi + + + Rättskemi + + + Kemi + + + + + Barn- och ungdomspsykiatri + + + Beroendelära + + + Psykiatri + + + MEDICIN + + + + + Biokemi + + + Biomaterial + + + Cariologi + + + Cell- och molekylärbiologi + + + Endodonti + + + Farmakologisk forskning + + + Fysiologi + + + Gerodontologi + + + Kirurgisk forskning + + + Morfologi + + + Odontologisk beteendevetenskap + + + Oral mikrobiologi + + + Oral patologi och rättsodontologi + + + Oral protetik + + + Ortodonti + + + Parodontologi + + + Pedodonti + + + Radiologisk forskning + + + Övrig odontologi + + + ODONTOLOGI + + + + + Biofarmaci + + + Biologisk beroendeforskning + + + Farmaceutisk biokemi + + + Farmaceutisk farmakologi + + + Farmaceutisk kemi + + + Farmaceutisk mikrobiologi + + + Toxikologi + + + Farmakognosi + + + Galenisk farmaci + + + Samhällsfarmaci + + + Övrig farmaci + + + FARMACI + + + + + Biokemi och klinisk kemi + + + Cellbiologi och genomforskning + + + Husdjurens etologi + + + Farmakologisk forskning + + + Fysiologi och näringslära + + + Husdjurshygien + + + Kirurgi + + + Livsmedelshygien + + + Medicin + + + Mikrobiologi och immunologi + + + Morfologi + + + Obstetrik och gynekologi + + + Patologi + + + Radiologi + + + Veterinärmedicinsk epidemiologi + + + Övrig veterinärmedicin + + + VETERINÄRMEDICIN + + + + + Barn + + + Hushålls- och kostvetenskap + + + Hälso- och sjukvård i samhället + + + Kommunikation mellan människor + + + Teknik och social förändring + + + Vatten i natur och samhälle + + + + + Arbetsterapi + + + Medicinsk laboratorievetenskap + + + Omvårdnad + + + Sjukgymnastik/fysioterapi + + + Social omsorg/socialpedagogik + + + Vetenskapsteori med inriktning mot vård- och omsorgsområdet + + + Vårdvetenskap + + + Etnicitet + + + Genus + + + Kulturarv och kulturproduktion + + + Idrott + + + Äldre och åldrande + + + TVÄRVETENSKAPLIGA FORSKNINGSOMRÅDEN + + + Ämneskategorier för vetenskapliga publikationer + \ No newline at end of file diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java index dad6cd8b460..340780dc583 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/VocabularyEntryDetailsIT.java @@ -162,6 +162,74 @@ public void srscSearchTopTest() throws Exception { .andExpect(jsonPath("$.page.totalElements", Matchers.is(12))); } + public void srscSearchTopNoAuthorityTest() throws Exception { + String tokenAdmin = getAuthToken(admin.getEmail(), password); + String tokenEPerson = getAuthToken(eperson.getEmail(), password); + getClient(tokenAdmin).perform(get("/api/submission/vocabularyEntryDetails/search/top") + .param("vocabulary", "srsc-noauthority")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB11", "HUMANITIES and RELIGION", + "HUMANITIES and RELIGION"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB12", "LAW/JURISPRUDENCE", + "LAW/JURISPRUDENCE"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB13", "SOCIAL SCIENCES", + "SOCIAL SCIENCES"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB14", "MATHEMATICS", + "MATHEMATICS"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB15", "NATURAL SCIENCES", + "NATURAL SCIENCES"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB16", "TECHNOLOGY", + "TECHNOLOGY"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB17", + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING", + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB18", "MEDICINE", + "MEDICINE"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB19", "ODONTOLOGY", + "ODONTOLOGY"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB21", "PHARMACY", + "PHARMACY"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB22", "VETERINARY MEDICINE", + "VETERINARY MEDICINE"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB23", + "INTERDISCIPLINARY RESEARCH AREAS", "INTERDISCIPLINARY RESEARCH AREAS") + ))) + .andExpect(jsonPath("$.page.totalElements", Matchers.is(12))); + + getClient(tokenEPerson).perform(get("/api/submission/vocabularyEntryDetails/search/top") + .param("vocabulary", "srsc-noauthority")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.vocabularyEntryDetails", Matchers.containsInAnyOrder( + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB11", + "HUMANITIES and RELIGION", "HUMANITIES and RELIGION"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB12", "LAW/JURISPRUDENCE", + "LAW/JURISPRUDENCE"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB13", "SOCIAL SCIENCES", + "SOCIAL SCIENCES"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB14", "MATHEMATICS", + "MATHEMATICS"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB15", "NATURAL SCIENCES", + "NATURAL SCIENCES"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB16", "TECHNOLOGY", + "TECHNOLOGY"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB17", + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING", + "FORESTRY, AGRICULTURAL SCIENCES and LANDSCAPE PLANNING"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB18", "MEDICINE", + "MEDICINE"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB19", "ODONTOLOGY", + "ODONTOLOGY"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB21", "PHARMACY", + "PHARMACY"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB22", "VETERINARY MEDICINE", + "VETERINARY MEDICINE"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB23", + "INTERDISCIPLINARY RESEARCH AREAS", "INTERDISCIPLINARY RESEARCH AREAS") + ))) + .andExpect(jsonPath("$.page.totalElements", Matchers.is(12))); + } + @Test public void srscSearchFirstLevel_MATHEMATICS_Test() throws Exception { String tokenAdmin = getAuthToken(admin.getEmail(), password); @@ -181,6 +249,25 @@ public void srscSearchFirstLevel_MATHEMATICS_Test() throws Exception { .andExpect(jsonPath("$.page.totalElements", Matchers.is(3))); } + @Test + public void srscSearchFirstLevel_MATHEMATICS_NoAuthorityTest() throws Exception { + String tokenAdmin = getAuthToken(admin.getEmail(), password); + getClient(tokenAdmin).perform(get("/api/submission/vocabularyEntryDetails/srsc-noauthority:SCB14/children")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.children", Matchers.containsInAnyOrder( + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB1401", + "Algebra, geometry and mathematical analysis", + "MATHEMATICS::Algebra, geometry and mathematical analysis"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB1402", + "Applied mathematics", "MATHEMATICS::Applied mathematics"), + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry("srsc-noauthority:SCB1409", "Other mathematics", + "MATHEMATICS::Other mathematics") + ))) + .andExpect(jsonPath("$._embedded.children[*].otherInformation.parent", + Matchers.everyItem(is("MATHEMATICS")))) + .andExpect(jsonPath("$.page.totalElements", Matchers.is(3))); + } + @Test public void srscSearchTopPaginationTest() throws Exception { String tokenAdmin = getAuthToken(admin.getEmail(), password); @@ -345,6 +432,17 @@ public void findParentByChildTest() throws Exception { ))); } + @Test + public void findParentByChildNoAuthorityTest() throws Exception { + String tokenEperson = getAuthToken(eperson.getEmail(), password); + getClient(tokenEperson).perform(get("/api/submission/vocabularyEntryDetails/srsc-noauthority:SCB180/parent")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", is( + VocabularyEntryDetailsMatcher.matchNoAuthorityEntry( + "srsc-noauthority:SCB18", "MEDICINE","MEDICINE") + ))); + } + @Test public void findParentByChildBadRequestTest() throws Exception { String tokenEperson = getAuthToken(eperson.getEmail(), password); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/VocabularyEntryDetailsMatcher.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/VocabularyEntryDetailsMatcher.java index 8eb2cba3c4b..d645ef1e05c 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/VocabularyEntryDetailsMatcher.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/matcher/VocabularyEntryDetailsMatcher.java @@ -8,6 +8,7 @@ package org.dspace.app.rest.matcher; import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath; +import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; @@ -25,6 +26,14 @@ private VocabularyEntryDetailsMatcher() { public static Matcher matchAuthorityEntry(String id, String display, String value) { return allOf( matchProperties(id, display, value), + hasJsonPath("$.authority", is(id)), + matchLinks(id)); + } + + public static Matcher matchNoAuthorityEntry(String id, String display, String value) { + return allOf( + matchProperties(id, display, value), + hasNoJsonPath("$.authority"), matchLinks(id)); } diff --git a/dspace/config/registries/cris-types.xml b/dspace/config/registries/cris-types.xml index 7f0f8d7ec63..90597ddffbc 100644 --- a/dspace/config/registries/cris-types.xml +++ b/dspace/config/registries/cris-types.xml @@ -152,14 +152,7 @@ cris virtual - author-orcid - - - - - cris - virtual - editor-orcid + orcid @@ -173,14 +166,7 @@ cris virtualsource - author-orcid - - - - - cris - virtualsource - editor-orcid + orcid diff --git a/dspace/config/spring/api/discovery.xml b/dspace/config/spring/api/discovery.xml index de6145afd67..3c7a70cf9e0 100644 --- a/dspace/config/spring/api/discovery.xml +++ b/dspace/config/spring/api/discovery.xml @@ -61,9 +61,6 @@ dc.contributor.editor - - - @@ -72,6 +69,9 @@ + + + @@ -91,6 +91,7 @@ + @@ -785,6 +786,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + search.resourcetype:WorkspaceItem AND supervised:true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + dc.contributor.author + dc.contributor.editor + + - - - - + + + + dc.contributor.author + dc.contributor.editor + + + + - + + + dc.contributor.author + dc.contributor.editor + + - + - + + + dc.contributor.author + dc.contributor.editor + + - + - - - - - - - -