]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
cspace-271: Adding common relation-related classes.
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 3 Aug 2009 23:43:36 +0000 (23:43 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 3 Aug 2009 23:43:36 +0000 (23:43 +0000)
services/common/build.xml [deleted file]
services/common/src/main/java/org/collectionspace/services/RelationJAXBSchema.java
services/common/src/main/java/org/collectionspace/services/RelationListItemJAXBSchema.java
services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/RelationsManager.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/RelationUtilsNuxeoImpl.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

diff --git a/services/common/build.xml b/services/common/build.xml
deleted file mode 100644 (file)
index 144607a..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-\r
-<project name="common" default="package" basedir=".">\r
-    <description>\r
-        collectionspace services common\r
-    </description>\r
-  <!-- set global properties for this build -->\r
-    <property name="services.trunk" value="../.."/>\r
-    <property file="${services.trunk}/build.properties" />\r
-    <property name="mvn.opts" value="" />\r
-    <property name="src" location="src"/>\r
-    <property name="build" location="build"/>\r
-\r
-    <condition property="osfamily-unix">\r
-        <os family="unix" />\r
-    </condition>\r
-    <condition property="osfamily-windows">\r
-        <os family="windows" />\r
-    </condition>\r
-\r
-    <target name="init" >\r
-    <!-- Create the time stamp -->\r
-        <tstamp/>\r
-    </target>\r
-\r
-    <target name="package" depends="package-unix,package-windows"\r
-  description="Package CollectionSpace Services" />\r
-    <target name="package-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="package" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="package-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="package" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-\r
-    <target name="install" depends="package,install-unix,install-windows"\r
-  description="Install" />\r
-    <target name="install-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="install" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="install-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="install" />\r
-            <arg value="-Dmaven.test.skip=true" />\r
-            <arg value="-f" />\r
-            <arg value="${basedir}/pom.xml" />\r
-            <arg value="-N" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    \r
-    <target name="clean" depends="clean-unix,clean-windows"\r
-  description="Delete target directories" >\r
-        <delete dir="${build}"/>\r
-    </target>\r
-    <target name="clean-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="clean" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="clean-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="clean" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-\r
-    <target name="test" depends="test-unix,test-windows" description="Run tests" />\r
-    <target name="test-unix" if="osfamily-unix">\r
-        <exec executable="mvn" failonerror="true">\r
-            <arg value="test" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-    <target name="test-windows" if="osfamily-windows">\r
-        <exec executable="cmd" failonerror="true">\r
-            <arg value="/c" />\r
-            <arg value="mvn.bat" />\r
-            <arg value="test" />\r
-            <arg value="${mvn.opts}" />\r
-        </exec>\r
-    </target>\r
-\r
-    <target name="deploy" depends="install"\r
-    description="deploy common elements in ${jboss.server.cspace}">\r
-        <copy file="${basedir}/src/main/config/service-config.xml"\r
-        todir="${jboss.server.cspace}/cspace/config/services"/>\r
-    </target>\r
-\r
-    <target name="undeploy"\r
-    description="undeploy common elements from ${jboss.server.cspace}">\r
-        <delete file="${jboss.server.cspace}/cspace/config/services/service-config.xml"/>\r
-    </target>\r
-\r
-    <target name="dist"\r
-    description="generate distribution for common elements" depends="install">\r
-        <copy todir="${services.trunk}/${dist.server.cspace}/cspace/config/services">\r
-            <fileset file="${basedir}/src/main/config/service-config.xml"/>\r
-        </copy>\r
-    </target>\r
-\r
-</project>\r
index 215aa46c2b4f6717c1dab0a63111aa02fc584893..66a1a20d58d1b5ff4fd40f3b87873a66ddd4f4f5 100644 (file)
@@ -4,22 +4,35 @@
 package org.collectionspace.services;\r
 \r
 /**\r
- * @author remillet\r
+ * @author Richard Millet\r
  *\r
  */\r
 public interface RelationJAXBSchema {\r
        \r
        // The Nuxeo root element name for the relation entity.\r
+       /** The Constant REL_ROOT_ELEM_NAME. */\r
        final static String REL_ROOT_ELEM_NAME = "relationtype";\r
        // Need to fix conflict between the Nuxeo XSD and the JAX-B XSD for the "relation" entity\r
        \r
+       /** The Constant DOCUMENT_ID_1. */\r
        final static String DOCUMENT_ID_1 = "documentId1";\r
+       \r
+       /** The Constant DOCUMENT_TYPE_1. */\r
        final static String DOCUMENT_TYPE_1 = "documentType1";\r
+       \r
+       /** The Constant DOCUMENT_ID_2. */\r
        final static String DOCUMENT_ID_2 = "documentId2";\r
+       \r
+       /** The Constant DOCUMENT_TYPE_2. */\r
        final static String DOCUMENT_TYPE_2 = "documentType2";\r
+       \r
+       /** The Constant RELATIONSHIP_TYPE. */\r
        final static String RELATIONSHIP_TYPE = "relationshipType";\r
        \r
+       /** The Constant ENUM_RELATIONSHIP_TYPE_ASSOC. */\r
        final static String ENUM_RELATIONSHIP_TYPE_ASSOC = "association";\r
+       \r
+       /** The Constant ENUM_RELATIONSHIP_TYPE_CONTAINS. */\r
        final static String ENUM_RELATIONSHIP_TYPE_CONTAINS = "contains";\r
 }\r
 \r
index a8203f93bae03dde6212b64ed0d7b613118f95dd..6212c7cc0de27a2cbcbf13feea3477ed6576a5ae 100644 (file)
@@ -1,6 +1,13 @@
 package org.collectionspace.services;\r
 \r
+/**\r
+ * The Interface RelationListItemJAXBSchema.\r
+ */\r
 public interface RelationListItemJAXBSchema {\r
+       \r
+       /** The Constant CSID. */\r
        final static String CSID = "csid";\r
+       \r
+       /** The Constant URI. */\r
        final static String URI = "url";\r
 }\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java
new file mode 100644 (file)
index 0000000..d49baba
--- /dev/null
@@ -0,0 +1,34 @@
+/**    \r
+ * RelationUtils.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+package org.collectionspace.services.common;\r
+\r
+/**\r
+ * The Interface RelationUtils.\r
+ */\r
+public interface RelationUtils {\r
+\r
+}\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/RelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/RelationsManager.java
new file mode 100644 (file)
index 0000000..c381db5
--- /dev/null
@@ -0,0 +1,56 @@
+/**    \r
+ * RelationsManager.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+package org.collectionspace.services.common;\r
+\r
+/**\r
+ * The Class RelationsManager.\r
+ */\r
+public class RelationsManager {\r
+       \r
+       /** The relation utils. */\r
+       private RelationUtils relationUtils = null;\r
+       \r
+       // FIXME: Add singleton patter here.\r
+       /**\r
+        * Sets the utils.\r
+        * \r
+        * @param utils the new utils\r
+        */\r
+       public void setUtils(RelationUtils utils) {\r
+               relationUtils = utils;\r
+       }\r
+       \r
+       /**\r
+        * Gets the relation utils.\r
+        * \r
+        * @return the relation utils\r
+        */\r
+       public RelationUtils getRelationUtils() {\r
+               return relationUtils;\r
+       }\r
+\r
+}\r
index deb8112cef083079ed7261f1a1445a247946af42..89bbd7c55b0cfd6a91bfc7a76550a1aed9935a2f 100644 (file)
  */\r
 package org.collectionspace.services.nuxeo;\r
 \r
+import java.io.IOException;\r
+\r
+import org.collectionspace.services.common.ServiceMain;\r
 import org.collectionspace.services.nuxeo.client.rest.NuxeoRESTClient;\r
+import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;\r
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+\r
+import org.dom4j.Document;\r
+import org.dom4j.DocumentException;\r
+import org.dom4j.dom.DOMDocument;\r
+import org.dom4j.dom.DOMDocumentFactory;\r
+\r
+import org.w3c.dom.DOMException;\r
+import org.w3c.dom.Element;\r
+\r
+import org.nuxeo.ecm.core.api.DocumentModel;\r
+import org.nuxeo.ecm.core.api.DocumentModelList;\r
+import org.nuxeo.ecm.core.api.DocumentRef;\r
+import org.nuxeo.ecm.core.api.IdRef;\r
+import org.nuxeo.ecm.core.api.ClientException;\r
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
+import org.nuxeo.ecm.core.client.NuxeoClient;\r
+\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
 /**\r
  * @author remillet\r
- *\r
+ * \r
  */\r
 public abstract class CollectionSpaceServiceNuxeoImpl {\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_URI = "http://" + CS_NUXEO_HOST + ":8080/nuxeo";\r
-    protected Logger logger = LoggerFactory.getLogger(CollectionSpaceServiceNuxeoImpl.class);\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_URI = "http://" + CS_NUXEO_HOST + ":8080/nuxeo";\r
+       \r
+       protected Logger logger = LoggerFactory\r
+                       .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
+\r
+// FIXME: Replace this method after integration of the relation code\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 Document deleteDocument(RepositoryInstance repoSession, String csid) throws DocumentException,\r
+                       IOException {\r
+               Document result = null;\r
+\r
+               try {\r
+                       repoSession = getRepositorySession();\r
+                       DocumentRef relDocumentRef = new IdRef(csid);\r
+                       repoSession.removeDocument(relDocumentRef);\r
+                       repoSession.save();\r
+                       result = new DOMDocument(); // set to non-null to indicate success\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       protected Document browseWorkspace(RepositoryInstance repoSession,\r
+                       String workspaceName) {\r
+\r
+               DOMDocumentFactory domfactory = new DOMDocumentFactory();\r
+               DOMDocument result = (DOMDocument) domfactory.createDocument();\r
+\r
+               try {\r
+                       repoSession = getRepositorySession();\r
+                       DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession,\r
+                                       workspaceName);\r
+\r
+                       Element current = result.createElement("document");\r
+                       try {\r
+                               current.setAttribute("title", workspaceModel.getTitle());\r
+                       } catch (Exception e) {\r
+                               e.printStackTrace();\r
+                       }\r
+                       current.setAttribute("type", workspaceModel.getType());\r
+                       current.setAttribute("id", workspaceModel.getId());\r
+                       current.setAttribute("name", workspaceModel.getName());\r
+                       current.setAttribute("url", getRelURL(workspaceName, workspaceModel.getRef().toString()));\r
+                       result.setRootElement((org.dom4j.Element) current);\r
+\r
+                       if (workspaceModel.isFolder()) {\r
+                               // Element childrenElem = result.createElement("children");\r
+                               // root.appendChild(childrenElem);\r
+\r
+                               DocumentModelList children = null;\r
+                               try {\r
+                                       children = repoSession.getChildren(workspaceModel.getRef());\r
+                               } catch (ClientException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
 \r
-    public NuxeoRESTClient getClient() {\r
-        NuxeoRESTClient nxClient = new NuxeoRESTClient(CS_NUXEO_URI);\r
+                               for (DocumentModel child : children) {\r
+                                       Element el = result.createElement("document");\r
+                                       try {\r
+                                               el.setAttribute("title", child.getTitle());\r
+                                       } catch (DOMException e) {\r
+                                               e.printStackTrace();\r
+                                       } catch (ClientException e) {\r
+                                               e.printStackTrace();\r
+                                       }\r
+                                       el.setAttribute("type", child.getType());\r
+                                       el.setAttribute("id", child.getId());\r
+                                       el.setAttribute("name", child.getName());\r
+                                       el.setAttribute("url", getRelURL(workspaceName, child.getRef()\r
+                                                       .toString()));\r
+                                       current.appendChild(el);\r
+                               }\r
+                       }\r
 \r
-        nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC);\r
-        nxClient.setBasicAuthentication("Administrator", "Administrator");\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               if (logger.isDebugEnabled() == true) {\r
+                       System.out.println(result.asXML());\r
+               }\r
 \r
-        return nxClient;\r
-    }\r
+               return result;\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
+    private static String getRelURL(String repo, String uuid) {\r
+        return '/' + repo + '/' + uuid;\r
+    }  \r
 }\r
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/RelationUtilsNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/RelationUtilsNuxeoImpl.java
new file mode 100644 (file)
index 0000000..2a355df
--- /dev/null
@@ -0,0 +1,154 @@
+package org.collectionspace.services.nuxeo;\r
+\r
+import java.io.IOException;\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.collectionspace.services.RelationJAXBSchema;\r
+import org.collectionspace.services.common.RelationUtils;\r
+import org.collectionspace.services.relation.Relation;\r
+import org.collectionspace.services.relation.RelationshipType;\r
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+import org.collectionspace.services.common.repository.DocumentException;\r
+\r
+//import org.dom4j.DocumentException;\r
+import org.nuxeo.ecm.core.api.ClientException;\r
+import org.nuxeo.ecm.core.api.DocumentModel;\r
+import org.nuxeo.ecm.core.api.DocumentModelList;\r
+import org.nuxeo.ecm.core.api.model.DocumentPart;\r
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class RelationUtilsNuxeoImpl implements RelationUtils {\r
+       \r
+       static public String CS_RELATION_SERVICE_NAME = "relations";\r
+       \r
+       final public static String REL_NUXEO_DOCTYPE = "Relation";\r
+       final public static String REL_NUXEO_SCHEMA_NAME = "relation";\r
+       final public static String REL_NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype";\r
+       final public static String REL_NUXEO_DC_TITLE = "CollectionSpace-Relation";\r
+       \r
+       private static Logger logger = LoggerFactory\r
+       .getLogger(RelationUtilsNuxeoImpl.class);       \r
+\r
+\r
+       static public void fillRelationFromDocModel(Relation relation, DocumentModel relDocModel)\r
+                       throws ClientException {\r
+               String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
+               Object valueObject = null;\r
+\r
+               valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+                               + RelationJAXBSchema.DOCUMENT_ID_1);\r
+               relation.setDocumentId1((String) valueObject);\r
+\r
+               valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+                               + RelationJAXBSchema.DOCUMENT_TYPE_1);\r
+               relation.setDocumentType1((String) valueObject);\r
+\r
+               valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+                               + RelationJAXBSchema.DOCUMENT_ID_2);\r
+               relation.setDocumentId2((String) valueObject);\r
+\r
+               valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+                               + RelationJAXBSchema.DOCUMENT_TYPE_1);\r
+               relation.setDocumentType2((String) valueObject);\r
+\r
+               valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+                               + RelationJAXBSchema.RELATIONSHIP_TYPE);\r
+               relation.setRelationshipType(RelationshipType\r
+                               .fromValue((String) valueObject));\r
+\r
+               if (logger.isDebugEnabled() == true) {\r
+                       System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");\r
+                       System.out.println(relation.toString());\r
+                       System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");\r
+               }\r
+       }\r
+\r
+       static public void fillDocModelFromRelation(Relation p, DocumentModel relDocModel)\r
+                       throws Exception {\r
+\r
+               // set the DublinCore title (this works)\r
+               relDocModel.setPropertyValue("dublincore:title", "default title");\r
+\r
+               // // set value for <documentType1> element\r
+               // try {\r
+               // relDocModel.setProperty("relation", "/relationtype/documentId1",\r
+               // "docId1");\r
+               // } catch (Exception x) {\r
+               // x.printStackTrace();\r
+               // }\r
+\r
+               String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
+               if (p.getDocumentId1() != null) {\r
+                       String property = xpathRoot + RelationJAXBSchema.DOCUMENT_ID_1;\r
+                       relDocModel.setProperty(REL_NUXEO_SCHEMA_NAME, property, p\r
+                                       .getDocumentId1());\r
+               }\r
+               if (p.getDocumentType1() != null) {\r
+                       String property = xpathRoot + RelationJAXBSchema.DOCUMENT_TYPE_1;\r
+                       relDocModel.setProperty(REL_NUXEO_SCHEMA_NAME, property, p\r
+                                       .getDocumentType1());\r
+               }\r
+               if (p.getDocumentId2() != null) {\r
+                       String property = xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2;\r
+                       relDocModel.setProperty(REL_NUXEO_SCHEMA_NAME, property, p\r
+                                       .getDocumentId2());\r
+               }\r
+               if (p.getDocumentType2() != null) {\r
+                       String property = xpathRoot + "/"\r
+                                       + RelationJAXBSchema.DOCUMENT_TYPE_2;\r
+                       relDocModel.setProperty(REL_NUXEO_SCHEMA_NAME, property, p\r
+                                       .getDocumentType2());\r
+               }\r
+\r
+               if (p.getRelationshipType() != null) {\r
+                       String property = xpathRoot + RelationJAXBSchema.RELATIONSHIP_TYPE;\r
+                       relDocModel.setProperty(REL_NUXEO_SCHEMA_NAME, property, p\r
+                                       .getRelationshipType().value());\r
+               }\r
+       }\r
+       \r
+       static public void printDocumentModel(DocumentModel documentModel) {\r
+               System.out.println(documentModel);\r
+       }\r
+       \r
+       static private void describeDocumentModel(DocumentModel docModel) throws Exception {\r
+               String[] schemas = docModel.getDeclaredSchemas();\r
+               for (int i = 0; schemas != null && i < schemas.length; i++) {\r
+                       System.out.println("Schema-" + i + "=" + schemas[i]);\r
+               }\r
+               \r
+               DocumentPart[] parts = docModel.getParts();\r
+               Map<String,Serializable> propertyValues = null;\r
+               for (int i = 0; parts != null && i < parts.length; i++) {\r
+                       System.out.println("Part-" + i + " name =" + parts[i].getName());\r
+                       System.out.println("Part-" + i + " path =" + parts[i].getPath());\r
+                       System.out.println("Part-" + i + " schema =" + parts[i].getSchema().getName());\r
+                       propertyValues = parts[i].exportValues();\r
+               }\r
+\r
+       }\r
+\r
+       static public List<Relation> getRelationships(RepositoryInstance repoSession)\r
+                       throws DocumentException, IOException, ClientException {\r
+               List<Relation> result = new ArrayList<Relation>();\r
+\r
+               DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
+                               repoSession, CS_RELATION_SERVICE_NAME);\r
+               DocumentModelList children = repoSession.getChildren(relationWorkspace\r
+                               .getRef());\r
+               Relation relation = null;\r
+               for (DocumentModel child : children) {\r
+                       relation = new Relation();\r
+                       fillRelationFromDocModel(relation, child);\r
+                       result.add(relation);\r
+               }\r
+\r
+               return result;\r
+       }\r
+\r
+}\r
index cc4cf47331301f44a56fc0fcaefa6728c2ffe6e1..35fc566750acb97baa7082d77f1de05c5d2c5b92 100644 (file)
@@ -20,22 +20,30 @@ package org.collectionspace.services.nuxeo.util;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+
 import org.collectionspace.services.common.repository.DocumentException;
