]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6375: Merged with branch that included changes for Nuxeo 6 and Tomcat 7 upgrades.
authorremillet <remillet@yahoo.com>
Wed, 15 Apr 2015 19:43:55 +0000 (12:43 -0700)
committerremillet <remillet@yahoo.com>
Wed, 15 Apr 2015 19:43:55 +0000 (12:43 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.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/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java

index 506f1f12d6a3696a9667f26179b6dbbcd419a8f1..075c15624d515f3973c88cf26396c4ee722b9721 100644 (file)
@@ -485,7 +485,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                try {
                        DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, itemcsid);
                        DocumentModel docModel = wrapper.getWrappedObject();
-                       String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
+                       String refName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.REF_NAME); //docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
                 authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(
                                repoSession, ctx, uriTemplateRegistry, repoClient,
                         serviceTypes,
index ce825c5a0cf1261dc712e767d470e3db61266fea..9f2aa7ae0b326de1a665b88e0930f586b5633146 100644 (file)
@@ -32,6 +32,7 @@ import org.collectionspace.services.jaxb.InvocableJAXBSchema;
 import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.batch.BatchCommon;
 import org.collectionspace.services.batch.BatchInvocable;
 import org.collectionspace.services.client.PoxPayloadIn;
@@ -45,12 +46,9 @@ import org.collectionspace.services.common.invocable.Invocable;
 import org.collectionspace.services.common.invocable.InvocationContext;
 import org.collectionspace.services.common.invocable.InvocationResults;
 import org.collectionspace.services.common.invocable.Invocable.InvocationError;
-
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
-
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.model.PropertyException;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -93,19 +91,19 @@ public class BatchDocumentModelHandler extends NuxeoDocumentModelHandler<BatchCo
                try {
                        DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, csid);
                        DocumentModel docModel = wrapper.getWrappedObject();
-                       Boolean supports = (Boolean) docModel.getPropertyValue(modeProperty);
+                       Boolean supports = (Boolean) NuxeoUtils.getProperyValue(docModel, modeProperty);
                        if (!supports) {
                                throw new BadRequestException("BatchResource: This Batch Job does not support Invocation Mode: "
                                                + invocationMode);
                        }
                        if (checkDocType) {
-                               List<String> forDocTypeList = (List<String>) docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPES);
+                               List<String> forDocTypeList = (List<String>) NuxeoUtils.getProperyValue(docModel, BatchJAXBSchema.FOR_DOC_TYPES); //docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPES);
                                if (forDocTypeList == null || !forDocTypeList.contains(invContext.getDocType())) {
                                        throw new BadRequestException("BatchResource: Invoked with unsupported document type: "
                                                        + invContext.getDocType());
                                }
                        }
