From 9e6e426eddbb6e699620b4c44fe7c96ec87d8314 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 25 Apr 2013 19:39:38 -0700 Subject: [PATCH] CSPACE-5763: Allow date values to be used in generic name and number properties in summary lists. --- .../common/context/ServiceBindingUtils.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java index 9f1bbc29e..2144f2976 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java @@ -17,6 +17,9 @@ import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import java.lang.IndexOutOfBoundsException; +import java.util.GregorianCalendar; +import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; +import org.collectionspace.services.common.api.Tools; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -176,10 +179,35 @@ public class ServiceBindingUtils { } */ String propName = getPropertyValue(sb, logicalFieldName); - if(propName==null||propName.isEmpty()) - return null; + if(Tools.isBlank(propName)) { + logger.warn("Property name is empty for property " + logicalFieldName + " in service " + sb.getName()); + logger.warn("This may be due to an improperly configured or missing " + + "generic property (objectNameProperty, objectNumberProperty ...) in tenant bindings configuration"); + return ""; + } try { - return (String)docModel.getPropertyValue(propName); + Object obj = docModel.getPropertyValue(propName); + if (obj == null) { + return ""; + } + if (String.class.isAssignableFrom(obj.getClass())) { + return (String)obj; + } else { + // Handle cases where a property value returned from the repository + // can't be directly cast to a String. + // + // FIXME: We may want to create a new utility method to centralize + // our handling of these cases, as similar conversions might currently + // be performed in multiple classes. - ADR 2013-04-25 + if (obj instanceof GregorianCalendar) { + return GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp((GregorianCalendar)obj); + } else { + logger.warn("Could not convert value of property " + propName + + " in path " + docModel.getPathAsString() + " to a String."); + logger.warn("This may be due to a new, as-yet-unhandled datatype returned from the repository"); + return ""; + } + } } catch(IndexOutOfBoundsException ioobe) { // Should not happen, but may with certain array forms if(logger.isTraceEnabled()) { -- 2.47.3