]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5130: Finished most of the special case handling for the Vocabulary item schema.
authorRichard Millet <remillet@berkeley.edu>
Thu, 3 May 2012 21:50:12 +0000 (14:50 -0700)
committerRichard Millet <remillet@berkeley.edu>
Thu, 3 May 2012 21:50:12 +0000 (14:50 -0700)
services/authority/jaxb/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityItemJAXBSchema.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/vocabulary/service/pom.xml
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemDocumentModelHandler.java

index 6c01bb5e7490a54a9a16cf9386b3777cac4eeaf4..e5e47982ee2d9c60531fa77dd2adb9d4d8f80a99 100644 (file)
@@ -25,24 +25,24 @@ package org.collectionspace.services.common.vocabulary;
 \r
 /**\r
  * @author pschmitz\r
- *\r
+ * \r
  */\r
 public interface AuthorityItemJAXBSchema {\r
-       final static String IN_AUTHORITY = "inAuthority";\r
+       final static String IN_AUTHORITY = "inAuthority";\r
        final static String REF_NAME = "refName";\r
        final static String ORDER = "order";\r
        final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String CSID = "csid";\r
-        final static String TERM_DISPLAY_NAME = "termDisplayName";\r
-        final static String TERM_NAME = "termName";\r
-        final static String TERM_STATUS = "termStatus";\r
-        final static String TERM_INFO_GROUP_SCHEMA_NAME = ""; //FIXME: REM - Needs to be defined.\r
-        // CSPACE-4813 - Remove all the below values and recompile all authorityitem related classes\r
-       final static String DISPLAY_NAME = "displayName";\r
+    final static String DISPLAY_NAME = "displayName"; // This is the display name element for the Vocabulary service's item    \r
+       final static String TERM_DISPLAY_NAME = "termDisplayName";\r
+       final static String TERM_NAME = "termName";\r
+       final static String TERM_STATUS = "termStatus";\r
+       final static String TERM_INFO_GROUP_SCHEMA_NAME = ""; // FIXME: REM - Needs\r
+                                                                                                                       // to be defined.\r
+       // CSPACE-4813 - Remove all the below values and recompile all authorityitem\r
+       // related classes\r
        final static String DISPLAY_NAME_COMPUTED = "displayNameComputed";\r
        final static String SHORT_DISPLAY_NAME = "shortDisplayName";\r
        final static String SHORT_DISPLAY_NAME_COMPUTED = "shortDisplayNameComputed";\r
-       //final static String TERM_STATUS = "termStatus";\r
+       // final static String TERM_STATUS = "termStatus";\r
 }\r
-\r
-\r
index 904a67307beec4dc6549cf62dfe8ef78d19e98a3..7d894f58c533d7382ec0022130a5e96f842afebc 100644 (file)
@@ -140,6 +140,25 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         this.authorityRefNameBase = value;
     }
 
+    /*
+     * Note that the Vocabulary service's item-documentmodel-handler will override this method.
+     */
+    protected ListResultField getListResultField() {
+       ListResultField result = new ListResultField();
+       // Per CSPACE-5132, the name of this element remains 'displayName'
+        // for backwards compatibility, although its value is obtained
+        // from the termDisplayName field.
+        //
+        // In CSPACE-5134, these list results will change substantially
+        // to return display names for both the preferred term and for
+        // each non-preferred term (if any).
+       result.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
+       result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
+                authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
+       
+       return result;
+    }
+    
     @Override
     public List<ListResultField> getListItemsArray() throws DocumentException {
         List<ListResultField> list = super.getListItemsArray();
@@ -154,7 +173,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)) { //FIXME: Add a special if-case for Vocabulary item's displayName
+            if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || AuthorityItemJAXBSchema.DISPLAY_NAME.equals(elName)) {
                 hasDisplayName = true;
             } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
                 hasShortId = true;
@@ -166,17 +185,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         }
         ListResultField field;
         if (!hasDisplayName) {
-            field = new ListResultField();
-            // Per CSPACE-5132, the name of this element remains 'displayName' //FIXME: Add a special case again for Vocab item's displayName
-            // for backwards compatibility, although its value is obtained
-            // from the termDisplayName field.
-            //
-            // In CSPACE-5134, these list results will change substantially
-            // to return display names for both the preferred term and for
-            // each non-preferred term (if any).
-            field.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
-            field.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
-                    authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
+               field = getListResultField();
             list.add(field);
         }
         if (!hasShortId) {
@@ -198,8 +207,8 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                     authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
             list.add(field);
         }
+        
         return list;
-
     }
 
 
