]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5133: Final changes for partial term queries that can return multiple display...
authorRichard Millet <remillet@berkeley.edu>
Thu, 17 May 2012 06:20:57 +0000 (23:20 -0700)
committerRichard Millet <remillet@berkeley.edu>
Thu, 17 May 2012 06:20:57 +0000 (23:20 -0700)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.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/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java

index 0f62c72f118c223f58f05bd0f9f5274ae3624ec1..64430e34ff1fbb4ddfc1f244173ad55bd67dfdb2 100644 (file)
@@ -8,12 +8,11 @@
     <totalItems>3</totalItems>
     <fieldsReturned>csid|uri|updatedAt|workflowState|order|displayName|shortIdentifier|refName|termStatus</fieldsReturned>
     <list-item>
-        <displayName>${Item3DupeOrder.displayName}</displayName>
-        <shortIdentifier>${Item3DupeOrder.itemID}</shortIdentifier>
-        <order>${Item3DupeOrder.order}</order>
-        <uri>/vocabularies/${Vocabulary1.CSID}/items/${Item3DupeOrder.CSID}</uri>
-                               <csid>${Item3DupeOrder.CSID}</csid>
-                               <termStatus/>
+        <displayName>${Item1.displayName}</displayName>
+        <shortIdentifier>${Item1.itemID}</shortIdentifier>
+        <order>${Item1.order}</order>
+        <uri>/vocabularies/${Vocabulary1.CSID}/items/${Item1.CSID}</uri>
+                               <csid>${Item1.CSID}</csid>
     </list-item>
     <list-item>
         <displayName>${Item2.displayName}</displayName>
         <order>${Item2.order}</order>
         <uri>/vocabularies/${Vocabulary1.CSID}/items/${Item2.CSID}</uri>
                                <csid>${Item2.CSID}</csid>
-                               <termStatus/>
     </list-item>
     <list-item>
-        <displayName>${Item1.displayName}</displayName>
-        <shortIdentifier>${Item1.itemID}</shortIdentifier>
-        <order>${Item1.order}</order>
-        <uri>/vocabularies/${Vocabulary1.CSID}/items/${Item1.CSID}</uri>
-                               <csid>${Item1.CSID}</csid>
-                               <termStatus/>
+        <displayName>${Item3DupeOrder.displayName}</displayName>
+        <shortIdentifier>${Item3DupeOrder.itemID}</shortIdentifier>
+        <order>${Item3DupeOrder.order}</order>
+        <uri>/vocabularies/${Vocabulary1.CSID}/items/${Item3DupeOrder.CSID}</uri>
+                               <csid>${Item3DupeOrder.CSID}</csid>
     </list-item>
 </ns3:abstract-common-list>
index b2c7febe8ddb9d7b34a39e92ec2e3ea90b3ab6ad..b9979ecb7489173aa133996fdd27a7e9e375a499 100644 (file)
@@ -63,6 +63,7 @@ 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.Property;
 import org.nuxeo.ecm.core.api.model.PropertyException;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 
@@ -521,24 +522,74 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
         }
     }
