From: Richard Millet Date: Wed, 28 Mar 2012 23:23:49 +0000 (-0700) Subject: CSPACE-4964: Added stubs for creating lifecycle permissions at init time. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=ac459f1b003cbeeef54ef679fa38cc5ff4527810;p=tmp%2Fjakarta-migration.git CSPACE-4964: Added stubs for creating lifecycle permissions at init time. --- diff --git a/services/authorization-mgt/import/build.xml b/services/authorization-mgt/import/build.xml index bb32302d8..b3a77ee73 100644 --- a/services/authorization-mgt/import/build.xml +++ b/services/authorization-mgt/import/build.xml @@ -124,7 +124,7 @@ - + diff --git a/services/client/pom.xml b/services/client/pom.xml index bc4973af3..56e2bec73 100644 --- a/services/client/pom.xml +++ b/services/client/pom.xml @@ -30,6 +30,11 @@ org.collectionspace.services.jaxb ${project.version} + + org.collectionspace.services + org.collectionspace.services.common-api + ${project.version} + diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java index 7ec701d0c..a729108fd 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java @@ -67,6 +67,7 @@ import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.TestServiceClient; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.common.api.FileTools; /** * BaseServiceTest. @@ -533,14 +534,11 @@ public abstract class BaseServiceTest { */ static protected Object getObjectFromFile(Class jaxbClass, String fileName) throws Exception { - - JAXBContext context = JAXBContext.newInstance(jaxbClass); - Unmarshaller unmarshaller = context.createUnmarshaller(); - //note: setting schema to null will turn validator off - unmarshaller.setSchema(null); - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - InputStream is = tccl.getResourceAsStream(fileName); - return getObjectFromStream(jaxbClass, is); + Object result = null; + + result = FileTools.getJaxbObjectFromFile(jaxbClass, fileName); + + return result; } /** @@ -572,21 +570,6 @@ public abstract class BaseServiceTest { return result; } - /** - * getObjectFromStream get object of given class from given inputstream - * @param jaxbClass - * @param is stream to read to construct the object - * @return - * @throws Exception - */ - static protected Object getObjectFromStream(Class jaxbClass, InputStream is) throws Exception { - JAXBContext context = JAXBContext.newInstance(jaxbClass); - Unmarshaller unmarshaller = context.createUnmarshaller(); - //note: setting schema to null will turn validator off - unmarshaller.setSchema(null); - return jaxbClass.cast(unmarshaller.unmarshal(is)); - } - /** * Map as string. * diff --git a/services/common-api/pom.xml b/services/common-api/pom.xml index a3bbef45b..cfe116a3a 100644 --- a/services/common-api/pom.xml +++ b/services/common-api/pom.xml @@ -7,7 +7,6 @@ 4.0.0 - org.collectionspace.services org.collectionspace.services.common-api services.common-api jar diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java index fcd32e12a..844de7945 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/FileTools.java @@ -30,8 +30,9 @@ package org.collectionspace.services.common.api; import java.io.*; import java.util.UUID; -import java.util.regex.Pattern; -import java.util.regex.Matcher; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; /** * @author Laramie Crocker @@ -40,6 +41,34 @@ import java.util.regex.Matcher; */ public class FileTools { + + /** + * getObjectFromStream get object of given class from given inputstream + * @param jaxbClass + * @param is stream to read to construct the object + * @return + * @throws Exception + */ + static protected Object getObjectFromStream(Class jaxbClass, InputStream is) throws Exception { + JAXBContext context = JAXBContext.newInstance(jaxbClass); + Unmarshaller unmarshaller = context.createUnmarshaller(); + //note: setting schema to null will turn validator off + unmarshaller.setSchema(null); + return jaxbClass.cast(unmarshaller.unmarshal(is)); + } + + static public Object getJaxbObjectFromFile(Class jaxbClass, String fileName) + throws Exception { + + JAXBContext context = JAXBContext.newInstance(jaxbClass); + Unmarshaller unmarshaller = context.createUnmarshaller(); + //note: setting schema to null will turn validator off + unmarshaller.setSchema(null); + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + InputStream is = tccl.getResourceAsStream(fileName); + return getObjectFromStream(jaxbClass, is); + } + public static String convertStreamToString(InputStream is) { /* * To convert the InputStream to String we use the diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index c8c1b4118..7d1a64324 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -144,6 +144,7 @@ public class ServiceMain { // Create all the default user accounts // try { + AuthorizationCommon.createDefaultPermissions(tenantBindingConfigReader); AuthorizationCommon.createDefaultAccounts(tenantBindingConfigReader); } catch(Exception e) { logger.error("Default accounts setup failed with exception(s): " + e.getLocalizedMessage()); diff --git a/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java b/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java index 68ceaffa9..4ecc953ab 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java +++ b/services/common/src/main/java/org/collectionspace/services/common/authorization_mgt/AuthorizationCommon.java @@ -21,11 +21,16 @@ import org.collectionspace.services.authorization.URIResourceImpl; import org.collectionspace.services.authorization.perms.EffectType; import org.collectionspace.services.authorization.perms.Permission; import org.collectionspace.services.authorization.perms.PermissionAction; +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.security.SecurityUtils; +import org.collectionspace.services.common.service.ServiceBindingType; import org.collectionspace.services.common.storage.DatabaseProductType; import org.collectionspace.services.common.storage.JDBCTools; import org.collectionspace.services.common.tenant.TenantBindingType; +import org.collectionspace.services.lifecycle.Lifecycle; +import org.mortbay.log.Log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.acls.model.AlreadyExistsException; @@ -86,8 +91,22 @@ public class AuthorizationCommon { return JDBCTools.getConnection(JDBCTools.CSPACE_REPOSITORY_NAME); } - public static void createDefaultPermissions(TenantBindingConfigReaderImpl tenantBindingConfigReader) + public static void createDefaultPermissions(TenantBindingConfigReaderImpl tenantBindingConfigReader) throws Exception { + Hashtable tenantBindings = + tenantBindingConfigReader.getTenantBindings(); + for (String tenantId : tenantBindings.keySet()) { + TenantBindingType tenantBinding = tenantBindings.get(tenantId); + for (ServiceBindingType serviceBinding : tenantBinding.getServiceBindings()) { + try { + DocumentHandler docHandler = ServiceConfigUtils.createDocumentHandlerInstance( + tenantBinding, serviceBinding); + Lifecycle lifecycle = docHandler.getLifecycle(); + } catch (IllegalStateException e) { + 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. + } + } + } // For each service binding in each tenancy, get the Nuxeo document type and retrieve it's life cycle type. For // that life cycle type, ask Nuxeo for all the configured transitions. For each of those transitions, // create: @@ -99,6 +118,7 @@ public class AuthorizationCommon { // // * add a new Permission/PermissionRole tuple to the Spring AuthZ tables // * persist the new Permission, and PermissionRole to the cspace database + } /* diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java b/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java index 51426de5e..ff59b020b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java @@ -25,12 +25,16 @@ package org.collectionspace.services.common.config; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.collectionspace.services.common.RepositoryClientConfigType; import org.collectionspace.services.common.ServiceConfig; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.service.ServiceBindingType; +import org.collectionspace.services.common.tenant.TenantBindingType; import org.collectionspace.services.common.types.PropertyItemType; import org.collectionspace.services.common.types.PropertyType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author pschmitz @@ -38,6 +42,48 @@ import org.collectionspace.services.common.types.PropertyType; */ public class ServiceConfigUtils { + final static Logger logger = LoggerFactory.getLogger(ServiceConfigUtils.class); + + /** + * Creates the document handler instance. + * + * @return the document handler + * + * @throws Exception the exception + */ + public static DocumentHandler createDocumentHandlerInstance(TenantBindingType tenantBinding, + ServiceBindingType serviceBinding) throws Exception { + DocumentHandler docHandler = null; + + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + Class c = tccl.loadClass(getDocumentHandlerClass(tenantBinding, serviceBinding)); + if (DocumentHandler.class.isAssignableFrom(c)) { + docHandler = (DocumentHandler) c.newInstance(); + } else { + throw new IllegalArgumentException("Not of type " + + DocumentHandler.class.getCanonicalName()); + } + + return docHandler; + } + + /** + * Gets the document handler class. + * + * @return the document handler class + */ + private static String getDocumentHandlerClass(TenantBindingType tenantBinding, + ServiceBindingType serviceBinding) { + if (serviceBinding.getDocumentHandler() == null + || serviceBinding.getDocumentHandler().isEmpty()) { + String msg = "Missing documentHandler in service binding for " + + serviceBinding.getName() + " for tenant id=" + tenantBinding.getId() + + " name=" + tenantBinding.getName(); + logger.error(msg); + throw new IllegalStateException(msg); + } + return serviceBinding.getDocumentHandler().trim(); + } /** * Gets the values of a configured property for a service. diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index c1465a2c7..c114ba955 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -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 * @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 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 diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java index a609e8d23..bc1c86e01 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java @@ -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 { public enum Action { - CREATE, GET, GET_ALL, UPDATE, DELETE } + + public Lifecycle getLifecycle(); /** * getServiceContext returns service context diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java index 73838db01..27a1c3a6d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentHandler.java @@ -6,6 +6,7 @@ import org.collectionspace.services.common.document.AbstractDocumentHandlerImpl; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.lifecycle.Lifecycle; public abstract class JpaDocumentHandler extends AbstractDocumentHandlerImpl{ @@ -34,5 +35,9 @@ public abstract class JpaDocumentHandler commonList.setTotalItems(docList.size()); return (TL) commonList; - } + } + + public Lifecycle getLifecycle() { + return null; // NOTE: As of 3/2012, none of the JPA-based services support a life cycle type. + } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 4619f6196..3f21659aa 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -24,18 +24,17 @@ 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 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.