+import org.collectionspace.services.common.ServiceMain;
+
 import org.dom4j.Document;
 import org.dom4j.io.SAXReader;
+
 import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.nuxeo.ecm.core.api.DocumentRef;
+import org.nuxeo.ecm.core.api.IdRef;
 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 
+ * Various utilities related to Nuxeo API
  */
 public class NuxeoUtils {
 
@@ -95,4 +103,43 @@ public class NuxeoUtils {
         }
         return doc;
     }
+    
+public static Document getDocument(RepositoryInstance repoSession, String csid)
+       throws DocumentException {
+               Document result = null;
+               
+               DocumentModel docModel = getDocumentModel(repoSession, csid);
+               result = getDocument(repoSession, docModel);
+               
+               return result;
+       }
+       
+       public static DocumentModel getWorkspaceModel(
+                       RepositoryInstance repoSession, String workspaceName)
+                       throws DocumentException, IOException, ClientException {
+               DocumentModel result = null;
+
+               String workspaceUUID = ServiceMain.getInstance().getWorkspaceId(
+                               workspaceName);
+               DocumentRef workspaceRef = new IdRef(workspaceUUID);
+               result = repoSession.getDocument(workspaceRef);
+
+               return result;
+       }
+
+       public static DocumentModel getDocumentModel(
+                       RepositoryInstance repoSession, String csid)
+                       throws DocumentException {
+               DocumentModel result = null;
+
+               try {
+                       DocumentRef documentRef = new IdRef(csid);
+                       result = repoSession.getDocument(documentRef);
+               } catch (ClientException e) {
+                       e.printStackTrace();
+               }
+
+               return result;
+       }
+           
 }