]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5133: Adding mock additional display names to list result for partial term...
authorRichard Millet <remillet@berkeley.edu>
Tue, 15 May 2012 23:24:37 +0000 (16:24 -0700)
committerRichard Millet <remillet@berkeley.edu>
Tue, 15 May 2012 23:24:37 +0000 (16:24 -0700)
Signed-off-by: Richard Millet <remillet@berkeley.edu>
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/CommonList.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java

index dc72d97a67d5ea6ac8c8ab84f77c8d8076249647..738ba114fb87d3585f9df6d1bb0011173a89bebc 100644 (file)
 package org.collectionspace.services.common.vocabulary.nuxeo;
 
 import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PayloadInputPart;
 import org.collectionspace.services.client.PayloadOutputPart;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.RelationClient;
 import org.collectionspace.services.common.ResourceBase;
-import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.api.CommonAPI;
 import org.collectionspace.services.common.api.RefName;
 import org.collectionspace.services.common.api.Tools;
@@ -41,17 +41,16 @@ import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.DocumentWrapperImpl;
 import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.repository.RepositoryClient;
-import org.collectionspace.services.common.repository.RepositoryClientFactory;
 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
 import org.collectionspace.services.config.service.ListResultField;
 import org.collectionspace.services.config.service.ObjectPartType;
+import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.collectionspace.services.nuxeo.client.java.CommonList; //FIXME: REM - 5/15/2012 - CommonList should be moved out of this package and into a more "common" package
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.relation.RelationResource;
@@ -60,27 +59,25 @@ import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationsDocListItem;
 import org.collectionspace.services.relation.RelationshipType;
 import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema;
+
 import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.model.PropertyException;
-import org.nuxeo.ecm.core.api.model.PropertyNotFoundException;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
-import org.nuxeo.runtime.transaction.TransactionHelper;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.ws.rs.PathParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 
 //import org.collectionspace.services.common.authority.AuthorityItemRelations;
 /**
@@ -173,6 +170,10 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         return result;
     }    
     
+    private boolean isTermDisplayName(String elName) {
+       return AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName);
+    }
+    
     @Override
     public List<ListResultField> getListItemsArray() throws DocumentException {
         List<ListResultField> list = super.getListItemsArray();
@@ -187,7 +188,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         for (int i = 0; i < nFields; i++) {
             ListResultField field = list.get(i);
             String elName = field.getElement();
-            if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || VocabularyItemJAXBSchema.DISPLAY_NAME.equals(elName)) {
+            if (isTermDisplayName(elName) == true) {
                 hasDisplayName = true;
             } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
                 hasShortId = true;
@@ -218,11 +219,10 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             field = getListResultsTermStatusField();
             list.add(field);
         }
-        
+                
         return list;
     }
-
-
+    
     /* (non-Javadoc)
      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
      */
@@ -474,8 +474,6 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     }
 
 
-
-
     /* (non-Javadoc)
      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
      */
@@ -515,6 +513,29 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         }
     }
 
+    @Override
+       protected Object getXPathValue(DocumentModel docModel, // REM - CSPACE-5133
+                       String schema, ListResultField field) {
+               Object result = null;
+
+               result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
+               String elName = field.getElement();
+               if (isTermDisplayName(elName) == true) {
+                       MultivaluedMap<String, String> queryParams = this.getServiceContext().getQueryParams();
+               String partialTerm = queryParams != null ? queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM) : null;
+               if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
+                       List<String> strList = new ArrayList<String>();
+                       strList.add((String)result);
+                       strList.add("Tiny");
+                       strList.add("Tucker");
+                       strList.add("Tim");
+                       result = strList;
+               }
+               }
+               
+               return result;
+       }
+    
     @Override
     public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
         MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
index fde044675a1de59820db65f468ef0023753de419..17bbcf838fb932b88260071726fc2b79c63ff773 100644 (file)
@@ -233,6 +233,7 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      */
     public TL extractCommonPartList(DocumentWrapper<WTL> docWrap) throws Exception;
     
