From 0e604880e5da3cf5e60d7a5ee9e41a3b4bf4eccc Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Tue, 15 Nov 2011 23:29:58 +0000 Subject: [PATCH] CSPACE-4394 - Added a "ts" filter parameter to the list/search for authority items. Takes a pipe ('|', a.k.a. %7C when URL encoded) separated list of strings that will be matched against the termStatus. All terms with a matching term status will be excluded from the results. This can result in 0 results, without problems. This can also be combined with other params, including pt. --- .../person/personTermStatusSearch.xml | 83 +++++++++++++++++++ .../xmlreplay/person/person_pmadry.xml | 2 +- .../xmlreplay/person/person_pschmitz.xml | 2 +- .../person/res/personlistActive.res.xml | 11 +++ .../person/res/personlistAll.res.xml | 14 ++++ .../person/res/personlistNone.res.xml | 8 ++ .../common/vocabulary/AuthorityResource.java | 14 +++- .../services/client/IQueryManager.java | 13 +++ .../services/common/query/QueryManager.java | 13 +++ .../query/nuxeo/QueryManagerNuxeoImpl.java | 32 +++++++ 10 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personTermStatusSearch.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistActive.res.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistAll.res.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistNone.res.xml diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personTermStatusSearch.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personTermStatusSearch.xml new file mode 100644 index 000000000..499951824 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personTermStatusSearch.xml @@ -0,0 +1,83 @@ + + + + + + POST + /cspace-services/personauthorities/ + person/personauthorities_common.xml + + TermStatusTestAuth + + + + POST + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/ + person/person_pschmitz.xml + + Approved + + + + POST + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/ + person/person_pmadry.xml + + Inactive + + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items + + + person/res/personlistAll.res.xml + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items?ts=Inactive + + + person/res/personlistActive.res.xml + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items?ts=Garbage + + + person/res/personlistAll.res.xml + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items?ts=Inactive%7CApproved + + + person/res/personlistNone.res.xml + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items?pt=Patrick + + + person/res/personlistActive.res.xml + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items?pt=Patrick&ts=Approved + + + person/res/personlistNone.res.xml + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pmadry.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pmadry.xml index 6e4b9731e..b6b8a196f 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pmadry.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pmadry.xml @@ -2,11 +2,11 @@ pmadry - urn:cspace:org.collectionspace.demo:personauthority:name(testpersonauth):person:name(pmadry)'Penelope Madry' false false Penelope Madry Penelope Madry, New York + ${termStatus} Project Manager for CollectionSpace diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pschmitz.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pschmitz.xml index 585a15d30..ee908b055 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pschmitz.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person_pschmitz.xml @@ -2,11 +2,11 @@ pschmitz - urn:cspace:org.collectionspace.demo:personauthority:name(testpersonauth):person:name(pschmitz)'Patrick Schmitz' false false Patrick Schmitz Patrick Schmitz, Berkeley + ${termStatus} Technical Lead for CollectionSpace This is a test PersonAuthority item Some mythical book diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistActive.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistActive.res.xml new file mode 100644 index 000000000..9fe8400f4 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistActive.res.xml @@ -0,0 +1,11 @@ + + + 0 + 40 + 1 + csid|uri|updatedAt|displayName|shortIdentifier|refName|termStatus + + pschmitz + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistAll.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistAll.res.xml new file mode 100644 index 000000000..322dbe506 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistAll.res.xml @@ -0,0 +1,14 @@ + + + 0 + 40 + 2 + csid|uri|updatedAt|displayName|shortIdentifier|refName|termStatus + + pschmitz + + + pmadry + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistNone.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistNone.res.xml new file mode 100644 index 000000000..8f085a324 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/res/personlistNone.res.xml @@ -0,0 +1,8 @@ + + + 0 + 40 + 0 + csid|uri|updatedAt|displayName|shortIdentifier|refName|termStatus + + diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index 0ada88dd6..f72d750c5 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -103,6 +103,8 @@ import java.util.List; @Produces("application/xml") public abstract class AuthorityResource extends ResourceBase { + + final static String SEARCH_TYPE_TERMSTATUS = "ts"; protected Class authCommonClass; protected Class resourceClass; @@ -638,6 +640,7 @@ public abstract class AuthorityResource try { MultivaluedMap queryParams = ui.getQueryParameters(); String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM); + String termStatus = queryParams.getFirst(SEARCH_TYPE_TERMSTATUS); String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); String advancedSearch = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_AS); @@ -660,12 +663,21 @@ public abstract class AuthorityResource if (sortBy == null || sortBy.isEmpty()) { myFilter.setOrderByClause(qualifiedDisplayNameField); } - + myFilter.appendWhereClause(authorityItemCommonSchemaName + ":" + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" + "'" + parentcsid + "'", IQueryManager.SEARCH_QUALIFIER_AND); + if (Tools.notBlank(termStatus)) { + // Start with the qualified termStatus field + String qualifiedTermStatusField = authorityItemCommonSchemaName + ":" + + AuthorityItemJAXBSchema.TERM_STATUS; + String[] filterTerms = termStatus.trim().split("\\|"); + String tsClause = QueryManager.createWhereClauseToFilterFromStringList(qualifiedTermStatusField, filterTerms, IQueryManager.FILTER_EXCLUDE); + myFilter.appendWhereClause(tsClause, IQueryManager.SEARCH_QUALIFIER_AND); + } + // AND vocabularyitems_common:displayName LIKE '%partialTerm%' // NOTE: Partial terms searches are mutually exclusive to keyword and advanced-search, but // the PT query param trumps the KW and AS query params. diff --git a/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java b/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java index 493d5fa3a..ceac6ee94 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java +++ b/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java @@ -56,6 +56,19 @@ public interface IQueryManager { public String createWhereClauseFromAdvancedSearch(String advancedSearch); + final static boolean FILTER_EXCLUDE = true; + final static boolean FILTER_INCLUDE = false; + + /** + * Creates a query to filter a qualified (string) field according to a list of string values. + * @param qualifiedField The schema-qualified field to filter on + * @param filterTerms the list of one or more strings to filter on + * @param fExclude If true, will require qualifiedField NOT match the filters strings. + * If false, will require qualifiedField does match one of the filters strings. + * @return queryString + */ + public String createWhereClauseToFilterFromStringList(String qualifiedField, String[] filterTerms, boolean fExclude); + /** * Creates the where clause for partial term match. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java b/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java index 8a0e0c0a0..86be6ed1c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java @@ -63,6 +63,19 @@ public class QueryManager { return queryManager.createWhereClauseForPartialMatch(field, partialTerm); } + /** + * Creates a query to filter a qualified (string) field according to a list of string values. + * @param qualifiedField The schema-qualified field to filter on + * @param filterTerms the list of one or more strings to filter on + * @param fExclude If true, will require qualifiedField NOT match the filters strings. + * If false, will require qualifiedField does match one of the filters strings. + * @return queryString + */ + static public String createWhereClauseToFilterFromStringList(String qualifiedField, String[] filterTerms, boolean fExclude) { + return queryManager.createWhereClauseToFilterFromStringList(qualifiedField, filterTerms, fExclude); + } + + /** * Creates a filtering where clause from docType, for invocables. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java index 16be5b55a..e7a8282c8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java @@ -296,4 +296,36 @@ public class QueryManagerNuxeoImpl implements IQueryManager { return fFilteredChars; } + + /** + * Creates a query to filter a qualified (string) field according to a list of string values. + * @param qualifiedField The schema-qualified field to filter on + * @param filterTerms the list of one or more strings to filter on + * @param fExclude If true, will require qualifiedField NOT match the filters strings. + * If false, will require qualifiedField does match one of the filters strings. + * @return queryString + */ + @Override + public String createWhereClauseToFilterFromStringList(String qualifiedField, String[] filterTerms, boolean fExclude) { + // Start with the qualified termStatus field + StringBuilder filterClause = new StringBuilder(qualifiedField); + if(filterTerms.length == 1) { + filterClause.append(fExclude?" <> '":" = '"); + filterClause.append(filterTerms[0]); + filterClause.append('\''); + } else { + filterClause.append(fExclude?" NOT IN (":" IN ("); + for(int i=0; i0) { + filterClause.append(','); + } + filterClause.append('\''); + filterClause.append(filterTerms[i]); + filterClause.append('\''); + } + filterClause.append(')'); + } + return filterClause.toString(); + } + } -- 2.47.3