]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4964: Added stubs for creating lifecycle permissions at init time.
authorRichard Millet <remillet@berkeley.edu>
Wed, 28 Mar 2012 23:23:49 +0000 (16:23 -0700)
committerRichard Millet <remillet@berkeley.edu>
Wed, 28 Mar 2012 23:23:49 +0000 (16:23 -0700)
12 files changed:
services/authorization-mgt/import/build.xml
services/client/pom.xml
services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
services/common-api/pom.xml
services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java
services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java

index bb32302d8b497be820f3f71a134de6b651b5a770..b3a77ee738d8d82e450ca2e9433afebdc12d5ff9 100644 (file)
     <target name="import-windows" if="osfamily-windows" depends="setup_hibernate.cfg">\r
         <exec executable="cmd" failonerror="true">\r
             <arg value="/c" />\r
-            <arg value="mvnDebug.bat" /> <!-- To debug, change command here to be 'mvnDebug.bat' -->\r
+            <arg value="mvn.bat" /> <!-- To debug, change command here to be 'mvnDebug.bat' -->\r
             <arg value="exec:java" />\r
             <arg value="-f" />\r
             <arg value="${basedir}/pom.xml" />\r
index bc4973af3d763539345fe807db417c1b2b5af167..56e2bec73f9f6bdfd08ac857c85ecca4dac6ae47 100644 (file)
             <artifactId>org.collectionspace.services.jaxb</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+                   <artifactId>org.collectionspace.services.common-api</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
         \r
 <!-- External dependencies -->\r
 \r
index 7ec701d0c5ffde06f371dc7349a785e630b3d836..a729108fd8916558473e2de1201aa5014c0c8b3d 100644 (file)
@@ -67,6 +67,7 @@ import org.collectionspace.services.client.PayloadInputPart;
 import org.collectionspace.services.client.PoxPayloadIn;\r
 import org.collectionspace.services.client.TestServiceClient;\r
 import org.collectionspace.services.jaxb.AbstractCommonList;\r
