]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4875 Added support to get the list of docTypes associated to a given service...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 2 Mar 2012 21:58:53 +0000 (13:58 -0800)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 2 Mar 2012 21:58:53 +0000 (13:58 -0800)
services/common/src/main/java/org/collectionspace/services/common/config/TenantBindingConfigReaderImpl.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java

index edde4fe634f086cedc2f90a2aa4732e8929de57f..1cd35ed8032722d0d837229ca1fb0e62d2c3fc7f 100644 (file)
@@ -386,6 +386,18 @@ public class TenantBindingConfigReaderImpl
         return docTypes.get(key);
     }
 
+    /**
+     * getServiceBinding gets service binding for given tenant for a given service
+     * @param tenantId
+     * @param serviceName
+     * @return
+     */
+    public List<ServiceBindingType> getServiceBindingsByType(
+            String tenantId, String serviceType) {
+       List<String> serviceTypes = new ArrayList<String>(1);
+       serviceTypes.add(serviceType);
+       return getServiceBindingsByType(tenantId, serviceTypes);
+    }
     /**
      * getServiceBinding gets service binding for given tenant for a given service
      * @param tenantId
index a59bd93fa145cd536dedcd61fd6591407c857aaa..648ec8d5717eed2191dbb2314d722608cdfaa79c 100644 (file)
@@ -25,6 +25,7 @@ package org.collectionspace.services.servicegroup;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 
 import org.collectionspace.services.ServiceGroupListItemJAXBSchema;
 import org.collectionspace.services.client.IQueryManager;
@@ -34,8 +35,10 @@ import org.collectionspace.services.client.ServiceGroupClient;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ResourceBase;
+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.RemoteServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.context.ServiceContextFactory;
@@ -43,6 +46,8 @@ 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.query.QueryManager;
+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.nuxeo.ecm.core.api.DocumentModel;
@@ -106,7 +111,18 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
         PoxPayloadOut result = null;
         ensureCSID(groupname, ResourceBase.READ);
         try {
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
+               ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
+            TenantBindingConfigReaderImpl tReader =
+                    ServiceMain.getInstance().getTenantBindingConfigReader();
+            // We need to get all the procedures, authorities, and objects.
+            List<ServiceBindingType> servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), groupname);
+            if (servicebindings == null || servicebindings.isEmpty()) {
+               // 404 if there are no mappings.
+                Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                        ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(groupname)).type("text/plain").build();
+                throw new WebApplicationException(response);
+            }
+               //Otherwise, build the response with a list
             ServicegroupsCommon common = new ServicegroupsCommon();
             common.setName(groupname);
             String uri = "/" + getServicePathComponent() + "/" + groupname;
@@ -114,13 +130,19 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl {
             result = new PoxPayloadOut(getServicePathComponent());
             result.addPart("ServicegroupsCommon", common);
             
-            /* If we cannot get the result, then...
-            if (result == null) {
-                Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                        ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build();
-                throw new WebApplicationException(response);
-            }
-            */
+               ServicegroupsCommon.HasDocTypes wrapper = common.getHasDocTypes();
+               if(wrapper==null) {
+                       wrapper = new ServicegroupsCommon.HasDocTypes();
+                       common.setHasDocTypes(wrapper);
+               }
+               List<String> hasDocTypes = wrapper.getHasDocType();
+               for(ServiceBindingType binding:servicebindings) {
+                       ServiceObjectType serviceObj = binding.getObject();
+                       if(serviceObj!=null) {
+                       String docType = serviceObj.getName();
+                       hasDocTypes.add(docType);
+                       }
+               }
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.READ_FAILED, groupname);
         }