-                       className = (String) docModel.getPropertyValue(BatchJAXBSchema.BATCH_CLASS_NAME);
+                       className = (String) NuxeoUtils.getProperyValue(docModel, BatchJAXBSchema.BATCH_CLASS_NAME); //docModel.getPropertyValue(BatchJAXBSchema.BATCH_CLASS_NAME);
                } catch (PropertyException pe) {
                        if (logger.isDebugEnabled()) {
                                logger.debug("Property exception getting batch values: ", pe);
index 9c5be602b6050244773743a888d4a142c38112be..69c134c83aaca7b69eb312aca3bee539ed923984 100644 (file)
@@ -169,6 +169,7 @@ public class ServiceBindingUtils {
                String logicalFieldName, DocumentModel docModel ) {
        // Now we have to get the number, which is configured as some field
        // on each docType
+       
        /* If we go to qualified field names, we'll need this
        String[] strings = qPropName.split(":");
        if(strings.length!=2) {
@@ -177,28 +178,37 @@ public class ServiceBindingUtils {
                                +logicalFieldName+" field for: "+docModel.getDocumentType().getName());
        }
        */
+       
        String propName = getPropertyValue(sb, logicalFieldName);
-       if(Tools.isBlank(propName)) {
+       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 {
-            Object obj = docModel.getPropertyValue(propName);
-            return DocumentUtils.propertyValueAsString(obj, docModel, propName);
-       } catch(IndexOutOfBoundsException ioobe) {
-                               // Should not happen, but may with certain array forms
-                               if(logger.isTraceEnabled()) {
-                                       logger.trace("SBUtils.getMappedField caught OOB exc, for Prop: "+propName
-                                               + " in: " + docModel.getDocumentType().getName()
-                                               + " csid: " + NuxeoUtils.getCsid(docModel));
-                               }
-                               return null;
-       } catch(ClientException ce) {
-               throw new RuntimeException(
-                               "getMappedFieldInDoc: Problem fetching: "+propName+" logicalfieldName: "+logicalFieldName+" docModel: "+docModel, ce);
-       }
+       //
+       // Try to get a value from the Nuxeo document for the property name.
+       //
+       String result = null;
+               try {
+                       Object obj = NuxeoUtils.getProperyValue(docModel, propName);
+                       result = DocumentUtils.propertyValueAsString(obj, docModel, propName);
+               } catch (IndexOutOfBoundsException ioobe) {
+                       // Should not happen, but may with certain array forms
+                       logger.trace("SBUtils.getMappedField caught OOB exc, for Prop: "
+                                       + propName + " in: " + docModel.getDocumentType().getName()
+                                       + " csid: " + NuxeoUtils.getCsid(docModel));
+               } catch (ClientException ce) {
+                       throw new RuntimeException(
+                                       "getMappedFieldInDoc: Problem fetching: " + propName
+                                                       + " logicalfieldName: " + logicalFieldName
+                                                       + " docModel CSID: " + docModel.getName(), ce);
+               } catch (Exception e) {
+                       logger.warn(String.format("Could not get a value for the property '%s' in Nuxeo document with CSID '%s'.",
+                                       propName, docModel.getName()));
+               }
+       
+       return result;
     } 
     
     private static ArrayList<String> commonProcedureServiceTypes = null;
index 50f0ad31192761d9984d03f5a9cc2f853cb87943..74be6d1cd66f803af86539d086a9c9245e6afd7f 100644 (file)
@@ -704,7 +704,7 @@ public class RefNameServiceUtils {
                         uri = template.buildUri(additionalValues);
                     } else if (template.getUriTemplateType() == UriTemplateFactory.ITEM) {
                         try {
-                            String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
+                            String inAuthorityCsid = (String) NuxeoUtils.getProperyValue(docModel, "inAuthority"); //docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
                             additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);
                             additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid);
                             uri = template.buildUri(additionalValues);
index 68389c8249457afe216ff9a665fb2518d852090c..6f81c24a6e163ccc1366acf61c3def2f4e5d278c 100644 (file)
@@ -756,7 +756,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
     protected String getSimpleStringProperty(DocumentModel docModel, String schema, String propName) {
        String xpath = "/"+schema+":"+propName;
        try {
-               return (String)docModel.getPropertyValue(xpath);
+               return (String) NuxeoUtils.getProperyValue(docModel, xpath); //docModel.getPropertyValue(xpath);
        } catch(PropertyException pe) {
                throw new RuntimeException("Problem retrieving property {"+xpath+"}. Not a simple String property?"
                                +pe.getLocalizedMessage());
@@ -777,27 +777,27 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
      * @param listName The name of the scalar list property
      * @return first value in list, as a String, or empty string if the list is empty
      */
-    protected String getFirstRepeatingStringProperty(
-               DocumentModel docModel, String schema, String listName) {
-       String xpath = "/"+schema+":"+listName+"/[0]";
-       try {
-               return (String)docModel.getPropertyValue(xpath);
-       } catch(PropertyException pe) {
-               throw new RuntimeException("Problem retrieving property {"+xpath+"}. Not a repeating scalar?"
-                               +pe.getLocalizedMessage());
-       } catch(IndexOutOfBoundsException ioobe) {
-               // Nuxeo sometimes handles missing sub, and sometimes does not. Odd.
-               return "";      // gracefully handle missing elements
-       } catch(ClassCastException cce) {
-               throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a repeating String property?"
-                               +cce.getLocalizedMessage());
-       } catch(Exception e) {
-               throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
-                               +e.getLocalizedMessage());
-       }
-    }
+       protected String getFirstRepeatingStringProperty(DocumentModel docModel,
+                       String schema, String listName) {
+               String xpath = "/" + schema + ":" + listName + "/[0]";
+               try {
+                       return (String) NuxeoUtils.getProperyValue(docModel, xpath); // docModel.getPropertyValue(xpath);
+               } catch (PropertyException pe) {
+                       throw new RuntimeException("Problem retrieving property {" + xpath
+                                       + "}. Not a repeating scalar?" + pe.getLocalizedMessage());
+               } catch (IndexOutOfBoundsException ioobe) {
+                       // Nuxeo sometimes handles missing sub, and sometimes does not. Odd.
+                       return ""; // gracefully handle missing elements
+               } catch (ClassCastException cce) {
+                       throw new RuntimeException("Problem retrieving property {" + xpath
+                                       + "} as String. Not a repeating String property?"
+                                       + cce.getLocalizedMessage());
+               } catch (Exception e) {
+                       throw new RuntimeException("Unknown problem retrieving property {"
+                                       + xpath + "}." + e.getLocalizedMessage());
+               }
+       }
    
-
     /**
      * Gets first of a repeating list of scalar values, as a String, from the document.
      *
@@ -812,7 +812,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
        
        String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName);
        try {
-               result = (String)docModel.getPropertyValue(xpath);
+               result = (String) NuxeoUtils.getProperyValue(docModel, xpath); //docModel.getPropertyValue(xpath);
        } catch(PropertyException pe) {
                throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad propertyNames?"
                                +pe.getLocalizedMessage());
index 2b4cf2aa07c8d703126a2153781805ab117485f1..15da22d1c5279ccca0d13d3132634b4987130604 100644 (file)
@@ -730,6 +730,27 @@ public class NuxeoUtils {
        return result;
     }
     
+    /*
+     * Returns the property value for an instance of a DocumentModel.  If there is no value for the
+     * property, we'll return null.
+     * 
+     * Beginning in Nuxeo 6, if a DocumentModel has no value for the property, we get a NPE when calling
+     * the DocumentModel.getPropertyValue method.  This method catches that NPE and instead returns null.
+     */
+    public static Object getProperyValue(DocumentModel docModel,
+               String propertyName) throws ClientException, PropertyException {
+       Object result = null;
+       
+       try {
+               result = docModel.getPropertyValue(propertyName);
+       } catch (NullPointerException npe) {
+                       logger.warn(String.format("Could not get a value for the property '%s' in Nuxeo document with CSID '%s'.",
+                                       propertyName, docModel.getName()));
+       }
+       
+       return result;
+    }
+    
     /**
      * Gets XPath value from schema. Note that only "/" and "[n]" are
      * supported for xpath. Can omit grouping elements for repeating complex types, 
@@ -750,20 +771,22 @@ public class NuxeoUtils {
                        String schema, String xpath) throws NuxeoDocumentException {
                Object result = null;
 
+               String targetCSID = null;
                xpath = schema + ":" + xpath;
                try {
                        Object value = docModel.getPropertyValue(xpath);
+                       targetCSID = docModel.getName();
                        String returnVal = null;
                        if (value == null) {
-                           // Nothing to do - leave returnVal null
+                               // Nothing to do - leave returnVal null
                        } else {
-                            returnVal = DocumentUtils.propertyValueAsString(value, docModel, xpath);
+                               returnVal = DocumentUtils.propertyValueAsString(value, docModel, xpath);
                        }
                        result = returnVal;
                } catch (ClientException ce) {
                        String msg = "Unknown Nuxeo client exception.";
                        if (ce instanceof PropertyException) {
-                               msg = "Problem retrieving property {" + xpath + "}. Bad XPath spec?" + ce.getLocalizedMessage();
+                               msg = String.format("Problem retrieving property for xpath { %s } with CSID = %s.", xpath, targetCSID);
                        }
                        throw new NuxeoDocumentException(msg, ce);  // We need to wrap this exception in order to retry failed requests caused by network errors
                } catch (ClassCastException cce) {
@@ -789,8 +812,8 @@ public class NuxeoUtils {
                                                + "}:" + ioobe.getLocalizedMessage());
                        }
                } catch (NullPointerException npe) {
-                       logger.error(String.format("Null value found for property %s for document with ID %s",
-                                       xpath, docModel.getId()), npe);
+                       logger.error(String.format("Null value found for property '%s' for document with ID %s",
+                                       xpath, docModel.getName()), npe);
                }
 
                return result;
index 1748a7a249c81ce7f940f7da895094208c95afe0..fd33314559e6dfe40a88e457afa7c2bca1be8b3c 100644 (file)
@@ -76,6 +76,7 @@ import org.collectionspace.services.jaxb.InvocableJAXBSchema;
 import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler;
 import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.jfree.util.Log;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.model.PropertyException;
@@ -151,7 +152,6 @@ public class ReportDocumentModelHandler extends NuxeoDocumentModelHandler<Report
                                +invocationMode);
                }
                
-               
                RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx);
                repoSession = this.getRepositorySession();
                if (repoSession == null) {
@@ -164,24 +164,23 @@ public class ReportDocumentModelHandler extends NuxeoDocumentModelHandler<Report
                try {
                        DocumentWrapper<DocumentModel> wrapper = repoClient.getDoc(repoSession, ctx, csid);
                        DocumentModel docModel = wrapper.getWrappedObject();
-                       Boolean supports = (Boolean)docModel.getPropertyValue(modeProperty);
+                       Boolean supports = (Boolean) NuxeoUtils.getProperyValue(docModel, modeProperty); //docModel.getPropertyValue(modeProperty);
                        if(supports == null || !supports) {
                                throw new BadRequestException(
                                                "ReportResource: This Report does not support Invocation Mode: "
                                        +invocationMode);
                        }
-               if(checkDocType) {
+               if (checkDocType) {
                        List<String> forDocTypeList = 
-                               (List<String>)docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPES);
-                       if(forDocTypeList==null
-                                       || !forDocTypeList.contains(invContext.getDocType())) {
+                               (List<String>) NuxeoUtils.getProperyValue(docModel, InvocableJAXBSchema.FOR_DOC_TYPES); //docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPES);
+                       if (forDocTypeList==null || !forDocTypeList.contains(invContext.getDocType())) {
                                throw new BadRequestException(
                                                "ReportResource: Invoked with unsupported document type: "
                                                +invContext.getDocType());
                        }
                }
-               reportFileNameProperty = ((String)docModel.getPropertyValue(ReportJAXBSchema.FILENAME)); // Set the outgoing param with the report file name
-                       String reportOutputMime = (String)docModel.getPropertyValue(ReportJAXBSchema.OUTPUT_MIME);
+               reportFileNameProperty = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.FILENAME); //docModel.getPropertyValue(ReportJAXBSchema.FILENAME)); // Set the outgoing param with the report file name
+                       String reportOutputMime = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.OUTPUT_MIME); //docModel.getPropertyValue(ReportJAXBSchema.OUTPUT_MIME);
                        if(!Tools.isEmpty(reportOutputMime)) {
                                outMimeType.append(reportOutputMime);
                        } else {
index 37b8ab39b2d02f0a5dc3909b88de443611da53a3..7394e1dcea8f1ee2d60a31089adb5af7c837ff02 100644 (file)
@@ -218,11 +218,12 @@ public class ServiceGroupDocumentModelHandler
            Map<String, String> additionalValues = new HashMap<String, String>();
            if (storedValuesResourceTemplate.getUriTemplateType() == UriTemplateFactory.ITEM) {
                 try {
-                    String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
+                    String inAuthorityCsid = (String) NuxeoUtils.getProperyValue(docModel, "inAuthority"); //docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY
                     additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);
                     additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid);
                 } catch (Exception e) {
-                    logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());
+                       String msg = String.format("Could not extract inAuthority property from authority item with CSID = ", docModel.getName());
+                    logger.warn(msg, e);
                 }
            } else {
                 additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid);
@@ -240,12 +241,18 @@ public class ServiceGroupDocumentModelHandler
 
             String value = ServiceBindingUtils.getMappedFieldInDoc(sb, 
                                                        ServiceBindingUtils.OBJ_NUMBER_PROP, docModel);
-            item.put(DOC_NUMBER_FIELD, value);
+            if (value != null) {
+               item.put(DOC_NUMBER_FIELD, value);
+            }
+            
             value = ServiceBindingUtils.getMappedFieldInDoc(sb, 
                                                        ServiceBindingUtils.OBJ_NAME_PROP, docModel);
-            item.put(DOC_NAME_FIELD, value);
-            item.put(DOC_TYPE_FIELD, docType);
+            if (value != null) {
+               item.put(DOC_NAME_FIELD, value);
+            }
             
+            item.put(DOC_TYPE_FIELD, docType);
+            // add the item to the list
             list.addItem(item);
             item.clear();
         }