diff --git a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java index 5b37a1ae60..31fecd2620 100644 --- a/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/content/ItemServiceImpl.java @@ -1379,22 +1379,23 @@ prevent the generation of resource policy entry values with null dspace_object a throws SQLException { List resultingMetadataValueList = new LinkedList<>(); RelationshipType relationshipType = relationship.getRelationshipType(); - HashMap hashMaps = new HashMap<>(); + HashMap hashMaps; String relationName = ""; Item otherItem = null; int place = 0; if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) { - hashMaps = (HashMap) virtualMetadataPopulator - .getMap().get(relationshipType.getLeftLabel()); + hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getLeftLabel()); otherItem = relationship.getRightItem(); relationName = relationship.getRelationshipType().getLeftLabel(); place = relationship.getLeftPlace(); } else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) { - hashMaps = (HashMap) virtualMetadataPopulator - .getMap().get(relationshipType.getRightLabel()); + hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getRightLabel()); otherItem = relationship.getLeftItem(); relationName = relationship.getRelationshipType().getRightLabel(); place = relationship.getRightPlace(); + } else { + //No virtual metadata can be created + return resultingMetadataValueList; } if (hashMaps != null && enableVirtualMetadata) { @@ -1402,8 +1403,11 @@ prevent the generation of resource policy entry values with null dspace_object a otherItem, relationName, relationship.getID(), place)); } - resultingMetadataValueList - .add(getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID())); + RelationshipMetadataValue relationMetadataFromOtherItem = + getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID()); + if (relationMetadataFromOtherItem != null) { + resultingMetadataValueList.add(relationMetadataFromOtherItem); + } return resultingMetadataValueList; } @@ -1420,11 +1424,13 @@ prevent the generation of resource policy entry values with null dspace_object a for (String value : virtualBean.getValues(context, otherItem)) { RelationshipMetadataValue metadataValue = constructMetadataValue(context, key); - metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId); - metadataValue.setUseForPlace(virtualBean.getUseForPlace()); - metadataValue.setPlace(place); - if (StringUtils.isNotBlank(metadataValue.getValue())) { - resultingMetadataValueList.add(metadataValue); + if (metadataValue != null) { + metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId); + metadataValue.setUseForPlace(virtualBean.getUseForPlace()); + metadataValue.setPlace(place); + if (StringUtils.isNotBlank(metadataValue.getValue())) { + resultingMetadataValueList.add(metadataValue); + } } } } @@ -1437,9 +1443,12 @@ prevent the generation of resource policy entry values with null dspace_object a RelationshipMetadataValue metadataValue = constructMetadataValue(context, MetadataSchemaEnum.RELATION .getName() + "." + relationName); - metadataValue.setAuthority(Constants.VIRTUAL_AUTHORITY_PREFIX + relationshipId); - metadataValue.setValue(otherItem.getID().toString()); - return metadataValue; + if (metadataValue != null) { + metadataValue.setAuthority(Constants.VIRTUAL_AUTHORITY_PREFIX + relationshipId); + metadataValue.setValue(otherItem.getID().toString()); + return metadataValue; + } + return null; } private String getEntityTypeStringFromMetadata(List list) { diff --git a/dspace-api/src/main/java/org/dspace/content/virtual/VirtualMetadataPopulator.java b/dspace-api/src/main/java/org/dspace/content/virtual/VirtualMetadataPopulator.java index 78ee7b0b41..64663f3574 100644 --- a/dspace-api/src/main/java/org/dspace/content/virtual/VirtualMetadataPopulator.java +++ b/dspace-api/src/main/java/org/dspace/content/virtual/VirtualMetadataPopulator.java @@ -22,13 +22,13 @@ public class VirtualMetadataPopulator { /** * The map that holds this representation */ - private Map map; + private Map> map; /** * Standard setter for the map * @param map The map to be used in the VirtualMetadataPopulator */ - public void setMap(Map map) { + public void setMap(Map> map) { this.map = map; } @@ -36,18 +36,16 @@ public class VirtualMetadataPopulator { * Standard getter for the map * @return The map that is used in the VirtualMetadataPopulator */ - public Map getMap() { + public Map> getMap() { return map; } public boolean isUseForPlaceTrueForRelationshipType(RelationshipType relationshipType, boolean isLeft) { - HashMap hashMaps = new HashMap<>(); + HashMap hashMaps; if (isLeft) { - hashMaps = (HashMap) this - .getMap().get(relationshipType.getLeftLabel()); + hashMaps = this.getMap().get(relationshipType.getLeftLabel()); } else { - hashMaps = (HashMap) this - .getMap().get(relationshipType.getRightLabel()); + hashMaps = this.getMap().get(relationshipType.getRightLabel()); } if (hashMaps != null) { for (Map.Entry entry : hashMaps.entrySet()) {