<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
<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
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
*/\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
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
</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
\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
*/\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
// 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
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
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
// \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
\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
*/\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
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;
* @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
//
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
import java.util.Map;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.lifecycle.Lifecycle;
/**
*
public interface DocumentHandler<T, TL, WT, WTL> {
public enum Action {
-
CREATE, GET, GET_ALL, UPDATE, DELETE
}
+
+ public Lifecycle getLifecycle();
/**
* getServiceContext returns service context
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
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
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;
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.