]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4875 Filled out the kw search support, returning list of items by serviceGroup...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 6 Mar 2012 01:08:30 +0000 (17:08 -0800)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 6 Mar 2012 01:08:30 +0000 (17:08 -0800)
services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml
services/common/src/main/java/org/collectionspace/services/common/context/ServiceBindingUtils.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java

index 382565066ff71832c74e8f1e0b4d7c5cfbf04636..296bffd472aa20d5b94bde1902a1afd1084c1f8e 100644 (file)
@@ -68,7 +68,8 @@
                                 but provides tools like keyword search across many types of services. 
                  -->
     <tenant:serviceBindings id="servicegroups" name="servicegroups" type="utility" version="0.1">
-           <!-- other URI paths through which this service could be accessed -->
+      <service:repositoryDomain xmlns:service="http://collectionspace.org/services/common/service">default-domain</service:repositoryDomain>
+      <service:documentHandler xmlns:service="http://collectionspace.org/services/common/service">org.collectionspace.services.servicegroup.nuxeo.ServiceGroupDocumentModelHandler</service:documentHandler>
     </tenant:serviceBindings>
     <!-- end servicegroup service meta-data -->
 
index eae2b3da6caae2dda0b8fd565856225d561f0882..bdbead40a4ae61585bb9068bbac9b348b1ef609f 100644 (file)
@@ -157,5 +157,19 @@ public class ServiceBindingUtils {
                                "getMappedFieldInDoc: Problem fetching: "+propName+" logicalfieldName: "+logicalFieldName+" docModel: "+docModel, ce);\r
        }\r
     } \r
+    \r
+    private static ArrayList<String> commonServiceTypes = null;\r
+    \r
+    public static ArrayList<String> getCommonServiceTypes() {\r
+       if(commonServiceTypes == null) {\r
+               commonServiceTypes = new ArrayList<String>();\r
+               commonServiceTypes.add(SERVICE_TYPE_AUTHORITY);\r
+               commonServiceTypes.add(SERVICE_TYPE_OBJECT);\r
+               commonServiceTypes.add(SERVICE_TYPE_PROCEDURE);\r
+       }\r
+       return commonServiceTypes;\r
+    }\r
+    \r
+\r
 \r
 }\r
index 92ff4be67ec58f1b4d489b284938bd11ddb280e2..76156efadbfb131d597018dcd9f0e5339cd035ee 100644 (file)
 package org.collectionspace.services.common.security;
 
 import java.security.MessageDigest;
+import java.util.ArrayList;
 import java.util.List;
 import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
 import java.util.StringTokenizer;
 
+import org.collectionspace.services.authorization.AuthZ;
+import org.collectionspace.services.authorization.CSpaceResource;
+import org.collectionspace.services.authorization.URIResourceImpl;
+import org.collectionspace.services.common.service.ServiceBindingType;
+import org.collectionspace.services.common.service.ServiceObjectType;
+
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
@@ -188,6 +195,21 @@ public class SecurityUtils {
                return result;
        }
     
