From 431fbba87f445ef3ea6049ba1992ad857ca6799b Mon Sep 17 00:00:00 2001 From: Ray Lee Date: Tue, 6 Oct 2020 15:08:38 -0400 Subject: [PATCH] DRYD-897: Add null check to getPropertyValuesByName. --- .../common/config/PropertyItemUtils.java | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java b/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java index d765959e8..cf93b2db5 100644 --- a/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java +++ b/services/config/src/main/java/org/collectionspace/services/common/config/PropertyItemUtils.java @@ -20,7 +20,7 @@ public class PropertyItemUtils { } return getPropertyValueByName(propNodeList.get(0).getItem(), propName); } - + public static List getPropertyValueListByNameFromNodeList(List propNodeList, String propName) { if (propNodeList == null || propNodeList.isEmpty()) { @@ -36,7 +36,7 @@ public class PropertyItemUtils { return result; } - + /** * @param propList the list of properties. * @param propName the property to fetch @@ -54,7 +54,7 @@ public class PropertyItemUtils { } return null; } - + /** * @param propNodeList the JAXB wrapping node of for the list to search for the named property * @param propName the name of the property of interest @@ -65,7 +65,7 @@ public class PropertyItemUtils { List propNodeList, String propName, String qualPrefix) { return getPropertyValuesByNameInNodeList(propNodeList, propName, qualPrefix, null); } - + /** * @param propNodeList the JAXB wrapping node of for the list to search for the named property * @param propName the name of the property of interest @@ -81,10 +81,10 @@ public class PropertyItemUtils { values = new ArrayList(); return values; } - return getPropertyValuesByName(propNodeList.get(0).getItem(), + return getPropertyValuesByName(propNodeList.get(0).getItem(), propName, qualPrefix, values); } - + /** * @param propNodeList the Item list to search for the named property * @param propName the name of the property of interest @@ -95,30 +95,37 @@ public class PropertyItemUtils { List propItems, String propName, String qualPrefix) { return getPropertyValuesByName(propItems, propName, qualPrefix, null); } - - /** - * @param propNodeList the Item list to search for the named property - * @param propName the name of the property of interest - * @param qualPrefix a namespace qualifier prefix (with ':') to prepend, or null - * @param values and existing list to append values to. If null, a new one will be created. - * @return values, or that is null, a new List of string values found for the named property - */ - public static List getPropertyValuesByName( - List propItems, String propName, String qualPrefix, - List values ) { - if(values==null) - values = new ArrayList(); - for(PropertyItemType propItem:propItems) { - if(propName.equals(propItem.getKey())) { - // TODO - the trim() belongs here, not down a few lines. - String value = propItem.getValue(); - if(value!=null) { - values.add((qualPrefix!=null)?(qualPrefix+value):value.trim()); - } - } - } - return values; - } + + /** + * @param propNodeList the Item list to search for the named property + * @param propName the name of the property of interest + * @param qualPrefix a namespace qualifier prefix (with ':') to prepend, or null + * @param values and existing list to append values to. If null, a new one will be created. + * @return values, or that is null, a new List of string values found for the named property + */ + public static List getPropertyValuesByName( + List propItems, String propName, String qualPrefix, + List values ) { + + if (values == null) { + values = new ArrayList(); + } + + if (propItems != null) { + for (PropertyItemType propItem : propItems) { + if (propName.equals(propItem.getKey())) { + // TODO - the trim() belongs here, not down a few lines. + String value = propItem.getValue(); + + if (value != null) { + values.add((qualPrefix != null) ? (qualPrefix + value) : value.trim()); + } + } + } + } + + return values; + } /** * @param propNodeList the wrapping list node from JAXB @@ -136,7 +143,7 @@ public class PropertyItemUtils { List propList = propNodeList.get(0).getItem(); return setPropertyValue(propList, propName, value, onlyIfNotSet); } - + /** * @param propName the property to set * @param value the new value to set @@ -171,5 +178,5 @@ public class PropertyItemUtils { } return valueSet; } - + } -- 2.47.3