+
     /**
      * Extract paging info.
      *
index 7e0dfc17202ba74a856bec59aea0e41f3b233266..7c944507011fb4be0aae43e6b2342ba97832c3b5 100644 (file)
@@ -200,9 +200,9 @@ public class NuxeoImageUtils {
                return uri + result + "/" + BlobInput.URI_CONTENT_PATH;\r
        }\r
 \r
-       static private HashMap<String, String> createBlobListItem(Blob blob,\r
+       static private HashMap<String, Object> createBlobListItem(Blob blob,\r
                        String uri) {\r
-               HashMap<String, String> item = new HashMap<String, String>();\r
+               HashMap<String, Object> item = new HashMap<String, Object>();\r
 \r
                String value = blob.getEncoding();\r
                if (value != null && !value.trim().isEmpty()) {\r
@@ -248,7 +248,7 @@ public class NuxeoImageUtils {
                                .getAdapter(BlobHolder.class);\r
                List<Blob> docBlobs = docBlobHolder.getBlobs();\r
                // List<BlobListItem> blobListItems = result.getBlobListItem();\r
-               HashMap<String, String> item = null;\r
+               HashMap<String, Object> item = null;\r
                for (Blob blob : docBlobs) {\r
                        item = createBlobListItem(blob, uri);\r
                        commonList.addItem(item);\r
index e13c0f33df3391d2028aa195256359190e5031a6..df6bfbfa3cf670b6bdcb6e4e06324c3041fa2726 100644 (file)
@@ -34,6 +34,9 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.jvnet.jaxb2_commons.lang.ToString;\r
 import javax.xml.parsers.DocumentBuilder;\r
 import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 import org.w3c.dom.Document;\r
 import org.w3c.dom.Element;\r
 \r
@@ -45,8 +48,7 @@ import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;\r
 import javax.xml.bind.annotation.XmlSeeAlso;\r
 \r
-//import org.slf4j.Logger;\r
-//import org.slf4j.LoggerFactory;\r
+import org.slf4j.LoggerFactory;\r
 \r
 /**\r
  * This class allows us to generically represent and marshall a set of list\r
@@ -66,7 +68,7 @@ import javax.xml.bind.annotation.XmlSeeAlso;
 public class CommonList extends AbstractCommonList {\r
        \r
        /** The logger. */\r
-       //private final Logger logger = LoggerFactory.getLogger(this.getClass());\r
+       private final Logger logger = LoggerFactory.getLogger(CommonList.class);\r
        @XmlTransient\r
        private DocumentBuilderFactory factory;\r
        @XmlTransient\r
@@ -129,6 +131,27 @@ public class CommonList extends AbstractCommonList {
                }\r
                return implodedString;\r
        }\r
+               \r
+       private void addItem(List<Element> anyList, String key, Object value) {\r
+               if (value != null ) {\r
+                       Element el = doc.createElement(key);\r
+                       if (value instanceof String) {\r
+                               el.setTextContent((String)value);\r
+                               anyList.add(el);\r
+                       } else if (value instanceof List<?>) {\r
+                               List<String> valueList = (List<String>)value;\r
+                               for (String val : valueList) {\r
+                                       addItem(anyList, key, val);\r
+                               }\r
+                       } else {\r
+                               logger.error("Unknown value type found while processing common list results: "\r
+                                               + value.getClass().getCanonicalName());\r
+                       }\r
+               } else {\r
+                       logger.trace("Null value encountered while processing common list results for key: "\r
+                                       + key);\r
+               }\r
+       }\r
        \r
        /**\r
         * Adds an item to the results list. Each item should have fields\r
@@ -138,18 +161,19 @@ public class CommonList extends AbstractCommonList {
         * @param itemInfo\r
         * @throws RuntimeException if this is called before fieldKeys has been set.\r
         */\r