+    
+    protected List<String> getPartialTermDisplayNameMatches(List<String> termDisplayNameList, String partialTerm) {
+       List<String> result = new ArrayList<String>();
+       
+       for (String termDisplayName : termDisplayNameList) {
+               if (termDisplayName.contains(partialTerm) == true) {
+                       result.add(termDisplayName);
+               }
+       }
+       
+       return result;
+    }
+    
+    @SuppressWarnings("unchecked")
+       private List<String> getPartialTermDisplayNameMatches(DocumentModel docModel, // REM - CSPACE-5133
+                       String schema, ListResultField field, String partialTerm) {
+       List<String> result = null;
+         
+       String xpath = field.getXpath(); // results in something like "persons_common:personTermGroupList/[0]/termDisplayName"
+       int endOfTermGroup = xpath.lastIndexOf("/[0]/");
+       String propertyName = endOfTermGroup != -1 ? xpath.substring(0, endOfTermGroup) : xpath; // it may not be multivalued so the xpath passed in would be the property name
+       Object value = null;
+       
+               try {
+                       value = docModel.getProperty(schema, propertyName);
+               } catch (Exception e) {
+                       logger.error("Could not extract term display name with property = "
+                                       + propertyName, e);
+               }
+               
+               if (value != null && value instanceof ArrayList) {
+                       ArrayList<HashMap<String, Object>> termGroupList = (ArrayList<HashMap<String, Object>>)value;
+                       int arrayListSize = termGroupList.size();
+                       if (arrayListSize > 1) { // if there's only 1 element in the list then we've already matched the primary term's display name
+                               List<String> displayNameList = new ArrayList<String>();
+                               for (int i = 1; i < arrayListSize; i++) { // start at 1, skip the primary term's displayName since we will always return it
+                                       HashMap<String, Object> map = (HashMap<String, Object>)termGroupList.get(i);
+                                       String termDisplayName = (String) map.get(AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+                                       displayNameList.add(i - 1, termDisplayName);
+                               }
+                               
+                               result = getPartialTermDisplayNameMatches(displayNameList, partialTerm);
+                       }
+               }
+
+       return result;
+    }
 
     @Override
-       protected Object getXPathValue(DocumentModel docModel, // REM - CSPACE-5133
+       protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
                        String schema, ListResultField field) {
-               Object result = null;
+               Object result = null;           
 
                result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath());
                String elName = field.getElement();
+               //
+               // If the list result value is the termDisplayName element, we need to check to see if a partial term query was made.
+               //
                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;
+                               String primaryTermDisplayName = (String)result;
+                       List<String> matches = getPartialTermDisplayNameMatches(docModel, schema, field, partialTerm);
+                       if (matches != null && matches.isEmpty() == false) {
+                               matches.add(0, primaryTermDisplayName); // insert the primary term's display name at the beginning of the list
+                               result = matches; // set the result to a list of matching term display names with the primary term's display name at the beginning
+                       }
                }
                }
                
index c3d5b510df9c8df2fab71efd4477dbbe06e18a85..d7c7b723df1d4e187442bf573bfc76c643e59335 100644 (file)
@@ -1024,7 +1024,7 @@ public abstract class AbstractServiceTestImpl<CLT, CPT, REQUEST_TYPE, RESPONSE_T
                 //
                 // Get the total count of non-deleted existing records
                 //
-                String parentCsid = this.createTestObject(testName);
+                String parentCsid = this.createTestObject("REM_" + testName);
 
                 //
                 // Create 3 new items
index 8fb3c9e02a714483af13ad38fbc3f8536d775b31..4bef1cb51cb632b984561281f695605eccde54e6 100644 (file)
@@ -212,7 +212,7 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
                                if (schema == null || schema.trim().isEmpty()) {\r
                                        schema = commonSchema;\r
                                }\r
-                               Object value = getXPathValue(docModel, schema, field);\r
+                               Object value = getListResultValue(docModel, schema, field);\r
                                if (value != null && value instanceof String) {\r
                                        String strValue = (String) value;\r
                                        if (strValue.trim().isEmpty() == true) {\r
index d7b189fb6d75606f8b41c07f48163c3e0f9eed6c..d0ec9fc6cdb4e31f6b3940fe70409cf47a97c7c9 100644 (file)
@@ -713,7 +713,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
      * @param xpath The XPath expression (without schema prefix)
      * @return value the indicated property value as a String
      */
-       protected Object getXPathValue(DocumentModel docModel, // REM - CSPACE-5133
+       protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133
                        String schema, ListResultField field) {
                Object result = null;
 
index 07a79270bfff242acc8e8eeb7a36e923238e85b9..e86d8265f58ff46d22112f409ea50748ea9516f6 100644 (file)
@@ -186,15 +186,30 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         String headerLabel = new PersonAuthorityClient().getItemCommonPartName();
         
         HashMap<String, String> personInfo = new HashMap<String, String>();
-        String shortId = "johnWayneTempActor";
+        String shortId = "MarkTwainAuthor";
         personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
         
         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
         PersonTermGroup term = new PersonTermGroup();
-        term.setTermDisplayName("John Wayne Temp");
-        term.setTermName("JohnWayneTemp");
+        term.setTermDisplayName("Mark Twain Primary");
+        term.setTermName("MarkTwainPrimary");
         terms.add(term);
         
+        term = new PersonTermGroup();
+        term.setTermDisplayName("Samuel Langhorne Clemens");
+        term.setTermName("SamuelLanghorneClemens");
+        terms.add(term);        
+        
+        term = new PersonTermGroup();
+        term.setTermDisplayName("Sam Clemens");
+        term.setTermName("SamClemens");
+        terms.add(term);   
+        
+        term = new PersonTermGroup();
+        term.setTermDisplayName("Huck Fin");
+        term.setTermName("Huck Fin");
+        terms.add(term);           
+        
         return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, terms, headerLabel);
     }