From 29168cda7cda914310f5145a2dc7da507c3ae1da Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 8 Nov 2010 23:11:13 +0000 Subject: [PATCH] CSPACE-2932: Moved utility routine to return primary value from a multivalued list to a base class. --- .../java/RemoteDocumentModelHandlerImpl.java | 39 +++++++++++++++++++ .../OrganizationDocumentModelHandler.java | 35 ----------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index b3019c2cb..83750d475 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -462,4 +462,43 @@ public abstract class RemoteDocumentModelHandlerImpl return ilistItem; } + /** + * Returns the primary value from a list of values. + * + * Assumes that the first value is the primary value. + * This assumption may change when and if the primary value + * is identified explicitly. + * + * @param values a list of values. + * @param propertyName the name of a property through + * which the value can be extracted. + * @return the primary value. + */ + protected String primaryValueFromMultivalue(List values, String propertyName) { + String primaryValue = ""; + if (values == null || values.size() == 0) { + return primaryValue; + } + Object value = values.get(0); + if (value instanceof String) { + if (value != null) { + primaryValue = (String) value; + } + // Multivalue group of fields + } else if (value instanceof Map) { + if (value != null) { + Map map = (Map) value; + if (map.values().size() > 0) { + if (map.get(propertyName) != null) { + primaryValue = (String) map.get(propertyName); + } + } + } + } else { + logger.warn("Unexpected type for property " + propertyName + + " in multivalue list: not String or Map."); + } + return primaryValue; + } + } diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java index 10d70b1bb..5b660abff 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java @@ -187,40 +187,5 @@ public class OrganizationDocumentModelHandler return OrganizationConstants.NUXEO_SCHEMA_NAME + ":" + prop; } - /** - * Returns the primary value from a list of values. - * - * Assumes that the first value is the primary value. - * This assumption may change when and if the primary value - * is identified explicitly. - * - * @param values a list of values. - * @param propertyName the name of a property through - * which the value can be extracted. - * @return the primary value. - */ - private String primaryValueFromMultivalue(List values, String propertyName) { - String primaryValue = ""; - if (values == null || values.size() == 0) { - return primaryValue; - } - Object value = values.get(0); - if (value instanceof String) { - if (value != null) { - primaryValue = (String) value; - } - // Multivalue group of fields - } else if (value instanceof Map) { - if (value != null) { - Map map = (Map) value; - if (map.values().size() > 0) { - if (map.get(propertyName) != null) { - primaryValue = (String) map.get(propertyName); - } - } - } - } - return primaryValue; - } } -- 2.47.3