From 790215a8dd3e7b60abd3b864ae961c97c6afd9a8 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Thu, 19 Apr 2012 13:04:53 -0700 Subject: [PATCH] CSPACE-5024 Added support in services to search across all vocabs of a given authority type. Only supports search, but supports all forms (keyword, partial term, advanced search). Callers must pass "_ALL_" as the parent specifier to access this. E.g. http://localhost:8180/cspace-services/personauthorities/_ALL_/items/?pt=joe --- .../common/vocabulary/AuthorityResource.java | 24 ++++++++++++------- .../AuthorityItemDocumentModelHandler.java | 22 +++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) 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 bf47c2dae..4e4e6dce9 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 @@ -124,6 +124,8 @@ public abstract class AuthorityResource final static String URN_PREFIX_ID = "id("; final static int URN_ID_PREFIX_LEN = URN_PREFIX_LEN + URN_PREFIX_ID.length(); final static String FETCH_SHORT_ID = "_fetch_"; + final static String PARENT_WILDCARD = "_ALL_"; + final Logger logger = LoggerFactory.getLogger(AuthorityResource.class); public enum SpecifierForm { @@ -661,12 +663,15 @@ public abstract class AuthorityResource // Note that docType defaults to the ServiceName, so we're fine with that. ServiceContext ctx = null; - String parentcsid = lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams); + String parentcsid = PARENT_WILDCARD.equals(specifier)?null: + lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams); ctx = createServiceContext(getItemServiceName(), queryParams); + + // For the wildcard case, parentcsid is null, but docHandler will deal with this. // We omit the parentShortId, only needed when doing a create... - DocumentHandler handler = createItemDocumentHandler(ctx, - parentcsid, null); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); + DocumentFilter myFilter = handler.getDocumentFilter(); // Need to make the default sort order for authority items // be on the displayName field @@ -674,11 +679,14 @@ public abstract class AuthorityResource if (sortBy == null || sortBy.isEmpty()) { myFilter.setOrderByClause(qualifiedDisplayNameField); } - - myFilter.appendWhereClause(authorityItemCommonSchemaName + ":" - + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" - + "'" + parentcsid + "'", - IQueryManager.SEARCH_QUALIFIER_AND); + + // If we are not wildcarding the parent, add a restriction + if(parentcsid!=null) { + myFilter.appendWhereClause(authorityItemCommonSchemaName + ":" + + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" + + "'" + parentcsid + "'", + IQueryManager.SEARCH_QUALIFIER_AND); + } if (Tools.notBlank(termStatus)) { // Start with the qualified termStatus field diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index f251ee25a..e439c38b3 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -58,6 +58,7 @@ import org.collectionspace.services.relation.RelationsCommon; import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationsDocListItem; import org.collectionspace.services.relation.RelationshipType; +import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.model.PropertyException; import org.nuxeo.ecm.core.api.model.PropertyNotFoundException; @@ -93,8 +94,8 @@ public abstract class AuthorityItemDocumentModelHandler /** * inVocabulary is the parent Authority for this context */ - protected String inAuthority; - protected String authorityRefNameBase; + protected String inAuthority = null; + protected String authorityRefNameBase = null; // Used to determine when the displayName changes as part of the update. protected String oldDisplayNameOnUpdate = null; protected String oldRefNameOnUpdate = null; @@ -104,10 +105,6 @@ public abstract class AuthorityItemDocumentModelHandler this.authorityItemCommonSchemaName = authorityItemCommonSchemaName; } - public String getInAuthority() { - return inAuthority; - } - public void setInAuthority(String inAuthority) { this.inAuthority = inAuthority; } @@ -121,10 +118,18 @@ public abstract class AuthorityItemDocumentModelHandler public String getUri(DocumentModel docModel) { // Laramie20110510 CSPACE-3932 String authorityServicePath = getAuthorityServicePath(); + if(inAuthority==null) { // Only happens on queries to wildcarded authorities + try { + inAuthority = (String) docModel.getProperty(authorityItemCommonSchemaName, + AuthorityItemJAXBSchema.IN_AUTHORITY); + } catch (ClientException pe) { + throw new RuntimeException("Could not get parent specifier for item!"); + } + } return "/" + authorityServicePath + '/' + inAuthority + '/' + AuthorityClient.ITEMS + '/' + getCsid(docModel); } - public String getAuthorityRefNameBase() { + protected String getAuthorityRefNameBase() { return this.authorityRefNameBase; } @@ -346,6 +351,9 @@ public abstract class AuthorityItemDocumentModelHandler * @throws Exception the exception */ private void handleInAuthority(DocumentModel docModel) throws Exception { + if(inAuthority==null) { // Only happens on queries to wildcarded authorities + throw new IllegalStateException("Trying to Create an object with no inAuthority value!"); + } docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority); } -- 2.47.3