<!-- javax -->\r
\r
<!-- jboss -->\r
- \r
+ <dependency>\r
+ <groupId>jboss</groupId>\r
+ <artifactId>jboss-remoting</artifactId>\r
+ <version>2.2.2.SP8</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
<!-- nuxeo -->\r
\r
+ <dependency>\r
+ <groupId>org.nuxeo.common</groupId>\r
+ <artifactId>nuxeo-common</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.runtime</groupId>\r
+ <artifactId>nuxeo-runtime</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-api</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-client</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-query</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-schema</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-io</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-facade</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.runtime</groupId>\r
+ <artifactId>nuxeo-runtime-osgi</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.osgi</groupId>\r
+ <artifactId>osgi-core</artifactId>\r
+ <version>4.1</version>\r
+ </dependency>\r
+\r
</dependencies>\r
\r
<build>\r
- <finalName>collectionspace-services-jaxrs-provider</finalName>\r
+ <finalName>CollectionSpace</finalName>\r
<plugins>\r
<plugin>\r
<groupId>org.codehaus.mojo</groupId>\r
<artifactId>jboss-maven-plugin</artifactId>\r
<configuration>\r
<jbossHome>${jboss.dir}</jbossHome>\r
+ <port>8180</port>\r
</configuration>\r
<executions>\r
<execution>\r
<goal>undeploy</goal>\r
</goals>\r
<configuration>\r
- <fileName>${basedir}/target/collectionspace-services.war</fileName>\r
+ <fileName>${basedir}/target/CollectionSpace.war</fileName>\r
</configuration>\r
</execution>\r
<execution>\r
+++ /dev/null
-org.nuxeo.runtime.server.enabled=false
-org.nuxeo.runtime.streaming.isServer=false
-<?xml version="1.0" encoding="UTF-8"?>\r
-<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">\r
-<web-app>\r
- <display-name>CollectionSpace</display-name>\r
-\r
- <context-param>\r
- <param-name>javax.ws.rs.Application</param-name>\r
- <param-value>org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication</param-value>\r
- </context-param>\r
-\r
- <context-param>\r
- <param-name>resteasy.servlet.mapping.prefix</param-name>\r
- <param-value>/nuxeo-rest</param-value>\r
- </context-param>\r
-\r
- <listener>\r
- <listener-class>\r
- org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap\r
- </listener-class>\r
- </listener>\r
-\r
- <servlet>\r
- <servlet-name>Resteasy</servlet-name>\r
- <servlet-class>\r
- org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher\r
- </servlet-class>\r
- </servlet>\r
-\r
- <servlet-mapping>\r
- <servlet-name>Resteasy</servlet-name>\r
- <url-pattern>/nuxeo-rest/*</url-pattern>\r
- </servlet-mapping>\r
-\r
-</web-app>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Document : web.xml
+ Created on : May 19, 2009, 1:31 PM
+ Author :
+ Copyright 2009 University of California at Berkeley
+ Description:
+ service layer web application
+-->
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <display-name>CollectionSpace</display-name>
+
+ <context-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>resteasy.servlet.mapping.prefix</param-name>
+ <param-value>/nuxeo-rest</param-value>
+ </context-param>
+
+ <!-- Listeners -->
+ <listener>
+ <listener-class>
+ org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
+ </listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>
+ org.collectionspace.services.common.ServiceContextListener
+ </listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>Resteasy</servlet-name>
+ <servlet-class>
+ org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
+ </servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Resteasy</servlet-name>
+ <url-pattern>/nuxeo-rest/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
<?xml version="1.0" encoding="UTF-8"?>\r
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">\r
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>\r
+ <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">\r
+ <file>file:/C:/dev/src/cs/src/services/trunk/build.xml</file>\r
+ <file>file:/C:/dev/src/cs/src/services/trunk/pom.xml</file>\r
+ </open-files>\r
</project-private>\r
import org.nuxeo.common.utils.IdUtils;
-import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
\r
private static final String SCHEME = "http";\r
private static final String HOST = "localhost";\r
- private static final String PORT = "8080";\r
+ private static final String PORT = "8180";\r
private static final String URI = "/CollectionSpace/nuxeo-rest";\r
private static final String URL = SCHEME + "://" +\r
HOST + ":" +\r
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <parent>
- <artifactId>org.collectionspace.services.collectionobject.3rdparty</artifactId>
- <groupId>org.collectionspace.services</groupId>
- <version>1.0</version>
- </parent>
+ <parent>
+ <groupId>org.nuxeo.ecm.platform</groupId>
+ <artifactId>nuxeo-platform-parent</artifactId>
+ <version>5.2-SNAPSHOT</version>
+ </parent>
- <artifactId>org.collectionspace.services.collectionobject.doctype</artifactId>
+ <artifactId>nuxeo-platform-cs-collectionobject</artifactId>
<packaging>jar</packaging>
- <name>services.collectionobject.doctype</name>
+ <name>nuxeo-platform-cs-collectionobject</name>
<description>
CollectionObject Nuxeo document type
</description>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+ <parent>\r
+ <artifactId>org.collectionspace.services.main</artifactId>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <version>1.0</version>\r
+ </parent>\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <version>1.0</version>\r
+ <artifactId>org.collectionspace.services.collectionobject</artifactId>\r
+ <packaging>pom</packaging>\r
+ <name>services.collectionobject</name>\r
+\r
+ <properties>\r
+ <nuxeo.version.5.2>5.2-SNAPSHOT</nuxeo.version.5.2>\r
+ <nuxeo.version.1.5>1.5-SNAPSHOT</nuxeo.version.1.5>\r
+ </properties>\r
+\r
+ <modules>\r
+ <module>jaxb</module>\r
+ <module>service</module>\r
+ <module>3rdparty</module>\r
+ <module>client</module>\r
+ </modules>\r
+\r
+ <build>\r
+ <pluginManagement>\r
+ <plugins>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ <configuration>\r
+ <source>1.5</source>\r
+ <target>1.5</target>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-site-plugin</artifactId>\r
+ <configuration>\r
+ <unzipCommand>/usr/bin/unzip -o > err.txt</unzipCommand>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-war-plugin</artifactId>\r
+ <version>2.0.1</version>\r
+ <configuration>\r
+ <warSourceExcludes>WEB-INF/lib/*.jar</warSourceExcludes>\r
+ <archive>\r
+ <manifest>\r
+ <addClasspath>true</addClasspath>\r
+\r
+ </manifest>\r
+ </archive>\r
+ </configuration>\r
+ </plugin>\r
+ </plugins>\r
+ </pluginManagement>\r
+ </build>\r
+</project>\r
final static String CO_NUXEO_DC_TITLE = "CollectionSpace-CollectionObject";\r
\r
// replace WORKSPACE_UID for resource workspace\r
- static String CS_COLLECTIONOBJECT_WORKSPACE_UID = "e4a8e3d4-0954-4c10-963a-cc4ed09d5112";\r
+ static String CS_COLLECTIONOBJECT_WORKSPACE_UID = "ed110dfd-34e2-4870-bfdb-3be13d19c3f9";\r
+ //"e4a8e3d4-0954-4c10-963a-cc4ed09d5112";\r
\r
public Document deleteCollectionObject(String csid)\r
throws DocumentException, IOException {\r
<version>1.0</version>\r
<name>services.common</name>\r
\r
+ <properties>\r
+ <jboss.version>4.2.3.GA</jboss.version>\r
+ <jboss.ejb.version>3.0</jboss.ejb.version>\r
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
+ <nuxeo.version.5.2>5.2-SNAPSHOT</nuxeo.version.5.2>\r
+ <nuxeo.version.1.5>1.5-SNAPSHOT</nuxeo.version.1.5>\r
+ </properties>\r
+ \r
<dependencies>\r
<dependency>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-multipart-provider</artifactId>\r
<version>1.0.2.GA</version>\r
</dependency>\r
+\r
+ <!-- utilities -->\r
<dependency>\r
<groupId>junit</groupId>\r
<artifactId>junit</artifactId>\r
<version>4.1</version>\r
<scope>test</scope>\r
</dependency>\r
-\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-api</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ </dependency>\r
<!-- javax -->\r
\r
\r
</dependency>\r
\r
<!-- jboss -->\r
-\r
+ <dependency>\r
+ <groupId>jboss</groupId>\r
+ <artifactId>jboss-remoting</artifactId>\r
+ <version>2.2.2.SP8</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
<!-- nuxeo -->\r
\r
+ <dependency>\r
+ <groupId>org.nuxeo.common</groupId>\r
+ <artifactId>nuxeo-common</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.runtime</groupId>\r
+ <artifactId>nuxeo-runtime</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
<dependency>\r
<groupId>org.nuxeo.ecm.core</groupId>\r
<artifactId>nuxeo-core-api</artifactId>\r
<version>${nuxeo.version.1.5}</version>\r
- <exclusions>\r
- <exclusion>\r
- <artifactId>jboss-remoting</artifactId>\r
- <groupId>jboss</groupId>\r
- </exclusion>\r
- </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-client</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-query</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-schema</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-io</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.ecm.core</groupId>\r
+ <artifactId>nuxeo-core-facade</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.nuxeo.runtime</groupId>\r
+ <artifactId>nuxeo-runtime-osgi</artifactId>\r
+ <version>${nuxeo.version.1.5}</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.osgi</groupId>\r
+ <artifactId>osgi-core</artifactId>\r
+ <version>4.1</version>\r
</dependency>\r
\r
+ <!-- fixme remove restlet dependencies once REST client is no more used -->\r
<dependency>\r
<groupId>org.restlet</groupId>\r
<artifactId>org.restlet</artifactId>\r
<version>1.0.7</version>\r
</dependency>\r
\r
- <!-- where is jaxen needed? -->\r
+ <!--fixme where is jaxen needed? -->\r
<dependency>\r
<groupId>jaxen</groupId>\r
<artifactId>jaxen</artifactId>\r
<version>1.1.1</version>\r
</dependency>\r
+\r
+ <dependency>\r
+ <groupId>com.sun.xml.bind</groupId>\r
+ <artifactId>jaxb-impl</artifactId>\r
+ <version>2.0.2</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jvnet.jaxb2-commons</groupId>\r
+ <artifactId>property-listener-injector</artifactId>\r
+ <version>1.0</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jvnet.jaxb2_commons</groupId>\r
+ <artifactId>runtime</artifactId>\r
+ <version>0.4.1.4</version>\r
+ </dependency>\r
</dependencies>\r
\r
<build>\r
<finalName>collectionspace-services-common</finalName>\r
<plugins>\r
+ <plugin>\r
+ <groupId>org.jvnet.jaxb2.maven2</groupId>\r
+ <artifactId>maven-jaxb2-plugin</artifactId>\r
+ <executions>\r
+ <execution>\r
+ <goals>\r
+ <goal>generate</goal>\r
+ </goals>\r
+ </execution>\r
+ </executions>\r
+ <dependencies>\r
+ <!-- javax.activation.DataSource provider is required by spec -->\r
+ <dependency>\r
+ <groupId>javax.activation</groupId>\r
+ <artifactId>activation</artifactId>\r
+ <version>1.1</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.sun.xml.bind</groupId>\r
+ <artifactId>jaxb-impl</artifactId>\r
+ <version>2.1.2</version>\r
+ </dependency>\r
+ </dependencies>\r
+ <configuration>\r
+ <args>\r
+ <arg>-XtoString</arg>\r
+ <arg>-Xinject-listener-code</arg>\r
+\r
+ <!-- <arg>-Xcollection-setter-injector</arg>\r
+ <arg>-Xfluent-api</arg> -->\r
+ </args>\r
+ <plugins>\r
+ <plugin>\r
+ <groupId>\r
+ org.jvnet.jaxb2_commons\r
+ </groupId>\r
+ <artifactId>basic</artifactId>\r
+ <version>0.4.1</version>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>\r
+ org.jvnet.jaxb2-commons\r
+ </groupId>\r
+ <artifactId>\r
+ property-listener-injector\r
+ </artifactId>\r
+ <version>1.0</version>\r
+ </plugin>\r
+\r
+ </plugins>\r
+ <!--generatePackage>\r
+ org.collectionspace.hello\r
+ </generatePackage-->\r
+ </configuration>\r
+ </plugin>\r
<plugin>\r
<groupId>org.apache.maven.plugins</groupId>\r
<artifactId>maven-compiler-plugin</artifactId>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Document : service-config.xml
+ Created on : May 19, 2009, 1:31 PM
+ Author :
+ Copyright 2009 University of California at Berkeley
+ Description:
+ Service layer configuration
+-->
+
+<ns1:service-config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:ns1='http://collectionspace.org/services/common'
+ xsi:schemaLocation='http://collectionspace.org/services/common ../resources/common.xsd'>
+ <nuxeo-client-config>
+ <!-- ip of network interface to which Nuxeo server is listening on -->
+ <host>127.0.0.1</host>
+ <port>62474</port>
+ <user>Administrator</user>
+ <password>Administrator</password>
+ </nuxeo-client-config>
+ <nuxeo-workspace>
+ <workspace>
+ <service-name>persons</service-name>
+ <workspace-name>People</workspace-name>
+ </workspace>
+ <workspace>
+ <service-name>collectionobjects</service-name>
+ <workspace-name>CollectionObjects</workspace-name>
+ </workspace>
+ </nuxeo-workspace>
+
+</ns1:service-config>
--- /dev/null
+/**
+ * Copyright 2009 University of California at Berkeley
+ */
+package org.collectionspace.services.common;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ * ServiceContextListener is a ServletContextListener that helps initialize
+ * the services layer at deployment and undeployment times
+ */
+public class ServiceContextListener implements ServletContextListener {
+
+ public void contextInitialized(ServletContextEvent event) {
+ try{
+ ServletContext sc = event.getServletContext();
+ ServiceMain svcMain = ServiceMain.getInstance(); //first access initializes as well
+ svcMain.getWorkspaceIds();
+ }catch(Exception e) {
+ e.printStackTrace();
+ //fail here
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent event) {
+ ServiceMain.getInstance().release();
+ }
+}
--- /dev/null
+/**
+ * Copyright 2009 University of California at Berkeley
+ */
+package org.collectionspace.services.common;
+
+import java.io.File;
+import java.util.Hashtable;
+import java.util.List;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import org.collectionspace.services.common.ServiceConfig.NuxeoWorkspace;
+import org.collectionspace.services.common.ServiceConfig.NuxeoWorkspace.Workspace;
+import org.collectionspace.services.nuxeo.NuxeoConnector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Main class for Services layer. It reads configuration and performs service
+ * level initialization. It is a singleton.
+ * @author
+ */
+public class ServiceMain {
+
+ private static volatile ServiceMain instance = null;
+ final private static String CONFIG_FILE_NAME = "./cs/service-config.xml";
+ final Logger logger = LoggerFactory.getLogger(ServiceMain.class);
+ private ServiceConfig serviceConfig;
+ private Hashtable<String, String> serviceWorkspaces = new Hashtable<String, String>();
+ private NuxeoConnector nuxeoConnector;
+
+ private ServiceMain() {
+ }
+
+ /**
+ * getInstance returns the ServiceMain singleton instance after proper
+ * initialization in a thread-safe manner
+ * @return
+ */
+ public static ServiceMain getInstance() {
+ if(instance == null){
+ synchronized(ServiceMain.class){
+ if(instance == null){
+ ServiceMain temp = new ServiceMain();
+ try{
+ temp.initialize();
+ }catch(Exception e){
+ instance = null;
+ if(e instanceof RuntimeException){
+ throw (RuntimeException) e;
+ }else{
+ throw new RuntimeException(e);
+ }
+ }
+ instance = temp;
+ }
+ }
+ }
+ return instance;
+ }
+
+ private void initialize() throws Exception {
+ serviceConfig = readConfig();
+ nuxeoConnector = NuxeoConnector.getInstance();
+ nuxeoConnector.initialize(serviceConfig.getNuxeoClientConfig());
+ }
+
+ /**
+ * release releases all resources occupied by service layer infrastructure
+ * but not necessarily those occupied by individual services
+ */
+ public void release() {
+ try{
+ if(nuxeoConnector != null){
+ nuxeoConnector.release();
+ }
+ serviceWorkspaces.clear();
+ instance = null;
+ }catch(Exception e){
+ e.printStackTrace();
+ //gobble it
+ }
+ }
+
+ private ServiceConfig readConfig() throws Exception {
+ JAXBContext jc = JAXBContext.newInstance(ServiceConfig.class);
+ Unmarshaller um = jc.createUnmarshaller();
+ File configFile = new File(CONFIG_FILE_NAME);
+ if(!configFile.exists()){
+ String msg = "Could not find configuration file " + CONFIG_FILE_NAME;
+ logger.error(msg);
+ throw new RuntimeException(msg);
+ }
+ ServiceConfig sconfig = (ServiceConfig) um.unmarshal(configFile);
+ if(logger.isDebugEnabled()){
+ logger.debug("readConfig() read config file " + configFile.getAbsolutePath());
+ }
+ return sconfig;
+ }
+
+ synchronized public void getWorkspaceIds() throws Exception {
+ Hashtable<String, String> workspaceIds = nuxeoConnector.retrieveWorkspaceIds();
+ NuxeoWorkspace nuxeoWorkspace = serviceConfig.getNuxeoWorkspace();
+ List<Workspace> workspaces = nuxeoWorkspace.getWorkspace();
+ for(Workspace workspace : workspaces){
+ String workspaceId = workspaceIds.get(workspace.getWorkspaceName().toLowerCase());
+ if(workspaceId == null){
+ logger.error("failed to retrieve workspace id for " + workspace.getWorkspaceName());
+ //FIXME: should we throw an exception here?
+ continue;
+ }
+ serviceWorkspaces.put(workspace.getServiceName(), workspaceId);
+ if(logger.isDebugEnabled()){
+ logger.debug("retrieved workspace id=" + workspaceId +
+ " service=" + workspace.getServiceName() +
+ " workspace=" + workspace.getWorkspaceName());
+ }
+ }
+ }
+
+ /**
+ * @return the serviceConfig
+ */
+ public ServiceConfig getServiceConfig() {
+ return serviceConfig;
+ }
+
+ synchronized public String getWorkspaceId(String serviceName) {
+ return serviceWorkspaces.get(serviceName);
+ }
+
+ /**
+ * @return the nuxeoConnector
+ */
+ public NuxeoConnector getNuxeoConnector() {
+ return nuxeoConnector;
+ }
+}
/**\r
- * \r
+ * Copyright 2009 University of California at Berkeley\r
*/\r
package org.collectionspace.services.nuxeo;\r
\r
-import org.collectionspace.services.nuxeo.NuxeoRESTClient;\r
-\r
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
+import org.nuxeo.ecm.core.client.NuxeoClient;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
\r
/**\r
* @author remillet\r
\r
//replace host if not running on localhost\r
//static String CS_NUXEO_HOST = "173.45.234.217";\r
- static String CS_NUXEO_HOST = "localhost";\r
+ static String CS_NUXEO_HOST = "localhost";\r
static String CS_NUXEO_URI = "http://" + CS_NUXEO_HOST + ":8080/nuxeo";\r
- \r
+ protected Logger logger = LoggerFactory.getLogger(CollectionSpaceServiceNuxeoImpl.class);\r
+\r
public NuxeoRESTClient getClient() {\r
- NuxeoRESTClient nxClient = new NuxeoRESTClient(CS_NUXEO_URI);\r
- \r
- nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC);\r
- nxClient.setBasicAuthentication("Administrator", "Administrator");\r
- \r
- return nxClient;\r
- }\r
+ NuxeoRESTClient nxClient = new NuxeoRESTClient(CS_NUXEO_URI);\r
+\r
+ nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC);\r
+ nxClient.setBasicAuthentication("Administrator", "Administrator");\r
+\r
+ return nxClient;\r
+ }\r
+\r
+ protected RepositoryInstance getRepositorySession() throws Exception {\r
+ //FIXME: is it possible to reuse repository session?\r
+ //Authentication failures happen while trying to reuse the session\r
+ NuxeoConnector nuxeoConnector = NuxeoConnector.getInstance();\r
+ return nuxeoConnector.getRepositorySession();\r
+ }\r
+\r
+ protected void releaseRepositorySession(RepositoryInstance repoSession) {\r
+ try{\r
+ //release session\r
+ NuxeoConnector nuxeoConnector = NuxeoConnector.getInstance();\r
+ nuxeoConnector.releaseRepositorySession(repoSession);\r
+ }catch(Exception e){\r
+ logger.error("Could not close the repository session", e);\r
+ //no need to throw this service specific exception\r
+ }\r
+ }\r
}\r
--- /dev/null
+/**
+ * Copyright 2009 University of California at Berkeley
+ */
+package org.collectionspace.services.nuxeo;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+import org.collectionspace.services.common.ServiceConfig.NuxeoClientConfig;
+import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.nuxeo.ecm.core.client.NuxeoApp;
+import org.nuxeo.ecm.core.client.NuxeoClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * NuxeoConnector creates Nuxeo remoting runtime and provides access to Nuxeo client.
+ * @author
+ */
+public class NuxeoConnector {
+
+ private Logger logger = LoggerFactory.getLogger(NuxeoConnector.class);
+ private static final NuxeoConnector self = new NuxeoConnector();
+ private NuxeoApp app;
+ private NuxeoClient client;
+ private volatile boolean initialized = false; //use volatile for lazy initialization in singleton
+ private NuxeoClientConfig nuxeoClientConfig;
+
+ private NuxeoConnector() {
+ }
+
+ public final static NuxeoConnector getInstance() {
+ return self;
+ }
+
+ /**
+ * initialize initialize the Nuxeo connector. It makes sure that the connector
+ * is initialized in a thread-safe manner and not initialized more than once.
+ * Initialization involves starting Nuxeo runtime, loading Nuxeo APIs jars
+ * in OSGI container as well as establishing initial connection.
+ * @param nuxeoClientConfig
+ * @throws java.lang.Exception
+ */
+ public void initialize(NuxeoClientConfig nuxeoClientConfig) throws Exception {
+
+ if(initialized == false){
+ synchronized(this){
+ if(initialized == false){
+ try{
+ this.nuxeoClientConfig = nuxeoClientConfig;
+ setProperties(nuxeoClientConfig);
+ app = new NuxeoApp();
+ app.start();
+ if(logger.isDebugEnabled()){
+ logger.debug("initialize() NuxeoApp started");
+ }
+ loadBundles();
+ client = NuxeoClient.getInstance();
+ initialized = true;
+ }catch(Exception e){
+ if(logger.isDebugEnabled()){
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * release releases resources occupied by Nuxeo remoting client runtime
+ * @throws java.lang.Exception
+ */
+ public void release() throws Exception {
+ if(initialized == true){
+ client.disconnect();
+ app.shutdown();
+ }
+ }
+
+ private void loadBundles() throws Exception {
+ String bundles = "nuxeo-client/lib/nuxeo-runtime-*:nuxeo-client/lib/nuxeo-*";
+ Collection<File> files = null;
+ if(bundles != null){
+ files = NuxeoApp.getBundleFiles(new File("."), bundles, ":");
+ }
+ if(logger.isDebugEnabled()){
+ logger.debug("loadBundles(): deploying bundles: " + files);
+ }
+ if(files != null){
+ app.deployBundles(files);
+ }
+ }
+
+ private void setProperties(NuxeoClientConfig nuxeoClientConfig) {
+ System.setProperty("org.nuxeo.runtime.server.enabled", Boolean.FALSE.toString());
+ System.setProperty("org.nuxeo.runtime.server.port", "" + nuxeoClientConfig.getPort());
+ System.setProperty("org.nuxeo.runtime.server.host", nuxeoClientConfig.getHost());
+ //System.setProperty("org.nuxeo.runtime.1.3.3.streaming.port", "3233");
+ System.setProperty("org.nuxeo.runtime.streaming.serverLocator", "socket://" + nuxeoClientConfig.getHost() + ":3233");
+ System.setProperty("org.nuxeo.runtime.streaming.isServer", Boolean.FALSE.toString());
+ //org.nuxeo.client.remote is part of the fix to Nuxeo Runtime to use Java Remote APIs
+ //from JBoss
+ System.setProperty("org.nuxeo.client.remote", Boolean.TRUE.toString());
+ }
+
+ /**
+ * getClient get Nuxeo client for accessing Nuxeo services remotely using
+ * Nuxeo Java (EJB) Remote APIS
+ * @return NuxeoClient
+ * @throws java.lang.Exception
+ */
+ public NuxeoClient getClient() throws Exception {
+ if(initialized == true){
+// if(client.isConnected()){
+// return client;
+// }else{
+ //authentication failure error comes when reusing the client
+ //fore connect for now
+ client.forceConnect(nuxeoClientConfig.getHost(), nuxeoClientConfig.getPort());
+ if(logger.isDebugEnabled()){
+ logger.debug("getClient(): connection successful port=" +
+ nuxeoClientConfig.getPort());
+ }
+ return client;
+// }
+ }
+ String msg = "NuxeoConnector is not initialized!";
+ logger.error(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ /**
+ * getRepositorySession get session to default repository
+ * @return RepositoryInstance
+ * @throws java.lang.Exception
+ */
+ public RepositoryInstance getRepositorySession() throws Exception {
+ RepositoryInstance repoSession = getClient().openRepository();
+ if(logger.isDebugEnabled()){
+ logger.debug("getRepositorySession() opened repository session");
+ }
+ return repoSession;
+ }
+
+ /**
+ * releaseRepositorySession releases given repository session
+ * @param repoSession
+ * @throws java.lang.Exception
+ */
+ public void releaseRepositorySession(RepositoryInstance repoSession) throws Exception {
+ if(repoSession != null){
+ getClient().releaseRepository(repoSession);
+ if(logger.isDebugEnabled()){
+ if(logger.isDebugEnabled()){
+ logger.debug("releaseRepositorySession() released repository session");
+ }
+ }
+ }
+ }
+
+ /**
+ * retrieveWorkspaceIds retrieves all workspace ids from default repository
+ * @return
+ * @throws java.lang.Exception
+ */
+ public Hashtable<String, String> retrieveWorkspaceIds() throws Exception {
+ RepositoryInstance repoSession = null;
+ Hashtable<String, String> workspaceIds = new Hashtable<String, String>();
+ try{
+ repoSession = getRepositorySession();
+ DocumentModel rootDoc = repoSession.getRootDocument();
+ DocumentModelList rootChildrenList = repoSession.getChildren(rootDoc.getRef());
+ Iterator<DocumentModel> riter = rootChildrenList.iterator();
+ if(riter.hasNext()){
+ DocumentModel domain = riter.next();
+ DocumentModelList domainChildrenList = repoSession.getChildren(domain.getRef());
+ Iterator<DocumentModel> diter = domainChildrenList.iterator();
+ if(diter.hasNext()){
+ DocumentModel childNode = diter.next();
+ if("Workspaces".equalsIgnoreCase(childNode.getName())){
+ DocumentModelList workspaceList = repoSession.getChildren(childNode.getRef());
+ Iterator<DocumentModel> wsiter = workspaceList.iterator();
+ while(wsiter.hasNext()){
+ DocumentModel workspace = wsiter.next();
+ if(logger.isDebugEnabled()){
+ logger.debug("workspace name=" + workspace.getName() +
+ " id=" + workspace.getId());
+ }
+ workspaceIds.put(workspace.getName().toLowerCase(), workspace.getId());
+ }
+ }
+ }
+ }
+ }finally{
+ if(repoSession != null){
+ releaseRepositorySession(repoSession);
+ }
+ }
+ return workspaceIds;
+ }
+}
--- /dev/null
+/**
+ * Copyright 2009 University of California at Berkeley
+ */
+package org.collectionspace.services.nuxeo;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import javax.ws.rs.WebApplicationException;
+import org.dom4j.Document;
+import org.dom4j.io.SAXReader;
+import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.nuxeo.ecm.core.io.DocumentPipe;
+import org.nuxeo.ecm.core.io.DocumentReader;
+import org.nuxeo.ecm.core.io.DocumentWriter;
+import org.nuxeo.ecm.core.io.impl.DocumentPipeImpl;
+import org.nuxeo.ecm.core.io.impl.plugins.SingleDocumentReader;
+import org.nuxeo.ecm.core.io.impl.plugins.XMLDocumentWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Various utilities related to Nuxeo
+ * @author
+ */
+public class NuxeoUtils {
+
+ private static Logger logger = LoggerFactory.getLogger(NuxeoUtils.class);
+
+ public static Document getDocument(RepositoryInstance repoSession, DocumentModel helloDoc)
+ throws Exception {
+ Document doc = null;
+ DocumentWriter writer = null;
+ DocumentReader reader = null;
+ ByteArrayOutputStream baos = null;
+ ByteArrayInputStream bais = null;
+ try{
+ baos = new ByteArrayOutputStream();
+ //nuxeo io.impl begin
+ reader = new SingleDocumentReader(repoSession, helloDoc);
+ writer = new XMLDocumentWriter(baos);
+ DocumentPipe pipe = new DocumentPipeImpl();
+ //nuxeo io.impl end
+ pipe.setReader(reader);
+ pipe.setWriter(writer);
+ pipe.run();
+ bais = new ByteArrayInputStream(baos.toByteArray());
+ SAXReader saxReader = new SAXReader();
+ doc = saxReader.read(bais);
+ }finally{
+ if(reader != null){
+ reader.close();
+ }
+ if(writer != null){
+ writer.close();
+ }
+ try{
+ if(bais != null){
+ bais.close();
+ }
+ if(baos != null){
+ baos.close();
+ }
+ }catch(IOException ioe){
+ logger.error("Failed to close io streams with {}", ioe);
+ throw new WebApplicationException();
+ }
+ }
+ return doc;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ Document : common.xsd
+ Created on : May 19, 2009, 1:31 PM
+ Author :
+ Copyright 2009 University of California at Berkeley
+ Description:
+ Schema for service layer configuration
+-->
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://collectionspace.org/services/common"
+ targetNamespace="http://collectionspace.org/services/common"
+ version="0.1"
+>
+
+ <xs:element name="service-config">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="nuxeo-client-config" minOccurs="1" maxOccurs="1">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="host" type="xs:string" minOccurs="1" maxOccurs="1" />
+ <xs:element name="port" type="xs:int" minOccurs="1" maxOccurs="1" />
+ <xs:element name="user" type="xs:string" minOccurs="1" maxOccurs="1" />
+ <!-- password should not be in cleartext -->
+ <xs:element name="password" type="xs:string" minOccurs="1" maxOccurs="1" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="nuxeo-workspace" minOccurs="0" maxOccurs="1" >
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="workspace" maxOccurs="unbounded" >
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="service-name" type="xs:string" minOccurs="1" maxOccurs="1" />
+ <xs:element name="workspace-name" type="xs:string" minOccurs="1" maxOccurs="1" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+
+</xs:schema>
+