]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5763: Allow date values to be used in generic name and number properties in...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 26 Apr 2013 02:39:38 +0000 (19:39 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 26 Apr 2013 02:39:38 +0000 (19:39 -0700)
services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java

index 9f1bbc29e64f44c21f3e27ef40671d2c869ac0f6..2144f2976054312c9212045c31ecf83b00d2bb59 100644 (file)
@@ -17,6 +17,9 @@ import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.ClientException;\r
 import org.nuxeo.ecm.core.api.DocumentModel;\r
 import java.lang.IndexOutOfBoundsException;\r
+import java.util.GregorianCalendar;\r
+import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;\r
+import org.collectionspace.services.common.api.Tools;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
@@ -176,10 +179,35 @@ public class ServiceBindingUtils {
        }\r
        */\r
        String propName = getPropertyValue(sb, logicalFieldName);\r
-       if(propName==null||propName.isEmpty())\r
-               return null;\r
+       if(Tools.isBlank(propName)) {\r
+                logger.warn("Property name is empty for property " + logicalFieldName + " in service " + sb.getName());\r
+                logger.warn("This may be due to an improperly configured or missing "\r
+                        + "generic property (objectNameProperty, objectNumberProperty ...) in tenant bindings configuration");\r
+               return "";\r
+        }\r
        try {\r
-               return (String)docModel.getPropertyValue(propName);\r
+            Object obj = docModel.getPropertyValue(propName);\r
+            if (obj == null) {\r
+                return "";\r
+            }\r
+            if (String.class.isAssignableFrom(obj.getClass())) {\r
+                return (String)obj;\r
+            } else {\r
+                // Handle cases where a property value returned from the repository\r
+                // can't be directly cast to a String.\r
+                //\r
+                // FIXME: We may want to create a new utility method to centralize\r
+                // our handling of these cases, as similar conversions might currently\r
+                // be performed in multiple classes. - ADR 2013-04-25\r
+                if (obj instanceof GregorianCalendar) {\r
+                    return GregorianCalendarDateTimeUtils.formatAsISO8601Timestamp((GregorianCalendar)obj);\r
+                } else {\r
+                    logger.warn("Could not convert value of property " + propName\r
+                            + " in path " + docModel.getPathAsString() + " to a String.");\r
+                    logger.warn("This may be due to a new, as-yet-unhandled datatype returned from the repository");\r
+                   return "";\r
+                }\r
+            }\r
        } catch(IndexOutOfBoundsException ioobe) {\r
                                // Should not happen, but may with certain array forms\r
                                if(logger.isTraceEnabled()) {\r