-       public void addItem(HashMap<String,String> itemInfo) {\r
-               if(fieldKeys==null) {\r
-                       throw new RuntimeException("CommonList.addItem: Cannot add items before fieldKeys are set.");\r
+       public void addItem(HashMap<String, Object> itemInfo) {\r
+               if (fieldKeys == null) {\r
+                       throw new RuntimeException(\r
+                                       "CommonList.addItem: Cannot add items before fieldKeys are set.");\r
                }\r
                List<AbstractCommonList.ListItem> itemsList = getListItem();\r
                AbstractCommonList.ListItem listItem = new AbstractCommonList.ListItem();\r
                itemsList.add(listItem);\r
+               \r
                List<Element> anyList = listItem.getAny();\r
-               for(String key:fieldKeys) {\r
-                       Element el = doc.createElement(key);\r
-                       el.setTextContent(itemInfo.get(key));\r
-                       anyList.add(el);\r
+               for (String key : fieldKeys) {\r
+                       Object value = itemInfo.get(key);\r
+                       addItem(anyList, key, value);\r
                }\r
        }\r
 \r
index 34f7646aa59bdd0ab171651a5db4ce6a526df586..8fb3c9e02a714483af13ad38fbc3f8536d775b31 100644 (file)
@@ -193,31 +193,39 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
                ListResultField field = resultsFields.get(i - NUM_STANDARD_LIST_RESULT_FIELDS); \r
                fields[i] = field.getElement();\r
         }\r
-        commonList.setFieldsReturned(fields);\r
-        Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();\r
-               HashMap<String,String> item = new HashMap<String,String>();\r
-        while(iter.hasNext()){\r
-            DocumentModel docModel = iter.next();\r
-            String id = NuxeoUtils.getCsid(docModel);\r
-            item.put(STANDARD_LIST_CSID_FIELD, id);\r
-            String uri = getUri(docModel);\r
-            item.put(STANDARD_LIST_URI_FIELD, uri);\r
-            item.put(STANDARD_LIST_UPDATED_AT_FIELD, getUpdatedAtAsString(docModel));\r
-            item.put(STANDARD_LIST_WORKFLOW_FIELD, docModel.getCurrentLifeCycleState());\r
-\r
-            for (ListResultField field : resultsFields ){\r
-               String schema = field.getSchema();\r
-               if(schema==null || schema.trim().isEmpty())\r
-                       schema = commonSchema;\r
-                String value = \r
-                       getXPathStringValue(docModel, schema, field.getXpath());\r
-                if(value!=null && !value.trim().isEmpty()) {\r
-                       item.put(field.getElement(), value);\r
-                }\r
-            }\r
-            commonList.addItem(item);\r
-            item.clear();\r
-        }\r
+               commonList.setFieldsReturned(fields);\r
+               Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();\r
+               HashMap<String, Object> item = new HashMap<String, Object>();\r
+               while (iter.hasNext()) {\r
+                       DocumentModel docModel = iter.next();\r
+                       String id = NuxeoUtils.getCsid(docModel);\r
+                       item.put(STANDARD_LIST_CSID_FIELD, id);\r
+                       String uri = getUri(docModel);\r
+                       item.put(STANDARD_LIST_URI_FIELD, uri);\r
+                       item.put(STANDARD_LIST_UPDATED_AT_FIELD,\r
+                                       getUpdatedAtAsString(docModel));\r
+                       item.put(STANDARD_LIST_WORKFLOW_FIELD,\r
+                                       docModel.getCurrentLifeCycleState());\r
+\r
+                       for (ListResultField field : resultsFields) {\r
+                               String schema = field.getSchema();\r
+                               if (schema == null || schema.trim().isEmpty()) {\r
+                                       schema = commonSchema;\r
+                               }\r
+                               Object value = getXPathValue(docModel, schema, field);\r
+                               if (value != null && value instanceof String) {\r
+                                       String strValue = (String) value;\r
+                                       if (strValue.trim().isEmpty() == true) {\r
+                                               value = null;\r
+                                       }\r
+                               }\r
+                               if (value != null) {\r
+                                       item.put(field.getElement(), value);\r
+                               }\r
+                       }\r
+                       commonList.addItem(item);\r
+                       item.clear();\r
+               }\r
 \r
         return commonList;\r
     }\r
@@ -271,7 +279,7 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
                            String xpath)\r
                            throws Exception {\r
         //Object prop = docModel.getProperty(label, elementName);\r
-        String value = getXPathStringValue(docModel, schema, xpath);\r
+        String value = (String)NuxeoUtils.getXPathValue(docModel, schema, xpath);\r
         return ReflectionMapper.callSetter(listItem, setterName, value);\r
     }\r
 \r
index c424b2ee95bf902f70fccb2c0edbee789091bbbb..d7b189fb6d75606f8b41c07f48163c3e0f9eed6c 100644 (file)
@@ -59,6 +59,8 @@ import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
 import org.collectionspace.services.common.vocabulary.RefNameUtils;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;
+import org.collectionspace.services.config.service.InitHandler.Params.Field;
+import org.collectionspace.services.config.service.ListResultField;
 import org.collectionspace.services.config.service.ObjectPartType;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.dom4j.Element;
@@ -711,52 +713,12 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
      * @param xpath The XPath expression (without schema prefix)
      * @return value the indicated property value as a String
      */
