]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6234: Allow values of integer fields to be emitted in list results.
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 4 Oct 2013 01:59:52 +0000 (18:59 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 4 Oct 2013 01:59:52 +0000 (18:59 -0700)
services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java

index aba922d85fe0369876a3e7958af506873d8253f8..dbeb451d0587405d41e940ac6b97944819717f2f 100644 (file)
@@ -882,7 +882,7 @@ public class DocumentUtils {
          * 
          * Note: currently, elements declared as xs:decimal in XSD schemas
          * are handled as the Nuxeo primitive DoubleType.  If this type
-         * changes, the test below should be changed accordingly.
+         * correspondence changes, the test below should be changed accordingly.
          *
          * @param type   a type.
         * @return       true, if is a Nuxeo decimal type;
@@ -920,6 +920,8 @@ public class DocumentUtils {
                     return GregorianCalendarDateTimeUtils.formatAsISO8601Date((GregorianCalendar)obj);
                 } else if (obj instanceof Double) {
                     return nuxeoDecimalValueToDecimalString(obj);
+                } else if (obj instanceof Long) {
+                    return nuxeoLongValueToString(obj);
                 } else if (obj instanceof Boolean) {
                     return String.valueOf(obj);
                 } else {
@@ -935,9 +937,10 @@ public class DocumentUtils {
          * Returns a string representation of the value of a Nuxeo decimal type.
          * 
          * Note: currently, elements declared as xs:decimal in XSD schemas
-         * are handled as the Nuxeo primitive DoubleType, and their values
-         * are convertible into the Java Double type.  If this type
-         * changes, the conversion below should be changed accordingly.
+         * are handled as the Nuxeo primitive DoubleType, and their values are
+         * convertible into the Java Double type.  If this type correspondence
+         * changes, the conversion below should be changed accordingly, as
+         * should any 'instanceof' or similar checks elsewhere in this code.
          *
         * @return  a string representation of the value of a Nuxeo decimal type.
          *     An empty string is returned if the value cannot be cast to the
@@ -967,6 +970,31 @@ public class DocumentUtils {
             }
             return formatter.format(doubleVal.doubleValue());
        }
+        
+        /*
+         * Returns a string representation of the value of a Nuxeo long type.
+         * 
+         * Note: currently, elements declared as xs:integer in XSD schemas
+         * are handled as the Nuxeo primitive LongType, and their values are
+         * convertible into the Java Long type.  If this type correspondence
+         * changes, the conversion below should be changed accordingly, as
+         * should any 'instanceof' or similar checks elsewhere in this code.
+         *
+        * @return  a string representation of the value of a Nuxeo long type.
+         *     An empty string is returned if the value cannot be cast to the
+         *     appropriate type.
+         */
+        private static String nuxeoLongValueToString(Object value) {
+            Long longVal;
+            try {
+                longVal = (Long) value;
+            } catch (ClassCastException cce) {
+                logger.warn("Could not convert a Nuxeo integer value to its string equivalent: "
+                        + cce.getMessage());
+                return "";
+            }
+            return longVal.toString();
+       }
 
         /*
          * Identifies whether a property type is a date type.