+import org.collectionspace.services.common.api.FileTools;\r
 \r
 /**\r
  * BaseServiceTest.\r
@@ -533,14 +534,11 @@ public abstract class BaseServiceTest<CLT> {
      */\r
     static protected Object getObjectFromFile(Class<?> jaxbClass, String fileName)\r
             throws Exception {\r
-\r
-        JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
-        Unmarshaller unmarshaller = context.createUnmarshaller();\r
-        //note: setting schema to null will turn validator off\r
-        unmarshaller.setSchema(null);\r
-        ClassLoader tccl = Thread.currentThread().getContextClassLoader();\r
-        InputStream is = tccl.getResourceAsStream(fileName);\r
-        return getObjectFromStream(jaxbClass, is);\r
+       Object result = null;\r
+       \r
+       result = FileTools.getJaxbObjectFromFile(jaxbClass, fileName);\r
+       \r
+        return result;\r
     }\r
 \r
     /**\r
@@ -572,21 +570,6 @@ public abstract class BaseServiceTest<CLT> {
         return result;\r
     }\r
 \r
-    /**\r
-     * getObjectFromStream get object of given class from given inputstream\r
-     * @param jaxbClass\r
-     * @param is stream to read to construct the object\r
-     * @return\r
-     * @throws Exception\r
-     */\r
-    static protected Object getObjectFromStream(Class<?> jaxbClass, InputStream is) throws Exception {\r
-        JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
-        Unmarshaller unmarshaller = context.createUnmarshaller();\r
-        //note: setting schema to null will turn validator off\r
-        unmarshaller.setSchema(null);\r
-        return jaxbClass.cast(unmarshaller.unmarshal(is));\r
-    }\r
-\r
     /**\r
      * Map as string.\r
      *\r
index a3bbef45bdabb75bf67fd87b4cf9ffddc41c1a44..cfe116a3a659405275e25dec4e9ce4a95cc32d61 100644 (file)
@@ -7,7 +7,6 @@
     </parent>\r
 \r
     <modelVersion>4.0.0</modelVersion>\r
-    <groupId>org.collectionspace.services</groupId>\r
     <artifactId>org.collectionspace.services.common-api</artifactId>\r
     <name>services.common-api</name>\r
     <packaging>jar</packaging>\r
index fcd32e12af5ebb30f813c547ba9b61d655c4bb17..844de7945fa9fdf67cb9a2a8a5fcfb6a1df27228 100644 (file)
@@ -30,8 +30,9 @@ package org.collectionspace.services.common.api;
 \r
 import java.io.*;\r
 import java.util.UUID;\r
-import java.util.regex.Pattern;\r
-import java.util.regex.Matcher;\r
+\r
+import javax.xml.bind.JAXBContext;\r
+import javax.xml.bind.Unmarshaller;\r
 \r
 /**\r
  * @author Laramie Crocker\r
@@ -40,6 +41,34 @@ import java.util.regex.Matcher;
  */\r
 public class FileTools {\r
 \r
+       \r
+    /**\r
+     * getObjectFromStream get object of given class from given inputstream\r
+     * @param jaxbClass\r
+     * @param is stream to read to construct the object\r
+     * @return\r
+     * @throws Exception\r
+     */\r
+    static protected Object getObjectFromStream(Class<?> jaxbClass, InputStream is) throws Exception {\r
+        JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
+        Unmarshaller unmarshaller = context.createUnmarshaller();\r
+        //note: setting schema to null will turn validator off\r
+        unmarshaller.setSchema(null);\r
+        return jaxbClass.cast(unmarshaller.unmarshal(is));\r
+    }\r
+\r
+    static public Object getJaxbObjectFromFile(Class<?> jaxbClass, String fileName)\r
+            throws Exception {\r
+\r
+        JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
+        Unmarshaller unmarshaller = context.createUnmarshaller();\r
+        //note: setting schema to null will turn validator off\r
+        unmarshaller.setSchema(null);\r
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();\r
+        InputStream is = tccl.getResourceAsStream(fileName);\r
+        return getObjectFromStream(jaxbClass, is);\r
+    }\r
+\r
        public static String convertStreamToString(InputStream is) {\r
                /*\r
                 * To convert the InputStream to String we use the\r
index c8c1b4118bf3f9d7ed6d7a96f19f29dcba5c63af..7d1a643249a92939d86c645d0b1e67f35f4f3ed6 100644 (file)
@@ -144,6 +144,7 @@ public class ServiceMain {
         // Create all the default user accounts\r
         //\r
         try {\r
+               AuthorizationCommon.createDefaultPermissions(tenantBindingConfigReader);\r
                AuthorizationCommon.createDefaultAccounts(tenantBindingConfigReader);\r
         } catch(Exception e) {\r
                logger.error("Default accounts setup failed with exception(s): " + e.getLocalizedMessage());\r
index 68ceaffa976d6385071dfeb821348fc6ba6bd7e0..4ecc953ab2927047f2b1f910ec5e85f53ad3185d 100644 (file)
@@ -21,11 +21,16 @@ import org.collectionspace.services.authorization.URIResourceImpl;
 import org.collectionspace.services.authorization.perms.EffectType;\r
 import org.collectionspace.services.authorization.perms.Permission;\r
 import org.collectionspace.services.authorization.perms.PermissionAction;\r
+import org.collectionspace.services.common.config.ServiceConfigUtils;\r
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
+import org.collectionspace.services.common.document.DocumentHandler;\r
 import org.collectionspace.services.common.security.SecurityUtils;\r
+import org.collectionspace.services.common.service.ServiceBindingType;\r
 import org.collectionspace.services.common.storage.DatabaseProductType;\r
 import org.collectionspace.services.common.storage.JDBCTools;\r
 import org.collectionspace.services.common.tenant.TenantBindingType;\r
+import org.collectionspace.services.lifecycle.Lifecycle;\r
+import org.mortbay.log.Log;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 import org.springframework.security.acls.model.AlreadyExistsException;\r
@@ -86,8 +91,22 @@ public class AuthorizationCommon {
         return JDBCTools.getConnection(JDBCTools.CSPACE_REPOSITORY_NAME);\r
     }\r
     \r
-    public static void createDefaultPermissions(TenantBindingConfigReaderImpl tenantBindingConfigReader)\r
+    public static void createDefaultPermissions(TenantBindingConfigReaderImpl tenantBindingConfigReader) throws Exception\r
     {\r
+        Hashtable<String, TenantBindingType> tenantBindings =\r
+               tenantBindingConfigReader.getTenantBindings();\r
+        for (String tenantId : tenantBindings.keySet()) {\r
+               TenantBindingType tenantBinding = tenantBindings.get(tenantId);\r
+               for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) {\r
+                       try {\r
+                               DocumentHandler docHandler = ServiceConfigUtils.createDocumentHandlerInstance(\r
+                                               tenantBinding, serviceBinding);\r
+                               Lifecycle lifecycle = docHandler.getLifecycle();\r
+                       } catch (IllegalStateException e) {\r
+                               Log.debug(e.getLocalizedMessage(), e); //We end up here if there is no document handler for the service -this is ok for some of the services.\r
+                       }\r
+               }\r
+        }\r
        // For each service binding in each tenancy, get the Nuxeo document type and retrieve it's life cycle type.  For\r
        // that life cycle type, ask Nuxeo for all the configured transitions.  For each of those transitions,\r
        // create:\r
@@ -99,6 +118,7 @@ public class AuthorizationCommon {
        //              \r
        //              * add a new Permission/PermissionRole tuple to the Spring AuthZ tables\r
        //              * persist the new Permission, and PermissionRole to the cspace database\r
+       \r
     }\r
     \r
     /*\r
index 51426de5e1f224e473675b69318909b258733459..ff59b020b9f702f486f07cd217aea719d92556c2 100644 (file)
@@ -25,12 +25,16 @@ package org.collectionspace.services.common.config;
 \r
 import java.util.ArrayList;\r
 import java.util.List;\r
-import java.util.Map;\r
 \r
 import org.collectionspace.services.common.RepositoryClientConfigType;\r
 import org.collectionspace.services.common.ServiceConfig;\r
+import org.collectionspace.services.common.document.DocumentHandler;\r
+import org.collectionspace.services.common.service.ServiceBindingType;\r
+import org.collectionspace.services.common.tenant.TenantBindingType;\r
 import org.collectionspace.services.common.types.PropertyItemType;\r
 import org.collectionspace.services.common.types.PropertyType;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 /**\r
  * @author pschmitz\r
@@ -38,6 +42,48 @@ import org.collectionspace.services.common.types.PropertyType;
  */\r
 public class ServiceConfigUtils {\r
 \r
+    final static Logger logger = LoggerFactory.getLogger(ServiceConfigUtils.class);\r
+\r
+    /**\r
+     * Creates the document handler instance.\r
+     * \r
+     * @return the document handler\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    public static DocumentHandler createDocumentHandlerInstance(TenantBindingType tenantBinding,\r
+               ServiceBindingType serviceBinding) throws Exception {\r
+       DocumentHandler docHandler = null;\r
+       \r
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();\r
+        Class<?> c = tccl.loadClass(getDocumentHandlerClass(tenantBinding, serviceBinding));\r
+        if (DocumentHandler.class.isAssignableFrom(c)) {\r
+            docHandler = (DocumentHandler) c.newInstance();\r
+        } else {\r
+            throw new IllegalArgumentException("Not of type "\r
+                    + DocumentHandler.class.getCanonicalName());\r
+        }\r
+\r
+        return docHandler;\r
+    }\r
+\r
+    /**\r
+     * Gets the document handler class.\r
+     * \r
+     * @return the document handler class\r
+     */\r
+    private static String getDocumentHandlerClass(TenantBindingType tenantBinding,\r
+               ServiceBindingType serviceBinding) {\r
+        if (serviceBinding.getDocumentHandler() == null\r
+                || serviceBinding.getDocumentHandler().isEmpty()) {\r
+            String msg = "Missing documentHandler in service binding for "\r
+                    + serviceBinding.getName() + " for tenant id=" + tenantBinding.getId()\r
+                    + " name=" + tenantBinding.getName();\r
+            logger.error(msg);\r
+            throw new IllegalStateException(msg);\r
+        }\r
+        return serviceBinding.getDocumentHandler().trim();\r
+    }\r
 \r
     /**\r
      * Gets the values of a configured property for a service.\r
index c1465a2c7283bab071c1dc8b3338d670b06638b1..c114ba955f7b5aa37f777ac7f5e93617ae629fdf 100644 (file)
@@ -35,6 +35,7 @@ import org.collectionspace.services.client.workflow.WorkflowClient;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.config.PropertyItemUtils;
+import org.collectionspace.services.common.config.ServiceConfigUtils;
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -482,14 +483,7 @@ public abstract class AbstractServiceContextImpl<IT, OT>
      * @throws Exception the exception
      */
     private DocumentHandler createDocumentHandlerInstance() throws Exception {
-        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-        Class<?> c = tccl.loadClass(getDocumentHandlerClass());
-        if (DocumentHandler.class.isAssignableFrom(c)) {
-            docHandler = (DocumentHandler) c.newInstance();
-        } else {
-            throw new IllegalArgumentException("Not of type "
-                    + DocumentHandler.class.getCanonicalName());
-        }
+        docHandler = ServiceConfigUtils.createDocumentHandlerInstance(tenantBinding, serviceBinding);
         //
         // Create a default document filter
         //
@@ -537,23 +531,6 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         documentFilter.setPagination(queryParams);
         return result;
     }
-
-    /**
-     * Gets the document handler class.
-     * 
-     * @return the document handler class
-     */
-    private String getDocumentHandlerClass() {
-        if (serviceBinding.getDocumentHandler() == null
-                || serviceBinding.getDocumentHandler().isEmpty()) {
-            String msg = "Missing documentHandler in service binding for "
-                    + getServiceName() + " for tenant id=" + getTenantId()
-                    + " name=" + getTenantName();
-            logger.error(msg);
-            throw new IllegalStateException(msg);
-        }
-        return serviceBinding.getDocumentHandler().trim();
-    }
     
     /*
      * If this element is set in the service binding then use it otherwise
index a609e8d23220da28627518758c2edb8d98e34274..bc1c86e01ea8e5dcf0b5a933c746e00751028b12 100644 (file)
@@ -19,6 +19,7 @@ package org.collectionspace.services.common.document;
 
 import java.util.Map;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.lifecycle.Lifecycle;
 
 /**
  *
@@ -41,9 +42,10 @@ import org.collectionspace.services.common.context.ServiceContext;
 public interface DocumentHandler<T, TL, WT, WTL> {
 
     public enum Action {
-
         CREATE, GET, GET_ALL, UPDATE, DELETE
     }
+    
+    public Lifecycle getLifecycle();
 
     /**
      * getServiceContext returns service context
index 73838db0130a504236211b83a1669f3a067da101..27a1c3a6d64cf2a6b293c8b7ff820501b49f20ec 100644 (file)
@@ -6,6 +6,7 @@ import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl;
 import org.collectionspace.services.common.document.DocumentFilter;\r
 import org.collectionspace.services.common.document.DocumentWrapper;\r
 import org.collectionspace.services.jaxb.AbstractCommonList;\r
+import org.collectionspace.services.lifecycle.Lifecycle;\r
 \r
 public abstract class JpaDocumentHandler<T, TL, WT, WLT>\r
        extends AbstractDocumentHandlerImpl<T, TL, WT, WLT>{\r
@@ -34,5 +35,9 @@ public abstract class JpaDocumentHandler<T, TL, WT, WLT>
         commonList.setTotalItems(docList.size());\r
 \r
         return (TL) commonList;\r
-    }  \r
+    }\r
+    \r
+    public Lifecycle getLifecycle() {\r
+       return null; // NOTE: As of 3/2012, none of the JPA-based services support a life cycle type.\r
+    }\r
 }\r
index 4619f619634f1f5d9c52989f938c9b56fcbf6fa2..3f21659aad2108f957db7e19e2aa12a6bf72dc32 100644 (file)
 package org.collectionspace.services.nuxeo.client.java;
 
 import java.util.List;
-import java.util.Map;
 
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.common.api.FileTools;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
 import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
-import org.collectionspace.services.nuxeo.client.*;
+import org.collectionspace.services.lifecycle.Lifecycle;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.common.profile.Profiler;
 import org.collectionspace.services.common.repository.RepositoryClient;
@@ -72,6 +71,19 @@ public abstract class DocumentModelHandler<T, TL>
     public final static String COLLECTIONSPACE_CORE_CREATED_BY = "createdBy";
     public final static String COLLECTIONSPACE_CORE_UPDATED_BY = "updatedBy";
 
+    public Lifecycle getLifecycle() {
+       Lifecycle result = null;
+       
+       try {
+                       result = (Lifecycle)FileTools.getJaxbObjectFromFile(Lifecycle.class, "default-lifecycle.xml");
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       
+       return result;
+    }
+    
     /*
      * We're using the "name" field of Nuxeo's DocumentModel to store
      * the CSID.