-       protected static String getXPathStringValue(DocumentModel docModel,
-                       String schema, String xpath) {
-               String result = null;
-
-               xpath = schema + ":" + xpath;
-               try {
-                       Object value = docModel.getPropertyValue(xpath);
-                       String returnVal = null;
-                       if (value == null) {
-                               // Nothing to do - leave returnVal null
-                       } else if (value instanceof GregorianCalendar) {
-                               returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar) value);
-                       } else {
-                               returnVal = value.toString();
-                       }
-                       result = returnVal;
-               } catch (PropertyException pe) {
-                       throw new RuntimeException("Problem retrieving property {" + xpath
-                                       + "}. Bad XPath spec?" + pe.getLocalizedMessage());
-               } catch (ClassCastException cce) {
-                       throw new RuntimeException("Problem retrieving property {" + xpath
-                                       + "} as String. Not a String property?"
-                                       + cce.getLocalizedMessage());
-               } catch (IndexOutOfBoundsException ioobe) {
-                       // Nuxeo seems to handle foo/[0]/bar when it is missing,
-                       // but not foo/bar[0] (for repeating scalars).
-                       if (xpath.endsWith("[0]")) { // gracefully handle missing elements
-                               result = "";
-                       } else {
-                               String msg = ioobe.getMessage();
-                               if (msg != null && msg.equals("Index: 0, Size: 0")) {
-                                       // Some other variant on a missing sub-field; quietly
-                                       // absorb.
-                                       result = "";
-                               }
-                       }
-                       // Otherwise, e.g., for true OOB indices, propagate the exception.
-                       if (result == null) {
-                               throw new RuntimeException("Problem retrieving property {" + xpath
-                                               + "}:" + ioobe.getLocalizedMessage());
-                       }
-               } catch (Exception e) {
-                       throw new RuntimeException("Unknown problem retrieving property {"
-                                       + xpath + "}." + e.getLocalizedMessage());
-               }
+       protected Object getXPathValue(DocumentModel docModel, // REM - CSPACE-5133
+                       String schema, ListResultField field) {
+               Object result = null;
 
+               result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
+               
                return result;
        }
    
index 75c42bda8424c4c05a6e02842ce46f3c4441df6b..836672215e20f9634cd5956f8e558be5af47e322 100644 (file)
@@ -22,9 +22,8 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.File;
 
-import java.io.Serializable;
+import java.util.GregorianCalendar;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.regex.Matcher;
@@ -37,11 +36,10 @@ import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
 import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.datetime.DateTimeFormatUtils;
 import org.collectionspace.services.common.document.DocumentException;
-import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.DocumentWrapperImpl;
 import org.collectionspace.services.common.query.QueryContext;
+import org.collectionspace.services.config.service.ListResultField;
 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 
 import org.dom4j.Document;
@@ -55,12 +53,10 @@ import org.nuxeo.ecm.core.api.CoreSession;
 import org.nuxeo.ecm.core.api.DocumentRef;
 import org.nuxeo.ecm.core.api.IdRef;
 import org.nuxeo.ecm.core.api.PathRef;
-import org.nuxeo.ecm.core.api.IterableQueryResult;
-import org.nuxeo.ecm.core.api.model.DocumentPart;
+import org.nuxeo.ecm.core.api.model.PropertyException;
 
 import org.nuxeo.ecm.core.io.DocumentPipe;
 import org.nuxeo.ecm.core.io.DocumentReader;
-import org.nuxeo.ecm.core.io.impl.plugins.DocumentTreeReader;
 import org.nuxeo.ecm.core.io.DocumentWriter;
 import org.nuxeo.ecm.core.io.impl.DocumentPipeImpl;
 import org.nuxeo.ecm.core.io.impl.plugins.SingleDocumentReader;
@@ -68,8 +64,6 @@ import org.nuxeo.ecm.core.io.impl.plugins.XMLDocumentWriter;
 
 import org.nuxeo.ecm.core.schema.SchemaManager;
 import org.nuxeo.ecm.core.search.api.client.querymodel.descriptor.QueryModelDescriptor;
-import org.nuxeo.ecm.core.storage.sql.jdbc.ResultSetQueryResult;
-import org.nuxeo.ecm.core.query.sql.NXQL;
 import org.nuxeo.runtime.api.Framework;
 
 
@@ -602,6 +596,71 @@ public class NuxeoUtils {
        return result;
     }
     
