Check for null values

Use typed Maps
This commit is contained in:
Ben Bosman
2019-02-07 12:55:02 +01:00
parent f2b3f7027c
commit 15eb85eb08
2 changed files with 30 additions and 23 deletions

View File

@@ -1379,22 +1379,23 @@ prevent the generation of resource policy entry values with null dspace_object a
throws SQLException { throws SQLException {
List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>(); List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>();
RelationshipType relationshipType = relationship.getRelationshipType(); RelationshipType relationshipType = relationship.getRelationshipType();
HashMap<String, VirtualBean> hashMaps = new HashMap<>(); HashMap<String, VirtualBean> hashMaps;
String relationName = ""; String relationName = "";
Item otherItem = null; Item otherItem = null;
int place = 0; int place = 0;
if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) { if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) {
hashMaps = (HashMap<String, VirtualBean>) virtualMetadataPopulator hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getLeftLabel());
.getMap().get(relationshipType.getLeftLabel());
otherItem = relationship.getRightItem(); otherItem = relationship.getRightItem();
relationName = relationship.getRelationshipType().getLeftLabel(); relationName = relationship.getRelationshipType().getLeftLabel();
place = relationship.getLeftPlace(); place = relationship.getLeftPlace();
} else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) { } else if (StringUtils.equals(relationshipType.getRightType().getLabel(), entityType)) {
hashMaps = (HashMap<String, VirtualBean>) virtualMetadataPopulator hashMaps = virtualMetadataPopulator.getMap().get(relationshipType.getRightLabel());
.getMap().get(relationshipType.getRightLabel());
otherItem = relationship.getLeftItem(); otherItem = relationship.getLeftItem();
relationName = relationship.getRelationshipType().getRightLabel(); relationName = relationship.getRelationshipType().getRightLabel();
place = relationship.getRightPlace(); place = relationship.getRightPlace();
} else {
//No virtual metadata can be created
return resultingMetadataValueList;
} }
if (hashMaps != null && enableVirtualMetadata) { if (hashMaps != null && enableVirtualMetadata) {
@@ -1402,8 +1403,11 @@ prevent the generation of resource policy entry values with null dspace_object a
otherItem, relationName, otherItem, relationName,
relationship.getID(), place)); relationship.getID(), place));
} }
resultingMetadataValueList RelationshipMetadataValue relationMetadataFromOtherItem =
.add(getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID())); getRelationMetadataFromOtherItem(context, otherItem, relationName, relationship.getID());
if (relationMetadataFromOtherItem != null) {
resultingMetadataValueList.add(relationMetadataFromOtherItem);
}
return resultingMetadataValueList; 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)) { for (String value : virtualBean.getValues(context, otherItem)) {
RelationshipMetadataValue metadataValue = constructMetadataValue(context, key); RelationshipMetadataValue metadataValue = constructMetadataValue(context, key);
metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId); if (metadataValue != null) {
metadataValue.setUseForPlace(virtualBean.getUseForPlace()); metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId);
metadataValue.setPlace(place); metadataValue.setUseForPlace(virtualBean.getUseForPlace());
if (StringUtils.isNotBlank(metadataValue.getValue())) { metadataValue.setPlace(place);
resultingMetadataValueList.add(metadataValue); 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, RelationshipMetadataValue metadataValue = constructMetadataValue(context,
MetadataSchemaEnum.RELATION MetadataSchemaEnum.RELATION
.getName() + "." + relationName); .getName() + "." + relationName);
metadataValue.setAuthority(Constants.VIRTUAL_AUTHORITY_PREFIX + relationshipId); if (metadataValue != null) {
metadataValue.setValue(otherItem.getID().toString()); metadataValue.setAuthority(Constants.VIRTUAL_AUTHORITY_PREFIX + relationshipId);
return metadataValue; metadataValue.setValue(otherItem.getID().toString());
return metadataValue;
}
return null;
} }
private String getEntityTypeStringFromMetadata(List<MetadataValue> list) { private String getEntityTypeStringFromMetadata(List<MetadataValue> list) {

View File

@@ -22,13 +22,13 @@ public class VirtualMetadataPopulator {
/** /**
* The map that holds this representation * The map that holds this representation
*/ */
private Map map; private Map<String, HashMap<String, VirtualBean>> map;
/** /**
* Standard setter for the map * Standard setter for the map
* @param map The map to be used in the VirtualMetadataPopulator * @param map The map to be used in the VirtualMetadataPopulator
*/ */
public void setMap(Map map) { public void setMap(Map<String, HashMap<String, VirtualBean>> map) {
this.map = map; this.map = map;
} }
@@ -36,18 +36,16 @@ public class VirtualMetadataPopulator {
* Standard getter for the map * Standard getter for the map
* @return The map that is used in the VirtualMetadataPopulator * @return The map that is used in the VirtualMetadataPopulator
*/ */
public Map getMap() { public Map<String, HashMap<String, VirtualBean>> getMap() {
return map; return map;
} }
public boolean isUseForPlaceTrueForRelationshipType(RelationshipType relationshipType, boolean isLeft) { public boolean isUseForPlaceTrueForRelationshipType(RelationshipType relationshipType, boolean isLeft) {
HashMap<String, VirtualBean> hashMaps = new HashMap<>(); HashMap<String, VirtualBean> hashMaps;
if (isLeft) { if (isLeft) {
hashMaps = (HashMap<String, VirtualBean>) this hashMaps = this.getMap().get(relationshipType.getLeftLabel());
.getMap().get(relationshipType.getLeftLabel());
} else { } else {
hashMaps = (HashMap<String, VirtualBean>) this hashMaps = this.getMap().get(relationshipType.getRightLabel());
.getMap().get(relationshipType.getRightLabel());
} }
if (hashMaps != null) { if (hashMaps != null) {
for (Map.Entry<String, VirtualBean> entry : hashMaps.entrySet()) { for (Map.Entry<String, VirtualBean> entry : hashMaps.entrySet()) {