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 {
List<RelationshipMetadataValue> resultingMetadataValueList = new LinkedList<>();
RelationshipType relationshipType = relationship.getRelationshipType();
HashMap<String, VirtualBean> hashMaps = new HashMap<>();
HashMap<String, VirtualBean> hashMaps;
String relationName = "";
Item otherItem = null;
int place = 0;
if (StringUtils.equals(relationshipType.getLeftType().getLabel(), entityType)) {
hashMaps = (HashMap<String, VirtualBean>) 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<String, VirtualBean>) 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,6 +1424,7 @@ 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);
if (metadataValue != null) {
metadataValue = constructResultingMetadataValue(item, value, metadataValue, relationshipId);
metadataValue.setUseForPlace(virtualBean.getUseForPlace());
metadataValue.setPlace(place);
@@ -1428,6 +1433,7 @@ prevent the generation of resource policy entry values with null dspace_object a
}
}
}
}
return resultingMetadataValueList;
}
@@ -1437,10 +1443,13 @@ prevent the generation of resource policy entry values with null dspace_object a
RelationshipMetadataValue metadataValue = constructMetadataValue(context,
MetadataSchemaEnum.RELATION
.getName() + "." + relationName);
if (metadataValue != null) {
metadataValue.setAuthority(Constants.VIRTUAL_AUTHORITY_PREFIX + relationshipId);
metadataValue.setValue(otherItem.getID().toString());
return metadataValue;
}
return null;
}
private String getEntityTypeStringFromMetadata(List<MetadataValue> list) {
String entityType = null;

View File

@@ -22,13 +22,13 @@ public class VirtualMetadataPopulator {
/**
* The map that holds this representation
*/
private Map map;
private Map<String, HashMap<String, VirtualBean>> 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<String, HashMap<String, VirtualBean>> 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<String, HashMap<String, VirtualBean>> getMap() {
return map;
}
public boolean isUseForPlaceTrueForRelationshipType(RelationshipType relationshipType, boolean isLeft) {
HashMap<String, VirtualBean> hashMaps = new HashMap<>();
HashMap<String, VirtualBean> hashMaps;
if (isLeft) {
hashMaps = (HashMap<String, VirtualBean>) this
.getMap().get(relationshipType.getLeftLabel());
hashMaps = this.getMap().get(relationshipType.getLeftLabel());
} else {
hashMaps = (HashMap<String, VirtualBean>) this
.getMap().get(relationshipType.getRightLabel());
hashMaps = this.getMap().get(relationshipType.getRightLabel());
}
if (hashMaps != null) {
for (Map.Entry<String, VirtualBean> entry : hashMaps.entrySet()) {