From 9f48cb4e50984f06db04bef2ce35589e84bdeb3b Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 15 Jan 2010 09:22:47 +0000 Subject: [PATCH] CSPACE-753: Added item term search functionality to Person and Organization services. --- .../services/OrganizationJAXBSchema.java | 1 + .../organization/OrgAuthorityResource.java | 17 +++- .../OrganizationDocumentModelHandler.java | 78 ++++++++++++++----- .../services/PersonJAXBSchema.java | 1 + .../person/PersonAuthorityResource.java | 22 +++++- .../nuxeo/PersonDocumentModelHandler.java | 46 +++++++---- 6 files changed, 127 insertions(+), 38 deletions(-) diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java index bd38eca97..72fd1bc33 100644 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java @@ -8,6 +8,7 @@ package org.collectionspace.services; * */ public interface OrganizationJAXBSchema { + final static String ORGANIZATIONS_COMMON="organizations_common"; final static String CSID = "csid"; final static String IN_AUTHORITY = "inAuthority"; final static String DISPLAY_NAME = "displayName"; diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 9af972287..a7a275c7f 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -31,6 +31,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; @@ -38,6 +39,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.common.AbstractCollectionSpaceResource; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -48,6 +50,7 @@ import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.organization.nuxeo.OrgAuthorityHandlerFactory; import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler; import org.collectionspace.services.organization.nuxeo.OrganizationHandlerFactory; @@ -403,6 +406,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResource { @Produces("application/xml") public OrganizationsCommonList getOrganizationList( @PathParam("csid") String parentcsid, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, @Context UriInfo ui) { OrganizationsCommonList organizationObjectList = new OrganizationsCommonList(); try { @@ -412,8 +416,17 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResource { MultivaluedMap queryParams = ui.getQueryParameters(); DocumentFilter myFilter = DocumentFilter.CreatePaginatedDocumentFilter(queryParams); - myFilter.setWhereClause( - "organizations_common:inAuthority='" + parentcsid + "'"); + myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + + ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" + + "'" + parentcsid + "'"); + + // AND organizations_common:displayName LIKE '%partialTerm%' + if (partialTerm != null && !partialTerm.isEmpty()) { + String ptClause = "AND " + OrganizationJAXBSchema.ORGANIZATIONS_COMMON + + ":" + OrganizationJAXBSchema.DISPLAY_NAME + + " LIKE " + "'%" + partialTerm + "%'"; + myFilter.appendWhereClause(ptClause); + } handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList(); diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java index dfebf095b..5f87b59d2 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java @@ -76,21 +76,66 @@ public class OrganizationDocumentModelHandler public void prepare(Action action) throws Exception { //no specific action needed } + + @Override + public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + // first fill all the parts of the document + super.handleCreate(wrapDoc); + handleGetDisplayName(wrapDoc.getWrappedObject()); + } + + private String prepareDefaultDisplayName(DocumentModel docModel) throws Exception { + String result = null; + + result = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), + OrganizationJAXBSchema.SHORT_NAME); + + return result; + } + + /** + * Handle get display name. + * + * @param docModel the doc model + * + * @return the string + * + * @throws Exception the exception + */ + private String handleGetDisplayName(DocumentModel docModel) throws Exception { + return handleGetDisplayName(docModel, true); + } + + /** + * Handle get display name. + * + * @param wrapDoc the wrap doc + * + * @return the string + * + * @throws Exception the exception + */ + private String handleGetDisplayName(DocumentModel docModel, boolean updateDocModel) throws Exception { + String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), + OrganizationJAXBSchema.DISPLAY_NAME); + if (displayName == null) { + displayName = prepareDefaultDisplayName(docModel); + if (updateDocModel == true) { + docModel.setProperty(getServiceContext().getCommonPartLabel( + "organizations"), OrganizationJAXBSchema.DISPLAY_NAME, + displayName); + } + } + + return displayName; + } /* Override handleGet so we can deal with defaulting the displayName * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper) */ @Override public void handleGet(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = wrapDoc.getWrappedObject(); - String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.DISPLAY_NAME); - if(displayName == null) { - displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.SHORT_NAME); - docModel.setProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.DISPLAY_NAME, displayName); - } + handleGetDisplayName(wrapDoc.getWrappedObject()); super.handleGet(wrapDoc); } @@ -153,16 +198,11 @@ public class OrganizationDocumentModelHandler while(iter.hasNext()){ DocumentModel docModel = iter.next(); OrganizationListItem ilistItem = new OrganizationListItem(); - // We look for a set display name, and fall back to teh short name if there is none - String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.DISPLAY_NAME); - if(displayName == null) - displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.SHORT_NAME); - ilistItem.setDisplayName( displayName ); - ilistItem.setRefName( - (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.REF_NAME)); + // We look for a set display name, and fall back to the short name if there is none + String displayName = handleGetDisplayName(docModel, false); + ilistItem.setDisplayName(displayName); + ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel( + "organizations"), OrganizationJAXBSchema.REF_NAME)); /* * These are not currently included in the listing - only in the details ilistItem.setLongName( diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java index b8e3e072b..87aaf3155 100644 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java +++ b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java @@ -8,6 +8,7 @@ package org.collectionspace.services; * */ public interface PersonJAXBSchema { + final static String PERSONS_COMMON = "persons_common"; final static String CSID = "csid"; final static String IN_AUTHORITY = "inAuthority"; final static String REF_NAME = "refName"; diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index cde4cc53a..5719d0c3a 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -31,6 +31,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; @@ -38,6 +39,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.PersonJAXBSchema; import org.collectionspace.services.common.AbstractCollectionSpaceResource; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -48,6 +50,7 @@ import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.person.nuxeo.PersonAuthorityHandlerFactory; import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler; import org.collectionspace.services.person.nuxeo.PersonHandlerFactory; @@ -403,6 +406,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResource { @Produces("application/xml") public PersonsCommonList getPersonList( @PathParam("csid") String parentcsid, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, @Context UriInfo ui) { PersonsCommonList personObjectList = new PersonsCommonList(); try { @@ -412,8 +416,22 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResource { MultivaluedMap queryParams = ui.getQueryParameters(); DocumentFilter myFilter = DocumentFilter.CreatePaginatedDocumentFilter(queryParams); - myFilter.setWhereClause( - "persons_common:inAuthority='" + parentcsid + "'"); + + // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" + myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + + PersonJAXBSchema.IN_AUTHORITY + + "='" + parentcsid + "'"); + + // AND persons_common:displayName LIKE '%partialTerm%' + if (partialTerm != null && !partialTerm.isEmpty()) { + String ptClause = "AND " + + PersonJAXBSchema.PERSONS_COMMON + ":" + + PersonJAXBSchema.DISPLAY_NAME + + " LIKE " + + "'%" + partialTerm + "%'"; + myFilter.appendWhereClause(ptClause); + } + handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java index 6db5909e7..3619a3c33 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java @@ -82,19 +82,38 @@ public class PersonDocumentModelHandler public void prepare(Action action) throws Exception { //no specific action needed } - + + @Override + public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + // first fill all the parts of the document + super.handleCreate(wrapDoc); + handleGetDisplayName(wrapDoc.getWrappedObject()); + } + + private String handleGetDisplayName(DocumentModel docModel) throws Exception { + return handleGetDisplayName(docModel, true); + } + + private String handleGetDisplayName(DocumentModel docModel, boolean updateDocModel) throws Exception { + String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), + PersonJAXBSchema.DISPLAY_NAME); + if (displayName == null) { + displayName = prepareDefaultDisplayName(docModel); + if (updateDocModel == true) { + docModel.setProperty(getServiceContext().getCommonPartLabel( + "persons"), PersonJAXBSchema.DISPLAY_NAME, displayName); + } + } + + return displayName; + } + /* Override handleGet so we can deal with defaulting the displayName * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleGet(org.collectionspace.services.common.document.DocumentWrapper) */ @Override public void handleGet(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = wrapDoc.getWrappedObject(); - String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), - PersonJAXBSchema.DISPLAY_NAME); - if(displayName == null) { - docModel.setProperty(getServiceContext().getCommonPartLabel("persons"), - PersonJAXBSchema.DISPLAY_NAME, prepareDefaultDisplayName(docModel)); - } + handleGetDisplayName(wrapDoc.getWrappedObject()); super.handleGet(wrapDoc); } @@ -223,13 +242,10 @@ public class PersonDocumentModelHandler DocumentModel docModel = iter.next(); PersonListItem ilistItem = new PersonListItem(); // We look for a set display name, and fall back to teh short name if there is none - String displayName = (String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), - PersonJAXBSchema.DISPLAY_NAME); - if(displayName == null) - displayName = prepareDefaultDisplayName(docModel); - ilistItem.setDisplayName( displayName ); - ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel("persons"), - PersonJAXBSchema.REF_NAME)); + String displayName = handleGetDisplayName(docModel, false); + ilistItem.setDisplayName(displayName); + ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel( + "persons"), PersonJAXBSchema.REF_NAME)); String id = NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setUri("/personauthorities/"+inAuthority+"/items/" + id); ilistItem.setCsid(id); -- 2.47.3