]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6001: Switch from allowing only an ending 'stop' character (by default, a...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 17 May 2013 03:21:25 +0000 (20:21 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 17 May 2013 03:21:25 +0000 (20:21 -0700)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index 43dc5dec03fc003f37d9cbf9ebabf6e5ac083d90..42748c70fc2cb1187de0c4a24c30f8103b0aa9a5 100644 (file)
                 <filename>authority/res/personItemsContainingWord2.res.xml</filename>
             </response>
         </test>
-        <!-- Using a stop character (|) at the end of the search expression -->
-        <test ID="ptStopCharSearchPersonItems">
+        <!-- Using an anchor character (^) at the end of the search expression -->
+        <test ID="ptTrailingAnchorCharSearchPersonItems">
             <expectedCodes>200</expectedCodes>
             <method>GET</method>
-            <uri>/cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word1}%7C</uri>
+            <uri>/cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word1}%5E</uri>
             <response>
                 <expected level="TEXT"/>
                 <filename>authority/res/personItemsOnlyWord1.res.xml</filename>
index b2843cf40d1692dbf7636f61561a186febbff5fc..c764a3c3387b3873ebc46335483bec73447d396b 100644 (file)
 package org.collectionspace.services.nuxeo.client.java;
 
 import java.io.Serializable;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -114,7 +110,7 @@ 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 = "|";
+    private static final String USER_SUPPLIED_ANCHOR_CHAR = "^";
 
     
     /**
@@ -1036,22 +1032,33 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             // 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(usesStartingWildcard)) {
+                if (usesStartingWildcard.equalsIgnoreCase(Boolean.FALSE.toString())) {
+                    partialTerm = handleProvidedStartingWildcard(partialTerm);
+                    // Otherwise, in the configuration where a leading wildcard
+                    // is usually automatically inserted, handle the cases where
+                    // a user has entered an anchor character in the first position
+                    // in the starting term value. In those cases, strip that
+                    // anchor character and don't add a leading wildcard
+                } else {
+                    if (partialTerm.startsWith(USER_SUPPLIED_ANCHOR_CHAR)) {
+                        partialTerm = partialTerm.substring(1, partialTerm.length());
+                        // Otherwise, automatically add 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
+            // If a designated 'anchor 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) {
+            if (partialTerm.endsWith(USER_SUPPLIED_ANCHOR_CHAR) && lastCharPos > 0) {
                     partialTerm = partialTerm.substring(0, lastCharPos);
             } else {
                 // Otherwise, automatically add a trailing wildcard