@@ -212,17 +221,6 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         super.handleCreate(wrapDoc);
         // Ensure we have required fields set properly
         handleInAuthority(wrapDoc.getWrappedObject());
-
-        // CSPACE-4813
-        /*
-        handleComputedDisplayNames(wrapDoc.getWrappedObject());
-        String displayName = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
-                AuthorityItemJAXBSchema.DISPLAY_NAME);
-        if (Tools.isEmpty(displayName)) {
-            logger.warn("Creating Authority Item with no displayName!");
-        }
-        *
-        */        
         
         // CSPACE-3178:
         // handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName);
@@ -230,6 +228,18 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         updateRefnameForAuthorityItem(wrapDoc, authorityItemCommonSchemaName, getAuthorityRefNameBase());
     }
 
+    /*
+     * Note that the Vocabulary service's document-model for items overrides this method.
+     */
+       protected String getPrimaryDisplayName(DocumentModel docModel, String schema,
+                       String complexPropertyName, String fieldName) {
+               String result = null;
+
+               result = getStringValueInPrimaryRepeatingComplexProperty(docModel, schema, complexPropertyName, fieldName);
+               
+               return result;
+       }
+    
     /* (non-Javadoc)
      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
      */
@@ -238,18 +248,14 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         // First, get a copy of the old displayName
         // oldDisplayNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
         //        AuthorityItemJAXBSchema.DISPLAY_NAME);
-        oldDisplayNameOnUpdate = (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
-                wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
-                getItemTermInfoGroupXPathBase(),
-                AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+        oldDisplayNameOnUpdate = getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
+                getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
         oldRefNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
                 AuthorityItemJAXBSchema.REF_NAME);
         super.handleUpdate(wrapDoc);