+    /**
+     * Gets XPath value from schema. Note that only "/" and "[n]" are
+     * supported for xpath. Can omit grouping elements for repeating complex types, 
+     * e.g., "fieldList/[0]" can be used as shorthand for "fieldList/field[0]" and
+     * "fieldGroupList/[0]/field" can be used as shorthand for "fieldGroupList/fieldGroup[0]/field".
+     * If there are no entries for a list of scalars or for a list of complex types, 
+     * a 0 index expression (e.g., "fieldGroupList/[0]/field") will safely return an empty
+     * string. A non-zero index will throw an IndexOutOfBoundsException if there are not
+     * that many elements in the list. 
+     * N.B.: This does not follow the XPath spec - indices are 0-based, not 1-based.
+     *
+     * @param docModel The document model to get info from
+     * @param schema The name of the schema (part)
+     * @param xpath The XPath expression (without schema prefix)
+     * @return value the indicated property value as a String
+     */
+       public static Object getXPathValue(DocumentModel docModel,
+                       String schema, String xpath) {
+               Object result = null;
+
+               xpath = schema + ":" + xpath;
+               try {
+                       Object value = docModel.getPropertyValue(xpath);
+                       String returnVal = null;
+                       if (value == null) {
+                               // Nothing to do - leave returnVal null
+                       } else if (value instanceof GregorianCalendar) {
+                               returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar) value);
+                       } else {
+                               returnVal = value.toString();
+                       }
+                       result = returnVal;
+               } catch (PropertyException pe) {
+                       throw new RuntimeException("Problem retrieving property {" + xpath
+                                       + "}. Bad XPath spec?" + pe.getLocalizedMessage());
+               } catch (ClassCastException cce) {
+                       throw new RuntimeException("Problem retrieving property {" + xpath
+                                       + "} as String. Not a String property?"
+                                       + cce.getLocalizedMessage());
+               } catch (IndexOutOfBoundsException ioobe) {
+                       // Nuxeo seems to handle foo/[0]/bar when it is missing,
+                       // but not foo/bar[0] (for repeating scalars).
+                       if (xpath.endsWith("[0]")) { // gracefully handle missing elements
+                               result = "";
+                       } else {
+                               String msg = ioobe.getMessage();
+                               if (msg != null && msg.equals("Index: 0, Size: 0")) {
+                                       // Some other variant on a missing sub-field; quietly
+                                       // absorb.
+                                       result = "";
+                               }
+                       }
+                       // Otherwise, e.g., for true OOB indices, propagate the exception.
+                       if (result == null) {
+                               throw new RuntimeException("Problem retrieving property {" + xpath
+                                               + "}:" + ioobe.getLocalizedMessage());
+                       }
+               } catch (Exception e) {
+                       throw new RuntimeException("Unknown problem retrieving property {"
+                                       + xpath + "}." + e.getLocalizedMessage());
+               }
+
+               return result;
+       }
+    
     static public String getPrimaryXPathPropertyName(String schema, String complexPropertyName, String fieldName) {
         if (Tools.isBlank(schema)) {
             return complexPropertyName + "/[0]/" + fieldName;
index 1e26f73a3960383464d1cec437e03423d509e3ce..92169aa25412ba6059313d7b63f9e97e2f33dfca 100644 (file)
@@ -137,7 +137,7 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
                fields[0] = ServiceGroupListItemJAXBSchema.NAME;
                fields[1] = ServiceGroupListItemJAXBSchema.URI;
                commonList.setFieldsReturned(fields);
-                       HashMap<String,String> item = new HashMap<String,String>();
+                       HashMap<String, Object> item = new HashMap<String, Object>();
                for(String groupName:svcGroups){
                    item.put(ServiceGroupListItemJAXBSchema.NAME, groupName);
                    String uri = "/" + getServiceName().toLowerCase() + "/" + groupName;
index cd3eddd311c4e0526d22c08b0b5004ed24d44353..0b7a138d1ce196aa9761061cd51da5ae7908adbf 100644 (file)
@@ -209,7 +209,7 @@ public class ServiceGroupDocumentModelHandler
         fields[6] = DOC_TYPE_FIELD;
         list.setFieldsReturned(fields);
         Iterator<DocumentModel> iter = docList.iterator();
-               HashMap<String,String> item = new HashMap<String,String>();
+               HashMap<String, Object> item = new HashMap<String,String>();
         while (iter.hasNext()) {
             DocumentModel docModel = iter.next();
             String docType = docModel.getDocumentType().getName();