]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5119,CSPACE-5139,CSPACE-5138: Additional work on authority item base classes...
authorAron Roberts <aron@socrates.berkeley.edu>
Wed, 2 May 2012 00:32:37 +0000 (17:32 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Wed, 2 May 2012 00:32:37 +0000 (17:32 -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/AuthorityResource.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/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java

index 70d6e0b07e4dcfd64dc306830908c13adbbc8d3a..024eab8bc9d3420fe67f9f38d36909fcbadb4971 100644 (file)
@@ -36,9 +36,6 @@ public interface AuthorityItemJAXBSchema {
         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 PREFERRED_TERM_DISPLAY_NAME_XPATH ="termGroupList/0/termDisplayName";\r
-        final static String PREFERRED_TERM_NAME_XPATH ="termGroupList/0/termName";\r
-        final static String PREFERRED_TERM_STATUS_XPATH ="termGroupList/0/termStatus";\r
         // CSPACE-4813\r
         /*\r
        final static String DISPLAY_NAME = "displayName";\r
index a5695ce06f915b6e532378eec8c503746fdab968..946bf848b397208bea0a3db79696782f4f177601 100644 (file)
@@ -82,6 +82,8 @@ import javax.ws.rs.core.UriInfo;
 
 import java.util.ArrayList;
 import java.util.List;
+import org.collectionspace.services.client.*;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
 /**
  * The Class AuthorityResource.
@@ -180,6 +182,8 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     }
 
     public abstract String getItemServiceName();
+    
+    public abstract String getItemTermInfoGroupXPathBase();
 
     @Override
     protected String getVersionString() {
@@ -223,9 +227,12 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         docHandler = (AuthorityItemDocumentModelHandler<?>) createDocumentHandler(ctx,
                 ctx.getCommonPartLabel(getItemServiceName()),
                 authCommonClass);
+        // FIXME - Richard and Aron think the following three lines should
+        // be in the constructor for the AuthorityItemDocumentModelHandler
+        // because all three are required fields.
         docHandler.setInAuthority(inAuthority);
         docHandler.setAuthorityRefNameBase(authorityRefNameBase);
-
+        docHandler.setItemTermInfoGroupXPathBase(getItemTermInfoGroupXPathBase());
         return docHandler;
     }
 
@@ -427,8 +434,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             if (sortBy == null || sortBy.isEmpty()) {
                 // String qualifiedDisplayNameField = authorityCommonSchemaName + ":"
                 //         + AuthorityItemJAXBSchema.DISPLAY_NAME;
-                String qualifiedDisplayNameField = AuthorityItemJAXBSchema.TERM_INFO_GROUP_SCHEMA_NAME + ":"
-                        + AuthorityItemJAXBSchema.TERM_DISPLAY_NAME;
+                String qualifiedDisplayNameField = getQualifiedDisplayNameField();
                 myFilter.setOrderByClause(qualifiedDisplayNameField);
             }
             String nameQ = queryParams.getFirst("refName");
@@ -441,6 +447,11 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             throw bigReThrow(e, ServiceMessages.GET_FAILED);
         }
     }
+    
+    protected String getQualifiedDisplayNameField() {
+        return NuxeoUtils.getPrimaryXPathPropertyName(authorityCommonSchemaName, 
+                getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+    }
 
     /**
      * Update authority.
@@ -666,8 +677,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW);
             String advancedSearch = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_AS);
 
-            String qualifiedDisplayNameField = authorityItemCommonSchemaName + ":"
-                    + AuthorityItemJAXBSchema.DISPLAY_NAME;
+            String qualifiedDisplayNameField = getQualifiedDisplayNameField();
 
             // Note that docType defaults to the ServiceName, so we're fine with that.
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
index 45230aa082b2aada0f5871fc7c3a32d87ceac860..f3efe483a4c4216c4ba81b2273af70c04e6fa9f3 100644 (file)
@@ -93,6 +93,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
 
     private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
     private String authorityItemCommonSchemaName;
+    private String authorityItemTermGroupXPathBase;
     /**
      * inVocabulary is the parent Authority for this context
      */
@@ -151,7 +152,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         for (int i = 0; i < nFields; i++) {
             ListResultField field = list.get(i);
             String elName = field.getElement();
-            if (AuthorityItemJAXBSchema.DISPLAY_NAME.equals(elName)) {
+            if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName)) {
                 hasDisplayName = true;
             } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
                 hasShortId = true;
@@ -164,7 +165,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         ListResultField field;
         if (!hasDisplayName) {
             field = new ListResultField();
-            field.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
+            field.setElement(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
             field.setXpath(AuthorityItemJAXBSchema.DISPLAY_NAME);
             list.add(field);
         }
@@ -225,16 +226,20 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         // First, get a copy of the old displayName
         // oldDisplayNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
         //        AuthorityItemJAXBSchema.DISPLAY_NAME);
-        oldDisplayNameOnUpdate = (String) RemoteDocumentModelHandlerImpl.getXPathStringValue(wrapDoc.getWrappedObject(),
-                    authorityItemCommonSchemaName, AuthorityItemJAXBSchema.PREFERRED_TERM_DISPLAY_NAME_XPATH);
+        oldDisplayNameOnUpdate = (String) getStringValueInPrimaryRepeatingComplexProperty(
+                wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
+                this.authorityItemTermGroupXPathBase,
+                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) RemoteDocumentModelHandlerImpl.getXPathStringValue(wrapDoc.getWrappedObject(),
-            authorityItemCommonSchemaName, AuthorityItemJAXBSchema.PREFERRED_TERM_DISPLAY_NAME_XPATH);
+        String newDisplayName = (String) getStringValueInPrimaryRepeatingComplexProperty(
+                wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
+                this.authorityItemTermGroupXPathBase,
+                AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
         if (newDisplayName != null && !newDisplayName.equals(oldDisplayNameOnUpdate)) {
             // Need to update the refName, and then fix all references.
             newRefNameOnUpdate = handleItemRefNameUpdateForDisplayName(wrapDoc.getWrappedObject(), newDisplayName);
@@ -314,10 +319,15 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
         String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
         String termDisplayName =
-                (String) RemoteDocumentModelHandlerImpl.getXPathStringValue(docModel,
-                    schemaName, AuthorityItemJAXBSchema.PREFERRED_TERM_DISPLAY_NAME_XPATH);
-        String termName = (String) RemoteDocumentModelHandlerImpl.getXPathStringValue(docModel,
-                    schemaName, AuthorityItemJAXBSchema.PREFERRED_TERM_NAME_XPATH);
+                (String) getStringValueInPrimaryRepeatingComplexProperty(
+                    docModel, authorityItemCommonSchemaName,
+                    this.authorityItemTermGroupXPathBase,
+                    AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+        String termName = 
+                (String) getStringValueInPrimaryRepeatingComplexProperty(
+                    docModel, authorityItemCommonSchemaName,
+                    this.authorityItemTermGroupXPathBase,
+                    AuthorityItemJAXBSchema.TERM_NAME);
         if (Tools.isEmpty(shortIdentifier)) {
             String generatedShortIdentifier =
                     AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName, termName);
@@ -342,8 +352,10 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         DocumentModel docModel = wrapDoc.getWrappedObject();
         String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
         String displayName =
-                RemoteDocumentModelHandlerImpl.getXPathStringValue(docModel, schemaName,
-                    AuthorityItemJAXBSchema.PREFERRED_TERM_DISPLAY_NAME_XPATH);
+                (String) getStringValueInPrimaryRepeatingComplexProperty(
+                    docModel, authorityItemCommonSchemaName,
+                    this.authorityItemTermGroupXPathBase,
+                    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.");
         }
@@ -1088,4 +1100,12 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         return relationsCommonList;
     }
     //============================= END TODO refactor ==========================
+
+    public String getItemTermInfoGroupXPathBase() {
+        return this.authorityItemTermGroupXPathBase;
+    }
+        
+    public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
+        this.authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
+    }
 }
index e00c93c7153dc4abe0a21c440e113cd56c2c0d9e..8717b8af20a54d324628449ef36aa689558a15f4 100644 (file)
@@ -60,6 +60,7 @@ 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.ObjectPartType;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.dom4j.Element;
 
 import org.nuxeo.ecm.core.api.DocumentModel;
@@ -672,7 +673,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
      */
     protected String getStringValueInPrimaryRepeatingComplexProperty(
                DocumentModel docModel, String schema, String complexPropertyName, String fieldName) {
-       String xpath = "/"+schema+":"+complexPropertyName+"/[0]/"+fieldName;
+       String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName);
        try {
                return (String)docModel.getPropertyValue(xpath);
        } catch(PropertyException pe) {
index 6daadf926c17f0a201d622dbf039927ed39bd508..46393459e7729185e498398023c373e9f29e2e69 100644 (file)
@@ -600,4 +600,8 @@ public class NuxeoUtils {
                
        return result;
     }
+    
+    static public String getPrimaryXPathPropertyName(String schema, String complexPropertyName, String fieldName) {
+       return schema + ":" + complexPropertyName + "/[0]/" + fieldName;
+    }
 }
index 7a06e57e301f28e83393bf2f452d0446400ad567..f5dc8c85edc24af51464726e60214d9301a7e2d3 100644 (file)
@@ -36,6 +36,7 @@ public class PersonAuthorityClient extends AuthorityWithContactsClientImpl<Perso
        public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;       
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
+        public static final String TERM_INFO_GROUP_XPATH_BASE = "personTermGroup";
        //
        // Subitem constants
        //
index c8227d917b22889a60bd3d29665d0759753e5801..7da7f28282acfacc70577edd1589c3aa2ff017e5 100644 (file)
@@ -55,6 +55,11 @@ public class PersonAuthorityResource extends
     public String getItemServiceName() {
         return PersonAuthorityClient.SERVICE_ITEM_NAME;
     }
+    
+    @Override
+    public String getItemTermInfoGroupXPathBase() {
+        return PersonAuthorityClient.TERM_INFO_GROUP_XPATH_BASE;
+    }
 
     @Override
     public Class<PersonauthoritiesCommon> getCommonPartClass() {