]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-753: Added item term search functionality to Person and Organization services.
authorRichard Millet <richard.millet@berkeley.edu>
Fri, 15 Jan 2010 09:22:47 +0000 (09:22 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Fri, 15 Jan 2010 09:22:47 +0000 (09:22 +0000)
services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java
services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java
services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonDocumentModelHandler.java

index bd38eca9713b4e118474527283101676a3ff9bff..72fd1bc33ec18db3f63f6563f11e75484d71c6f6 100644 (file)
@@ -8,6 +8,7 @@ package org.collectionspace.services;
  *\r
  */\r
 public interface OrganizationJAXBSchema {\r
+       final static String ORGANIZATIONS_COMMON="organizations_common";        \r
        final static String CSID = "csid";\r
        final static String IN_AUTHORITY = "inAuthority";\r
        final static String DISPLAY_NAME = "displayName";\r
index 9af972287ad5acf0a210e8f492ebbc050955e29d..a7a275c7fc997d5380b9933fb076ba80e6ef64cb 100644 (file)
@@ -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<String, String> 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();
index dfebf095bb14f287a188e0ca4b1c4a0c0ef57e42..5f87b59d27447ce04ed5ec4d2c589476bb904dd1 100644 (file)
@@ -76,21 +76,66 @@ public class OrganizationDocumentModelHandler
     public void prepare(Action action) throws Exception {
         //no specific action needed
     }
+       
+    @Override
+    public void handleCreate(DocumentWrapper<DocumentModel> 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<DocumentModel> 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(
index b8e3e072b8385e97132437fcc6ec5222ce73d0ea..87aaf31551f400a83208f468f25204abc54edc45 100644 (file)
@@ -8,6 +8,7 @@ package org.collectionspace.services;
  *\r
  */\r
 public interface PersonJAXBSchema {\r
+       final static String PERSONS_COMMON = "persons_common";\r
        final static String CSID = "csid";\r
        final static String IN_AUTHORITY = "inAuthority";\r
        final static String REF_NAME = "refName";\r
index cde4cc53a47315e843b0f10d988dcac5f7b17050..5719d0c3a83ba224c31d12a812b5080aae6e93ab 100644 (file)
@@ -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<String, String> 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();
index 6db5909e7a6d55a04328e208bde7854c0e43d6a6..3619a3c33bf79057047d17f628b446f62458773e 100644 (file)
@@ -82,19 +82,38 @@ public class PersonDocumentModelHandler
     public void prepare(Action action) throws Exception {
         //no specific action needed
     }
-
+       
+    @Override
+    public void handleCreate(DocumentWrapper<DocumentModel> 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<DocumentModel> 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);