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.collectionspace.services.common.document.DocumentUtils;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
}\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
+ return DocumentUtils.propertyValueAsString(obj, docModel, propName);\r
} catch(IndexOutOfBoundsException ioobe) {\r
// Should not happen, but may with certain array forms\r
if(logger.isTraceEnabled()) {\r
import java.text.NumberFormat;
import java.util.ArrayList;
+import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.xml.transform.TransformerException;
import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.datetime.DateTimeFormatUtils;
import org.collectionspace.services.config.service.ObjectPartContentType;
import org.nuxeo.ecm.core.io.ExportConstants;
import org.nuxeo.common.collections.PrimitiveArrays;
+import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.model.Property;
import org.nuxeo.ecm.core.schema.SchemaManager;
import org.nuxeo.ecm.core.schema.TypeConstants;
parent.appendChild(element);
// extract the element content
if (type.isSimpleType()) {
+ // Avoid returning scientific notation representations of
+ // very large or very small decimal values. See CSPACE-4691.
if (isNuxeoDecimalType(type) && valueMatchesNuxeoType(type, value)) {
element.setTextContent(nuxeoDecimalValueToDecimalString(value));
/*
return ((SimpleType)type).getPrimitiveType() instanceof DoubleType;
}
+ /**
+ * Obtains a String representation of a Nuxeo property value, where
+ * the latter is an opaque Object that may or may not be directly
+ * convertible to a string.
+ *
+ * @param obj an Object containing a property value
+ * @param docModel the document model associated with this property.
+ * @param propertyPath a path to the property, such as a property name, XPath, etc.
+ * @return a String representation of the Nuxeo property value.
+ */
+ static public String propertyValueAsString(Object obj, DocumentModel docModel, String propertyPath) {
+ 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: This method provides specific, hard-coded formatting
+ // for String representations of property values. We might want
+ // to add the ability to specify these formats via configuration.
+ // - ADR 2013-04-26
+ if (obj instanceof GregorianCalendar) {
+ return GregorianCalendarDateTimeUtils.formatAsISO8601Date((GregorianCalendar)obj);
+ } else if (obj instanceof Double) {
+ return nuxeoDecimalValueToDecimalString(obj);
+ } else {
+ logger.warn("Could not convert value of property " + propertyPath
+ + " in document " + docModel.getPathAsString() + " to a String.");
+ logger.warn("This may be due to a new, as-yet-unhandled datatype returned from the repository");
+ return "";
+ }
+ }
+ }
+
/*
* Returns a string representation of the value of a Nuxeo decimal type.
*