--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>\r
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>\r
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>\r
+ <classpathentry combineaccessrules="false" kind="src" path="/org.collectionspace.services.collectionobject.jaxb"/>\r
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
+ <classpathentry kind="output" path="target/classes"/>\r
+</classpath>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>javaee-addressbook-client</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Thu Mar 26 13:03:04 PDT 2009\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate\r
+org.eclipse.jdt.core.compiler.debug.localVariable=generate\r
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.6\r
--- /dev/null
+#Thu Feb 26 16:30:28 PST 2009\r
+activeProfiles=\r
+eclipse.preferences.version=1\r
+fullBuildGoals=process-test-resources\r
+includeModules=false\r
+resolveWorkspaceProjects=true\r
+resourceFilterGoals=process-resources resources\:testResources\r
+version=1\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+\r
+ <parent>\r
+ <artifactId>org.collectionspace.services.relation</artifactId>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <version>1.0</version>\r
+ </parent>\r
+\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.relation.client</artifactId>\r
+ <version>1.0</version>\r
+ <name>services.relation.client</name>\r
+ \r
+ <dependencies>\r
+<!-- <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.relation.jaxb</artifactId>\r
+ <version>1.0</version>\r
+ </dependency> -->\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.common</artifactId>\r
+ <version>1.0</version>\r
+ </dependency>\r
+ \r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.client</artifactId>\r
+ <version>1.0</version>\r
+ </dependency>\r
+ \r
+ <dependency>\r
+ <groupId>org.testng</groupId>\r
+ <artifactId>testng</artifactId>\r
+ <version>5.6</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-api</artifactId>\r
+ <version>1.5.2</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ <version>1.5.2</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-jaxrs</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ <!-- filter out unwanted jars -->\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>tjws</groupId>\r
+ <artifactId>webserver</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-jaxb-provider</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-multipart-provider</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>commons-httpclient</groupId>\r
+ <artifactId>commons-httpclient</artifactId>\r
+ <version>3.1</version>\r
+ </dependency>\r
+ </dependencies>\r
+ \r
+ <build>\r
+ <finalName>cspace-services-relation-client</finalName>\r
+ <plugins>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-surefire-plugin</artifactId>\r
+ <configuration>\r
+ <systemProperties>\r
+ <property>\r
+ <name>log4j.configuration</name>\r
+ <value>log4j.xml</value>\r
+ </property>\r
+ </systemProperties>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ <version>2.0.2</version>\r
+ <configuration>\r
+ <source>1.5</source>\r
+ <target>1.5</target>\r
+ </configuration>\r
+ </plugin>\r
+ </plugins>\r
+ </build>\r
+</project>\r
--- /dev/null
+package org.collectionspace.services.client;
+
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.relation.Relation;
+import org.collectionspace.services.relation.RelationList;
+
+import org.jboss.resteasy.client.ProxyFactory;
+import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+
+/**
+ * A RelationClient.
+
+ * @version $Revision:$
+ */
+public class RelationClient extends BaseServiceClient {
+
+ /**
+ *
+ */
+ private static final RelationClient instance = new RelationClient();
+ /**
+ *
+ */
+ private RelationProxy relationProxy;
+
+ /**
+ *
+ * Default constructor for RelationClient class.
+ *
+ */
+ private RelationClient() {
+ ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
+ RegisterBuiltin.register(factory);
+ if(useAuth()){
+ relationProxy = ProxyFactory.create(RelationProxy.class,
+ getBaseURL(), getHttpClient());
+ }else{
+ relationProxy = ProxyFactory.create(RelationProxy.class,
+ getBaseURL());
+ }
+ }
+
+ /**
+ * FIXME Comment this
+ *
+ * @return
+ */
+ public static RelationClient getInstance() {
+ return instance;
+ }
+
+ /**
+ * @return
+ * @see org.collectionspace.hello.client.RelationProxy#getRelation()
+ */
+ public ClientResponse<RelationList> getRelationList() {
+ return relationProxy.getRelationList();
+ }
+
+ /**
+ * @param csid
+ * @return
+ * @see org.collectionspace.hello.client.RelationProxy#getRelation(java.lang.String)
+ */
+ public ClientResponse<Relation> getRelation(String csid) {
+ return relationProxy.getRelation(csid);
+ }
+
+ /**
+ * @param relation
+ * @return
+ * @see org.collectionspace.hello.client.RelationProxy#createRelation(org.collectionspace.hello.Relation)
+ */
+ public ClientResponse<Response> createRelation(Relation relation) {
+ return relationProxy.createRelation(relation);
+ }
+
+ /**
+ * @param csid
+ * @param relation
+ * @return
+ * @see org.collectionspace.hello.client.RelationProxy#updateRelation(java.lang.Long, org.collectionspace.hello.Relation)
+ */
+ public ClientResponse<Relation> updateRelation(String csid, Relation relation) {
+ return relationProxy.updateRelation(csid, relation);
+ }
+
+ /**
+ * @param csid
+ * @return
+ * @see org.collectionspace.hello.client.RelationProxy#deleteRelation(java.lang.Long)
+ */
+ public ClientResponse<Response> deleteRelation(String csid) {
+ return relationProxy.deleteRelation(csid);
+ }
+}
--- /dev/null
+package org.collectionspace.services.client;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.collectionspace.services.relation.Relation;
+import org.collectionspace.services.relation.RelationList;
+import org.jboss.resteasy.client.ClientResponse;
+
+/**
+ * @version $Revision:$
+ */
+@Path("/relations/")
+@Produces({"application/xml"})
+@Consumes({"application/xml"})
+public interface RelationProxy {
+
+ @GET
+ ClientResponse<RelationList> getRelationList();
+
+ //(C)reate
+ @POST
+ ClientResponse<Response> createRelation(Relation co);
+
+ //(R)ead
+ @GET
+ @Path("/{csid}")
+ ClientResponse<Relation> getRelation(@PathParam("csid") String csid);
+
+ //(U)pdate
+ @PUT
+ @Path("/{csid}")
+ ClientResponse<Relation> updateRelation(@PathParam("csid") String csid, Relation co);
+
+ //(D)elete
+ @DELETE
+ @Path("/{csid}")
+ ClientResponse<Response> deleteRelation(@PathParam("csid") String csid);
+}
\ No newline at end of file
--- /dev/null
+package org.collectionspace.services.client.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import org.jboss.resteasy.client.ClientResponse;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.collectionspace.services.relation.Relation;
+import org.collectionspace.services.relation.RelationList;
+import org.collectionspace.services.relation.RelationshipType;
+
+import org.collectionspace.services.client.RelationClient;
+import org.collectionspace.services.RelationJAXBSchema;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A RelationNuxeoServiceTest.
+ *
+ * @version $Revision:$
+ */
+public class RelationServiceTest {
+
+ /** The relation client. */
+ private RelationClient relationClient = RelationClient.getInstance();
+
+ /** The update id. */
+ private String updateId = null;
+
+ /** The delete id. */
+ private String deleteId = null;
+
+ /** The logger. */
+ final Logger logger = LoggerFactory.getLogger(RelationServiceTest.class);
+
+ /**
+ * Creates the relation.
+ */
+ @Test
+ public void createRelation() {
+ long identifier = this.createIdentifier();
+
+ Relation relation = createRelation(identifier);
+ ClientResponse<Response> res = relationClient.createRelation(relation);
+ Assert.assertEquals(res.getStatus(), Response.Status.CREATED.getStatusCode());
+
+ String responseString = res.toString();
+ System.out.println(responseString);
+
+ //store updateId locally for "update" test
+ if(updateId == null){
+ updateId = extractId(res);
+ }else{
+ deleteId = extractId(res);
+ verbose("Set deleteId: " + deleteId);
+ }
+ }
+
+ /**
+ * Update relation.
+ */
+ @Test(dependsOnMethods = {"createRelation"})
+ public void updateRelation() {
+ ClientResponse<Relation> res = relationClient.getRelation(updateId);
+ Relation relation = res.getEntity();
+ verbose("Got Relation to update with ID: " + updateId,
+ relation, Relation.class);
+
+ //relation.setCsid("updated-" + updateId);
+ relation.setDocumentId1("updated-" + relation.getDocumentId1());
+ relation.setDocumentType1("updated-" + relation.getDocumentType1());
+
+ // make call to update service
+ res = relationClient.updateRelation(updateId, relation);
+
+ // check the response
+ Relation updatedRelation = res.getEntity();
+ Assert.assertEquals(updatedRelation.getDocumentId1(), relation.getDocumentId1());
+ verbose("updateRelation: ", updatedRelation, Relation.class);
+
+ return;
+ }
+
+ /**
+ * Creates the collection.
+ */
+ @Test(dependsOnMethods = {"createRelation"})
+ public void createCollection() {
+ for(int i = 0; i < 3; i++){
+ this.createRelation();
+ }
+ }
+
+ /**
+ * Gets the relation list.
+ *
+ * @return the relation list
+ */
+ @Test(dependsOnMethods = {"createCollection"})
+ public void getRelationList() {
+ //the resource method is expected to return at least an empty list
+ RelationList coList = relationClient.getRelationList().getEntity();
+ List<RelationList.RelationListItem> coItemList = coList.getRelationListItem();
+ int i = 0;
+ for(RelationList.RelationListItem pli : coItemList){
+ verbose("getRelationList: list-item[" + i + "] csid=" + pli.getCsid());
+ verbose("getRelationList: list-item[" + i + "] URI=" + pli.getUri());
+ i++;
+ System.out.println();
+ }
+ }
+
+ /**
+ * Delete relation.
+ */
+ @Test(dependsOnMethods = {"createCollection"})
+ public void deleteRelation() {
+ verbose("Calling deleteRelation:" + deleteId);
+ ClientResponse<Response> res = relationClient.deleteRelation(deleteId);
+ verbose("deleteRelation: csid=" + deleteId);
+ verbose("deleteRelation: status = " + res.getStatus());
+ Assert.assertEquals(res.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
+ }
+
+ /**
+ * Creates the relation.
+ *
+ * @param identifier the identifier
+ *
+ * @return the relation
+ */
+ private Relation createRelation(long identifier) {
+ Relation relation = createRelation("documentId1-" + identifier,
+ "documentType1-" + identifier + "-type",
+ "documentType1-" + identifier + "-type",
+ "documentType1-" + identifier + "-type",
+ RelationshipType.fromValue(
+ RelationJAXBSchema.ENUM_RELATIONSHIP_TYPE_ASSOC));
+
+ return relation;
+ }
+
+ /**
+ * Creates the relation.
+ *
+ * @param documentId1 the document id1
+ * @param documentType1 the document type1
+ * @param documentId2 the document id2
+ * @param documentType2 the document type2
+ * @param rt the rt
+ *
+ * @return the relation
+ */
+ private Relation createRelation(String documentId1, String documentType1,
+ String documentId2, String documentType2, RelationshipType rt) {
+ Relation relation = new Relation();
+
+ relation.setDocumentId1(documentId1);
+ relation.setDocumentType1(documentType1);
+ relation.setDocumentId2(documentId2);
+ relation.setDocumentType2(documentType2);
+
+ relation.setRelationshipType(rt);
+
+ return relation;
+ }
+
+ /**
+ * Extract id.
+ *
+ * @param res the res
+ *
+ * @return the string
+ */
+ private String extractId(ClientResponse<Response> res) {
+ MultivaluedMap mvm = res.getMetadata();
+ String uri = (String) ((ArrayList) mvm.get("Location")).get(0);
+ String[] segments = uri.split("/");
+ String id = segments[segments.length - 1];
+ verbose("id=" + id);
+ return id;
+ }
+
+ /**
+ * Verbose.
+ *
+ * @param msg the msg
+ */
+ private void verbose(String msg) {
+// if(logger.isInfoEnabled()){
+// logger.debug(msg);
+// }
+ System.out.println(msg);
+ }
+
+ /**
+ * Verbose.
+ *
+ * @param msg the msg
+ * @param o the o
+ * @param clazz the clazz
+ */
+ private void verbose(String msg, Object o, Class clazz) {
+ try{
+ verbose(msg);
+ JAXBContext jc = JAXBContext.newInstance(clazz);
+ Marshaller m = jc.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
+ Boolean.TRUE);
+ m.marshal(o, System.out);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Verbose map.
+ *
+ * @param map the map
+ */
+ private void verboseMap(MultivaluedMap map) {
+ for(Object entry : map.entrySet()){
+ MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;
+ verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue());
+ }
+ }
+
+ /**
+ * Creates the identifier.
+ *
+ * @return the long
+ */
+ private long createIdentifier() {
+ long identifier = System.currentTimeMillis();
+ return identifier;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+ <appender name="unit-tests"
+ class="org.apache.log4j.RollingFileAppender">
+ <param name="File" value="./target/unit-tests.log" />
+ <param name="MaxFileSize" value="10240KB" />
+ <param name="MaxBackupIndex" value="6" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+ <!--logger name="org.apache.commons.httpclient" additivity="false">
+ <level value="info" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger>
+
+ <logger name="httpclient.wire" additivity="false">
+ <level value="info" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger>
+
+ <logger name="org.collectionspace" additivity="false">
+ <level value="info" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger-->
+ <category name="org.apache.commons.httpclient">
+ <priority value="INFO"/>
+ </category>
+ <category name="httpclient.wire">
+ <priority value="INFO"/>
+ </category>
+ <category name="org.collectionspace.services.client">
+ <priority value="DEBUG"/>
+ </category>
+ <root>
+ <priority value="debug" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </root>
+
+</log4j:configuration>
+
+
+
+
<groupId>org.collectionspace.services</groupId>\r
<version>1.0</version>\r
</parent>\r
+ \r
<modelVersion>4.0.0</modelVersion>\r
<groupId>org.collectionspace.services</groupId>\r
<version>1.0</version>\r
</properties>\r
\r
<modules>\r
+ <module>service</module>\r
<module>3rdparty</module>\r
+ <module>client</module>\r
</modules>\r
\r
<build>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>\r
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>\r
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>\r
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
+ <classpathentry kind="output" path="target/classes"/>\r
+</classpath>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+ <name>org.collectionspace.services.relation.service</name>\r
+ <comment></comment>\r
+ <projects>\r
+ </projects>\r
+ <buildSpec>\r
+ <buildCommand>\r
+ <name>org.eclipse.jdt.core.javabuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ <buildCommand>\r
+ <name>org.maven.ide.eclipse.maven2Builder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ </buildSpec>\r
+ <natures>\r
+ <nature>org.eclipse.jdt.core.javanature</nature>\r
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>\r
+ </natures>\r
+</projectDescription>\r
--- /dev/null
+#Thu Jul 16 13:51:06 PDT 2009\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.source=1.6\r
--- /dev/null
+#Thu Jul 16 13:50:16 PDT 2009\r
+activeProfiles=\r
+eclipse.preferences.version=1\r
+fullBuildGoals=process-test-resources\r
+includeModules=false\r
+resolveWorkspaceProjects=true\r
+resourceFilterGoals=process-resources resources\:testResources\r
+version=1\r
--- /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
+\r
+ <parent>\r
+ <artifactId>org.collectionspace.services.relation</artifactId>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <version>1.0</version>\r
+ </parent>\r
+ \r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.relation.service</artifactId>\r
+ <packaging>jar</packaging>\r
+ <version>1.0</version>\r
+ <name>services.relation.service</name>\r
+\r
+ <dependencies>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.common</artifactId>\r
+ <version>1.0</version>\r
+ </dependency>\r
+<!-- <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.relation.jaxb</artifactId>\r
+ <version>1.0</version>\r
+ </dependency> -->\r
+ \r
+ <dependency>\r
+ <groupId>junit</groupId>\r
+ <artifactId>junit</artifactId>\r
+ <version>4.1</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.testng</groupId>\r
+ <artifactId>testng</artifactId>\r
+ <version>5.6</version>\r
+ </dependency>\r
+ \r
+\r
+ <!-- javax -->\r
+\r
+\r
+ <dependency>\r
+ <groupId>javax.security</groupId>\r
+ <artifactId>jaas</artifactId>\r
+ <version>1.0.01</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+\r
+ <dependency>\r
+ <groupId>dom4j</groupId>\r
+ <artifactId>dom4j</artifactId>\r
+ <version>1.6.1</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ \r
+ <!-- jboss -->\r
+\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-jaxrs</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>tjws</groupId>\r
+ <artifactId>webserver</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.jboss.resteasy</groupId>\r
+ <artifactId>resteasy-jaxb-provider</artifactId>\r
+ <version>1.0.2.GA</version>\r
+ </dependency>\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
+ <!-- nuxeo -->\r
+\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
+\r
+ <dependency>\r
+ <groupId>org.restlet</groupId>\r
+ <artifactId>org.restlet</artifactId>\r
+ <version>1.0.7</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.noelios.restlet</groupId>\r
+ <artifactId>com.noelios.restlet.ext.httpclient</artifactId>\r
+ <version>1.0.7</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>com.noelios.restlet</groupId>\r
+ <artifactId>com.noelios.restlet</artifactId>\r
+ <version>1.0.7</version>\r
+ </dependency>\r
+\r
+ </dependencies>\r
+ \r
+ <build>\r
+ <finalName>collectionspace-services-relation</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
+ </configuration>\r
+ </plugin>\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
+ </plugins>\r
+ </build>\r
+</project>\r
--- /dev/null
+/**
+ * RelationResource.java
+ *
+ * {Purpose of This Class}
+ *
+ * {Other Notes Relating to This Class (Optional)}
+ *
+ * $LastChangedBy: $
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ *
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 {Contributing Institution}
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
+package org.collectionspace.services;
+
+import java.util.Iterator;
+import java.util.List;
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.collectionspace.services.RelationService;
+import org.collectionspace.services.relation.*;
+import org.collectionspace.services.relation.RelationList.*;
+import org.collectionspace.services.RelationJAXBSchema;
+import org.collectionspace.services.common.ServiceMain;
+
+import org.dom4j.Document;
+import org.dom4j.Element;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class RelationResource.
+ */
+@Path("/relations")
+@Consumes("application/xml")
+@Produces("application/xml")
+public class RelationResource {
+
+ /** The logger. */
+ final Logger logger = LoggerFactory
+ .getLogger(RelationResource.class);
+
+ // This should be a DI wired by a container like Spring, Seam, or EJB3
+ /** The Constant service. */
+ final static RelationService service = new RelationServiceNuxeoImpl();
+
+ /**
+ * Instantiates a new relation resource.
+ */
+ public RelationResource() {
+ // do nothing
+ }
+
+ /**
+ * Gets the relation list.
+ *
+ * @param ui the ui
+ *
+ * @return the relation list
+ */
+ @GET
+ public RelationList getRelationList(@Context UriInfo ui) {
+
+ URI absoluteURI = ui.getAbsolutePath();
+ String uriString = absoluteURI.toString();
+
+ RelationList p = new RelationList();
+ try {
+ Document document = service.getRelationList();
+ Element root = document.getRootElement();
+
+ // debug
+ System.err.println(document.asXML());
+
+ List<RelationList.RelationListItem> list = p
+ .getRelationListItem();
+ for (Iterator i = root.elementIterator(); i.hasNext();) {
+ Element element = (Element) i.next();
+ // debug
+ System.err.println();
+ element.asXML();
+
+ // set the Relation list item entity elements
+ RelationListItem pli = new RelationListItem();
+ pli.setUri(element.attributeValue("url"));
+ pli.setCsid(element.attributeValue("id"));
+ list.add(pli);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return p;
+ }
+
+ /**
+ * Creates the relation.
+ *
+ * @param ui the ui
+ * @param co the co
+ *
+ * @return the response
+ */
+ @POST
+ public Response createRelation(@Context UriInfo ui, Relation co) {
+ String csid = null;
+
+ try {
+ Document document = service.postRelation(co);
+ Element root = document.getRootElement();
+ csid = root.attributeValue("id");
+ co.setCsid(csid);
+ } catch (Exception e) {
+ Response response = Response.status(Response.Status.NOT_FOUND)
+ .entity("Create failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+
+ //debug
+ verbose("createRelation: ", co);
+
+ UriBuilder uriBuilder = ui.getAbsolutePathBuilder();
+ uriBuilder.path(csid);
+ URI uri = uriBuilder.build();
+
+ //debug
+ System.out.println(uri.toString());
+
+ Response response = Response.created(uri).build();
+ return response;
+ }
+
+ /**
+ * Gets the relation.
+ *
+ * @param csid the csid
+ *
+ * @return the relation
+ */
+ @GET
+ @Path("{csid}")
+ public Relation getRelation(@PathParam("csid") String csid) {
+
+ Relation co = null;
+ try {
+ Document document = service.getRelation(csid);
+ Element root = document.getRootElement();
+ co = new Relation();
+
+ // TODO: recognize schema thru namespace uri
+ // Namespace ns = new Namespace("relation",
+ // "http://collectionspace.org/relation");
+
+ Iterator<Element> siter = root.elementIterator("schema");
+ while (siter.hasNext()) {
+ Element schemaElement = siter.next();
+ System.err.println("Relation.getRelation() called.");
+
+ // TODO: recognize schema thru namespace uri
+ if (RelationService.REL_SCHEMA_NAME.equals(schemaElement
+ .attribute("name").getValue())) {
+ Iterator<Element> relIter = schemaElement
+ .elementIterator(RelationJAXBSchema.REL_ROOT_ELEM_NAME);
+ Iterator<Element> relIter2 = schemaElement
+ .elementIterator("rel:" + RelationJAXBSchema.REL_ROOT_ELEM_NAME);
+
+ while (relIter.hasNext()) {
+ Element relElement = relIter.next();
+
+ Element ele = relElement
+ .element(RelationJAXBSchema.DOCUMENT_ID_1);
+ if (ele != null) {
+ co.setDocumentId1((String) ele.getData());
+ }
+ ele = relElement
+ .element(RelationJAXBSchema.DOCUMENT_TYPE_1);
+ if (ele != null) {
+ co.setDocumentType1((String) ele.getData());
+ }
+ ele = relElement
+ .element(RelationJAXBSchema.DOCUMENT_ID_2);
+ if (ele != null) {
+ co.setDocumentId2((String) ele.getData());
+ }
+ ele = relElement
+ .element(RelationJAXBSchema.DOCUMENT_TYPE_2);
+ if (ele != null) {
+ co.setDocumentType2((String) ele.getData());
+ }
+ ele = relElement
+ .element(RelationJAXBSchema.RELATIONSHIP_TYPE);
+ if (ele != null) {
+ RelationshipType rt = RelationshipType
+ .fromValue((String) ele.getData());
+ co.setRelationshipType(rt);
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed")
+ .type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (co == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND)
+ .entity(
+ "Get failed, the requested Relation CSID:" + csid
+ + ": was not found.").type("text/plain")
+ .build();
+ throw new WebApplicationException(response);
+ }
+ verbose("getRelation: ", co);
+
+ return co;
+ }
+
+ /**
+ * Update relation.
+ *
+ * @param csid the csid
+ * @param theUpdate the the update
+ *
+ * @return the relation
+ */
+ @PUT
+ @Path("{csid}")
+ public Relation updateRelation(
+ @PathParam("csid") String csid, Relation theUpdate) {
+
+ verbose("updateRelation with input: ", theUpdate);
+
+ String status = null;
+ try {
+
+ Document document = service.putRelation(csid, theUpdate);
+ Element root = document.getRootElement();
+ for (Iterator i = root.elementIterator(); i.hasNext();) {
+ Element element = (Element) i.next();
+ if ("docRef".equals(element.getName())) {
+ status = (String) element.getData();
+ verbose("updateRelation response: " + status);
+ }
+ }
+ } catch (Exception e) {
+ // FIXME: NOT_FOUND?
+ Response response = Response.status(Response.Status.NOT_FOUND)
+ .entity("Update failed ").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+
+ return theUpdate;
+ }
+
+ /**
+ * Delete relation.
+ *
+ * @param csid the csid
+ */
+ @DELETE
+ @Path("{csid}")
+ public void deleteRelation(@PathParam("csid") String csid) {
+
+ verbose("deleteRelation with csid=" + csid);
+ try {
+
+ Document document = service.deleteRelation(csid);
+ Element root = document.getRootElement();
+ for (Iterator i = root.elementIterator(); i.hasNext();) {
+ Element element = (Element) i.next();
+ if ("docRef".equals(element.getName())) {
+ String status = (String) element.getData();
+ verbose("deleteRelationt response: " + status);
+ }
+ }
+ } catch (Exception e) {
+ // FIXME: NOT_FOUND?
+ Response response = Response.status(Response.Status.NOT_FOUND)
+ .entity("Delete failed ").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+
+ }
+
+ /**
+ * Verbose.
+ *
+ * @param msg the msg
+ * @param co the co
+ */
+ private void verbose(String msg, Relation co) {
+ try {
+ verbose(msg);
+ JAXBContext jc = JAXBContext.newInstance(Relation.class);
+
+ Marshaller m = jc.createMarshaller();
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ m.marshal(co, System.out);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Verbose.
+ *
+ * @param msg the msg
+ */
+ private void verbose(String msg) {
+ System.out.println("RelationResource. " + msg);
+ }
+
+}
--- /dev/null
+/** \r
+ * RelationService.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;\r
+\r
+import java.io.IOException;\r
+import org.dom4j.Document;\r
+import org.dom4j.DocumentException;\r
+\r
+import org.collectionspace.services.relation.Relation;\r
+\r
+/**\r
+ * @author remillet\r
+ * \r
+ */\r
+public interface RelationService {\r
+\r
+ /** The Constant REL_SCHEMA_NAME. */\r
+ public final static String REL_SCHEMA_NAME = "relation";\r
+\r
+ // Create\r
+ /**\r
+ * Post relation.\r
+ * \r
+ * @param co the co\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ Document postRelation(Relation co)\r
+ throws DocumentException, IOException;\r
+\r
+ // Read single object\r
+ /**\r
+ * Gets the relation.\r
+ * \r
+ * @param csid the csid\r
+ * \r
+ * @return the relation\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ Document getRelation(String csid) throws DocumentException,\r
+ IOException;\r
+\r
+ // Read a list of objects\r
+ /**\r
+ * Gets the relation list.\r
+ * \r
+ * @return the relation list\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ Document getRelationList() throws DocumentException, IOException;\r
+\r
+ // Update\r
+ /**\r
+ * Put relation.\r
+ * \r
+ * @param csid the csid\r
+ * @param theUpdate the the update\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ Document putRelation(String csid, Relation theUpdate)\r
+ throws DocumentException, IOException;\r
+\r
+ // Delete\r
+ /**\r
+ * Delete relation.\r
+ * \r
+ * @param csid the csid\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ Document deleteRelation(String csid) throws DocumentException,\r
+ IOException;\r
+}\r
--- /dev/null
+/** \r
+ * RelationServiceNuxeoImpl.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;\r
+\r
+//import java.io.ByteArrayInputStream;\r
+import java.io.IOException;\r
+//import java.io.Serializable;\r
+//import java.util.ArrayList;\r
+//import java.util.Arrays;\r
+//import java.util.HashMap;\r
+//import java.util.List;\r
+//import java.util.Map;\r
+//import java.util.Iterator;\r
+\r
+//import org.collectionspace.services.nuxeo.NuxeoRESTClient;\r
+import org.collectionspace.services.nuxeo.CollectionSpaceServiceNuxeoImpl;\r
+import org.collectionspace.services.nuxeo.RelationUtilsNuxeoImpl;\r
+import org.collectionspace.services.relation.Relation;\r
+//import org.collectionspace.services.relation.RelationList;\r
+//import org.collectionspace.services.relation.RelationshipType;\r
+//import org.collectionspace.services.RelationJAXBSchema;\r
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+//import org.collectionspace.services.common.ServiceMain;\r
+\r
+import org.dom4j.Document;\r
+//import org.dom4j.Element;\r
+//import org.dom4j.dom.DOMDocument;\r
+import org.dom4j.DocumentException;\r
+//import org.dom4j.io.SAXReader;\r
+//import org.restlet.resource.Representation;\r
+\r
+import org.nuxeo.common.utils.IdUtils;\r
+//import org.nuxeo.ecm.core.api.ClientException;\r
+import org.nuxeo.ecm.core.api.IdRef;\r
+import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\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.DocumentRef;\r
+\r
+\r
+\r
+/**\r
+ * @author remillet\r
+ * \r
+ */\r
+public class RelationServiceNuxeoImpl extends\r
+ CollectionSpaceServiceNuxeoImpl implements RelationService {\r
+\r
+ // replace WORKSPACE_UID for resource workspace\r
+ // static String CS_RELATION_WORKSPACE_UID = "55f99358-5dbe-4462-8000-c5c3c2063919";\r
+\r
+ /**\r
+ * Delete relation.\r
+ * \r
+ * @param csid the csid\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ public Document deleteRelation(String csid)\r
+ throws DocumentException, IOException {\r
+ Document result = null;\r
+ \r
+ RepositoryInstance repoSession = null;\r
+ try {\r
+ repoSession = getRepositorySession();\r
+ result = deleteDocument(repoSession, csid);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ } finally {\r
+ if(repoSession != null) {\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+ \r
+ /**\r
+ * Gets the relation.\r
+ * \r
+ * @param csid the csid\r
+ * \r
+ * @return the relation\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ public Document getRelation(String csid)\r
+ throws DocumentException, IOException {\r
+ Document result = null;\r
+ RepositoryInstance repoSession = null;\r
+ \r
+ try {\r
+ repoSession = getRepositorySession();\r
+ result = NuxeoUtils.getDocument(repoSession, csid);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ } finally {\r
+ if (repoSession != null) {\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
+ \r
+ // Dump out the contents of the result\r
+ if (logger.isDebugEnabled() == true) {\r
+ System.out.println(result.asXML());\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Gets the relation list.\r
+ * \r
+ * @return the relation list\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ public Document getRelationList() throws DocumentException, IOException {\r
+ Document result = null;\r
+ RepositoryInstance repoSession = null;\r
+\r
+ try {\r
+ repoSession = getRepositorySession();\r
+ RelationUtilsNuxeoImpl.getRelationships(repoSession);\r
+ \r
+ result = this.browseWorkspace(repoSession, RelationUtilsNuxeoImpl.CS_RELATION_SERVICE_NAME);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ } finally {\r
+ if (repoSession != null) {\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
+ \r
+ if (logger.isDebugEnabled() == true) {\r
+ System.out.println(result.asXML());\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ // Create a new relation document\r
+ /**\r
+ * Post relation.\r
+ * \r
+ * @param co the co\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ public Document postRelation(Relation co) throws DocumentException,\r
+ IOException {\r
+ Document result = null;\r
+ RepositoryInstance repoSession = null;\r
+ \r
+ try {\r
+ repoSession = getRepositorySession();\r
+ \r
+ // get the Nuxeo 'Relations' workspace\r
+ DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession,\r
+ RelationUtilsNuxeoImpl.CS_RELATION_SERVICE_NAME);\r
+ \r
+ String docType = RelationUtilsNuxeoImpl.REL_NUXEO_DOCTYPE;\r
+ String id = IdUtils.generateId("New " + docType);\r
+ \r
+ //create document model\r
+ String workspacePath = workspaceModel.getPathAsString(); \r
+ DocumentModel newRelDocModel = repoSession.createDocumentModel(workspacePath, id, docType);\r
+\r
+ //debug\r
+ if (logger.isDebugEnabled() == true) {\r
+ RelationUtilsNuxeoImpl.printDocumentModel(newRelDocModel);\r
+ }\r
+ RelationUtilsNuxeoImpl.fillDocModelFromRelation(co, newRelDocModel);\r
+ \r
+ //create document with the new DocumentModel\r
+ DocumentModel resultDocModel = repoSession.createDocument(newRelDocModel);\r
+ repoSession.save();\r
+\r
+ result = NuxeoUtils.getDocument(repoSession, resultDocModel);\r
+\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ } finally {\r
+ if (repoSession != null) {\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
+\r
+ // Dump out the contents of the result\r
+ if (logger.isDebugEnabled() == true) {\r
+ System.out.println(result.asXML());\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+ /**\r
+ * Put relation.\r
+ * \r
+ * @param csid the csid\r
+ * @param theUpdate the the update\r
+ * \r
+ * @return the document\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ public Document putRelation(String csid, Relation theUpdate)\r
+ throws DocumentException, IOException {\r
+ \r
+ Document result = null;\r
+ RepositoryInstance repoSession = null;\r
+ try{\r
+ repoSession = getRepositorySession();\r
+ DocumentRef documentRef = new IdRef(csid);\r
+ DocumentModel documentModel = repoSession.getDocument(documentRef);\r
+ RelationUtilsNuxeoImpl.fillDocModelFromRelation(theUpdate, documentModel);\r
+ repoSession.saveDocument(documentModel);\r
+ repoSession.save();\r
+ result = NuxeoUtils.getDocument(repoSession, documentModel);\r
+ } catch(Exception e){\r
+ e.printStackTrace();\r
+ } finally{\r
+ if(repoSession != null){\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
+ \r
+ return result;\r
+ } \r
+\r
+}\r
--- /dev/null
+/**
+ * RelationServiceTest.java
+ *
+ * {Purpose of This Class}
+ *
+ * {Other Notes Relating to This Class (Optional)}
+ *
+ * $LastChangedBy: $
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ *
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 {Contributing Institution}
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
+package org.collectionspace.services.test;
+
+//import org.collectionspace.services.collectionobject.CollectionObject;
+//import org.collectionspace.services.collectionobject.CollectionObjectList;
+
+/**
+ * A RelationServiceTest.
+ *
+ * @version $Revision:$
+ */
+public class RelationServiceTest {
+ //empty
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+
+ <appender name="unit-tests"
+ class="org.apache.log4j.RollingFileAppender">
+ <param name="File" value="./target/unit-tests.log" />
+ <param name="MaxFileSize" value="10240KB" />
+ <param name="MaxBackupIndex" value="6" />
+ <layout class="org.apache.log4j.TTCCLayout">
+ <param name="DateFormat" value="ISO8601" />
+ </layout>
+ </appender>
+
+ <logger name="org.apache.commons.httpclient" additivity="false">
+ <level value="warn" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger>
+
+ <logger name="httpclient.wire" additivity="false">
+ <level value="info" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </logger>
+
+ <root>
+ <priority value="debug" />
+ <appender-ref ref="console" />
+ <appender-ref ref="unit-tests" />
+ </root>
+
+</log4j:configuration>
+
+
+
+