+       public static List<ServiceBindingType> getReadableServiceBindingsForCurrentUser(
+                       List<ServiceBindingType> serviceBindings) {
+               ArrayList<ServiceBindingType> readableList = 
+                               new ArrayList<ServiceBindingType>(serviceBindings.size());
+               AuthZ authZ = AuthZ.get();
+       for(ServiceBindingType binding:serviceBindings) {
+               String resourceName = binding.getName().toLowerCase();
+               CSpaceResource res = new URIResourceImpl(resourceName, "GET");
+               if (authZ.isAccessAllowed(res) == true) {
+                       readableList.add(binding);
+               }
+       }
+       return readableList;
+       }
+    
     /**
      * Checks if is entity is action as a proxy for all sub-resources.
      *
index b0272b0a8d19bac929eaafab800ab7f3f1328161..92a01600658386c36747bda44098d227f0afeb3c 100644 (file)
@@ -58,6 +58,7 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.repository.RepositoryClient;\r
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;\r
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
+import org.collectionspace.services.common.security.SecurityUtils;\r
 import org.collectionspace.services.common.service.ServiceBindingType;\r
 import org.collectionspace.services.jaxb.AbstractCommonList;\r
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
@@ -329,6 +330,8 @@ public class RefNameServiceUtils {
                logger.error("RefNameServiceUtils.getAuthorityRefDocs: No services bindings found, cannot proceed!");\r
             return null;\r
         }\r
+        // Filter the list for current user rights\r
+        servicebindings = SecurityUtils.getReadableServiceBindingsForCurrentUser(servicebindings);\r
         \r
         // Need to escape the quotes in the refName\r
         // TODO What if they are already escaped?\r
index 91ae0a9b2450428d75b481800834d42e2ca8ed1c..8d13e45c7b228a36d37352b040cadb8b9c1abd50 100644 (file)
@@ -69,6 +69,9 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
     private AbstractCommonList commonList;\r
     \r
     protected static final int NUM_STANDARD_LIST_RESULT_FIELDS = 3;\r
+    protected static final String STANDARD_LIST_CSID_FIELD = "csid";\r
+    protected static final String STANDARD_LIST_URI_FIELD = "uri";\r
+    protected static final String STANDARD_LIST_UPDATED_AT_FIELD = "updatedAt";\r
 \r
     @Override\r
     public AbstractCommonList getCommonPartList() {\r
@@ -184,9 +187,9 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
         List<ListResultField> resultsFields = getListItemsArray();\r
         int nFields = resultsFields.size()+NUM_STANDARD_LIST_RESULT_FIELDS;\r
         String fields[] = new String[nFields];\r
-        fields[0] = "csid";\r
-        fields[1] = "uri";\r
-        fields[2] = "updatedAt";\r
+        fields[0] = STANDARD_LIST_CSID_FIELD;\r
+        fields[1] = STANDARD_LIST_URI_FIELD;\r
+        fields[2] = STANDARD_LIST_UPDATED_AT_FIELD;\r
         for(int i=NUM_STANDARD_LIST_RESULT_FIELDS;i<nFields;i++) {\r
                ListResultField field = resultsFields.get(i-NUM_STANDARD_LIST_RESULT_FIELDS); \r
                fields[i]=field.getElement();\r
@@ -197,10 +200,10 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
         while(iter.hasNext()){\r
             DocumentModel docModel = iter.next();\r
             String id = NuxeoUtils.getCsid(docModel);\r
-            item.put(fields[0], id);\r
+            item.put(STANDARD_LIST_CSID_FIELD, id);\r
             String uri = getUri(docModel);\r
-            item.put(fields[1], uri);\r
-            item.put(fields[2], getUpdatedAtAsString(docModel));\r
+            item.put(STANDARD_LIST_URI_FIELD, uri);\r
+            item.put(STANDARD_LIST_UPDATED_AT_FIELD, getUpdatedAtAsString(docModel));\r
 \r
             for (ListResultField field : resultsFields ){\r
                String schema = field.getSchema();\r
index 648ec8d5717eed2191dbb2314d722608cdfaa79c..7f89309b7e0482e4da3d8dbfbaba38f5096858b5 100644 (file)
@@ -39,19 +39,30 @@ import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
+import org.collectionspace.services.common.context.ServiceBindingUtils;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.context.ServiceContextFactory;
+import org.collectionspace.services.common.document.DocumentException;
 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.document.DocumentWrapper;
 import org.collectionspace.services.common.query.QueryManager;
+import org.collectionspace.services.common.repository.RepositoryClient;
+import org.collectionspace.services.common.repository.RepositoryClientFactory;
 import org.collectionspace.services.common.service.ServiceBindingType;
 import org.collectionspace.services.common.service.ServiceObjectType;
 import org.collectionspace.services.nuxeo.client.java.CommonList;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.collectionspace.services.servicegroup.nuxeo.ServiceGroupDocumentModelHandler;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.model.PropertyException;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
@@ -68,7 +79,9 @@ import javax.ws.rs.core.UriInfo;
 @Produces({"application/xml"})
 @Consumes({"application/xml"})
 public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
-       
+
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+    
     @Override
     public String getServiceName(){
         return ServiceGroupClient.SERVICE_NAME;
@@ -96,10 +109,50 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
 
     @Override
     public ServiceContextFactory<PoxPayloadIn, PoxPayloadOut> getServiceContextFactory() {
-        return RemoteServiceContextFactory.get();
+        return MultipartServiceContextFactory.get();
     }
 
 
+    //======================= GET without specifier: List  =====================================
+    @GET
+    public AbstractCommonList getList(@Context UriInfo ui) {
+        try {
+            CommonList commonList = new CommonList();
+            AbstractCommonList list = (AbstractCommonList)commonList;
+               ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
+               String commonSchema = ctx.getCommonPartLabel();
+               ArrayList<String> svcGroups = new ArrayList<String>();
+               svcGroups.add("procedure");
+               svcGroups.add("object");
+               svcGroups.add("authority");
+               // Fetch the list of groups from the tenant-bindings config, and prepare a list item
+               // for each one.
+               // We always declare this a full list, of the size that we are returning. 
+               // Not quite in the spirit of what paging means, but tells callers not to ask for more.
+               list.setPageNum(0);
+               list.setPageSize(svcGroups.size());
+               list.setItemsInPage(svcGroups.size());
+               list.setTotalItems(svcGroups.size());
+               String fields[] = new String[2];
+               fields[0] = ServiceGroupListItemJAXBSchema.NAME;
+               fields[1] = ServiceGroupListItemJAXBSchema.URI;
+               commonList.setFieldsReturned(fields);
+                       HashMap<String,String> item = new HashMap<String,String>();
+               for(String groupName:svcGroups){
+                   item.put(ServiceGroupListItemJAXBSchema.NAME, groupName);
+                   String uri = "/" + getServiceName().toLowerCase() + "/" + groupName;
+                   item.put(ServiceGroupListItemJAXBSchema.URI, uri);
+                   commonList.addItem(item);
+                   item.clear();
+               }
+               return list;
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.LIST_FAILED);
+        }
+        
+    }
+
+    
     //======================= GET ====================================================
     // NOTE that csid is not a good name for the specifier, but if we name it anything else, 
     // our AuthZ gets confused!!!
@@ -115,7 +168,14 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
             TenantBindingConfigReaderImpl tReader =
                     ServiceMain.getInstance().getTenantBindingConfigReader();
             // We need to get all the procedures, authorities, and objects.
-            List<ServiceBindingType> servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupname);
+               ArrayList<String> groupsList = null;  
+               if("common".equalsIgnoreCase(groupname)) {
+                       groupsList = ServiceBindingUtils.getCommonServiceTypes();
+               } else {
+                       groupsList = new ArrayList<String>();
+                       groupsList.add(groupname);
+               }
+            List<ServiceBindingType> servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupsList);
             if (servicebindings == null || servicebindings.isEmpty()) {
                // 404 if there are no mappings.
                 Response response = Response.status(Response.Status.NOT_FOUND).entity(
@@ -151,44 +211,33 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
     }
 
 
-    //======================= GET without specifier: List  =====================================
     @GET
-    public AbstractCommonList getList(@Context UriInfo ui) {
+    @Path("{csid}/items")
+    public AbstractCommonList getItems(
+            @Context UriInfo ui,
+            @PathParam("csid") String serviceGroupName) {
+        ensureCSID(serviceGroupName, ResourceBase.READ);
+        AbstractCommonList list = null;
         try {
-            CommonList commonList = new CommonList();
-            AbstractCommonList list = (AbstractCommonList)commonList;
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+            String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW);
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
-               String commonSchema = ctx.getCommonPartLabel();
-               ArrayList<String> svcGroups = new ArrayList<String>();
-               svcGroups.add("procedure");
-               svcGroups.add("object");
-               svcGroups.add("authority");
-               // Fetch the list of groups from the tenant-bindings config, and prepare a list item
-               // for each one.
-               // We always declare this a full list, of the size that we are returning. 
-               // Not quite in the spirit of what paging means, but tells callers not to ask for more.
-               list.setPageNum(0);
-               list.setPageSize(svcGroups.size());
-               list.setItemsInPage(svcGroups.size());
-               list.setTotalItems(svcGroups.size());
-               String fields[] = new String[2];
-               fields[0] = ServiceGroupListItemJAXBSchema.NAME;
-               fields[1] = ServiceGroupListItemJAXBSchema.URI;
-               commonList.setFieldsReturned(fields);
-                       HashMap<String,String> item = new HashMap<String,String>();
-               for(String groupName:svcGroups){
-                   item.put(ServiceGroupListItemJAXBSchema.NAME, groupName);
-                   String uri = "/" + getServiceName().toLowerCase() + "/" + groupName;
-                   item.put(ServiceGroupListItemJAXBSchema.URI, uri);
-                   commonList.addItem(item);
-                   item.clear();
+               ServiceGroupDocumentModelHandler handler = (ServiceGroupDocumentModelHandler)
+                                               createDocumentHandler(ctx);
+               ArrayList<String> groupsList = null;  
+               if("common".equalsIgnoreCase(serviceGroupName)) {
+                       groupsList = ServiceBindingUtils.getCommonServiceTypes();
+               } else {
+                       groupsList = new ArrayList<String>();
+                       groupsList.add(serviceGroupName);
                }
-               return list;
+            list = handler.getItemsForGroup(ctx, groupsList, keywords);
         } catch (Exception e) {
-            throw bigReThrow(e, ServiceMessages.LIST_FAILED);
+            throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName);
         }
-        
+
+        return list;
     }
 
-    
+
 }