From: Aron Roberts Date: Fri, 10 May 2013 19:50:06 +0000 (-0700) Subject: CSPACE-6001: Allow the use of a stop character, initially a vertical bar (|) symbol... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=2be855941614b01940769d475be5e0840aad6531;p=tmp%2Fjakarta-migration.git CSPACE-6001: Allow the use of a stop character, initially a vertical bar (|) symbol, at the end of a partial term matching search expression. This character negates any implicit, automatically-added wildcard at the end of that search expression. --- diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml index eef0603a6..43dc5dec0 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml @@ -66,7 +66,7 @@ /cspace-services/personauthorities/${createPersonAuthority1.CSID}/items authority/personitem.xml - ${createPersonAuthority1.word2} ${createPersonAuthority1.word1} + ${createPersonAuthority1.word1} ${createPersonAuthority1.word2} ${createPersonAuthority1.word1}item1 A bio note for this Person. @@ -198,7 +198,7 @@ - + 200 GET /cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word1PartialTermStem} @@ -208,7 +208,7 @@ - + 200 GET /cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word2PartialTermStem} @@ -227,6 +227,16 @@ authority/res/personItemsContainingWord2.res.xml + + + 200 + GET + /cspace-services/personauthorities/_ALL_/items?pt=${createPersonAuthority1.word1}%7C + + + authority/res/personItemsOnlyWord1.res.xml + + 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 index 000000000..50f513dce --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsOnlyWord1.res.xml @@ -0,0 +1,9 @@ + + + 1 + + ${createPersonAuthority1.word1}item2 + + + + diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index ca7ae8200..b2aa40722 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -114,6 +114,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient 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