]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-749, CSPACE-1643, etc. Added keyword search support to vocab and authorities...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 6 Jul 2010 15:56:46 +0000 (15:56 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 6 Jul 2010 15:56:46 +0000 (15:56 +0000)
services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java
services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java

index 3ac1e2742b4ca9609d683805edf42d560796dc81..e7c1cabea940c12998b5b471a44e47dfec5f5e1e 100644 (file)
@@ -28,6 +28,8 @@ package org.collectionspace.services.common.query;
 \r
 public interface IQueryManager {\r
        \r
+       final static String SEARCH_GROUP_OPEN = "(";\r
+       final static String SEARCH_GROUP_CLOSE = ")";\r
        final static String SEARCH_TERM_SEPARATOR = " ";\r
        final static String SEARCH_LIKE = " LIKE ";\r
     final static String SEARCH_TYPE_KEYWORDS = "keywords";\r
index 972a47638c6702fd73bb38197ea1e82db01a019e..d6bd14f2033c025eefc36916902ce058caddd7e4 100644 (file)
@@ -83,7 +83,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
         */\r
        public String createWhereClauseFromKeywords(String keywords) {\r
                String result = null;\r
-               StringBuffer whereClause = new StringBuffer();\r
+               StringBuffer whereClause = new StringBuffer(SEARCH_GROUP_OPEN);\r
                StringTokenizer stringTokenizer = new StringTokenizer(keywords);\r
                while (stringTokenizer.hasMoreElements() == true) {\r
                        whereClause.append(ECM_FULLTEXT_LIKE + "'" +\r
@@ -98,7 +98,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
                        }\r
                }               \r
                \r
-               result = whereClause.toString();\r
+               result = whereClause.append(SEARCH_GROUP_CLOSE).toString();\r
            if (logger.isDebugEnabled()) {\r
                logger.debug("Final built WHERE clause is: " + result);\r
            }\r
index 312f248235c88e06541e5662cedf28d670e66ca8..9bda83231415fe18424cd587c807bd5bad5c2c30 100644 (file)
@@ -60,6 +60,7 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -684,6 +685,7 @@ AbstractMultiPartCollectionSpaceResourceImpl {
        public AuthItemCommonList getAuthorityItemList(
                        @PathParam("csid") String parentcsid,
                        @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+                       @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
                        @Context UriInfo ui) {
                try {
                        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
@@ -704,6 +706,9 @@ AbstractMultiPartCollectionSpaceResourceImpl {
                                + IQueryManager.SEARCH_LIKE
                                + "'%" + partialTerm + "%'";
                                myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
+                       } else if (keywords != null) {
+                               String kwdClause = QueryManager.createWhereClauseFromKeywords(keywords);
+                               myFilter.appendWhereClause(kwdClause, IQueryManager.SEARCH_QUALIFIER_AND);
                        }
                        if (logger.isDebugEnabled()) {
                                logger.debug("getAuthorityItemList filtered WHERE clause: "
@@ -741,6 +746,7 @@ AbstractMultiPartCollectionSpaceResourceImpl {
        public AuthItemCommonList getAuthorityItemListByAuthName(
                        @PathParam("specifier") String specifier,
                        @QueryParam(IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+                       @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
                        @Context UriInfo ui) {
                try {
                        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
@@ -751,7 +757,7 @@ AbstractMultiPartCollectionSpaceResourceImpl {
                        // Need to get an Authority by name
                        ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
                        String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
-                       return getAuthorityItemList(parentcsid, partialTerm, ui);
+                       return getAuthorityItemList(parentcsid, partialTerm, keywords, ui);
                } catch (UnauthorizedException ue) {
                        Response response = Response.status(
                                        Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
index d01f1213cd6e949a732a8b43cc3d1778fa2cd917..695667c20e4283671812d4d44ba42b4c5cf26a53 100644 (file)
@@ -194,15 +194,19 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl {
     }
 
     /**
-     * Read item list, filtering by partial term match.
+     * Read item list, filtering by partial term match, or keywords. Only one of
+     * partialTerm or keywords should be specified. If both are specified, keywords
+     * will be ignored.
      *
      * @param vcsid the vcsid
      * @param partialTerm A partial term on which to match,
      *     which will filter list results to return only matched resources.
+     * @param keywords A set of keywords on which to match,
+     *     which will filter list results to return only matched resources.
      * @return the client response
      */
-    public ClientResponse<PersonsCommonList> readItemList(String vcsid, String partialTerm) {
-        return personAuthorityProxy.readItemList(vcsid, partialTerm);
+    public ClientResponse<PersonsCommonList> readItemList(String vcsid, String partialTerm, String keywords) {
+        return personAuthorityProxy.readItemList(vcsid, partialTerm, keywords);
     }
 
     /**
index 56faaf1869d0aa24e9c36c013925677727f02069..ad3a0eaf013a02e03e1472dc0d77e2afa47cbc4c 100644 (file)
@@ -69,7 +69,8 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy {
     @Path("/{csid}/items/")
     ClientResponse<PersonsCommonList>readItemList(
             @PathParam("csid") String parentcsid,
-            @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm);
+            @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm,
+            @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords);
 
     /**
      * @param parentcsid 
index a6558eafc3538bccbee271e78c3e00c7a412f0d0..a8928158a3efcaa09766d24032d0ff0a69f17200 100644 (file)
@@ -72,6 +72,10 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
     //
     // shortId
     final String TEST_SHORT_ID = "lechWalesa";
+    
+    final String TEST_KWD_BIRTH_PLACE = "Gdansk"; // Probably wrong on facts
+
+    final String TEST_KWD_NO_MATCH = "Foobar";
 
     // Non-existent partial term name (first letters of each of the words
     // in a pangram for the English alphabet).
@@ -143,6 +147,14 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         }
     }
 
+    private String getKwdTerm() {
+        return TEST_KWD_BIRTH_PLACE;
+    }
+
+    private String getKwdTermNonExistent() {
+        return TEST_KWD_NO_MATCH;
+    }
+
     @BeforeClass
     public void setup() {
         try {
@@ -177,7 +189,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         if (logger.isDebugEnabled()) {
             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
         }
-        numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm);
+        numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
         if (logger.isDebugEnabled()) {
             logger.debug("Found " + numMatchesFound + " match(es), expected " +
                 NUM_MATCHES_EXPECTED + " match(es).");
@@ -203,7 +215,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
         }
         numMatchesFound =
-            readItemListByPartialTerm(knownResourceId, partialTerm);
+               readItemListWithFilters(testName, knownResourceId, partialTerm, null);
                 if (logger.isDebugEnabled()) {
         logger.debug("Found " + numMatchesFound + " match(es), expected " +
                 NUM_MATCHES_EXPECTED + " match(es).");
@@ -229,7 +241,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
         }
         numMatchesFound =
-            readItemListByPartialTerm(knownResourceId, partialTerm);
+               readItemListWithFilters(testName, knownResourceId, partialTerm, null);
         if (logger.isDebugEnabled()) {
             logger.debug("Found " + numMatchesFound + " match(es), expected " +
                 NUM_MATCHES_EXPECTED + " match(es).");
@@ -252,7 +264,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         if (logger.isDebugEnabled()) {
             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
         }
-        numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm);
+        numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
         // Zero matches are expected on a non-existent term.
         if (logger.isDebugEnabled()) {
             logger.debug("Found " + numMatchesFound + " match(es), expected " +
@@ -288,6 +300,28 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
     }
 */
+    /**
+     * Reads an item list by partial term.
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"readListByKwdTerm"}, dependsOnGroups = {"readListByPartialTerm"})
+    public void keywordTermMatch(String testName) {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        int numMatchesFound = 0;
+        String kwdTerm = getKwdTerm();
+        if (logger.isDebugEnabled()) {
+            logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
+        }
+        numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
+        if (logger.isDebugEnabled()) {
+            logger.debug("Found " + numMatchesFound + " match(es), expected " +
+                NUM_MATCHES_EXPECTED + " match(es).");
+        }
+        Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+    }
+
     
     // Failure outcomes
 
@@ -307,7 +341,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         if (logger.isDebugEnabled()) {
             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
         }
-        numMatchesFound = readItemListByPartialTerm(knownResourceId, partialTerm);
+        numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
         // Zero matches are expected on a non-existent term.
         if (logger.isDebugEnabled()) {
             logger.debug("Found " + numMatchesFound + " match(es), expected " +
@@ -317,16 +351,44 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
     }
 
     /**
-     * Reads an item list by partial term, given an authority and a term.
-     *
+     * Reads an item list by partial term, with a partial term that is not
+     * expected to be matched by any term in any resource.
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
+    public void keywordTermMatchOnNonexistentTerm(String testName) {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        int numMatchesFound = 0;
+        int ZERO_MATCHES_EXPECTED = 0;
+        String kwdTerm = getKwdTermNonExistent();
+        if (logger.isDebugEnabled()) {
+            logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
+        }
+        numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
+        // Zero matches are expected on a non-existent term.
+        if (logger.isDebugEnabled()) {
+            logger.debug("Found " + numMatchesFound + " match(es), expected " +
+                ZERO_MATCHES_EXPECTED + " match(es).");
+        }
+        Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
+    }
+
+    /**
+     * Reads an item list by partial term or keywords, given an authority and a term.
+     * Only one of partialTerm or keywords should be specified. 
+     * If both are specified, keywords will be ignored.
+     * 
+     * @param testName Calling test name
      * @param authorityCsid The CSID of the authority within which partial term matching
      *     will be performed.
      * @param partialTerm A partial term to match item resources.
+     * @param partialTerm A keyword list to match item resources.
      * @return The number of item resources matched by the partial term.
      */
-    private int readItemListByPartialTerm(String authorityCsid, String partialTerm) {
-
-        String testName = "readItemListByPartialTerm";
+    private int readItemListWithFilters(String testName, 
+               String authorityCsid, String partialTerm, String keywords) {
 
         // Perform setup.
         int expectedStatusCode = Response.Status.OK.getStatusCode();
@@ -337,7 +399,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         PersonAuthorityClient client = new PersonAuthorityClient();
         ClientResponse<PersonsCommonList> res = null;
         if (authorityCsid != null) {
-           res = client.readItemList(authorityCsid, partialTerm);
+               res = client.readItemList(authorityCsid, partialTerm, keywords);
         } else {
             Assert.fail("readItemListByPartialTerm passed null csid!");
         }
@@ -502,6 +564,7 @@ public class PersonAuthoritySearchTest extends BaseServiceTest {
         partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
         partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
         partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
+        partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
         partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
         MultipartOutput multipart =
             PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName, partialTermPersonMap,