-        // handleComputedDisplayNames(wrapDoc.getWrappedObject());
-        // String newDisplayName = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
-        //        AuthorityItemJAXBSchema.DISPLAY_NAME);
-        String newDisplayName = (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
-                wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
+
+        // Now, check the new display and handle the refname update.
+        String newDisplayName = (String) getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
                 this.authorityItemTermGroupXPathBase,
                 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
         if (newDisplayName != null && !newDisplayName.equals(oldDisplayNameOnUpdate)) {
@@ -328,24 +334,28 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
      * If no short identifier was provided in the input payload, generate a
      * short identifier from the preferred term display name or term name.
      */
-    private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
-        String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
-        String termDisplayName =
-                (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
-                    docModel, authorityItemCommonSchemaName,
-                    getItemTermInfoGroupXPathBase(),
-                    AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
-        String termName = 
-                (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
-                    docModel, authorityItemCommonSchemaName,
-                    getItemTermInfoGroupXPathBase(),
-                    AuthorityItemJAXBSchema.TERM_NAME);
-        if (Tools.isEmpty(shortIdentifier)) {
-            String generatedShortIdentifier =
-                    AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName, termName);
-            docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
-        }
-    }
+       private void handleDisplayNameAsShortIdentifier(DocumentModel docModel,
+                       String schemaName) throws Exception {
+               String shortIdentifier = (String) docModel.getProperty(schemaName,
+                               AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+
+               String termDisplayName = getPrimaryDisplayName(
+                               docModel, authorityItemCommonSchemaName,
+                               getItemTermInfoGroupXPathBase(),
+                               AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+
+               String termName = getPrimaryDisplayName(
+                               docModel, authorityItemCommonSchemaName,
+                               getItemTermInfoGroupXPathBase(),
+                               AuthorityItemJAXBSchema.TERM_NAME);
+
+               if (Tools.isEmpty(shortIdentifier)) {
+                       String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
+                                                       termName);
+                       docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
+                                       generatedShortIdentifier);
+               }
+       }
 
     /**
      * Generate a refName for the authority item from the short identifier
@@ -363,14 +373,13 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             String authorityRefBaseName) throws Exception {
         DocumentModel docModel = wrapDoc.getWrappedObject();
         String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
-        String displayName =
-                (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
-                    docModel, authorityItemCommonSchemaName,
-                    getItemTermInfoGroupXPathBase(),
-                    AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+        String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
+                    getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+        
         if (Tools.isEmpty(authorityRefBaseName)) {
             throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
         }
+        
         RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName);
         String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString();
         docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refName);
@@ -1120,4 +1129,8 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
         this.authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
     }
+    
+    protected String getAuthorityItemCommonSchemaName() {
+       return authorityItemCommonSchemaName;
+    }
 }
index 95d82fb240d4e67742bd5799dbcd08b01d8e7ea1..f05ee9a9f1700b411a674c70fc407160ccb20aee 100644 (file)
@@ -671,17 +671,19 @@ 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 getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
-               DocumentModel docModel, String schema, String complexPropertyName, String fieldName) {
+    protected String getStringValueInPrimaryRepeatingComplexProperty(
+               DocumentModel docModel, String schema, String complexPropertyName, String fieldName) {          
+       String result = null;
+       
        String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName);
        try {
-               return (String)docModel.getPropertyValue(xpath);
+               result = (String)docModel.getPropertyValue(xpath);
        } catch(PropertyException pe) {
                throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad propertyNames?"
                                +pe.getLocalizedMessage());
        } catch(IndexOutOfBoundsException ioobe) {
                // Nuxeo sometimes handles missing sub, and sometimes does not. Odd.
-               return "";      // gracefully handle missing elements
+               result = "";    // gracefully handle missing elements
        } catch(ClassCastException cce) {
                throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a String property?"
                                +cce.getLocalizedMessage());
@@ -689,6 +691,8 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
                throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
                                +e.getLocalizedMessage());
        }
+       
+       return result;
     }
    
     /**
@@ -707,43 +711,51 @@ 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) {
-       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();
-               }
-               return 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
-                       return "";
-               } else {
-                       String msg = ioobe.getMessage();
-                       if(msg!=null && msg.equals("Index: 0, Size: 0")) {
-                               // Some other variant on a missing sub-field; quietly absorb.
-                               return "";
-                       } // Otherwise, e.g., for true OOB indices, propagate the exception.
-               }
-               throw new RuntimeException("Problem retrieving property {"+xpath+"}:"
-                               +ioobe.getLocalizedMessage());
-       } catch(Exception e) {
-               throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
-                               +e.getLocalizedMessage());
-       }
-    }
+       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.
+                       }
+                       throw new RuntimeException("Problem retrieving property {" + xpath
+                                       + "}:" + ioobe.getLocalizedMessage());
+               } catch (Exception e) {
+                       throw new RuntimeException("Unknown problem retrieving property {"
+                                       + xpath + "}." + e.getLocalizedMessage());
+               }
+
+               return result;
+       }
    
 }
index 05b700e8f8c969e93a1df2edfcad1b06f6f36299..dcea9792509c28ab1c138d45bc6c2b1424e60e05 100644 (file)
@@ -7,7 +7,6 @@
     </parent>\r
     \r
     <modelVersion>4.0.0</modelVersion>\r
-    <groupId>org.collectionspace.services</groupId>\r
     <artifactId>org.collectionspace.services.vocabulary.service</artifactId>\r
     <name>services.vocabulary.service</name>\r
     <packaging>jar</packaging>\r
             <artifactId>org.collectionspace.services.common</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.config</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.authority.service</artifactId>\r
index c941ce5c52bef8dd78d00fc70e3adf51cefcfd84..dcd7f2bf6f641ebfa7b92abfc596b37ffb233657 100644 (file)
@@ -25,8 +25,13 @@ package org.collectionspace.services.vocabulary.nuxeo;
 
 import org.collectionspace.services.client.VocabularyClient;
 import org.collectionspace.services.common.context.ServiceBindingUtils;
+import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
+import org.collectionspace.services.config.service.ListResultField;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
+import org.nuxeo.ecm.core.api.ClientException;
+import org.nuxeo.ecm.core.api.DocumentModel;
 
 /**
  * VocabularyItemDocumentModelHandler
@@ -62,5 +67,41 @@ public class VocabularyItemDocumentModelHandler
     public String getQProperty(String prop) {
         return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;
     }
+    
+    /*
+     * Because the Vocabulary service's item schema is not standard, we need to override the default authority item schema behavior.
+     * (non-Javadoc)
+     * @see org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler#getPrimaryDisplayName(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String, java.lang.String)
+     */
+       @Override
+       protected String getPrimaryDisplayName(DocumentModel docModel,
+                       String schema, String complexPropertyName, String fieldName) {
+               String result = null;
+
+               try {
+                       result = (String) docModel.getProperty(schema, AuthorityItemJAXBSchema.DISPLAY_NAME);
+               } catch (Exception e) {
+                       throw new RuntimeException("Unknown problem retrieving property {"
+                                       + schema + ":" + fieldName + "}." + e.getLocalizedMessage());
+               }
+
+               return result;
+       }
+    
+    /*
+     * Because the Vocabulary service's item schema is not standard, we need to override this method.
+     */
+    @Override
+       protected ListResultField getListResultField() {
+               ListResultField result = new ListResultField();
+
+               result.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
+               result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(this.getAuthorityItemCommonSchemaName(),
+                               getItemTermInfoGroupXPathBase(),
+                               AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
+
+               return result;
+       }
+    
 }