]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6001: Allow the use of a stop character, initially a vertical bar (|) symbol...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 10 May 2013 19:50:06 +0000 (12:50 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 10 May 2013 19:50:06 +0000 (12:50 -0700)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsOnlyWord1.res.xml [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index eef0603a6a977b5ab25fefd0462a43cf8be257d8..43dc5dec03fc003f37d9cbf9ebabf6e5ac083d90 100644 (file)
@@ -66,7 +66,7 @@
             <uri>/cspace-services/personauthorities/${createPersonAuthority1.CSID}/items</uri>
             <filename>authority/personitem.xml</filename>
             <vars>
-                <var ID="itemDisplayName">${createPersonAuthority1.word2} ${createPersonAuthority1.word1}</var>
+                <var ID="itemDisplayName">${createPersonAuthority1.word1} ${createPersonAuthority1.word2}</var>
                 <var ID="itemShortIdentifier">${createPersonAuthority1.word1}item1</var>
                 <var ID="itemBioNote">A bio note for this Person.</var>
             </vars>
         <!-- Partial term searches -->
         
         <!-- Stem matching on first word -->
-        <test ID="ptStemSearchPersonItems">
+        <test ID="ptStemSearchPersonItemsFirstWord">
             <expectedCodes>200</expectedCodes>
             <method>GET</method>
             <uri>/cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word1PartialTermStem}</uri>
             </response>
         </test>
         <!-- Stem matching on second word -->
-        <test ID="ptStemSearchPersonItems">
+        <test ID="ptStemSearchPersonItemsSecondWord">
             <expectedCodes>200</expectedCodes>
             <method>GET</method>
             <uri>/cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word2PartialTermStem}</uri>
                 <filename>authority/res/personItemsContainingWord2.res.xml</filename>
             </response>
         </test>
+        <!-- Using a stop character (|) at the end of the search expression -->
+        <test ID="ptStopCharSearchPersonItems">
+            <expectedCodes>200</expectedCodes>
+            <method>GET</method>
+            <uri>/cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word1}%7C</uri>
+            <response>
+                <expected level="TEXT"/>
+                <filename>authority/res/personItemsOnlyWord1.res.xml</filename>
+            </response>
+        </test>
         
         <!-- Advanced searches -->
         
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsOnlyWord1.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsOnlyWord1.res.xml
new file mode 100644 (file)
index 0000000..50f513d
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+<ns2:abstract-common-list xmlns:ns2="http://collectionspace.org/services/jaxb">\r
+    <totalItems>1</totalItems>\r
+    <list-item>\r
+        <shortIdentifier>${createPersonAuthority1.word1}item2</shortIdentifier>\r
+    </list-item>\r
+</ns2:abstract-common-list>\r
+\r
+\r
index ca7ae82009b24641f5a470443717a81372218bdd..b2aa40722bb191d6be0c250a7f40b03cd012a55d 100644 (file)
@@ -114,6 +114,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
     // FIXME: Get this value from an existing constant, if available
     private static final String USER_SUPPLIED_WILDCARD = "*";
     private static final String USER_SUPPLIED_WILDCARD_REGEX = "\\" + USER_SUPPLIED_WILDCARD;
+    private static final String USER_SUPPLIED_STOP_CHAR = "|";
+
     
     /**
      * Instantiates a new repository java client impl.
@@ -1017,35 +1019,46 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
         limitClause =
                 " LIMIT " + getMaxItemsLimitOnJdbcQueries(maxListItemsLimit); // implicit int-to-String conversion
         
+        // After building the individual parts of the query, set the values
+        // of replaceable parameters that will be inserted into that query
+        // and optionally add restrictions
+        
         List<String> params = new ArrayList<>();
         
-        // Read tenant bindings configuration to determine whether
-        // to automatically insert leading, as well as trailing, wildcards
-        // into the term matching string.
-        String usesStartingWildcard = TenantBindingUtils.getPropertyValue(tenantBinding,
-                IQueryManager.TENANT_USES_STARTING_WILDCARD_FOR_PARTIAL_TERM);
-        // Handle user-provided leading wildcard characters, in the
-        // configuration where a leading wildcard is not automatically inserted.
-        // (The user-provided wildcard must be in the first, or "starting"
-        // character position in the partial term value.)
-        if (Tools.notBlank(usesStartingWildcard) && usesStartingWildcard.equalsIgnoreCase(Boolean.FALSE.toString())) {
-            partialTerm = handleProvidedStartingWildcard(partialTerm);
-            // Otherwise, automatically insert a leading wildcard
-        } else {
-            partialTerm = JDBCTools.SQL_WILDCARD + partialTerm;
+        if (Tools.notBlank(whereClause)) {
+                        
+            // Read tenant bindings configuration to determine whether
+            // to automatically insert leading, as well as trailing, wildcards
+            // into the term matching string.
+            String usesStartingWildcard = TenantBindingUtils.getPropertyValue(tenantBinding,
+                    IQueryManager.TENANT_USES_STARTING_WILDCARD_FOR_PARTIAL_TERM);
+            // Handle user-provided leading wildcard characters, in the
+            // configuration where a leading wildcard is not automatically inserted.
+            // (The user-provided wildcard must be in the first, or "starting"
+            // character position in the partial term value.)
+            if (Tools.notBlank(usesStartingWildcard) && usesStartingWildcard.equalsIgnoreCase(Boolean.FALSE.toString())) {
+                partialTerm = handleProvidedStartingWildcard(partialTerm);
+                // Otherwise, automatically insert a leading wildcard
+            } else {
+                partialTerm = JDBCTools.SQL_WILDCARD + partialTerm;
+            }
+            // Add SQL wildcards in the midst of the partial term match search
+            // expression, whever user-supplied wildcards appear, except in the
+            // first or last character positions of the search expression.
+            partialTerm = subtituteWildcardsInPartialTerm(partialTerm);
+
+            // If a designated 'stop character' is present as the last character
+            // in the search expression, strip that character and don't add
+            // a trailing wildcard
+            int lastCharPos = partialTerm.length() - 1;
+            if (partialTerm.endsWith(USER_SUPPLIED_STOP_CHAR) && lastCharPos > 0) {
+                    partialTerm = partialTerm.substring(0, lastCharPos);
+            } else {
+                // Otherwise, automatically add a trailing wildcard
+                partialTerm = partialTerm + JDBCTools.SQL_WILDCARD;
+            }
+            params.add(partialTerm);
         }
-        // Add SQL wildcards in the midst of the partial term match search
-        // expression, whever user-supplied wildcards appear, except in the
-        // first or last character positions of the search expression.
-        partialTerm = subtituteWildcardsInPartialTerm(partialTerm);
-        
-        // FIXME: We may wish to handle instances where a designated 'stop
-        // character' has been inserted by the user as the last character in
-        // the search expression, whereupon we would strip that stop character
-        // and skip the automatic adding of a trailing wildcard, below.
-        
-        // Automatically add a trailing wildcard
-        params.add(partialTerm + JDBCTools.SQL_WILDCARD);
         
         // Optionally add restrictions to the default query, based on variables
         // in the current request
@@ -1144,7 +1157,11 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             return result; // return an empty list of document models
         } 
 
-        // Get a list of document models, using the IDs obtained from the query
+        // Get a list of document models, using the list of IDs obtained from the query
+        //
+        // FIXME: Check whether we have a 'get document models from list of CSIDs'
+        // utility method like this, and if not, add this to the appropriate
+        // framework class
         DocumentModel docModel;
         for (String docId : docIds) {
             docModel = NuxeoUtils.getDocumentModel(repoSession, docId);