]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-59, CSPACE-60, added common service layer initialization (reading config,...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 21 May 2009 21:29:03 +0000 (21:29 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 21 May 2009 21:29:03 +0000 (21:29 +0000)
17 files changed:
JaxRsServiceProvider/pom.xml
JaxRsServiceProvider/src/main/resources/nuxeo.properties [deleted file]
JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml
nbproject/private/private.xml
sandbox/sanjay/prototypes/jaxrs-prototype/jaxrs-nuxeo-javaapi-service/src/main/java/org/collectionspace/hello/services/MultischemaResource.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml
services/collectionobject/pom.xml [new file with mode: 0644]
services/collectionobject/service/src/main/java/org/collectionspace/services/CollectionObjectServiceNuxeoImpl.java
services/common/pom.xml
services/common/src/main/config/service-config.xml [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/ServiceContextListener.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoConnector.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoUtils.java [new file with mode: 0644]
services/common/src/main/resources/common.xsd [new file with mode: 0644]

index e59c41b1528a301803273a3ded003e51e5d026fc..684c2df8aac356e50189be20170352c7e284f927 100644 (file)
         <!-- 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
diff --git a/JaxRsServiceProvider/src/main/resources/nuxeo.properties b/JaxRsServiceProvider/src/main/resources/nuxeo.properties
deleted file mode 100644 (file)
index 3c9d5af..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-org.nuxeo.runtime.server.enabled=false
-org.nuxeo.runtime.streaming.isServer=false
index 6777d8f8effaccc0af1d18b677e51de51ea9a9bb..29379ffcbb05581dc10968d6841b341533af8213 100644 (file)
@@ -1,34 +1,49 @@
-<?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>
index cc2c0e57c4f9286a6ee78a9b3557c26caca57415..392f2c6e0e7e402755846b50cf1a0ef08121fb8a 100644 (file)
@@ -1,4 +1,8 @@
 <?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
index 9b41c3fe82cc1e0799c6745984aa13565f78768a..43d3635042112e91c1f543146468875699827397 100644 (file)
@@ -11,7 +11,7 @@ public abstract class CollectionSpaceClient {
        \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
index d5eb52d948852497860ed28d2383e3eba2225c4c..56fc1f11df8407f10b4c334662f74553de6c8e1a 100644 (file)
@@ -3,15 +3,15 @@
   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>
diff --git a/services/collectionobject/pom.xml b/services/collectionobject/pom.xml
new file mode 100644 (file)
index 0000000..c413cb0
--- /dev/null
@@ -0,0 +1,62 @@
+<?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 &gt; 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
index 17fa1cf30ad950169eca8c0172605908150963bd..cf3a9679e429448ce32b714b249bcfb3c26958d1 100644 (file)
@@ -33,7 +33,8 @@ public class CollectionObjectServiceNuxeoImpl extends
        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
index 2af9ac8c9b121a1c5a4ff2490c4154ef018a1ef4..ec0232a6cb58b6f06905d47c5cc43289fed666fe 100644 (file)
     <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
diff --git a/services/common/src/main/config/service-config.xml b/services/common/src/main/config/service-config.xml
new file mode 100644 (file)
index 0000000..552ff18
--- /dev/null
@@ -0,0 +1,33 @@
+<?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>
diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceContextListener.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceContextListener.java
new file mode 100644 (file)
index 0000000..5015d73
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * 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();
+    }
+}
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
new file mode 100644 (file)
index 0000000..c96971c
--- /dev/null
@@ -0,0 +1,137 @@
+/**
+ * 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;
+    }
+}
index 5f131c81eedaefe674b9f4440ebb8f4b200c4d32..9b2318b9c0d39c926d5df7602de19c9da6f88cf2 100644 (file)
@@ -1,10 +1,12 @@
 /**\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
@@ -14,15 +16,34 @@ public abstract class CollectionSpaceServiceNuxeoImpl {
 \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
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoConnector.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoConnector.java
new file mode 100644 (file)
index 0000000..1767f22
--- /dev/null
@@ -0,0 +1,205 @@
+/**
+ * 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;
+    }
+}
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoUtils.java
new file mode 100644 (file)
index 0000000..059f265
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * 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;
+    }
+}
diff --git a/services/common/src/main/resources/common.xsd b/services/common/src/main/resources/common.xsd
new file mode 100644 (file)
index 0000000..9b6b135
--- /dev/null
@@ -0,0 +1,51 @@
+<?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>
+