]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-418 relation entity schema is flatten
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Tue, 29 Sep 2009 23:29:20 +0000 (23:29 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Tue, 29 Sep 2009 23:29:20 +0000 (23:29 +0000)
CSPACE-81,394 schema extension supported between consumer and service using multipart messaging, between service and repository using nuxeo repository. relationship service is refactored to use repository client and document handler. tenant binding updated for the relationship service. service context and document handler are further refactored to accommodate the use case of "local" service-service interaction and "remote" interaction. All remotely accessible services now use RemoteServiceContext and RemoteDocumentHandler. Removed unused RepresentationHandlers from all the services where applicable.
TEST: services/trunk mvn test passes

M    services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
D    services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java
M    services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java
M    services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectHandlerFactory.java
M    services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
M    services/JaxRsServiceProvider/pom.xml
M    services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClientFactory.java
M    services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java
M    services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
M    services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResource.java
A    services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java
A  + services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java
M    services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
D    services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextImpl.java
A    services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
R    services/common/src/main/java/org/collectionspace/services/common/relation/RelationJAXBSchema.java
R    services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java
D    services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java
A    services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java
A    services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java
D    services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java
D    services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java
M    services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
A    services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java
M    services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
M    services/common/src/main/config/tenant-bindings.xml
A  + services/common/src/main/resources/relations-common.xsd
D    services/common/src/main/resources/relation.xsd
M    services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
M    services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java
M    services/pom.xml
M    services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
M    services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeHandlerFactory.java
D    services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeRepresenationHandler.java
M    services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java
M    services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
D    services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java
D    services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java
M    services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationHandlerFactory.java
D    services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java
M    services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java
D    services/relation/service/src/main/java/org/collectionspace/services/relation/RelationService.java
A  + services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations-common.xsd
D    services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relation.xsd
M    services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/OSGI-INF/core-types-contrib.xml
M    services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java
A    services/relation/client/src/test/resources/log4j.properties
D    services/relation/client/src/test/resources/log4j.xml
M    services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java
M    services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java
M    services/relation/client/pom.xml

47 files changed:
services/JaxRsServiceProvider/pom.xml
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectHandlerFactory.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java [deleted file]
services/common/src/main/config/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java [moved from services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextImpl.java with 67% similarity]
services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java [deleted file]
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java [deleted file]
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/repository/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClientFactory.java
services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java [deleted file]
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/common/src/main/resources/relations-common.xsd [moved from services/common/src/main/resources/relation.xsd with 89% similarity]
services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeHandlerFactory.java
services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeRepresenationHandler.java [deleted file]
services/pom.xml
services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/OSGI-INF/core-types-contrib.xml
services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations-common.xsd [moved from services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relation.xsd with 76% similarity]
services/relation/client/pom.xml
services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java
services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java
services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java
services/relation/client/src/test/resources/log4j.properties [new file with mode: 0644]
services/relation/client/src/test/resources/log4j.xml [deleted file]
services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java [deleted file]
services/relation/service/src/main/java/org/collectionspace/services/relation/RelationService.java [deleted file]
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationHandlerFactory.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java [deleted file]
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java [deleted file]

index a5137dd1847364b73266549e476d31d796bdf466..66e6c6ffff3ff064385fab65cbd82e626b09757c 100644 (file)
             <artifactId>org.collectionspace.services.acquisition.service</artifactId>\r
             <version>1.0</version>\r
         </dependency>\r
-        <!--dependency>\r
+        <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.relation.service</artifactId>\r
             <version>1.0</version>\r
         </dependency>\r
-        <dependency>\r
+        <!--dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.query.service</artifactId>\r
             <version>1.0</version>\r
index ad54486436ea80ab92bb72308f7b7699ce3726a1..1651aef3240241c6ae73ae1cdfeddaa5bfbaa6a1 100644 (file)
@@ -4,7 +4,7 @@ import org.collectionspace.services.collectionobject.CollectionObjectResource;
 import org.collectionspace.services.id.IDResource;
 import org.collectionspace.services.intake.IntakeResource;
 ////import org.collectionspace.services.relation.RelationResource;
-//import org.collectionspace.services.relation.NewRelationResource;
+import org.collectionspace.services.relation.NewRelationResource;
 import org.collectionspace.services.acquisition.AcquisitionResource;
 //import org.collectionspace.services.query.QueryResource;
 
@@ -24,7 +24,7 @@ public class CollectionSpaceJaxRsApplication extends Application {
         singletons.add(new IntakeResource());
         singletons.add(new AcquisitionResource());
 //        singletons.add(new RelationResource());
-        //singletons.add(new NewRelationResource());
+        singletons.add(new NewRelationResource());
 //        singletons.add(new QueryResource());
 //        singletons.add(new DomainIdentifierResource());
 //        singletons.add(new PingResource());
index 41ca543bdbe1a12268ed26c459dd0c065f965bc7..d1178429e27b7a3b38e470aa7e5079a0c3b27392 100644 (file)
@@ -39,6 +39,7 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.acquisition.nuxeo.AcquisitionHandlerFactory;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
+import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.repository.DocumentNotFoundException;
 import org.collectionspace.services.common.repository.DocumentHandler;
@@ -63,7 +64,7 @@ public class AcquisitionResource
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
         DocumentHandler docHandler = AcquisitionHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
@@ -84,7 +85,7 @@ public class AcquisitionResource
     public Response createAcquisition(MultipartInput input) {
 
         try{
-            ServiceContext ctx = createServiceContext(input);
+            RemoteServiceContext ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(AcquisitionResource.class);
@@ -117,7 +118,7 @@ public class AcquisitionResource
         }
         MultipartOutput result = null;
         try{
-            ServiceContext ctx = createServiceContext(null);
+            RemoteServiceContext ctx = createServiceContext(null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = ctx.getOutput();
@@ -152,7 +153,7 @@ public class AcquisitionResource
     public AcquisitionsCommonList getAcquisitionList(@Context UriInfo ui) {
         AcquisitionsCommonList acquisitionObjectList = new AcquisitionsCommonList();
         try{
-            ServiceContext ctx = createServiceContext(null);
+            RemoteServiceContext ctx = createServiceContext(null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             acquisitionObjectList = (AcquisitionsCommonList) handler.getCommonPartList();
@@ -187,7 +188,7 @@ public class AcquisitionResource
         }
         MultipartOutput result = null;
         try{
-            ServiceContext ctx = createServiceContext(theUpdate);
+            RemoteServiceContext ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = ctx.getOutput();
index 33d3cc4d9d99d4bc628110b46a3f2bf2257a6afa..4c3f15ce030333b5ea9ae0ad0658c8f181c2a5fc 100644 (file)
@@ -31,8 +31,9 @@ import org.collectionspace.services.common.repository.DocumentWrapper;
 import org.collectionspace.services.acquisition.AcquisitionsCommon;
 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
 import org.collectionspace.services.acquisition.AcquisitionsCommonList.AcquisitionListItem;
-import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 
+import org.collectionspace.services.common.repository.DocumentHandler.Action;
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -45,7 +46,7 @@ import org.slf4j.LoggerFactory;
  * $LastChangedDate: $
  */
 public class AcquisitionDocumentModelHandler
-        extends DocumentModelHandler<AcquisitionsCommon, AcquisitionsCommonList> {
+        extends RemoteDocumentModelHandler<AcquisitionsCommon, AcquisitionsCommonList> {
 
     private final Logger logger = LoggerFactory.getLogger(AcquisitionDocumentModelHandler.class);
     /**
index 4a9d5930ed8a5300d818512a9909f47041d9841f..91107383dade9ac11fd68adcd3e46b5b5237bf12 100644 (file)
@@ -40,6 +40,7 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
+import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.repository.DocumentNotFoundException;
 import org.collectionspace.services.common.repository.DocumentHandler;
@@ -64,7 +65,7 @@ public class CollectionObjectResource
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
         DocumentHandler docHandler = CollectionObjectHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
@@ -80,7 +81,7 @@ public class CollectionObjectResource
     @POST
     public Response createCollectionObject(MultipartInput input) {
         try{
-            ServiceContext ctx = createServiceContext(input);
+            RemoteServiceContext ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(CollectionObjectResource.class);
@@ -113,7 +114,7 @@ public class CollectionObjectResource
         }
         MultipartOutput result = null;
         try{
-            ServiceContext ctx = createServiceContext(null);
+            RemoteServiceContext ctx = createServiceContext(null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = ctx.getOutput();
@@ -148,7 +149,7 @@ public class CollectionObjectResource
     public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui) {
         CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
         try{
-            ServiceContext ctx = createServiceContext(null);
+            RemoteServiceContext ctx = createServiceContext(null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
@@ -180,7 +181,7 @@ public class CollectionObjectResource
         }
         MultipartOutput result = null;
         try{
-            ServiceContext ctx = createServiceContext(theUpdate);
+            RemoteServiceContext ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = ctx.getOutput();
index 800f6d5b2a8cca818feae626c1176bfe0cb12fad..e201534809cda6a08702e5fa63244b8b558bc9d3 100644 (file)
@@ -31,7 +31,7 @@ import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
 import org.collectionspace.services.common.repository.DocumentWrapper;
-import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
  * $LastChangedDate: $
  */
 public class CollectionObjectDocumentModelHandler
-        extends DocumentModelHandler<CollectionobjectsCommon, CollectionobjectsCommonList> {
+        extends RemoteDocumentModelHandler<CollectionobjectsCommon, CollectionobjectsCommonList> {
 
     private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
     /**
@@ -139,6 +139,7 @@ public class CollectionObjectDocumentModelHandler
         docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
     }
 
+    @Override
     public String getDocumentType() {
         return CollectionObjectConstants.NUXEO_DOCTYPE;
     }
index da019e737c86383f37f88f332890b13566aff63c..a7de6e827191087d13904c1c2d5fc32bda025e4b 100644 (file)
@@ -47,9 +47,7 @@ public class CollectionObjectHandlerFactory {
     public DocumentHandler getHandler(String clientType) {
         if(ClientType.JAVA.toString().equals(clientType)){
             return new CollectionObjectDocumentModelHandler();
-        } else if(ClientType.REST.toString().equals(clientType)) {
-            return new CollectionObjectRepresenationHandler();
-        }
+        } 
         throw new IllegalArgumentException("Not supported client=" + clientType);
     }
 }
diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectRepresenationHandler.java
deleted file mode 100644 (file)
index 034b087..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-/**
- *  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 University of California at Berkeley
-
- *  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
-
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.collectionspace.services.collectionobject.nuxeo;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import java.util.StringTokenizer;
-import org.collectionspace.services.CollectionObjectJAXBSchema;
-import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
-import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
-import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
-import org.collectionspace.services.common.repository.DocumentWrapper;
-import org.collectionspace.services.nuxeo.client.rest.RepresentationHandler;
-
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * CollectionObjectDocumentModelHandler
- *
- * $LastChangedRevision: $
- * $LastChangedDate: $
- */
-public class CollectionObjectRepresenationHandler
-        extends RepresentationHandler<CollectionobjectsCommon, CollectionobjectsCommonList>
-{
-
-    private final Logger logger = LoggerFactory.getLogger(CollectionObjectRepresenationHandler.class);
-    /**
-     * collectionObject is used to stash JAXB object to use when handle is called
-     * for Action.CREATE, Action.UPDATE or Action.GET
-     */
-    private CollectionobjectsCommon collectionObject;
-    /**
-     * collectionObjectList is stashed when handle is called
-     * for ACTION.GET_ALL
-     */
-    private CollectionobjectsCommonList collectionObjectList;
-
-    @Override
-    public void prepare(Action action) throws Exception {
-        switch(action){
-            case CREATE:
-            case UPDATE:
-                prepare();
-        }
-    }
-
-    private void prepare() {
-        Map<String, String> queryParams = getQueryParams();
-        CollectionobjectsCommon co = getCommonPart();
-        // todo: intelligent merge needed
-        if(co.getObjectNumber() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.OBJECT_NUMBER, co.getObjectNumber());
-        }
-
-        if(co.getOtherNumber() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.OTHER_NUMBER, co.getOtherNumber());
-        }
-
-        if(co.getBriefDescription() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, co.getBriefDescription());
-        }
-
-        if(co.getComments() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.COMMENTS, co.getComments());
-        }
-
-        if(co.getDistFeatures() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.DIST_FEATURES, co.getDistFeatures());
-        }
-
-        if(co.getObjectName() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.OBJECT_NAME, co.getObjectName());
-        }
-
-        if(co.getResponsibleDept() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, co.getResponsibleDept());
-        }
-
-        if(co.getTitle() != null){
-            queryParams.put(CollectionObjectConstants.NUXEO_SCHEMA_NAME +
-                    ":" + CollectionObjectJAXBSchema.TITLE, co.getTitle());
-        }
-    }
-
-    @Override
-    public CollectionobjectsCommon extractCommonPart(DocumentWrapper wrapDoc)
-            throws Exception {
-        Document document = (Document) wrapDoc.getWrappedObject();
-        CollectionobjectsCommon co = new CollectionobjectsCommon();
-
-        //FIXME property get should be dynamically set using schema inspection
-        //so it does not require hard coding
-        Element root = document.getRootElement();
-
-        // TODO: recognize schema thru namespace uri
-        // Namespace ns = new Namespace("collectionobject",
-        // "http://collectionspace.org/collectionobject");
-
-        Iterator<Element> siter = root.elementIterator("schema");
-        while(siter.hasNext()){
-
-            Element schemaElement = siter.next();
-            if(logger.isDebugEnabled()){
-                logger.debug("getCommonObject() populating Common Object");
-            }
-            // TODO: recognize schema thru namespace uri
-            if(CollectionObjectConstants.NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){
-                Element ele = schemaElement.element(CollectionObjectJAXBSchema.OBJECT_NUMBER);
-                if(ele != null){
-                    co.setObjectNumber((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.OTHER_NUMBER);
-                if(ele != null){
-                    co.setOtherNumber((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION);
-                if(ele != null){
-                    co.setBriefDescription((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.COMMENTS);
-                if(ele != null){
-                    co.setComments((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.DIST_FEATURES);
-                if(ele != null){
-                    co.setDistFeatures((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.OBJECT_NAME);
-                if(ele != null){
-                    co.setObjectName((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT);
-                if(ele != null){
-                    co.setResponsibleDept((String) ele.getData());
-                }
-                ele = schemaElement.element(CollectionObjectJAXBSchema.TITLE);
-                if(ele != null){
-                    co.setTitle((String) ele.getData());
-                }
-            }
-        }
-        return co;
-    }
-
-    @Override
-    public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper wrapDoc)
-            throws Exception {
-        //Nuxeo REST takes create/update through queryParams, nothing to do here
-    }
-
-    @Override
-    public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
-        Document document = (Document) wrapDoc.getWrappedObject();
-        // debug
-        if(logger.isDebugEnabled()){
-            logger.debug(document.asXML());
-        }
-        CollectionobjectsCommonList coList = new CollectionobjectsCommonList();
-        List<CollectionobjectsCommonList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
-        Element root = document.getRootElement();
-        for(Iterator i = root.elementIterator(); i.hasNext();){
-
-            Element element = (Element) i.next();
-            if(logger.isDebugEnabled()){
-                logger.debug(element.asXML());
-            }
-            // set the CollectionObject list item entity elements
-            CollectionObjectListItem coListItem = new CollectionObjectListItem();
-            coListItem.setObjectNumber(element.attributeValue("title"));
-            String id = element.attributeValue("id");
-            coListItem.setCsid(id);
-            coListItem.setUri("/collectionobjects/" + id);
-
-            list.add(coListItem);
-        }
-        return coList;
-    }
-
-
-    @Override
-    public CollectionobjectsCommon getCommonPart() {
-        return collectionObject;
-    }
-
-    @Override
-    public void setCommonPart(CollectionobjectsCommon obj) {
-        this.collectionObject = obj;
-    }
-
-    @Override
-    public CollectionobjectsCommonList getCommonPartList() {
-        return collectionObjectList;
-    }
-
-    @Override
-    public void setCommonPartList(CollectionobjectsCommonList obj) {
-        this.collectionObjectList = obj;
-    }
-    
-    public String getDocumentType() {
-       return CollectionObjectConstants.NUXEO_DOCTYPE;
-    }
-
-
-    @Override
-    public String getQProperty(String prop) {
-        return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
-    }
-
-}
-
index ddcec896d9ba1e2fe30d6d14a444243d2113ce30..66c7c7177741a96c5e2cc1a6ec509a7b3967bb6e 100644 (file)
@@ -54,7 +54,7 @@
         <!-- begin intake service meta-data -->
         <tenant:serviceBindings name="Intakes" version="0.1">
             <service:repositoryClient xmlns:service='http://collectionspace.org/services/common/service'>nuxeo-java</service:repositoryClient>
-            <service:object id="2" name="Intake" version="0.1"
+            <service:object id="1" name="Intake" version="0.1"
             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
                             versionable="true" auditable="false"
@@ -82,7 +82,7 @@
                 <!-- begin acquisition service meta-data -->
         <tenant:serviceBindings name="Acquisitions" version="0.1">
             <service:repositoryClient xmlns:service='http://collectionspace.org/services/common/service'>nuxeo-java</service:repositoryClient>
-            <service:object id="2" name="Acquisition" version="0.1"
+            <service:object id="1" name="Acquisition" version="0.1"
             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
                             versionable="true" auditable="false"
             </service:object>
         </tenant:serviceBindings>
         <!-- end acquisition service meta-data -->
+        <!-- begin relation service meta-data -->
+        <tenant:serviceBindings name="Relations" version="0.1">
+            <service:repositoryClient xmlns:service='http://collectionspace.org/services/common/service'>nuxeo-java</service:repositoryClient>
+            <service:object id="1" name="Relation" version="0.1"
+            xmlns:service='http://collectionspace.org/services/common/service'>
+                <service:part id="0" control_group="Managed"
+                            versionable="true" auditable="false"
+                            label="relations-system" updated="" order="0">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                        namespaceURI="http://collectionspace.org/services/common/system"
+                        schemaLocation="http://collectionspace.org/services/common/system http://collectionspace.org/services/common/system/system-response.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+                <service:part id="1" control_group="Managed"
+                            versionable="true" auditable="false"
+                            label="relations-common" updated="" order="1">
+                    <service:content contentType="application/xml">
+                        <service:xmlContent
+                        namespaceURI="http://collectionspace.org/services/relation"
+                        schemaLocation="http://collectionspace.org/services/relation http://services.collectionspace.org/relation/relations-common.xsd">
+                        </service:xmlContent>
+                    </service:content>
+                </service:part>
+            </service:object>
+        </tenant:serviceBindings>
+        <!-- end relation service meta-data -->
     </tenant:tenantBinding>
     <!-- end movinimages.us tenant meta-data -->
 </tenant:TenantBindingConfig>
index ad2fef0dcc03b24405d155c036c6698dec327cce..e66ea566dfc4a7f383dc6450ea6ca8fec71f7365 100644 (file)
@@ -23,8 +23,9 @@
  */\r
 package org.collectionspace.services.common;\r
 \r
+import org.collectionspace.services.common.context.RemoteServiceContext;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
-import org.collectionspace.services.common.context.ServiceContextImpl;\r
+import org.collectionspace.services.common.context.RemoteServiceContextImpl;\r
 import org.collectionspace.services.common.repository.DocumentHandler;\r
 import org.collectionspace.services.common.repository.RepositoryClient;\r
 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
@@ -59,12 +60,12 @@ public abstract class AbstractCollectionSpaceResource
     }\r
 \r
     @Override\r
-    public ServiceContext createServiceContext(MultipartInput input) throws Exception {\r
-        ServiceContext ctx = new ServiceContextImpl(getServiceName());\r
+    public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception {\r
+        RemoteServiceContext ctx = new RemoteServiceContextImpl(getServiceName());\r
         ctx.setInput(input);\r
         return ctx;\r
     }\r
 \r
     @Override\r
-    abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
+    abstract public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;\r
 }\r
index 2f601c334f85c3892ecabf4df238d8aa0e514f61..11062548f09d3b1ee228110299445e311a11b935 100644 (file)
@@ -24,6 +24,7 @@
 
 package org.collectionspace.services.common;
 
+import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.repository.DocumentHandler;
 import org.collectionspace.services.common.repository.RepositoryClient;
@@ -59,7 +60,7 @@ public interface CollectionSpaceResource {
      * @param input
      * @return
      */
-    public ServiceContext createServiceContext(MultipartInput input) throws Exception;
+    public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception;
 
     /**
      * createDocumentHandler creates a document handler and populates it with given
@@ -69,5 +70,5 @@ public interface CollectionSpaceResource {
      * @param ctx
      * @return
      */
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;
+    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;
 }
similarity index 67%
rename from services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextImpl.java
rename to services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
index b88a6a7e063db7b16019e0c2c1a43896ca835fd3..fdebfe5d420d899ab7f7be365a4b0192c8aa9f39 100644 (file)
  */
 package org.collectionspace.services.common.context;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.ws.rs.core.MediaType;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.config.TenantBindingConfigReader;
-import org.collectionspace.services.common.repository.DocumentUtils;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.service.ServiceBindingType;
 import org.collectionspace.services.common.service.ServiceObjectType;
 import org.collectionspace.services.common.tenant.TenantBindingType;
-import org.jboss.resteasy.plugins.providers.multipart.InputPart;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
 
 /**
- * ServiceContextImpl
+ * AbstractServiceContext
  *
  * $LastChangedRevision: $
  * $LastChangedDate: $
  */
-public class ServiceContextImpl
-        implements ServiceContext {
+public abstract class AbstractServiceContext<T1, T2>
+        implements ServiceContext<T1, T2> {
 
-    final Logger logger = LoggerFactory.getLogger(ServiceContextImpl.class);
-    private TenantBindingType tenantBinding;
-    private ServiceBindingType serviceBinding;
-    //input stores original content as received over the wire
-    private MultipartInput input;
-    private MultipartOutput output;
+    final Logger logger = LoggerFactory.getLogger(AbstractServiceContext.class);
     Map<String, ObjectPartType> objectPartMap = new HashMap<String, ObjectPartType>();
+    private ServiceBindingType serviceBinding;
+    private TenantBindingType tenantBinding;
 
-    @Override
-    public String toString() {
-        return "ServiceContextImpl [" +
-                "service name=" + serviceBinding.getName() + " " +
-                "service version=" + serviceBinding.getVersion() + " " +
-                "tenant id=" + tenantBinding.getId() + " " +
-                "tenant name=" + tenantBinding.getName() + " " + tenantBinding.getDisplayName() + " " +
-                "tenant repository domain=" + tenantBinding.getRepositoryDomain() + " " +
-                "]";
-    }
-
-    public ServiceContextImpl(String serviceName) {
+    public AbstractServiceContext(String serviceName) {
         TenantBindingConfigReader tReader =
                 ServiceMain.getInstance().getTenantBindingConfigReader();
         //TODO: get tenant binding from security context (Subject.g
@@ -97,38 +74,36 @@ public class ServiceContextImpl
             logger.debug("tenantId=" + tenantId +
                     " service binding=" + serviceBinding.getName());
         }
-        output = new MultipartOutput();
-    }
-
-    @Override
-    public String getTenantId() {
-        return tenantBinding.getId();
-    }
-
-    @Override
-    public String getTenantName() {
-        return tenantBinding.getName();
     }
 
+    /**
+     * getCommonPartLabel get common part label
+     * @return
+     */
     @Override
-    public ServiceBindingType getServiceBinding() {
-        return serviceBinding;
+    public String getCommonPartLabel() {
+        return getServiceName().toLowerCase() + "-common";
     }
 
     @Override
-    public String getServiceName() {
-        return serviceBinding.getName();
+    public Map<String, ObjectPartType> getPartsMetadata() {
+        if(objectPartMap.size() != 0){
+            return objectPartMap;
+        }
+        ServiceBindingType serviceBinding = getServiceBinding();
+        List<ServiceObjectType> objectTypes = serviceBinding.getObject();
+        for(ServiceObjectType objectType : objectTypes){
+            List<ObjectPartType> objectPartTypes = objectType.getPart();
+            for(ObjectPartType objectPartType : objectPartTypes){
+                objectPartMap.put(objectPartType.getLabel(), objectPartType);
+            }
+        }
+        return objectPartMap;
     }
 
     @Override
     public String getQualifiedServiceName() {
-        return TenantBindingConfigReader.getTenantQualifiedServiceName(
-                getTenantId(), getServiceName());
-    }
-
-    @Override
-    public String getRepositoryDomainName() {
-        return tenantBinding.getRepositoryDomain();
+        return TenantBindingConfigReader.getTenantQualifiedServiceName(getTenantId(), getServiceName());
     }
 
     @Override
@@ -143,97 +118,63 @@ public class ServiceContextImpl
     }
 
     @Override
-    public String getRepositoryWorkspaceName() {
-        //service name is workspace name by convention
-        return serviceBinding.getName();
+    public String getRepositoryDomainName() {
+        return tenantBinding.getRepositoryDomain();
     }
 
     @Override
     public String getRepositoryWorkspaceId() {
-        TenantBindingConfigReader tbConfigReader =
-                ServiceMain.getInstance().getTenantBindingConfigReader();
+        TenantBindingConfigReader tbConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
         return tbConfigReader.getWorkspaceId(getTenantId(), getServiceName());
     }
 
     @Override
-    public MultipartInput getInput() {
-        return input;
+    public String getRepositoryWorkspaceName() {
+        //service name is workspace name by convention
+        return serviceBinding.getName();
     }
 
     @Override
-    public MultipartOutput getOutput() {
-        return output;
+    public ServiceBindingType getServiceBinding() {
+        return serviceBinding;
     }
 
     @Override
-    public Object getInputPart(String label, Class clazz) throws IOException {
-        Object obj = null;
-        if(getInput() != null){
-            MultipartInput fdip = getInput();
-
-            for(InputPart part : fdip.getParts()){
-                String partLabel = part.getHeaders().getFirst("label");
-                if(label.equalsIgnoreCase(partLabel)){
-                    if(logger.isDebugEnabled()){
-                        logger.debug("received part label=" + partLabel +
-                                "\npayload=" + part.getBodyAsString());
-                    }
-                    obj = part.getBody(clazz, null);
-                    break;
-                }
-            }
-        }
-        return obj;
+    public String getServiceName() {
+        return serviceBinding.getName();
     }
 
     @Override
-    public void addOutputPart(String label, Document doc, String contentType) throws Exception {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        try{
-            DocumentUtils.writeDocument(doc, baos);
-            baos.close();
-            OutputPart part = output.addPart(new String(baos.toByteArray()),
-                    MediaType.valueOf(contentType));
-            part.getHeaders().add("label", label);
-        }finally{
-            if(baos != null){
-                try{
-                    baos.close();
-                }catch(Exception e){
-                }
-            }
-        }
+    public String getTenantId() {
+        return tenantBinding.getId();
     }
 
     @Override
-    public void setInput(MultipartInput input) throws IOException {
-        this.input = input;
+    public String getTenantName() {
+        return tenantBinding.getName();
     }
 
     @Override
-    public Map<String, ObjectPartType> getPartsMetadata() {
-        if(objectPartMap.size() != 0){
-            return objectPartMap;
-        }
+    public abstract T1 getInput();
 
-        ServiceBindingType serviceBinding = getServiceBinding();
-        List<ServiceObjectType> objectTypes = serviceBinding.getObject();
-        for(ServiceObjectType objectType : objectTypes){
-            List<ObjectPartType> objectPartTypes = objectType.getPart();
-            for(ObjectPartType objectPartType : objectPartTypes){
-                objectPartMap.put(objectPartType.getLabel(), objectPartType);
-            }
+    @Override
+    public abstract void setInput(T1 input) throws Exception;
 
-        }
-        return objectPartMap;
-    }
+    @Override
+    public abstract T2 getOutput();
 
-    /**
-     * getCommonPartLabel get common part label
-     * @return
-     */
     @Override
-    public String getCommonPartLabel() {
-        return getServiceName().toLowerCase() + "-common";
+    public abstract void setOutput(T2 output) throws Exception;
+
+    @Override
+    public String toString() {
+        return "AbstractServiceContext [" +
+                "service name=" + serviceBinding.getName() + " " +
+                "service version=" + serviceBinding.getVersion() + " " +
+                "tenant id=" + tenantBinding.getId() + " " +
+                "tenant name=" + tenantBinding.getName() + " " +
+                tenantBinding.getDisplayName() + " " +
+                "tenant repository domain=" + tenantBinding.getRepositoryDomain() + " " +
+                "]";
     }
 }
diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java
new file mode 100644 (file)
index 0000000..9ec071d
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ *  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 University of California at Berkeley
+
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.context;
+
+import java.io.IOException;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteServiceContext is used to encapsulate the service context of a
+ * remotely invokable service
+ */
+public interface RemoteServiceContext
+        extends ServiceContext<MultipartInput, MultipartOutput> {
+
+    /**
+     * Get input parts as received over the wire from service consumer
+     * @return the input
+     */
+    @Override
+    public MultipartInput getInput();
+
+    /**
+     * setInput is used to set request input before starting to
+     * process input data
+     * @param input
+     * @exception IOException
+     */
+    @Override
+    public void setInput(MultipartInput input) throws Exception;
+
+    /**
+     * Get output parts to send over the wire to service consumer
+     * @return the output
+     */
+    @Override
+    public MultipartOutput getOutput();
+
+    /**
+     * Set output parts to send over the wire to service consumer
+     * @return the output
+     */
+    @Override
+    public void setOutput(MultipartOutput output) throws Exception;
+
+    /**
+     * getInputPart returns part for given label from input
+     * @param label
+     * @param clazz class of the object
+     * @return part
+     */
+    public Object getInputPart(String label, Class clazz) throws IOException;
+
+    /**
+     * addOutputPart adds given XML part with given label and content type to output
+     * @param label
+     * @param document
+     * @param contentType media type
+     */
+    public void addOutputPart(String label, Document doc, String contentType) throws Exception;
+
+    /**
+     * getLocalContext clones the remote context minus remote messaging data parts
+     * this method is useful to object a local service context to invoke a service locally
+     * @param local context class namee
+     * @return local service context
+     */
+    public ServiceContext getLocalContext(String localContextClassName) throws Exception;
+}
diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java
new file mode 100644 (file)
index 0000000..af6f5b4
--- /dev/null
@@ -0,0 +1,132 @@
+/**
+ *  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 University of California at Berkeley
+
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.context;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import javax.ws.rs.core.MediaType;
+import org.collectionspace.services.common.repository.DocumentUtils;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteServiceContextImpl
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public class RemoteServiceContextImpl
+        extends AbstractServiceContext<MultipartInput, MultipartOutput>
+        implements RemoteServiceContext {
+
+    final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
+    //input stores original content as received over the wire
+    private MultipartInput input;
+    private MultipartOutput output;
+
+    public RemoteServiceContextImpl(String serviceName) {
+        super(serviceName);
+        output = new MultipartOutput();
+    }
+
+    @Override
+    public MultipartInput getInput() {
+        return input;
+    }
+
+    @Override
+    public void setInput(MultipartInput input) throws IOException {
+        this.input = input;
+    }
+
+    @Override
+    public MultipartOutput getOutput() {
+        return output;
+    }
+
+    @Override
+    public void setOutput(MultipartOutput output) throws Exception {
+        this.output = output;
+    }
+
+    @Override
+    public Object getInputPart(String label, Class clazz) throws IOException {
+        Object obj = null;
+        if(getInput() != null){
+            MultipartInput fdip = getInput();
+
+            for(InputPart part : fdip.getParts()){
+                String partLabel = part.getHeaders().getFirst("label");
+                if(label.equalsIgnoreCase(partLabel)){
+                    if(logger.isDebugEnabled()){
+                        logger.debug("received part label=" + partLabel +
+                                "\npayload=" + part.getBodyAsString());
+                    }
+                    obj = part.getBody(clazz, null);
+                    break;
+                }
+            }
+        }
+        return obj;
+    }
+
+    @Override
+    public void addOutputPart(String label, Document doc, String contentType) throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try{
+            DocumentUtils.writeDocument(doc, baos);
+            baos.close();
+            OutputPart part = output.addPart(new String(baos.toByteArray()),
+                    MediaType.valueOf(contentType));
+            part.getHeaders().add("label", label);
+        }finally{
+            if(baos != null){
+                try{
+                    baos.close();
+                }catch(Exception e){
+                }
+            }
+        }
+    }
+
+    @Override
+    public ServiceContext getLocalContext(String localContextClassName) throws Exception {
+        ClassLoader cloader = Thread.currentThread().getContextClassLoader();
+        Class ctxClass = cloader.loadClass(localContextClassName);
+        if(!ServiceContext.class.isAssignableFrom(ctxClass)) {
+            throw new IllegalArgumentException("getLocalContext requires " +
+                    " implementation of " + ServiceContext.class.getName());
+        }
+        
+        Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
+        ServiceContext ctx = (ServiceContext)ctor.newInstance(getServiceName());
+        return ctx;
+    }
+}
index a74d5561db37d883508adfd106ccb538b8ba7fdf..ab63c0e11363d8acf6eaa0a82b39708607703549 100644 (file)
  */
 package org.collectionspace.services.common.context;
 
-import java.io.IOException;
 import java.util.Map;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.service.ServiceBindingType;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.w3c.dom.Document;
 
 /**
  *
@@ -38,7 +34,7 @@ import org.w3c.dom.Document;
  * between various components of the service framework while processing
  * a service request.
  */
-public interface ServiceContext {
+public interface ServiceContext<T1, T2> {
 
     /**
      * getTenantId get tenant id
@@ -108,41 +104,31 @@ public interface ServiceContext {
      */
     public String getRepositoryWorkspaceId();
 
-    /**
-     * setInput is used to set (multipart) request input before starting to
-     * process input data
-     * @param input multipart data input
-     * @exception IOException
-     */
-    public void setInput(MultipartInput input) throws IOException;
-
     /**
      * Get input parts as received over the wire from service consumer
      * @return the input
      */
-    public MultipartInput getInput();
+    public T1 getInput();
 
     /**
-     * Get output parts to send over the wire to service consumer
-     * @return the output
+     * setInput is used to set request input before starting to
+     * process input data
+     * @param input
+     * @exception Exception
      */
-    public MultipartOutput getOutput();
+    public void setInput(T1 input) throws Exception;
 
     /**
-     * getInputPart returns part for given label from input
-     * @param label
-     * @param clazz class of the object
-     * @return part
+     * Get output parts to send over the wire to service consumer
+     * @return the output
      */
-    public Object getInputPart(String label, Class clazz) throws IOException;
+    public T2 getOutput();
 
     /**
-     * addOutputPart adds given XML part with given label and content type to output
-     * @param label
-     * @param document
-     * @param contentType media type
+     * setOutput set output
+     * @param output
      */
-    public void addOutputPart(String label, Document doc, String contentType) throws Exception;
+    public void setOutput(T2 output) throws Exception;
 
     /**
      * getPartsMetadata returns metadata for object parts used by the service
index 07e17b35bad409b020759bb8c6545b19fc4e8ee9..e6345719aab36e3bed6fd239135876f803d61afd 100644 (file)
@@ -1,5 +1,5 @@
 /**    \r
- * RelationUtils.java\r
+ * IRelationsManager.java\r
  *\r
  * {Purpose of This Class}\r
  *\r
  */\r
 package org.collectionspace.services.common.relation;\r
 \r
-import java.io.IOException;\r
 import java.util.List;\r
 \r
+\r
 import org.collectionspace.services.common.repository.DocumentException;\r
-import org.collectionspace.services.relation.Relation;\r
-import org.dom4j.Document;\r
+import org.collectionspace.services.relation.RelationsCommon;\r
 import org.nuxeo.ecm.core.api.DocumentModel;\r
 \r
 /**\r
- * The Interface RelationUtils.\r
+ * The Interface IRelationsManager.\r
  */\r
 public interface IRelationsManager {\r
 \r
-       /**\r
-        * Gets the relationships.\r
-        * \r
-        * @param repoSession the repo session\r
-        * \r
-        * @return the relationships\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       public List<Relation> getRelationships(Object repoSession)\r
-                       throws DocumentException;\r
+    /** The Constant SUBJECT. */\r
+    static public final String SUBJECT = "subjectCsid";\r
+    /** The Constant PREDICATE. */\r
+    static public final String PREDICATE = "predicate";\r
+    /** The Constant OBJECT. */\r
+    static public final String OBJECT = "objectCsid";\r
+\r
+\r
+    /**\r
+     * Gets the relationships for the entity corresponding to the CSID=csid.\r
+     * The csid refers to either the subject *OR* the object.\r
+     *\r
+     * @param nuxeoRepoSession the nuxeo repo session\r
+     * @param csid the csid\r
+     *\r
+     * @return the relationships\r
+     *\r
+     * @throws DocumentException the document exception\r
+     */\r
+    public List<RelationsCommon> getRelationships(Object nuxeoRepoSession, String csid)\r
+            throws DocumentException;\r
+\r
+    /**\r
+     * Gets the relationships.\r
+     *\r
+     * @param repoSession the repo session\r
+     * @param subjectCsid the subject csid\r
+     * @param relationType the relation type\r
+     * @param objectCsid the object csid\r
+     *\r
+     * @return the relationships\r
+     *\r
+     * @throws DocumentException the document exception\r
+     */\r
+    public List<RelationsCommon> getRelationships(Object repoSession,\r
+            String subjectCsid,\r
+            String relationType,\r
+            String objectCsid)\r
+            throws DocumentException;\r
+\r
+    /**\r
+     * Creates the relationship.\r
+     *\r
+     * @param repoSession the repo session\r
+     * @param subjectCsid the subject csid\r
+     * @param predicate the predicate\r
+     * @param objectCsid the object csid\r
+     *\r
+     * @return the relation\r
+     *\r
+     * @throws DocumentException the document exception\r
+     */\r
+    public RelationsCommon createRelationship(Object repoSession, String subjectCsid,\r
+            String predicate, String objectCsid) throws DocumentException;\r
 \r
-       /**\r
-        * Gets the relationships for the entity corresponding to the CSID=csid.\r
-        * The csid refers to either the subject *OR* the object.\r
-        * \r
-        * @param nuxeoRepoSession the nuxeo repo session\r
-        * @param csid the csid\r
-        * \r
-        * @return the relationships\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       public List<Relation> getRelationships(Object nuxeoRepoSession, String csid)\r
-               throws DocumentException;\r
-       \r
-       /**\r
-        * Gets the relationships.\r
-        * \r
-        * @param repoSession the repo session\r
-        * @param subjectCsid the subject csid\r
-        * @param relationType the relation type\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return the relationships\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       public List<Relation> getRelationships(Object repoSession,\r
-                       String subjectCsid, \r
-                       String relationType, \r
-                       String objectCsid)\r
-               throws DocumentException;\r
+    /**\r
+     * Gets the q property name.\r
+     *\r
+     * @param propertyName the property name\r
+     *\r
+     * @return the q property name\r
+     */\r
+    public String getQPropertyName(String propertyName);\r
 \r
-       /**\r
-        * Creates the relationship.\r
-        * \r
-        * @param repoSession the repo session\r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return the relation\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       public Relation createRelationship(Object repoSession, String subjectCsid,\r
-                       String predicate, String objectCsid) throws DocumentException;\r
-       \r
-       /**\r
-        * Gets the q property name.\r
-        * \r
-        * @param propertyName the property name\r
-        * \r
-        * @return the q property name\r
-        */\r
-       public String getQPropertyName(String propertyName);\r
-       \r
-       /**\r
-        * Checks if is query match.\r
-        * \r
-        * @param documentModel the document model\r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return true, if is query match\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       public boolean isQueryMatch(DocumentModel documentModel,\r
-                       String subjectCsid,\r
-                       String predicate,\r
-                       String objectCsid) throws DocumentException;    \r
-}
\ No newline at end of file
+    /**\r
+     * Checks if is query match.\r
+     *\r
+     * @param documentModel the document model\r
+     * @param subjectCsid the subject csid\r
+     * @param predicate the predicate\r
+     * @param objectCsid the object csid\r
+     *\r
+     * @return true, if is query match\r
+     *\r
+     * @throws DocumentException the document exception\r
+     */\r
+    public boolean isQueryMatch(DocumentModel documentModel,\r
+            String subjectCsid,\r
+            String predicate,\r
+            String objectCsid) throws DocumentException;\r
+}\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java
deleted file mode 100644 (file)
index 4658e85..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/**    \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.relation;\r
-\r
-import java.io.IOException;\r
-import java.util.List;\r
-\r
-import org.collectionspace.services.common.repository.DocumentException;\r
-import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl;\r
-import org.collectionspace.services.relation.Relation;\r
-import org.collectionspace.services.common.relation.IRelationsManager;\r
-\r
-import org.dom4j.Document;\r
-import org.nuxeo.ecm.core.api.DocumentModel;\r
-\r
-/**\r
- * The Class RelationsManager.\r
- */\r
-public class RelationsManager {\r
-\r
-       /** The Constant SUBJECT. */\r
-       static public final String SUBJECT = "subjectCsid";\r
-       \r
-       /** The Constant PREDICATE. */\r
-       static public final String PREDICATE = "predicate";\r
-       \r
-       /** The Constant OBJECT. */\r
-       static public final String OBJECT = "objectCsid";\r
-\r
-       /** The relation utils. */\r
-       static private IRelationsManager relationUtils = new RelationsManagerNuxeoImpl();\r
-\r
-       /**\r
-        * Gets the relationships.\r
-        * \r
-        * @param repoSession the repo session\r
-        * \r
-        * @return the relationships\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public List<Relation> getRelationships(Object repoSession)\r
-                       throws DocumentException {\r
-               return relationUtils.getRelationships(repoSession);\r
-       }\r
-               \r
-       /**\r
-        * Gets the relationships.\r
-        * \r
-        * @param repoSession the repo session\r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return the relationships\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public List<Relation> getRelationships(Object repoSession, String subjectCsid, String predicate, String objectCsid)\r
-                       throws DocumentException {\r
-               return relationUtils.getRelationships(repoSession, subjectCsid, predicate, objectCsid);\r
-       }\r
-       \r
-       /**\r
-        * Gets the relationships.\r
-        * \r
-        * @param repoSession the repo session\r
-        * @param csid the csid\r
-        * \r
-        * @return the relationships\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public List<Relation> getRelationships(Object repoSession,\r
-                       String csid) throws DocumentException {\r
-               return relationUtils.getRelationships(repoSession, csid);\r
-       }\r
-               \r
-       /**\r
-        * Creates the relationship.\r
-        * \r
-        * @param repoSession the repo session\r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return the relation\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public Relation createRelationship(Object repoSession,\r
-                       String subjectCsid,\r
-                       String predicate,\r
-                       String objectCsid) throws DocumentException {\r
-               return relationUtils.createRelationship(repoSession, subjectCsid,\r
-                               predicate, objectCsid);\r
-       }\r
-       \r
-       /**\r
-        * Gets the q property name.\r
-        * \r
-        * @param propertyName the property name\r
-        * \r
-        * @return the q property name\r
-        */\r
-       static public String getQPropertyName(String propertyName) {\r
-               return relationUtils.getQPropertyName(propertyName);\r
-       }\r
-       \r
-       /**\r
-        * Checks if is query match.\r
-        * \r
-        * @param documentModel the document model\r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return true, if is query match\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public boolean isQueryMatch(DocumentModel documentModel,\r
-                       String subjectCsid, String predicate, String objectCsid)\r
-                       throws DocumentException {\r
-               return relationUtils.isQueryMatch(documentModel, subjectCsid,\r
-                               predicate, objectCsid);\r
-       }\r
-\r
-}\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java
new file mode 100644 (file)
index 0000000..6945552
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ *  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 University of California at Berkeley
+
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.relation.nuxeo;
+
+/**
+ * CollectionObjectConstants processes CollectionObject document
+ *
+ */
+public class RelationConstants {
+
+    public final static String NUXEO_DOCTYPE = "Relation";
+    public final static String NUXEO_SCHEMA_NAME = "relation";
+    public final static String NUXEO_DC_TITLE = "CollectionSpace-Relation";
+    /** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */
+    final public static String NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype";
+}
diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java
deleted file mode 100644 (file)
index aa3effe..0000000
+++ /dev/null
@@ -1,633 +0,0 @@
-/**    \r
- * RelationUtilsNuxeoImpl.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.relation.nuxeo;\r
-\r
-import java.io.IOException;\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.collectionspace.services.common.relation.RelationJAXBSchema;\r
-import org.collectionspace.services.common.relation.RelationListItemJAXBSchema;\r
-import org.collectionspace.services.common.relation.IRelationsManager;\r
-\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.relation.RelationList.RelationListItem;\r
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
-import org.collectionspace.services.common.repository.DocumentException;\r
-\r
-import org.dom4j.Document;\r
-import org.dom4j.Element;\r
-import org.dom4j.dom.DOMElement;\r
-import org.dom4j.dom.DOMDocument;\r
-import org.dom4j.dom.DOMDocumentFactory;\r
-//import org.dom4j.DocumentException;\r
-\r
-import org.nuxeo.common.utils.IdUtils;\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
-//import org.w3c.dom.DOMException;\r
-//import org.w3c.dom.Element;\r
-\r
-/**\r
- * The Class RelationUtilsNuxeoImpl.\r
- */\r
-public class RelationsManagerNuxeoImpl implements IRelationsManager {\r
-       \r
-       /** The C s_ relatio n_ servic e_ name. */\r
-       static public String CS_RELATION_SERVICE_NAME = "relations";\r
-       \r
-       /** The C s_ empt y_ string. */\r
-       static public String CS_EMPTY_STRING = "";\r
-       \r
-       /** The Constant REL_NUXEO_DOCTYPE. */\r
-       final public static String REL_NUXEO_DOCTYPE = "Relation";\r
-       \r
-       /** The Constant REL_NUXEO_SCHEMA_NAME. */\r
-       final public static String REL_NUXEO_SCHEMA_NAME = "relation";\r
-       \r
-       /** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */\r
-       final public static String REL_NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype";\r
-       \r
-       /** The Constant REL_NUXEO_DC_TITLE. */\r
-       final public static String REL_NUXEO_DC_TITLE = "CollectionSpace-Relation";\r
-       \r
-       /** The logger. */\r
-       private static Logger logger = LoggerFactory\r
-       .getLogger(RelationsManagerNuxeoImpl.class);    \r
-\r
-\r
-       /**\r
-        * Fill relation from doc model.\r
-        * \r
-        * @param relation the relation\r
-        * @param relDocModel the rel doc model\r
-        * \r
-        * @throws ClientException the client exception\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
-               relation.setCsid(relDocModel.getId());\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_2);\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
-       /**\r
-        * Fill relation list item from doc model.\r
-        * \r
-        * @param relationListItem the relation list item\r
-        * @param relDocModel the rel doc model\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public void fillRelationListItemFromDocModel(RelationListItem relationListItem,\r
-                       DocumentModel relDocModel)\r
-               throws DocumentException {\r
-\r
-               try {\r
-                       relationListItem.setCsid(\r
-                                       relDocModel.getId());\r
-                       relationListItem.setUri(\r
-                                       getRelURL(CS_RELATION_SERVICE_NAME, relDocModel.getId()));\r
-               } catch (Exception e) {\r
-                       if (logger.isDebugEnabled()) {\r
-                               logger.debug("Caught exception in fillRelationListItemFromDocModel", e);\r
-                       }\r
-                       throw new DocumentException(e);\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Fill doc model list from relation list.\r
-        * \r
-        * @param relationList the relation list\r
-        * @param relDocModelList the rel doc model list\r
-        * \r
-        * @throws Exception the exception\r
-        */\r
-       static public void fillDocModelListFromRelationList(RelationList relationList,\r
-                       DocumentModelList relDocModelList)\r
-               throws Exception {\r
-       }       \r
-       \r
-       /**\r
-        * Fill doc model from relation.\r
-        * \r
-        * @param p the p\r
-        * @param relDocModel the rel doc model\r
-        * \r
-        * @throws Exception the exception\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
-       /**\r
-        * Prints the document model.\r
-        * \r
-        * @param documentModel the document model\r
-        */\r
-       static public void printDocumentModel(DocumentModel documentModel) {\r
-               System.out.println(documentModel);\r
-       }\r
-       \r
-       /**\r
-        * Describe document model.\r
-        * \r
-        * @param docModel the doc model\r
-        * \r
-        * @throws Exception the exception\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
-       /**\r
-        * Creates the relationship.\r
-        * \r
-        * @param nuxeoRepoSession the nuxeo repo session\r
-        * @param newRelation the new relation\r
-        * \r
-        * @return the document model\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public DocumentModel createRelationship(Object nuxeoRepoSession, Relation newRelation)\r
-                       throws DocumentException {\r
-               DocumentModel result = null;\r
-               RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
-               \r
-               try {\r
-                       // get the Nuxeo 'Relations' workspace\r
-                       DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession,\r
-                                       CS_RELATION_SERVICE_NAME);\r
-                       \r
-               String docType = 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
-               newRelation.setCsid(newRelDocModel.getId());\r
-               fillDocModelFromRelation(newRelation, newRelDocModel);\r
-               \r
-               //create document with the new DocumentModel\r
-               result = repoSession.createDocument(newRelDocModel);\r
-               repoSession.save();\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-                       throw new DocumentException(e);\r
-               }\r
-               \r
-               return result;\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.common.RelationUtils#createRelationship(java.lang.Object, java.lang.String, java.lang.String, java.lang.String)\r
-        */\r
-       public Relation createRelationship(Object nuxeoRepoSession, String subjectCsid, String predicate,\r
-                       String objectCsid) throws DocumentException {\r
-               Relation result = null;\r
-               RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
-               \r
-        Relation temp = new Relation();\r
-        temp.setDocumentId1(subjectCsid);\r
-        temp.setRelationshipType(null);\r
-        temp.setDocumentId2(objectCsid);\r
-        createRelationship(repoSession, temp);\r
-               \r
-               return result;\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object)\r
-        */\r
-       public List<Relation> getRelationships(Object nuxeoRepoSession)\r
-                       throws DocumentException {\r
-               List<Relation> result = null;\r
-               RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
-\r
-               try {\r
-                       DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
-                                       repoSession, CS_RELATION_SERVICE_NAME);\r
-                       DocumentModelList children = repoSession.getChildren(relationWorkspace\r
-                                       .getRef());\r
-                       \r
-                       result = new ArrayList<Relation>();\r
-                       Relation relation = null;\r
-                       for (DocumentModel child : children) {\r
-                               relation = new Relation();\r
-                               fillRelationFromDocModel(relation, child);\r
-                               result.add(relation);\r
-                       }\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-                       throw new DocumentException(e);\r
-               }\r
-\r
-               return result;\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object, java.lang.String)\r
-        */\r
-       public List<Relation> getRelationships(Object nuxeoRepoSession, String csid)\r
-                       throws DocumentException {\r
-               List<Relation> result = null;\r
-               RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
-                               \r
-               try {\r
-                       DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
-                                       repoSession, CS_RELATION_SERVICE_NAME);\r
-                       DocumentModelList children = repoSession.getChildren(relationWorkspace\r
-                                       .getRef());\r
-                       \r
-                       result = new ArrayList<Relation>();\r
-                       Relation relation = null;\r
-                       for (DocumentModel child : children) {\r
-                               if ((isSubjectOfRelation(csid, child) == true) ||\r
-                                               (isObjectOfRelation(csid, child) == true)) {\r
-                                       relation = new Relation();\r
-                                       fillRelationFromDocModel(relation, child);\r
-                                       result.add(relation);\r
-                               }\r
-                       }\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-                       throw new DocumentException(e);\r
-               }\r
-               \r
-               return result;\r
-       }\r
-       \r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object, java.lang.String, java.lang.String, java.lang.String)\r
-        */\r
-       public List<Relation> getRelationships(Object nuxeoRepoSession,\r
-                       String subjectCsid, \r
-                       String predicate, \r
-                       String objectCsid) throws DocumentException {\r
-               List<Relation> result = null;\r
-               RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
-               \r
-               try {\r
-                       DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
-                                       repoSession, CS_RELATION_SERVICE_NAME);\r
-                       DocumentModelList children = repoSession.getChildren(relationWorkspace\r
-                                       .getRef());\r
-                       \r
-                       result = new ArrayList<Relation>();\r
-                       Relation relation = null;\r
-                       for (DocumentModel child : children) {\r
-                               if (isQueryMatch(child, subjectCsid, predicate, objectCsid) == true) {\r
-                                       relation = new Relation();\r
-                                       fillRelationFromDocModel(relation, child);\r
-                                       result.add(relation);                   }\r
-                       }\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-                       throw new DocumentException(e);\r
-               }\r
-               \r
-               return result;\r
-       }\r
-               \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.common.relation.RelationUtils#getQPropertyName(java.lang.String)\r
-        */\r
-       public String getQPropertyName(String propertyName) {\r
-               return "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/" + propertyName;\r
-       }\r
-               \r
-       /**\r
-        * Checks if is subject of relation.\r
-        * \r
-        * @param csid the csid\r
-        * @param documentModel the document model\r
-        * \r
-        * @return true, if is subject of relation\r
-        * \r
-        * @throws ClientException the client exception\r
-        */\r
-       private boolean isSubjectOfRelation(String csid, DocumentModel documentModel)\r
-                       throws ClientException {\r
-               boolean result = false;\r
-               String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
-\r
-               Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
-                               + RelationJAXBSchema.DOCUMENT_ID_1);\r
-               if (valueObject != null && csid != null) {\r
-                       String subjectID = (String) valueObject;\r
-                       result = subjectID.equals(csid);\r
-               }\r
-               \r
-               return result;\r
-       }\r
-\r
-       /**\r
-        * Checks if is object of relation.\r
-        * \r
-        * @param csid the csid\r
-        * @param documentModel the document model\r
-        * \r
-        * @return true, if is object of relation\r
-        * \r
-        * @throws ClientException the client exception\r
-        */\r
-       private boolean isObjectOfRelation(String csid, DocumentModel documentModel)\r
-                       throws ClientException {\r
-               boolean result = false;\r
-               String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
-\r
-               Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
-                               xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2);\r
-               if (valueObject != null  && csid != null) {\r
-                       String subjectID = (String) valueObject;\r
-                       result = subjectID.equals(csid);\r
-               }\r
-\r
-               return result;\r
-       }\r
-       \r
-       /**\r
-        * Checks if is predicate of relation.\r
-        * \r
-        * @param predicate the predicate\r
-        * @param documentModel the document model\r
-        * \r
-        * @return true, if is predicate of relation\r
-        * \r
-        * @throws ClientException the client exception\r
-        */\r
-       private boolean isPredicateOfRelation(String predicate,\r
-                       DocumentModel documentModel) throws ClientException {\r
-               boolean result = false;\r
-               String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
-\r
-               Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
-                               xpathRoot + RelationJAXBSchema.RELATIONSHIP_TYPE);\r
-               if (valueObject != null  && predicate != null) {\r
-                       String relationType = (String) valueObject;\r
-                       result = predicate.equalsIgnoreCase(relationType);\r
-               }\r
-\r
-               return result;\r
-       }\r
-\r
-       /**\r
-        * Gets the object from subject.\r
-        * \r
-        * @param csid the csid\r
-        * @param documentModel the document model\r
-        * \r
-        * @return the object from subject\r
-        * \r
-        * @throws ClientException the client exception\r
-        */\r
-       private String getObjectFromSubject(String csid, DocumentModel documentModel)\r
-                       throws ClientException {\r
-               String result = null;\r
-               String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
-\r
-               Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
-                               xpathRoot + RelationJAXBSchema.DOCUMENT_ID_1);\r
-               if (valueObject != null) {\r
-                       String subjectID = (String) valueObject;\r
-                       if (subjectID.equals(csid) == true) {\r
-                               valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
-                                               xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2);\r
-                               if (valueObject != null) {\r
-                                       result = (String) valueObject;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               return result;\r
-       }\r
-       \r
-       /**\r
-        * Gets the document.\r
-        * \r
-        * @param relationList the relation list\r
-        * \r
-        * @return the document\r
-        * \r
-        * @throws DocumentException the document exception\r
-        */\r
-       static public Document getDocument(List<Relation> relationList)\r
-                       throws DocumentException {\r
-               DOMDocumentFactory domfactory = new DOMDocumentFactory();\r
-               DOMDocument result = (DOMDocument) domfactory.createDocument();\r
-\r
-               try {\r
-                       // setup the root element\r
-                       DOMElement root = (DOMElement) result\r
-                                       .createElement(RelationListItemJAXBSchema.REL_ROOT_ELEM_NAME);\r
-                       result.setRootElement((org.dom4j.Element) root);\r
-\r
-                       // populate the document with child elements\r
-                       for (Relation child : relationList) {\r
-                               DOMElement el = (DOMElement) result.createElement(RelationJAXBSchema.REL_ROOT_ELEM_NAME);\r
-                               el.setAttribute(RelationListItemJAXBSchema.CSID, child\r
-                                               .getCsid());\r
-                               el.setAttribute(RelationListItemJAXBSchema.URI, getRelURL(\r
-                                               CS_RELATION_SERVICE_NAME, child.getCsid()));\r
-\r
-                               if (logger.isDebugEnabled() == true) {\r
-                                       System.out.println(el.asXML());\r
-                               }\r
-                               \r
-                               root.appendChild(el);\r
-                       }\r
-               } catch (Exception e) {\r
-                       if (logger.isDebugEnabled()) {\r
-                               logger.debug("Caught exception ", e);\r
-                       }\r
-                       throw new DocumentException(e);\r
-               }\r
-\r
-               if (logger.isDebugEnabled() == true) {\r
-                       System.out.println(result.asXML());\r
-               }\r
-\r
-               return result;\r
-       }\r
-       \r
-       /**\r
-        * Checks if is query match.\r
-        * \r
-        * @param documentModel the document model\r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return true, if is query match\r
-        * \r
-        * @throws ClientException the client exception\r
-        */\r
-       public boolean isQueryMatch(DocumentModel documentModel,\r
-                       String subjectCsid,\r
-                       String predicate,\r
-                       String objectCsid) throws DocumentException {\r
-               boolean result = true;\r
-               \r
-               try {\r
-               block: {\r
-                       if (subjectCsid != null) {\r
-                               if (isSubjectOfRelation(subjectCsid, documentModel) == false) {\r
-                                       result = false;\r
-                                       break block;\r
-                               }\r
-                       }\r
-                       if (predicate != null) {\r
-                               if (isPredicateOfRelation(predicate, documentModel) == false) {\r
-                                       result = false;\r
-                                       break block;\r
-                               }\r
-                       }\r
-                       if (objectCsid != null) {\r
-                               if (isObjectOfRelation(objectCsid, documentModel) == false) {\r
-                                       result = false;\r
-                                       break block;\r
-                               }\r
-                       }\r
-               }\r
-               } catch (ClientException e) {\r
-                       if (logger.isDebugEnabled() == true) {\r
-                               e.printStackTrace();\r
-                       }\r
-                       throw new DocumentException(e);\r
-               }\r
-               \r
-               return result;\r
-       }\r
-       \r
-    /**\r
-     * Gets the rel url.\r
-     * \r
-     * @param repo the repo\r
-     * @param uuid the uuid\r
-     * \r
-     * @return the rel url\r
-     */\r
-    private static String getRelURL(String repo, String uuid) {\r
-        return '/' + repo + '/' + uuid;\r
-    }  \r
-       \r
-}\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java
new file mode 100644 (file)
index 0000000..9a2684e
--- /dev/null
@@ -0,0 +1,248 @@
+/**
+ *  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 University of California at Berkeley
+
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.relation.nuxeo;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.collectionspace.services.common.relation.RelationJAXBSchema;
+import org.collectionspace.services.common.repository.DocumentException;
+import org.collectionspace.services.common.repository.DocumentWrapper;
+import org.collectionspace.services.relation.RelationsCommonList;
+import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
+import org.nuxeo.ecm.core.api.ClientException;
+import org.nuxeo.ecm.core.api.DocumentModel;
+import org.nuxeo.ecm.core.api.DocumentModelList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * RelationsUtils
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public class RelationsUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger(RelationsUtils.class);
+
+    public static RelationsCommonList extractCommonPartList(DocumentWrapper wrapDoc,
+            String serviceContextPath)
+            throws Exception {
+        DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
+
+        RelationsCommonList relList = new RelationsCommonList();
+        List<RelationsCommonList.RelationListItem> list = relList.getRelationListItem();
+
+        //FIXME: iterating over a long list of documents is not a long term
+        //strategy...need to change to more efficient iterating in future
+        Iterator<DocumentModel> iter = docList.iterator();
+        while(iter.hasNext()){
+            DocumentModel docModel = iter.next();
+            RelationListItem relationListItem = getRelationListItem(docModel,
+                    serviceContextPath);
+            list.add(relationListItem);
+        }
+        return relList;
+    }
+
+    public static RelationListItem getRelationListItem(DocumentModel docModel,
+            String serviceContextPath) throws Exception {
+        RelationListItem relationListItem = new RelationListItem();
+        relationListItem.setUri(serviceContextPath + docModel.getId());
+        relationListItem.setCsid(docModel.getId());
+        return relationListItem;
+    }
+
+    public static void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
+        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
+        //FIXME property setter should be dynamically set using schema inspection
+        //so it does not require hard coding
+        // a default title for the Dublin Core schema
+        docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
+    }
+
+    /**
+     * Checks if is subject of relation.
+     *
+     * @param csid the csid
+     * @param documentModel the document model
+     *
+     * @return true, if is subject of relation
+     *
+     * @throws Exception 
+     */
+    private static boolean isSubjectOfRelation(String csid, DocumentModel documentModel)
+            throws Exception {
+        boolean result = false;
+        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME, RelationJAXBSchema.DOCUMENT_ID_1);
+        if(valueObject != null && csid != null){
+            String subjectID = (String) valueObject;
+            result = subjectID.equals(csid);
+        }
+
+        return result;
+    }
+
+    /**
+     * Checks if is object of relation.
+     *
+     * @param csid the csid
+     * @param documentModel the document model
+     *
+     * @return true, if is object of relation
+     *
+     * @throws Exception 
+     */
+    private static boolean isObjectOfRelation(String csid, DocumentModel documentModel)
+            throws Exception {
+        boolean result = false;
+
+        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
+                RelationJAXBSchema.DOCUMENT_ID_2);
+        if(valueObject != null && csid != null){
+            String subjectID = (String) valueObject;
+            result = subjectID.equals(csid);
+        }
+
+        return result;
+    }
+
+    /**
+     * Checks if is predicate of relation.
+     *
+     * @param predicate the predicate
+     * @param documentModel the document model
+     *
+     * @return true, if is predicate of relation
+     *
+     * @throws Exception 
+     */
+    private static boolean isPredicateOfRelation(String predicate,
+            DocumentModel documentModel) throws Exception {
+        boolean result = false;
+
+        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
+                RelationJAXBSchema.RELATIONSHIP_TYPE);
+        if(valueObject != null && predicate != null){
+            String relationType = (String) valueObject;
+            result = predicate.equalsIgnoreCase(relationType);
+        }
+
+        return result;
+    }
+
+    /**
+     * Gets the object from subject.
+     *
+     * @param csid the csid
+     * @param documentModel the document model
+     *
+     * @return the object from subject
+     *
+     * @throws Exception 
+     */
+    private static String getObjectFromSubject(String csid, DocumentModel documentModel)
+            throws Exception {
+        String result = null;
+
+        Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
+                RelationJAXBSchema.DOCUMENT_ID_1);
+        if(valueObject != null){
+            String subjectID = (String) valueObject;
+            if(subjectID.equals(csid) == true){
+                valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
+                        RelationJAXBSchema.DOCUMENT_ID_2);
+                if(valueObject != null){
+                    result = (String) valueObject;
+                }
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Checks if is query match.
+     *
+     * @param documentModel the document model
+     * @param subjectCsid the subject csid
+     * @param predicate the predicate
+     * @param objectCsid the object csid
+     *
+     * @return true, if is query match
+     *
+     * @throws ClientException the client exception
+     */
+    public static boolean isQueryMatch(DocumentModel documentModel,
+            String subjectCsid,
+            String predicate,
+            String objectCsid) throws DocumentException {
+        boolean result = true;
+
+        try{
+            block:
+            {
+                if(subjectCsid != null){
+                    if(isSubjectOfRelation(subjectCsid, documentModel) == false){
+                        result = false;
+                        break block;
+                    }
+                }
+                if(predicate != null){
+                    if(isPredicateOfRelation(predicate, documentModel) == false){
+                        result = false;
+                        break block;
+                    }
+                }
+                if(objectCsid != null){
+                    if(isObjectOfRelation(objectCsid, documentModel) == false){
+                        result = false;
+                        break block;
+                    }
+                }
+            }
+        }catch(Exception e){
+            if(logger.isDebugEnabled() == true){
+                e.printStackTrace();
+            }
+            throw new DocumentException(e);
+        }
+
+        return result;
+    }
+
+    /**
+     * Gets the rel url.
+     *
+     * @param repo the repo
+     * @param uuid the uuid
+     *
+     * @return the rel url
+     */
+    private static String getRelURL(String repo, String uuid) {
+        return '/' + repo + '/' + uuid;
+    }
+}
+
index 5afe00bcb4c151d8d7c51d5ac6ea6b40dadc28f8..50774375a67a7366c2be6ad7f9add5c691544b90 100644 (file)
  */
 package org.collectionspace.services.common.repository;
 
-import java.io.IOException;
 import java.util.Map;
 import org.collectionspace.services.common.context.ServiceContext;
-import org.w3c.dom.Document;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 
 /**
  *
index 0159fc0e8dc9ed763627b2a064bd9c2a5589a4b1..5d8083cca6d50a52b8843a7828842a306514b298 100644 (file)
@@ -23,7 +23,6 @@
  */
 package org.collectionspace.services.common.repository;
 
-import java.lang.ClassLoader;
 import java.util.Hashtable;
 import org.collectionspace.services.common.RepositoryClientConfigType;
 import org.collectionspace.services.common.ServiceMain;
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java
deleted file mode 100644 (file)
index 4b49abc..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**\r
- * Copyright 2009 University of California at Berkeley\r
- */\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.common.repository.DocumentNotFoundException;\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
-public abstract class CollectionSpaceServiceNuxeoImpl {\r
-\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
-    \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
-               NuxeoClient client = NuxeoConnector.getInstance().getClient();\r
-               RepositoryInstance repoSession = client.openRepository();\r
-               if (logger.isDebugEnabled()) {\r
-                       logger.debug("getRepository() repository root: "\r
-                                       + repoSession.getRootDocument());\r
-               }\r
-               return repoSession;\r
-       }\r
-\r
-    protected void releaseRepositorySession(RepositoryInstance repoSession) {\r
-               try {\r
-                       NuxeoClient client = NuxeoConnector.getInstance().getClient();\r
-                       // release session\r
-                       client.releaseRepository(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
-}\r
index 977d31b31329849736683c63fadc5d0f444cfa75..4c57ab22a0692d419640942ea58e58a0f61b96f2 100644 (file)
  */
 package org.collectionspace.services.nuxeo.client.java;
 
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import javax.ws.rs.core.MediaType;
 import org.collectionspace.services.common.repository.DocumentWrapper;
 import org.collectionspace.services.common.repository.AbstractDocumentHandler;
-import org.collectionspace.services.common.repository.BadRequestException;
-import org.collectionspace.services.common.repository.DocumentUtils;
-import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.nuxeo.client.*;
-import org.jboss.resteasy.plugins.providers.multipart.InputPart;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
 
 /**
  * DocumentModelHandler is a base abstract Nuxeo document handler
@@ -95,76 +81,16 @@ public abstract class DocumentModelHandler<T, TL>
     }
 
     @Override
-    public void completeUpdate(DocumentWrapper wrapDoc) throws Exception {
-        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
-        //return at least those document part(s) that were received
-        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
-        List<InputPart> inputParts = getServiceContext().getInput().getParts();
-        for(InputPart part : inputParts){
-            String partLabel = part.getHeaders().getFirst("label");
-            ObjectPartType partMeta = partsMetaMap.get(partLabel);
-            extractObject(docModel, partLabel, partMeta);
-        }
-    }
+    public abstract void completeUpdate(DocumentWrapper wrapDoc) throws Exception;
 
     @Override
-    public void extractAllParts(DocumentWrapper wrapDoc) throws Exception {
-
-        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
-        String[] schemas = docModel.getDeclaredSchemas();
-        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
-        for(String schema : schemas){
-            ObjectPartType partMeta = partsMetaMap.get(schema);
-            if(partMeta == null){
-                continue; //unknown part, ignore
-            }
-            extractObject(docModel, schema, partMeta);
-        }
-    }
+    public abstract void extractAllParts(DocumentWrapper wrapDoc) throws Exception;
 
     @Override
     public abstract T extractCommonPart(DocumentWrapper wrapDoc) throws Exception;
 
     @Override
-    public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
-
-        //TODO filling extension parts should be dynamic
-        //Nuxeo APIs lack to support stream/byte[] input, get/setting properties is
-        //not an ideal way of populating objects.
-        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
-        MultipartInput input = getServiceContext().getInput();
-        if(input.getParts().isEmpty()){
-            String msg = "No payload found!";
-            logger.error(msg + "Ctx=" + getServiceContext().toString());
-            throw new BadRequestException(msg);
-        }
-
-        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
-
-        //iterate over parts received and fill those parts
-        List<InputPart> inputParts = input.getParts();
-        for(InputPart part : inputParts){
-
-            String partLabel = part.getHeaders().getFirst("label");
-            //skip if the part is not in metadata
-            if(!partsMetaMap.containsKey(partLabel)){
-                continue;
-            }
-            InputStream payload = part.getBody(InputStream.class, null);
-
-            //check if this is an xml part
-            if(part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)){
-                if(payload != null){
-                    Document document = DocumentUtils.parseDocument(payload);
-                    //TODO: callback to handler if registered to validate the
-                    //document
-                    Map<String, Object> objectProps = DocumentUtils.parseProperties(document);
-                    docModel.setProperties(partLabel, objectProps);
-                }
-            }
-        }//rof
-
-    }
+    public abstract void fillAllParts(DocumentWrapper wrapDoc) throws Exception;
 
     @Override
     public abstract void fillCommonPart(T obj, DocumentWrapper wrapDoc) throws Exception;
@@ -190,32 +116,4 @@ public abstract class DocumentModelHandler<T, TL>
     @Override
     public abstract String getDocumentType();
 
-    /**
-     * extractObject extracts an XML object from given DocumentModel
-     * @param docModel
-     * @param schema of the object to extract
-     * @param partMeta metadata for the object to extract
-     * @throws Exception
-     */
-    protected void extractObject(DocumentModel docModel, String schema, ObjectPartType partMeta)
-            throws Exception {
-        MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType());
-        if(mt.equals(MediaType.APPLICATION_XML_TYPE)){
-            Map<String, Object> objectProps = docModel.getProperties(schema);
-            //unqualify properties before sending the doc over the wire (to save bandwidh)
-            //FIXME: is there a better way to avoid duplication of a collection?
-            Map<String, Object> unQObjectProperties = new HashMap<String, Object>();
-            Set<Entry<String, Object>> qualifiedEntries = objectProps.entrySet();
-            for(Entry<String, Object> entry : qualifiedEntries){
-                String unqProp = getUnQProperty(entry.getKey());
-                unQObjectProperties.put(unqProp, entry.getValue());
-            }
-            Document doc = DocumentUtils.buildDocument(partMeta, schema, unQObjectProperties);
-            if(logger.isDebugEnabled()){
-                DocumentUtils.writeDocument(doc, System.out);
-            }
-            getServiceContext().addOutputPart(schema, doc, partMeta.getContent().getContentType());
-        } //TODO: handle other media types
-    }
-
 }
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java
new file mode 100644 (file)
index 0000000..5c2fb15
--- /dev/null
@@ -0,0 +1,169 @@
+/**
+ *  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 University of California at Berkeley
+
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.nuxeo.client.java;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import javax.ws.rs.core.MediaType;
+import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.repository.BadRequestException;
+import org.collectionspace.services.common.repository.DocumentUtils;
+import org.collectionspace.services.common.repository.DocumentWrapper;
+import org.collectionspace.services.common.service.ObjectPartType;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.nuxeo.ecm.core.api.DocumentModel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteDocumentModelHandler
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public abstract class RemoteDocumentModelHandler<T, TL>
+        extends DocumentModelHandler<T, TL> {
+
+    private final Logger logger = LoggerFactory.getLogger(RemoteDocumentModelHandler.class);
+
+    @Override
+    public void setServiceContext(ServiceContext ctx) {
+        if(ctx instanceof RemoteServiceContext){
+            super.setServiceContext(ctx);
+        } else {
+        throw new IllegalArgumentException("setServiceContext requires instance of " +
+                RemoteServiceContext.class.getName());
+        }
+    }
+
+    @Override
+    public abstract String getDocumentType();
+
+    @Override
+    public void completeUpdate(DocumentWrapper wrapDoc) throws Exception {
+        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
+        //return at least those document part(s) that were received
+        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
+        RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+        List<InputPart> inputParts = ctx.getInput().getParts();
+        for(InputPart part : inputParts){
+            String partLabel = part.getHeaders().getFirst("label");
+            ObjectPartType partMeta = partsMetaMap.get(partLabel);
+            extractPart(docModel, partLabel, partMeta);
+        }
+    }
+
+    @Override
+    public void extractAllParts(DocumentWrapper wrapDoc) throws Exception {
+
+        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
+        String[] schemas = docModel.getDeclaredSchemas();
+        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
+        for(String schema : schemas){
+            ObjectPartType partMeta = partsMetaMap.get(schema);
+            if(partMeta == null){
+                continue; //unknown part, ignore
+            }
+            extractPart(docModel, schema, partMeta);
+        }
+    }
+
+    @Override
+    public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
+
+        //TODO filling extension parts should be dynamic
+        //Nuxeo APIs lack to support stream/byte[] input, get/setting properties is
+        //not an ideal way of populating objects.
+        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
+        RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+        MultipartInput input = ctx.getInput();
+        if(input.getParts().isEmpty()){
+            String msg = "No payload found!";
+            logger.error(msg + "Ctx=" + getServiceContext().toString());
+            throw new BadRequestException(msg);
+        }
+
+        Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
+
+        //iterate over parts received and fill those parts
+        List<InputPart> inputParts = input.getParts();
+        for(InputPart part : inputParts){
+
+            String partLabel = part.getHeaders().getFirst("label");
+            //skip if the part is not in metadata
+            if(!partsMetaMap.containsKey(partLabel)){
+                continue;
+            }
+            InputStream payload = part.getBody(InputStream.class, null);
+
+            //check if this is an xml part
+            if(part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)){
+                if(payload != null){
+                    Document document = DocumentUtils.parseDocument(payload);
+                    //TODO: callback to handler if registered to validate the
+                    //document
+                    Map<String, Object> objectProps = DocumentUtils.parseProperties(document);
+                    docModel.setProperties(partLabel, objectProps);
+                }
+            }
+        }//rof
+
+    }
+
+    /**
+     * extractPart extracts an XML object from given DocumentModel
+     * @param docModel
+     * @param schema of the object to extract
+     * @param partMeta metadata for the object to extract
+     * @throws Exception
+     */
+    protected void extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
+            throws Exception {
+        MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType());
+        if(mt.equals(MediaType.APPLICATION_XML_TYPE)){
+            Map<String, Object> objectProps = docModel.getProperties(schema);
+            //unqualify properties before sending the doc over the wire (to save bandwidh)
+            //FIXME: is there a better way to avoid duplication of a collection?
+            Map<String, Object> unQObjectProperties = new HashMap<String, Object>();
+            Set<Entry<String, Object>> qualifiedEntries = objectProps.entrySet();
+            for(Entry<String, Object> entry : qualifiedEntries){
+                String unqProp = getUnQProperty(entry.getKey());
+                unQObjectProperties.put(unqProp, entry.getValue());
+            }
+            Document doc = DocumentUtils.buildDocument(partMeta, schema, unQObjectProperties);
+            if(logger.isDebugEnabled()){
+                DocumentUtils.writeDocument(doc, System.out);
+            }
+            RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+            ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
+        } //TODO: handle other media types
+    }
+}
index d27869ea7bd3ca6e5157fdfbad84e1143b25cea3..90b1935b89f38b081efc4afc44480f8755a071a2 100644 (file)
@@ -21,8 +21,9 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
+import java.io.Serializable;
+import java.util.Map;
 import org.collectionspace.services.common.repository.DocumentException;
-import org.collectionspace.services.common.ServiceMain;
 
 import org.dom4j.Document;
 import org.dom4j.io.SAXReader;
@@ -32,6 +33,7 @@ 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.api.model.DocumentPart;
 import org.nuxeo.ecm.core.io.DocumentPipe;
 import org.nuxeo.ecm.core.io.DocumentReader;
 import org.nuxeo.ecm.core.io.DocumentWriter;
@@ -175,4 +177,21 @@ public class NuxeoUtils {
 
         return result;
     }
+
+    public static void printDocumentModel(DocumentModel docModel) throws Exception {
+        String[] schemas = docModel.getDeclaredSchemas();
+        for(int i = 0; schemas != null && i < schemas.length; i++){
+            logger.debug("Schema-" + i + "=" + schemas[i]);
+        }
+
+        DocumentPart[] parts = docModel.getParts();
+        Map<String, Serializable> propertyValues = null;
+        for(int i = 0; parts != null && i < parts.length; i++){
+            logger.debug("Part-" + i + " name =" + parts[i].getName());
+            logger.debug("Part-" + i + " path =" + parts[i].getPath());
+            logger.debug("Part-" + i + " schema =" + parts[i].getSchema().getName());
+            propertyValues = parts[i].exportValues();
+        }
+
+    }
 }
similarity index 89%
rename from services/common/src/main/resources/relation.xsd
rename to services/common/src/main/resources/relations-common.xsd
index a1da1ecf1091016e3b96fa94b1697d8175389207..8bbc6587c6e74cb94b09eda7ab019863bcf40ce5 100644 (file)
 -->\r
 <xs:schema\r
     xmlns:xs="http://www.w3.org/2001/XMLSchema"\r
-    xmlns="http://services.collectionspace.org/relation"\r
-    xmlns:rel="http://services.collectionspace.org/relation"\r
-    targetNamespace="http://services.collectionspace.org/relation"\r
+    xmlns="http://collectionspace.org/services/relation"\r
+    xmlns:rel="http://collectionspace.org/services/relation"\r
+    targetNamespace="http://collectionspace.org/services/relation"\r
     >\r
 \r
     <!-- Relation -->\r
-    <xs:element name="relation">\r
+    <xs:element name="relations-common">\r
         <xs:complexType>\r
             <xs:sequence>\r
                <xs:element name="csid" type="xs:string" />            \r
@@ -48,7 +48,7 @@
     </xs:simpleType>\r
 \r
     <!-- collection objects as in nuxeo repository -->\r
-    <xs:element name="relation-list">\r
+    <xs:element name="relations-common-list">\r
         <xs:complexType>\r
             <xs:sequence>\r
                 <xs:element name="relation-list-item" maxOccurs="unbounded">\r
index 3a1dd56e3a69303d6892d085b86f892c39086300..0c7d425e1758f0035bcf1cb0fdfac475189bfd4e 100644 (file)
@@ -43,6 +43,7 @@ import org.collectionspace.services.intake.IntakesCommonList.*;
 import org.collectionspace.services.intake.nuxeo.IntakeHandlerFactory;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.repository.DocumentNotFoundException;
 import org.collectionspace.services.common.repository.DocumentHandler;
@@ -72,7 +73,7 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
         DocumentHandler docHandler = IntakeHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
@@ -88,7 +89,7 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     @POST
     public Response createIntake(MultipartInput input) {
         try{
-            ServiceContext ctx = createServiceContext(input);
+            RemoteServiceContext ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //intakeObject.setCsid(csid);
@@ -122,7 +123,7 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
         }
         MultipartOutput result = null;
         try{
-            ServiceContext ctx = createServiceContext(null);
+            RemoteServiceContext ctx = createServiceContext(null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = ctx.getOutput();
@@ -156,7 +157,7 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     public IntakesCommonList getIntakeList(@Context UriInfo ui) {
         IntakesCommonList intakeObjectList = new IntakesCommonList();
         try{
-            ServiceContext ctx = createServiceContext(null);
+            RemoteServiceContext ctx = createServiceContext(null);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             intakeObjectList = (IntakesCommonList) handler.getCommonPartList();
@@ -188,7 +189,7 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
         }
         MultipartOutput result = null;
         try{
-            ServiceContext ctx = createServiceContext(theUpdate);
+            RemoteServiceContext ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = ctx.getOutput();
index 71f44b007be6a6aec660104b63c07570c119cfd0..78e5834fbc254f1b9173f0ec32bcad39c011d5aa 100644 (file)
@@ -27,12 +27,13 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.collectionspace.services.IntakeJAXBSchema;
+import org.collectionspace.services.common.repository.DocumentHandler.Action;
 import org.collectionspace.services.common.repository.DocumentWrapper;
 import org.collectionspace.services.intake.IntakesCommon;
 import org.collectionspace.services.intake.IntakesCommonList;
 import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
-import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -45,7 +46,7 @@ import org.slf4j.LoggerFactory;
  * $LastChangedDate: $
  */
 public class IntakeDocumentModelHandler
-        extends DocumentModelHandler<IntakesCommon, IntakesCommonList> {
+        extends RemoteDocumentModelHandler<IntakesCommon, IntakesCommonList> {
 
     private final Logger logger = LoggerFactory.getLogger(IntakeDocumentModelHandler.class);
     /**
index aaa4374e142c225eb4d4d787f4e7d2b96169a74a..077b226a96dbbb43142565c40b141283e480f428 100644 (file)
@@ -47,9 +47,7 @@ public class IntakeHandlerFactory {
     public DocumentHandler getHandler(String clientType) {
         if(ClientType.JAVA.toString().equals(clientType)){
             return new IntakeDocumentModelHandler();
-        } else if(ClientType.REST.toString().equals(clientType)) {
-            return new IntakeRepresenationHandler();
-        }
+        } 
         throw new IllegalArgumentException("Not supported client=" + clientType);
     }
 }
diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeRepresenationHandler.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeRepresenationHandler.java
deleted file mode 100644 (file)
index 628114c..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/**
- *  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 University of California at Berkeley
-
- *  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
-
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.collectionspace.services.intake.nuxeo;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.collectionspace.services.IntakeJAXBSchema;
-import org.collectionspace.services.common.repository.DocumentWrapper;
-import org.collectionspace.services.intake.IntakesCommon;
-import org.collectionspace.services.intake.IntakesCommonList;
-import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem;
-import org.collectionspace.services.nuxeo.client.rest.RepresentationHandler;
-import org.dom4j.Document;
-import org.dom4j.Element;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * IntakeDocumentModelHandler
- *
- * $LastChangedRevision: $
- * $LastChangedDate: $
- */
-public class IntakeRepresenationHandler
-        extends RepresentationHandler<IntakesCommon, IntakesCommonList> {
-
-    private final Logger logger = LoggerFactory.getLogger(IntakeRepresenationHandler.class);
-    /**
-     * intakeObj is used to stash JAXB object to use when handle is called
-     * for Action.CREATE, Action.UPDATE or Action.GET
-     */
-    private IntakesCommon intake;
-    /**
-     * intakeListObject is stashed when handle is called
-     * for ACTION.GET_ALL
-     */
-    private IntakesCommonList intakeList;
-
-    @Override
-    public void prepare(Action action) throws Exception {
-        switch(action){
-            case CREATE:
-            case UPDATE:
-                prepare();
-        }
-    }
-
-    private void prepare() {
-        Map<String, String> queryParams = getQueryParams();
-        IntakesCommon intakeObject = getCommonPart();
-        if(intakeObject.getCurrentOwner() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.CURRENT_OWNER, intakeObject.getCurrentOwner());
-        }
-
-        if(intakeObject.getDepositor() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.DEPOSITOR, intakeObject.getDepositor());
-        }
-
-        if(intakeObject.getDepositorsRequirements() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS, intakeObject.getDepositorsRequirements());
-        }
-
-        if(intakeObject.getEntryDate() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.ENTRY_DATE, intakeObject.getEntryDate());
-        }
-
-        if(intakeObject.getEntryMethod() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.ENTRY_METHOD, intakeObject.getEntryMethod());
-        }
-
-        if(intakeObject.getEntryNote() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.ENTRY_NOTE, intakeObject.getEntryNote());
-        }
-
-        if(intakeObject.getEntryNumber() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.ENTRY_NUMBER, intakeObject.getEntryNumber());
-        }
-
-        if(intakeObject.getEntryReason() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.ENTRY_REASON, intakeObject.getEntryReason());
-        }
-
-        if(intakeObject.getPackingNote() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.PACKING_NOTE, intakeObject.getPackingNote());
-        }
-
-        if(intakeObject.getReturnDate() != null){
-            queryParams.put(IntakeConstants.NUXEO_SCHEMA_NAME + ":" +
-                    IntakeJAXBSchema.RETURN_DATE, intakeObject.getReturnDate());
-        }
-    }
-
-    @Override
-    public IntakesCommon extractCommonPart(DocumentWrapper wrapDoc)
-            throws Exception {
-        Document document = (Document) wrapDoc.getWrappedObject();
-        IntakesCommon intakeObj = new IntakesCommon();
-
-        //FIXME property get should be dynamically set using schema inspection
-        //so it does not require hard coding
-        Element root = document.getRootElement();
-
-        // TODO: recognize schema thru namespace uri
-        // Namespace ns = new Namespace("intakeObj",
-        // "http://collectionspace.org/intakeObj");
-
-        Iterator<Element> siter = root.elementIterator("schema");
-        while(siter.hasNext()){
-
-            Element schemaElement = siter.next();
-            if(logger.isDebugEnabled()){
-                logger.debug("getCommonObject() populating Common Object");
-            }
-            // TODO: recognize schema thru namespace uri
-            if(IntakeConstants.NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){
-                Element ele = schemaElement.element(IntakeJAXBSchema.CURRENT_OWNER);
-                if(ele != null){
-                    intakeObj.setCurrentOwner((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.DEPOSITOR);
-                if(ele != null){
-                    intakeObj.setDepositor((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS);
-                if(ele != null){
-                    intakeObj.setDepositorsRequirements((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.ENTRY_DATE);
-                if(ele != null){
-                    intakeObj.setEntryDate((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.ENTRY_METHOD);
-                if(ele != null){
-                    intakeObj.setEntryMethod((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.ENTRY_NOTE);
-                if(ele != null){
-                    intakeObj.setEntryNote((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.ENTRY_NUMBER);
-                if(ele != null){
-                    intakeObj.setEntryNumber((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.ENTRY_REASON);
-                if(ele != null){
-                    intakeObj.setEntryReason((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.PACKING_NOTE);
-                if(ele != null){
-                    intakeObj.setPackingNote((String) ele.getData());
-                }
-                ele = schemaElement.element(IntakeJAXBSchema.RETURN_DATE);
-                if(ele != null){
-                    intakeObj.setReturnDate((String) ele.getData());
-                }
-            }
-        }
-        return intakeObj;
-    }
-
-    @Override
-    public void fillCommonPart(IntakesCommon co, DocumentWrapper wrapDoc)
-            throws Exception {
-        //Nuxeo REST takes create/update through queryParams, nothing to do here
-    }
-
-    @Override
-    public IntakesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
-        Document document = (Document) wrapDoc.getWrappedObject();
-        if(logger.isDebugEnabled()){
-            logger.debug(document.asXML());
-        }
-        IntakesCommonList intakeListObject = new IntakesCommonList();
-        List<IntakesCommonList.IntakeListItem> list = intakeListObject.getIntakeListItem();
-        Element root = document.getRootElement();
-        for(Iterator i = root.elementIterator(); i.hasNext();){
-
-            Element element = (Element) i.next();
-            if(logger.isDebugEnabled()){
-                logger.debug(element.asXML());
-            }
-            // set the intakeObj list item entity elements
-            IntakeListItem ilistItem = new IntakeListItem();
-            ilistItem.setEntryNumber(element.attributeValue("entryNumber"));
-            String id = element.attributeValue("id");
-            ilistItem.setCsid(id);
-            ilistItem.setUri("/intakes/" + id);
-            list.add(ilistItem);
-        }
-        return intakeListObject;
-    }
-
-
-    @Override
-    public IntakesCommon getCommonPart() {
-        return intake;
-    }
-
-    @Override
-    public void setCommonPart(IntakesCommon obj) {
-        this.intake = obj;
-    }
-
-    @Override
-    public IntakesCommonList getCommonPartList() {
-        return intakeList;
-    }
-
-    @Override
-    public void setCommonPartList(IntakesCommonList obj) {
-        this.intakeList = obj;
-    }
-
-    /* (non-Javadoc)
-     * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
-     */
-    @Override
-    public String getDocumentType() {
-        return IntakeConstants.NUXEO_DOCTYPE;
-    }
-
-    /**
-     * getQProperty converts the given property to qualified schema property
-     * @param prop
-     * @return
-     */
-    @Override
-    public String getQProperty(String prop) {
-        return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
-    }
-}
-
index ec406fe07e78cc2c01ad920ded871c0c034c17d3..8ee2b2af5e31154edfca1fba648cb5a0d2c19290 100644 (file)
@@ -18,7 +18,7 @@
         <!-- add modules below in the order based on dependencies -->\r
         <module>common</module>\r
         <module>authentication</module>\r
-        <!--module>relation</module-->\r
+        <module>relation</module>\r
         <!--module>query</module-->\r
         <module>acquisition</module>\r
         <module>vocabulary</module>\r
index 2fe513f959509c48b32f6b7389309eba50c160be..151b2c157fa3c1cd53cdd6942060aa6c145e1788 100644 (file)
 -->
 <component name="org.collectionspace.relation.coreTypes">
   <extension target="org.nuxeo.ecm.core.schema.TypeService" point="schema">
-    <schema name="relation" prefix="rel" src="schemas/relation.xsd"/>
+    <schema name="relations-common" prefix="relations-common" src="schemas/relations-common.xsd"/>
   </extension>
   <extension target="org.nuxeo.ecm.core.schema.TypeService" point="doctype">
     <doctype name="Relation" extends="Document">
       <schema name="common"/>
       <schema name="dublincore"/>
-      <schema name="relation"/>
+      <schema name="relations-common"/>
     </doctype>
   </extension>
 </component>
similarity index 76%
rename from services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relation.xsd
rename to services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations-common.xsd
index cbd7d0cd90acb81f92ae05f3bc68b5418ab6b524..78e5fb47f44d667f17bbc4bdc042347dbf94d4b4 100644 (file)
     targetNamespace="http://collectionspace.org/relation/"\r
     version="0.1">\r
 \r
-    <!-- Note: Nuxeo creates a table with the name of the complextype instead of the name of the element -->\r
-    <xs:element name="relationtype" type="rel:relation"/>\r
-    <xs:complexType name="relation">\r
-        <xs:sequence>\r
             <!-- Note: nuxeo ecm types does not support xs:anyURI type -->\r
             <!-- if xs:anyURI is used, it fails to register that doctype -->\r
 \r
             <!-- document-type-1 would be the doc-type of the container collectionobject -->\r
             <!-- document-id-2 would be the id of the contained (or child) collectionobject -->\r
             <!-- document-type-2 would be the doc-type of the collectionobejct -->\r
-            <xs:element name="documentId1" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
-            <xs:element name="documentType1" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
-            <xs:element name="documentId2" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
-            <xs:element name="documentType2" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="documentId1" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="documentType1" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="documentId2" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
+    <xs:element name="documentType2" type="xs:string"  minOccurs="1" maxOccurs="1"/>\r
 \r
             <!-- type of relatinoship between two entities -->\r
-            <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
-        </xs:sequence>\r
-    </xs:complexType>\r
+    <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
+\r
 \r
 \r
     <!-- enumeration defining the type of relationship between two entities -->\r
index f05cbae5d5fa9a016dc96c0051f86ccf33d29f98..c1265e90ceb44afb86c38cc2b42ae6b5a46faef8 100644 (file)
             <version>1.0</version>\r
         </dependency>\r
 \r
-        <dependency>\r
-            <groupId>org.collectionspace.services</groupId>\r
-            <artifactId>org.collectionspace.services.relation.service</artifactId>\r
-            <version>1.0</version>\r
-        </dependency>\r
 \r
         <dependency>\r
             <groupId>org.testng</groupId>\r
@@ -93,7 +88,7 @@
                     <systemProperties>\r
                         <property>\r
                             <name>log4j.configuration</name>\r
-                            <value>log4j.xml</value>\r
+                            <value>file:target/test-classes/log4j.properties</value>\r
                         </property>\r
                     </systemProperties>\r
                 </configuration>\r
index 952c0fa569392e123a6c354d1438a43555d75ad2..1014fb9cc0dcc5d48f0bd186bbfa9aca6959d380 100644 (file)
@@ -1,16 +1,14 @@
 package org.collectionspace.services.client;
 
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.relation.Relation;
-import org.collectionspace.services.relation.RelationList;
+import org.collectionspace.services.relation.RelationsCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
 import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
 
 /**
@@ -53,11 +51,11 @@ public class RelationClient extends BaseServiceClient implements RelationProxy {
      * @return
      * @see org.collectionspace.hello.client.RelationProxy#getRelation()
      */
-    public ClientResponse<RelationList> readList() {
+    public ClientResponse<RelationsCommonList> readList() {
         return relationProxy.readList();
     }
     
-    public ClientResponse<RelationList> readList_SPO(String subjectCsid,
+    public ClientResponse<RelationsCommonList> readList_SPO(String subjectCsid,
                        String predicate,
                        String objectCsid) {
        return relationProxy.readList_SPO(subjectCsid, predicate, objectCsid);
@@ -68,7 +66,7 @@ public class RelationClient extends BaseServiceClient implements RelationProxy {
      * @return
      * @see org.collectionspace.hello.client.RelationProxy#getRelation(java.lang.String)
      */
-    public ClientResponse<Relation> read(String csid) {
+    public ClientResponse<MultipartInput> read(String csid) {
         return relationProxy.read(csid);
     }
 
@@ -77,8 +75,8 @@ public class RelationClient extends BaseServiceClient implements RelationProxy {
      * @return
      * @see org.collectionspace.hello.client.RelationProxy#createRelation(org.collectionspace.hello.Relation)
      */
-    public ClientResponse<Response> create(Relation relation) {
-        return relationProxy.create(relation);
+    public ClientResponse<Response> create(MultipartOutput multipart) {
+        return relationProxy.create(multipart);
     }
 
     /**
@@ -87,8 +85,8 @@ public class RelationClient extends BaseServiceClient implements RelationProxy {
      * @return
      * @see org.collectionspace.hello.client.RelationProxy#updateRelation(java.lang.Long, org.collectionspace.hello.Relation)
      */
-    public ClientResponse<Relation> update(String csid, Relation relation) {
-        return relationProxy.update(csid, relation);
+    public ClientResponse<MultipartInput> update(String csid, MultipartOutput multipart) {
+        return relationProxy.update(csid, multipart);
     }
 
     /**
index 9a4d8fcdeb1b83ebcafc922163a652da68f895ea..d6e75f97734327f276fbce797374bade55b6ff76 100644 (file)
@@ -8,47 +8,48 @@ 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.Context;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.relation.Relation;
-import org.collectionspace.services.relation.RelationList;
+import org.collectionspace.services.relation.RelationsCommonList;
 import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 
 /**
  * @version $Revision:$
  */
 @Path("/relations/")
-@Produces({"application/xml"})
-@Consumes({"application/xml"})
+@Produces({"multipart/mixed"})
+@Consumes({"multipart/mixed"})
 public interface RelationProxy {
 
     @GET
-    ClientResponse<RelationList> readList();
-    
-       @GET
-       @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}")
-       ClientResponse<RelationList> readList_SPO(@PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid);
+    @Produces({"application/xml"})
+    ClientResponse<RelationsCommonList> readList();
+
+    @GET
+    @Produces({"application/xml"})
+    @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}")
+    ClientResponse<RelationsCommonList> readList_SPO(@PathParam("subjectCsid") String subjectCsid,
+            @PathParam("predicate") String predicate,
+            @PathParam("objectCsid") String objectCsid);
 
     //(C)reate
     @POST
-    ClientResponse<Response> create(Relation co);
+    ClientResponse<Response> create(MultipartOutput multipart);
 
     //(R)ead
     @GET
     @Path("/{csid}")
-    ClientResponse<Relation> read(@PathParam("csid") String csid);
+    ClientResponse<MultipartInput> read(@PathParam("csid") String csid);
 
     //(U)pdate
     @PUT
     @Path("/{csid}")
-    ClientResponse<Relation> update(@PathParam("csid") String csid, Relation co);
+    ClientResponse<MultipartInput> update(@PathParam("csid") String csid, MultipartOutput multipart);
 
     //(D)elete
     @DELETE
     @Path("/{csid}")
     ClientResponse<Response> delete(@PathParam("csid") String csid);
-}
\ No newline at end of file
+}
index 43fa7d9e08c55401b914997c756220b41bbdeef5..26147f1d114e13ec126762fd500414303025bbc3 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.collectionspace.services.client.test;
 
 import java.util.List;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
 
 import org.collectionspace.services.client.RelationClient;
-import org.collectionspace.services.client.test.ServiceRequestType;
-import org.collectionspace.services.relation.Relation;
-import org.collectionspace.services.relation.RelationList;
+import org.collectionspace.services.relation.RelationsCommon;
+import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationshipType;
 
 import org.jboss.resteasy.client.ClientResponse;
 
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -50,14 +50,12 @@ public class RelationServiceTest extends AbstractServiceTest {
 
     private RelationClient client = new RelationClient();
     final String SERVICE_PATH_COMPONENT = "relations";
-    private String knownResourceId = null; 
+    private String knownResourceId = null;
 
     // ---------------------------------------------------------------
     // CRUD tests : CREATE tests
     // ---------------------------------------------------------------
-
     // Success outcomes
-    
     @Override
     @Test
     public void create() {
@@ -69,8 +67,8 @@ public class RelationServiceTest extends AbstractServiceTest {
 
         // Submit the request to the service and store the response.
         String identifier = createIdentifier();
-        Relation relation = createRelationInstance(identifier);
-        ClientResponse<Response> res = client.create(relation);
+        MultipartOutput multipart = createRelationInstance(identifier);
+        ClientResponse<Response> res = client.create(multipart);
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
@@ -80,12 +78,13 @@ public class RelationServiceTest extends AbstractServiceTest {
         // Does it exactly match the expected status code?
         verbose("create: status = " + statusCode);
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
         // Store the ID returned from this create operation for
         // additional tests below.
         knownResourceId = extractId(res);
+        verbose("create: knownResourceId=" + knownResourceId);
     }
 
     @Override
@@ -97,313 +96,323 @@ public class RelationServiceTest extends AbstractServiceTest {
     }
 
     // Failure outcomes
-
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void createWithEmptyEntityBody() {}
-    public void createWithMalformedXml() {}
-    public void createWithWrongXmlSchema() {}
+    public void createWithEmptyEntityBody() {
+    }
+
+    public void createWithMalformedXml() {
+    }
 
-/*
+    public void createWithWrongXmlSchema() {
+    }
+
+    /*
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
     public void createWithEmptyEntityBody() {
     
-        // Perform setup.
-        setupCreateWithEmptyEntityBody();
-
-        // Submit the request to the service and store the response.
-        String method = REQUEST_TYPE.httpMethodName();
-        String url = getServiceRootURL();
-        String mediaType = MediaType.APPLICATION_XML;
-        final String entity = "";
-        int statusCode = submitRequest(method, url, mediaType, entity);
-        
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    // Perform setup.
+    setupCreateWithEmptyEntityBody();
+
+    // Submit the request to the service and store the response.
+    String method = REQUEST_TYPE.httpMethodName();
+    String url = getServiceRootURL();
+    String mediaType = MediaType.APPLICATION_XML;
+    final String entity = "";
+    int statusCode = submitRequest(method, url, mediaType, entity);
+
+    // Check the status code of the response: does it match
+    // the expected response(s)?
+    verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+    Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
     public void createWithMalformedXml() {
     
-        // Perform setup.
-        setupCreateWithMalformedXml();
-
-        // Submit the request to the service and store the response.
-        String method = REQUEST_TYPE.httpMethodName();
-        String url = getServiceRootURL();
-        String mediaType = MediaType.APPLICATION_XML;
-        final String entity = MALFORMED_XML_DATA; // Constant from base class.
-        int statusCode = submitRequest(method, url, mediaType, entity);
-        
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    // Perform setup.
+    setupCreateWithMalformedXml();
+
+    // Submit the request to the service and store the response.
+    String method = REQUEST_TYPE.httpMethodName();
+    String url = getServiceRootURL();
+    String mediaType = MediaType.APPLICATION_XML;
+    final String entity = MALFORMED_XML_DATA; // Constant from base class.
+    int statusCode = submitRequest(method, url, mediaType, entity);
+
+    // Check the status code of the response: does it match
+    // the expected response(s)?
+    verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
+    Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+    Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
     @Override
     @Test(dependsOnMethods = {"create", "testSubmitRequest"})
     public void createWithWrongXmlSchema() {
     
-        // Perform setup.
-        setupCreateWithWrongXmlSchema();
-     
-        // Submit the request to the service and store the response.
-        String method = REQUEST_TYPE.httpMethodName();
-        String url = getServiceRootURL();
-        String mediaType = MediaType.APPLICATION_XML;
-        final String entity = WRONG_XML_SCHEMA_DATA;
-        int statusCode = submitRequest(method, url, mediaType, entity);
-        
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    // Perform setup.
+    setupCreateWithWrongXmlSchema();
+
+    // Submit the request to the service and store the response.
+    String method = REQUEST_TYPE.httpMethodName();
+    String url = getServiceRootURL();
+    String mediaType = MediaType.APPLICATION_XML;
+    final String entity = WRONG_XML_SCHEMA_DATA;
+    int statusCode = submitRequest(method, url, mediaType, entity);
+
+    // Check the status code of the response: does it match
+    // the expected response(s)?
+    verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
+    Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+    Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
-*/
-
-
+     */
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
-
     // Success outcomes
-
     @Override
     @Test(dependsOnMethods = {"create"})
     public void read() {
-    
+
         // Perform setup.
         setupRead();
 
         // Submit the request to the service and store the response.
-        ClientResponse<Relation> res = client.read(knownResourceId);
+        ClientResponse<MultipartInput> res = client.read(knownResourceId);
         int statusCode = res.getStatus();
-            
+
         // Check the status code of the response: does it match
         // the expected response(s)?
         verbose("read: status = " + statusCode);
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
         // Verify that the resource identifier 
-               Relation returnedRelation = res.getEntity();
-               Assert.assertEquals(returnedRelation.getCsid(), knownResourceId);
+        //FIXME: remove the following try catch once Aron fixes signatures
+        try{
+            MultipartInput input = (MultipartInput) res.getEntity();
+            RelationsCommon relation = (RelationsCommon) extractPart(input,
+                    getCommonPartName(), RelationsCommon.class);
+            Assert.assertNotNull(relation);
+        }catch(Exception e){
+            throw new RuntimeException(e);
+        }
 
     }
 
     // Failure outcomes
-    
     @Override
     @Test(dependsOnMethods = {"read"})
     public void readNonExistent() {
 
         // Perform setup.
         setupReadNonExistent();
-        
+
         // Submit the request to the service and store the response.
-        ClientResponse<Relation> res = client.read(NON_EXISTENT_ID);
+        ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
         // the expected response(s)?
         verbose("readNonExistent: status = " + res.getStatus());
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
-
     // ---------------------------------------------------------------
     // CRUD tests : READ_LIST tests
     // ---------------------------------------------------------------
-
     // Success outcomes
-
     @Override
-    @Test(dependsOnMethods = {"createList"})
+    @Test(dependsOnMethods = {"createList", "read"})
     public void readList() {
-    
+
         // Perform setup.
         setupReadList();
 
         // Submit the request to the service and store the response.
-        ClientResponse<RelationList> res = client.readList();
-        RelationList list = res.getEntity();
+        ClientResponse<RelationsCommonList> res = client.readList();
+        RelationsCommonList list = res.getEntity();
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
         // the expected response(s)?
         verbose("readList: status = " + res.getStatus());
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
         // Optionally output additional data about list members for debugging.
         boolean iterateThroughList = false;
-        if (iterateThroughList && logger.isDebugEnabled()) {
-            List<RelationList.RelationListItem> items =
-                list.getRelationListItem();
+        if(iterateThroughList && logger.isDebugEnabled()){
+            List<RelationsCommonList.RelationListItem> items =
+                    list.getRelationListItem();
             int i = 0;
-            for(RelationList.RelationListItem item : items){
+            for(RelationsCommonList.RelationListItem item : items){
                 verbose("readList: list-item[" + i + "] csid=" +
-                    item.getCsid());
+                        item.getCsid());
                 verbose("readList: list-item[" + i + "] URI=" +
-                    item.getUri());
+                        item.getUri());
                 i++;
             }
         }
-        
+
     }
 
     // Failure outcomes
-    
     // None at present.
-
-
     // ---------------------------------------------------------------
     // CRUD tests : UPDATE tests
     // ---------------------------------------------------------------
-
     // Success outcomes
-
     @Override
-    @Test(dependsOnMethods = {"create"})
+    @Test(dependsOnMethods = {"read"})
     public void update() {
-    
+
         // Perform setup.
         setupUpdate();
-
-        // Retrieve an existing resource that we can update.
-        ClientResponse<Relation> res = client.read(knownResourceId);
-        verbose("read: status = " + res.getStatus());
-        Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
-        Relation relation = res.getEntity();
-        verbose("Got object to update with ID: " + knownResourceId,
-                relation, Relation.class);
-
-        // Update the content of this resource.
-        relation.setDocumentId1("updated-" + relation.getDocumentId1());
-        relation.setDocumentType1("updated-" + relation.getDocumentType1());
-        relation.setDocumentId2("updated-" + relation.getDocumentId2());
-        relation.setDocumentType2("updated-" + relation.getDocumentType2());
-
-        // Submit the request to the service and store the response.
-        res = client.update(knownResourceId, relation);
-        int statusCode = res.getStatus();
-        Relation updatedObject = res.getEntity();
-
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("update: status = " + res.getStatus());
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-        
-        // Check the contents of the response: does it match
-        // what was submitted?
-        verbose("update: ", updatedObject, Relation.class);
-        final String msg =
-          "Data in updated object did not match submitted data.";
-        Assert.assertEquals(
-          updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
-        Assert.assertEquals(
-          updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
-        Assert.assertEquals(
-          updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
-        Assert.assertEquals(
-          updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
+        try{
+            // Retrieve an existing resource that we can update.
+            ClientResponse<MultipartInput> res =
+                    client.read(knownResourceId);
+            verbose("update: read status = " + res.getStatus());
+            Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+            verbose("Got object to update with ID: " + knownResourceId);
+            MultipartInput input = (MultipartInput) res.getEntity();
+            RelationsCommon relation = (RelationsCommon) extractPart(input,
+                    getCommonPartName(), RelationsCommon.class);
+            Assert.assertNotNull(relation);
+
+            // Update the content of this resource.
+            relation.setDocumentId1("updated-" + relation.getDocumentId1());
+            relation.setDocumentType1("updated-" + relation.getDocumentType1());
+            relation.setDocumentId2("updated-" + relation.getDocumentId2());
+            relation.setDocumentType2("updated-" + relation.getDocumentType2());
+            verbose("updated object", relation, RelationsCommon.class);
+
+            // Submit the request to the service and store the response.
+            MultipartOutput output = new MultipartOutput();
+            OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
+            commonPart.getHeaders().add("label", getCommonPartName());
+            res = client.update(knownResourceId, output);
+            int statusCode = res.getStatus();
+            // Check the status code of the response: does it match the expected response(s)?
+            verbose("update: status = " + res.getStatus());
+            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+            input = (MultipartInput) res.getEntity();
+            RelationsCommon updatedObject =
+                    (RelationsCommon) extractPart(input,
+                    getCommonPartName(), RelationsCommon.class);
+            Assert.assertNotNull(updatedObject);
+
+            final String msg =
+                    "Data in updated object did not match submitted data.";
+            Assert.assertEquals(
+                    updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
+            Assert.assertEquals(
+                    updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
+            Assert.assertEquals(
+                    updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
+            Assert.assertEquals(
+                    updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
+        }catch(Exception e){
+            e.printStackTrace();
+        }
 
     }
-    
-    // Failure outcomes
 
+    // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
-    public void updateWithEmptyEntityBody() {}
-    public void updateWithMalformedXml() {}
-    public void updateWithWrongXmlSchema() {}
+    public void updateWithEmptyEntityBody() {
+    }
+
+    public void updateWithMalformedXml() {
+    }
 
-/*
+    public void updateWithWrongXmlSchema() {
+    }
+
+    /*
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
     public void updateWithEmptyEntityBody() {
     
-        // Perform setup.
-        setupUpdateWithEmptyEntityBody();
-
-        // Submit the request to the service and store the response.
-        String method = REQUEST_TYPE.httpMethodName();
-        String url = getResourceURL(knownResourceId);
-        String mediaType = MediaType.APPLICATION_XML;
-        final String entity = "";
-        int statusCode = submitRequest(method, url, mediaType, entity);
-        
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    // Perform setup.
+    setupUpdateWithEmptyEntityBody();
+
+    // Submit the request to the service and store the response.
+    String method = REQUEST_TYPE.httpMethodName();
+    String url = getResourceURL(knownResourceId);
+    String mediaType = MediaType.APPLICATION_XML;
+    final String entity = "";
+    int statusCode = submitRequest(method, url, mediaType, entity);
+
+    // Check the status code of the response: does it match
+    // the expected response(s)?
+    verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
+    Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+    Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
     public void updateWithMalformedXml() {
 
-        // Perform setup.
-        setupUpdateWithMalformedXml();
-
-        // Submit the request to the service and store the response.
-        String method = REQUEST_TYPE.httpMethodName();
-        String url = getResourceURL(knownResourceId);
-        String mediaType = MediaType.APPLICATION_XML;
-        final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
-        int statusCode = submitRequest(method, url, mediaType, entity);
-        
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    // Perform setup.
+    setupUpdateWithMalformedXml();
+
+    // Submit the request to the service and store the response.
+    String method = REQUEST_TYPE.httpMethodName();
+    String url = getResourceURL(knownResourceId);
+    String mediaType = MediaType.APPLICATION_XML;
+    final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
+    int statusCode = submitRequest(method, url, mediaType, entity);
+
+    // Check the status code of the response: does it match
+    // the expected response(s)?
+    verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
+    Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+    Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
     @Override
     @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
     public void updateWithWrongXmlSchema() {
     
-        // Perform setup.
-        setupUpdateWithWrongXmlSchema();
-        
-        // Submit the request to the service and store the response.
-        String method = REQUEST_TYPE.httpMethodName();
-        String url = getResourceURL(knownResourceId);
-        String mediaType = MediaType.APPLICATION_XML;
-        final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
-        int statusCode = submitRequest(method, url, mediaType, entity);
-        
-        // Check the status code of the response: does it match
-        // the expected response(s)?
-        verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
-        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    // Perform setup.
+    setupUpdateWithWrongXmlSchema();
+
+    // Submit the request to the service and store the response.
+    String method = REQUEST_TYPE.httpMethodName();
+    String url = getResourceURL(knownResourceId);
+    String mediaType = MediaType.APPLICATION_XML;
+    final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
+    int statusCode = submitRequest(method, url, mediaType, entity);
+
+    // Check the status code of the response: does it match
+    // the expected response(s)?
+    verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
+    Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+    Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
-*/
-
-
+     */
     @Override
     @Test(dependsOnMethods = {"update", "testSubmitRequest"})
     public void updateNonExistent() {
@@ -414,28 +423,25 @@ public class RelationServiceTest extends AbstractServiceTest {
         // Submit the request to the service and store the response.
         // Note: The ID used in this 'create' call may be arbitrary.
         // The only relevant ID may be the one used in update(), below.
-        Relation relation = createRelationInstance(NON_EXISTENT_ID);
-        ClientResponse<Relation> res =
-          client.update(NON_EXISTENT_ID, relation);
+        MultipartOutput multipart = createRelationInstance(NON_EXISTENT_ID);
+        ClientResponse<MultipartInput> res =
+                client.update(NON_EXISTENT_ID, multipart);
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
         // the expected response(s)?
         verbose("updateNonExistent: status = " + res.getStatus());
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
-
     // ---------------------------------------------------------------
     // CRUD tests : DELETE tests
     // ---------------------------------------------------------------
-
     // Success outcomes
-
     @Override
-    @Test(dependsOnMethods = {"create", "read", "update"})
+    @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
     public void delete() {
 
         // Perform setup.
@@ -449,12 +455,11 @@ public class RelationServiceTest extends AbstractServiceTest {
         // the expected response(s)?
         verbose("delete: status = " + res.getStatus());
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
     // Failure outcomes
-
     @Override
     @Test(dependsOnMethods = {"delete"})
     public void deleteNonExistent() {
@@ -470,24 +475,20 @@ public class RelationServiceTest extends AbstractServiceTest {
         // the expected response(s)?
         verbose("deleteNonExistent: status = " + res.getStatus());
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-            invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
     }
 
-
     // ---------------------------------------------------------------
     // RELATE_OBJECT tests
     // ---------------------------------------------------------------
-    
     @Test(dependsOnMethods = {"create"})
     public void relateObjects() {
     }
 
-
     // ---------------------------------------------------------------
     // Utility tests : tests of code used in tests above
     // ---------------------------------------------------------------
-
     /**
      * Tests the code for manually submitting data that is used by several
      * of the methods above.
@@ -502,31 +503,34 @@ public class RelationServiceTest extends AbstractServiceTest {
         String method = ServiceRequestType.READ.httpMethodName();
         String url = getResourceURL(knownResourceId);
         int statusCode = submitRequest(method, url);
-        
+
         // Check the status code of the response: does it match
         // the expected response(s)?
         verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
 
-    }          
-
+    }
 
     // ---------------------------------------------------------------
     // Utility methods used by tests above
     // ---------------------------------------------------------------
-    
     @Override
     public String getServicePathComponent() {
         return SERVICE_PATH_COMPONENT;
     }
 
-    private Relation createRelationInstance(String identifier) {
-        String result = null;
-        Relation relation = new Relation();
+    private MultipartOutput createRelationInstance(String identifier) {
+        RelationsCommon relation = new RelationsCommon();
         fillRelation(relation, identifier);
-        return relation;
+
+        MultipartOutput multipart = new MultipartOutput();
+        OutputPart commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
+        commonPart.getHeaders().add("label", getCommonPartName());
+        verbose("to be created, relation common ", relation, RelationsCommon.class);
+
+        return multipart;
     }
-    
+
     /**
      * Fills the relation.
      * 
@@ -534,12 +538,12 @@ public class RelationServiceTest extends AbstractServiceTest {
      * 
      * @return the relation
      */
-    private void fillRelation(Relation relation, String identifier) {
+    private void fillRelation(RelationsCommon relation, String identifier) {
         fillRelation(relation, "Subject-" + identifier,
-            "SubjectType-" + identifier + "-type",
-            "Object-" + identifier,
-            "ObjectType-" + identifier + "-type",
-            RelationshipType.COLLECTIONOBJECT_INTAKE);
+                "SubjectType-" + identifier + "-type",
+                "Object-" + identifier,
+                "ObjectType-" + identifier + "-type",
+                RelationshipType.COLLECTIONOBJECT_INTAKE);
     }
 
     /**
@@ -553,17 +557,15 @@ public class RelationServiceTest extends AbstractServiceTest {
      * 
      * @return the relation
      */
-    private void fillRelation(Relation relation,
-        String documentId1, String documentType1,
-        String documentId2, String documentType2,
-        RelationshipType rt)
-    {
+    private void fillRelation(RelationsCommon relation,
+            String documentId1, String documentType1,
+            String documentId2, String documentType2,
+            RelationshipType rt) {
         relation.setDocumentId1(documentId1);
         relation.setDocumentType1(documentType1);
         relation.setDocumentId2(documentId2);
         relation.setDocumentType2(documentType2);
-        
+
         relation.setRelationshipType(rt);
     }
-
 }
diff --git a/services/relation/client/src/test/resources/log4j.properties b/services/relation/client/src/test/resources/log4j.properties
new file mode 100644 (file)
index 0000000..18c5103
--- /dev/null
@@ -0,0 +1,23 @@
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=INFO\r
diff --git a/services/relation/client/src/test/resources/log4j.xml b/services/relation/client/src/test/resources/log4j.xml
deleted file mode 100644 (file)
index b26abaa..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-<?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>
-
-
-
-
index 4dfc50536132fb682c4edba817837d7d2aa6211f..a68481761ebad99a43e590c5ba00df939da1195b 100644 (file)
@@ -41,16 +41,17 @@ 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.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.NuxeoClientType;
+import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.relation.RelationsManager;
+import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.repository.DocumentNotFoundException;
 import org.collectionspace.services.common.repository.DocumentHandler;
+import org.collectionspace.services.relation.nuxeo.RelationHandlerFactory;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,9 +61,8 @@ import org.slf4j.LoggerFactory;
 @Produces("multipart/mixed")
 public class NewRelationResource extends AbstractCollectionSpaceResource {
 
-       public final static String serviceName = "relations";
-       final Logger logger = LoggerFactory.getLogger(NewRelationResource.class);
-       
+    public final static String serviceName = "relations";
+    final Logger logger = LoggerFactory.getLogger(NewRelationResource.class);
 
     @Override
     public String getServiceName() {
@@ -70,326 +70,276 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
         DocumentHandler docHandler = RelationHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
         if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), CollectionobjectsCommon.class);
+            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), RelationsCommon.class);
             if(obj != null){
-                docHandler.setCommonPart((CollectionobjectsCommon) obj);
+                docHandler.setCommonPart((RelationsCommon) obj);
             }
         }
         return docHandler;
     }
 
-       
-//     public NewRelationResource() {
-//     }
+    @POST
+    public Response createRelation(MultipartInput input) {
 
-       @POST
-       public Response createRelation(Relation relation) {
-
-               String csid = null;
-               try {
-                       getDefaultHandler().setCommonObject(relation);
-                       csid = getDefaultClient().create(SERVICE_NAME, getDefaultHandler());
-                       relation.setCsid(csid);
-                       if (logger.isDebugEnabled()) {
-                               verbose("createRelation: ", relation);
-                       }
-                       UriBuilder path = UriBuilder.fromResource(RelationResource.class);
-                       path.path("" + csid);
-                       Response response = Response.created(path.build()).build();
-                       return response;
-               } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in createRelation", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Create failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-       }
-       
-       /*
-        * Prototype for using NXQL -will move away from here once protyping is finished.
-        */
-       @GET
-       @Path("query/{queryValue}")
-       public Response getQuery(@PathParam("queryValue") String queryString) {
-               
-               Response result = null;
-               
-               if (logger.isDebugEnabled() == true) {
-                       logger.debug("Query string is: " + queryString);
-               }
-               
-               //getDefaultClient().
-                               
-               result = Response.status(Response.Status.ACCEPTED).entity(
-                                               "Query performed. Look in $JBOSS_HOME/server/cspace/log/" +
-                                               "directory for results ").type("text/plain").build();
-               
-               return result;
-       }
+        try{
+            RemoteServiceContext ctx = createServiceContext(input);
+            DocumentHandler handler = createDocumentHandler(ctx);
+            String csid = getRepositoryClient(ctx).create(ctx, handler);
+            UriBuilder path = UriBuilder.fromResource(NewRelationResource.class);
+            path.path("" + csid);
+            Response response = Response.created(path.build()).build();
+            return response;
+        }catch(Exception e){
+            if(logger.isDebugEnabled()){
+                logger.debug("Caught exception in createRelation", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity(
+                    "Create failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+    }
 
-       @GET
-       @Path("{csid}")
-       public Relation getRelation(@PathParam("csid") String csid) {
-               if (logger.isDebugEnabled()) {
-                       verbose("getRelation with csid=" + csid);
-               }
-               if (csid == null || "".equals(csid)) {
-                       logger.error("getRelation: missing csid!");
-                       Response response = Response.status(Response.Status.BAD_REQUEST)
-                                       .entity("get failed on Relation csid=" + csid).type(
-                                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-               Relation relation = null;
-               try {
-                       getDefaultClient().get(csid, getDefaultHandler());
-                       relation = (Relation) getDefaultHandler().getCommonObject();
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("getRelation", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND)
-                                       .entity("Get failed on Relation csid=" + csid).type(
-                                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("getRelation", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed")
-                                       .type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
+    @GET
+    @Path("{csid}")
+    public MultipartOutput getRelation(@PathParam("csid") String csid) {
+        if(logger.isDebugEnabled()){
+            logger.debug("getRelation with csid=" + csid);
+        }
+        if(csid == null || "".equals(csid)){
+            logger.error("getRelation: missing csid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity("get failed on Relation csid=" + csid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        MultipartOutput result = null;
+        try{
+            RemoteServiceContext ctx = createServiceContext(null);
+            DocumentHandler handler = createDocumentHandler(ctx);
+            getRepositoryClient(ctx).get(ctx, csid, handler);
+            result = ctx.getOutput();
+        }catch(DocumentNotFoundException dnfe){
+            if(logger.isDebugEnabled()){
+                logger.debug("getRelation", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity("Get failed on Relation csid=" + csid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }catch(Exception e){
+            if(logger.isDebugEnabled()){
+                logger.debug("getRelation", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
 
-               if (relation == 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);
-               }
-               if (logger.isDebugEnabled()) {
-                       verbose("getRelation: ", relation);
-               }
-               return relation;
-       }
-       
-       /*
-        * BEGIN OF GET LIST
-        */
+        if(result == 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);
+        }
+        return result;
+    }
 
-       @GET
-       public RelationList getRelationList(@Context UriInfo ui) {
-               return this.getRelationListRequest(null, null, null);
-       }
+    /*
+     * BEGIN OF GET LIST
+     */
+    @GET
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList(@Context UriInfo ui) {
+        return this.getRelationList(null, null, null);
+    }
 
-       @GET
-       @Path("subject/{subjectCsid}")
-       public RelationList getRelationList_S(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid) {
-               return this.getRelationListRequest(subjectCsid, null, null);
-       }
-       
-       @GET
-       @Path("type/{predicate}")
-       public RelationList getRelationList_P(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate) {
-               return this.getRelationListRequest(null, predicate, null);
-       }
+    @GET
+    @Path("subject/{subjectCsid}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_S(@Context UriInfo ui,
+            @PathParam("subjectCsid") String subjectCsid) {
+        return this.getRelationList(subjectCsid, null, null);
+    }
 
-       @GET
-       @Path("object/{objectCsid}")
-       public RelationList getRelationList_O(@Context UriInfo ui,
-                       @PathParam("objectCsid") String objectCsid) {
-               return this.getRelationListRequest(null, null, objectCsid);
-       }
+    @GET
+    @Path("type/{predicate}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_P(@Context UriInfo ui,
+            @PathParam("predicate") String predicate) {
+        return this.getRelationList(null, predicate, null);
+    }
 
-       @GET
-       @Path("type/{predicate}/subject/{subjectCsid}")
-       public RelationList getRelationList_PS(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("subjectCsid") String subjectCsid) {
-               return this.getRelationListRequest(subjectCsid, predicate, null);
-       }
-       
-       @GET
-       @Path("subject/{subjectCsid}/type/{predicate}")
-       public RelationList getRelationList_SP(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate) {
-               return this.getRelationListRequest(subjectCsid, predicate, null);
-       }
-       
-       @GET
-       @Path("type/{predicate}/object/{objectCsid}")
-       public RelationList getRelationList_PO(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid) {
-               return this.getRelationListRequest(null, predicate, objectCsid);
-       }       
-       
-       @GET
-       @Path("object/{objectCsid}/type/{predicate}")
-       public RelationList getRelationList_OP(@Context UriInfo ui,
-                       @PathParam("objectCsid") String objectCsid,
-                       @PathParam("predicate") String predicate) {
-               return this.getRelationListRequest(null, predicate, objectCsid);
-       }
-       
-       @GET
-       @Path("type/{predicate}/subject/{subjectCsid}/object/{objectCsid}")
-       public RelationList getRelationList_PSO(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("objectCsid") String objectCsid) {
-               return this.getRelationListRequest(subjectCsid, predicate, objectCsid);
-       }
+    @GET
+    @Path("object/{objectCsid}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_O(@Context UriInfo ui,
+            @PathParam("objectCsid") String objectCsid) {
+        return this.getRelationList(null, null, objectCsid);
+    }
 
-       @GET
-       @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}")
-       public RelationList getRelationList_SPO(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid) {
-               return this.getRelationListRequest(subjectCsid, predicate, objectCsid);
-       }
-       
-       /*
-        * END OF GET LIST
-        */
-       
-       @PUT
-       @Path("{csid}")
-       public Relation updateRelation(@PathParam("csid") String csid,
-                       Relation theUpdate) {
-               if (logger.isDebugEnabled()) {
-                       verbose("updateRelation with csid=" + csid);
-               }
-               if (csid == null || "".equals(csid)) {
-                       logger.error("updateRelation: missing csid!");
-                       Response response = Response.status(Response.Status.BAD_REQUEST)
-                                       .entity("update failed on Relation csid=" + csid).type(
-                                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-               if (logger.isDebugEnabled()) {
-                       verbose("updateRelation with input: ", theUpdate);
-               }
-               try {
-                       getDefaultHandler().setCommonObject(theUpdate);
-                       getDefaultClient().update(csid, getDefaultHandler());
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("caugth exception in updateRelation", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND)
-                                       .entity("Update failed on Relation csid=" + csid).type(
-                                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (Exception e) {
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Update failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-               return theUpdate;
-       }
+    @GET
+    @Path("type/{predicate}/subject/{subjectCsid}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_PS(@Context UriInfo ui,
+            @PathParam("predicate") String predicate,
+            @PathParam("subjectCsid") String subjectCsid) {
+        return this.getRelationList(subjectCsid, predicate, null);
+    }
 
-       @DELETE
-       @Path("{csid}")
-       public Response deleteRelation(@PathParam("csid") String csid) {
+    @GET
+    @Path("subject/{subjectCsid}/type/{predicate}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_SP(@Context UriInfo ui,
+            @PathParam("subjectCsid") String subjectCsid,
+            @PathParam("predicate") String predicate) {
+        return this.getRelationList(subjectCsid, predicate, null);
+    }
 
-               if (logger.isDebugEnabled()) {
-                       verbose("deleteRelation with csid=" + csid);
-               }
-               if (csid == null || "".equals(csid)) {
-                       logger.error("deleteRelation: missing csid!");
-                       Response response = Response.status(Response.Status.BAD_REQUEST)
-                                       .entity("delete failed on Relation csid=" + csid).type(
-                                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-               try {
-                       getDefaultClient().delete(csid);
-                       return Response.status(HttpResponseCodes.SC_OK).build();
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("caught exception in deleteRelation", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND)
-                                       .entity("Delete failed on Relation csid=" + csid).type(
-                                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (Exception e) {
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Delete failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
+    @GET
+    @Path("type/{predicate}/object/{objectCsid}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_PO(@Context UriInfo ui,
+            @PathParam("predicate") String predicate,
+            @PathParam("objectCsid") String objectCsid) {
+        return this.getRelationList(null, predicate, objectCsid);
+    }
 
-       }
+    @GET
+    @Path("object/{objectCsid}/type/{predicate}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_OP(@Context UriInfo ui,
+            @PathParam("objectCsid") String objectCsid,
+            @PathParam("predicate") String predicate) {
+        return this.getRelationList(null, predicate, objectCsid);
+    }
 
-       /*
-        * Private Methods
-        */
+    @GET
+    @Path("type/{predicate}/subject/{subjectCsid}/object/{objectCsid}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_PSO(@Context UriInfo ui,
+            @PathParam("predicate") String predicate,
+            @PathParam("subjectCsid") String subjectCsid,
+            @PathParam("objectCsid") String objectCsid) {
+        return this.getRelationList(subjectCsid, predicate, objectCsid);
+    }
 
-       /**
-        * Gets the relation list request.
-        * 
-        * @return the relation list request
-        * 
-        * @throws WebApplicationException the web application exception
-        */
-       private RelationList getRelationListRequest(String subjectCsid,
-                       String predicate,
-                       String objectCsid)
-                               throws WebApplicationException {
-               RelationList relationList = new RelationList();
-               try {
-                       Map propsFromPath = getDefaultHandler().getProperties();
-                       propsFromPath.put(RelationsManager.SUBJECT, subjectCsid);
-                       propsFromPath.put(RelationsManager.PREDICATE, predicate);
-                       propsFromPath.put(RelationsManager.OBJECT, objectCsid);
+    @GET
+    @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}")
+    @Produces("application/xml")
+    public RelationsCommonList getRelationList_SPO(@Context UriInfo ui,
+            @PathParam("subjectCsid") String subjectCsid,
+            @PathParam("predicate") String predicate,
+            @PathParam("objectCsid") String objectCsid) {
+        return this.getRelationList(subjectCsid, predicate, objectCsid);
+    }
+    /*
+     * END OF GET LIST
+     */
 
-                       getDefaultClient().getAll(SERVICE_NAME, getDefaultHandler());
-                       relationList = (RelationList) getDefaultHandler().getCommonObjectList();
-               } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in getRelationList", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Index failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-               return relationList;
-       }
+    @PUT
+    @Path("{csid}")
+    public MultipartOutput updateRelation(@PathParam("csid") String csid,
+            MultipartInput theUpdate) {
+        if(logger.isDebugEnabled()){
+            logger.debug("updateRelation with csid=" + csid);
+        }
+        if(csid == null || "".equals(csid)){
+            logger.error("updateRelation: missing csid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity("update failed on Relation csid=" + csid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        MultipartOutput result = null;
+        try{
+            RemoteServiceContext ctx = createServiceContext(theUpdate);
+            DocumentHandler handler = createDocumentHandler(ctx);
+            getRepositoryClient(ctx).update(ctx, csid, handler);
+            result = ctx.getOutput();
+        }catch(DocumentNotFoundException dnfe){
+            if(logger.isDebugEnabled()){
+                logger.debug("caugth exception in updateRelation", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity("Update failed on Relation csid=" + csid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }catch(Exception e){
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity(
+                    "Update failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return result;
+    }
 
-       private void verbose(String msg, Relation relation) {
-               try {
-                       verbose(msg);
-                       JAXBContext jc = JAXBContext.newInstance(Relation.class);
+    @DELETE
+    @Path("{csid}")
+    public Response deleteRelation(@PathParam("csid") String csid) {
 
-                       Marshaller m = jc.createMarshaller();
-                       m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-                       m.marshal(relation, System.out);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
+        if(logger.isDebugEnabled()){
+            logger.debug("deleteRelation with csid=" + csid);
+        }
+        if(csid == null || "".equals(csid)){
+            logger.error("deleteRelation: missing csid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity("delete failed on Relation csid=" + csid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        try{
+            ServiceContext ctx = createServiceContext(null);
+            getRepositoryClient(ctx).delete(ctx, csid);
+            return Response.status(HttpResponseCodes.SC_OK).build();
+        }catch(DocumentNotFoundException dnfe){
+            if(logger.isDebugEnabled()){
+                logger.debug("caught exception in deleteRelation", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity("Delete failed on Relation csid=" + csid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }catch(Exception e){
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity(
+                    "Delete failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
 
-       }
+    }
 
-       private void verbose(String msg) {
-               System.out.println("RelationResource. " + msg);
-       }
+    /*
+     * Private Methods
+     */
+    /**
+     * Gets the relation list request.
+     *
+     * @return the relation list request
+     *
+     * @throws WebApplicationException the web application exception
+     */
+    private RelationsCommonList getRelationList(String subjectCsid,
+            String predicate,
+            String objectCsid)
+            throws WebApplicationException {
+        RelationsCommonList relationList = new RelationsCommonList();
+        try{
+            RemoteServiceContext ctx = createServiceContext(null);
+            DocumentHandler handler = createDocumentHandler(ctx);
+            Map propsFromPath = handler.getProperties();
+            propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid);
+            propsFromPath.put(IRelationsManager.PREDICATE, predicate);
+            propsFromPath.put(IRelationsManager.OBJECT, objectCsid);
+            getRepositoryClient(ctx).getAll(ctx, handler);
+            relationList = (RelationsCommonList) handler.getCommonPartList();
+        }catch(Exception e){
+            if(logger.isDebugEnabled()){
+                logger.debug("Caught exception in getRelationList", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity(
+                    "Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return relationList;
+    }
 }
diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java
deleted file mode 100644 (file)
index 3ab53cc..0000000
+++ /dev/null
@@ -1,653 +0,0 @@
-/**    
- * 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.relation;
-
-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.relation.RelationService;
-import org.collectionspace.services.relation.*;
-import org.collectionspace.services.relation.RelationList.*;
-
-import org.collectionspace.services.relation.nuxeo.RelationServiceNuxeoImpl;
-import org.collectionspace.services.common.relation.RelationJAXBSchema;
-import org.collectionspace.services.common.relation.RelationListItemJAXBSchema;
-
-import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.repository.DocumentException;
-import org.collectionspace.services.common.repository.DocumentNotFoundException;
-
-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
-       }
-
-       /**
-        * Returns a list of *all* relation entities.
-        * 
-        * @param ui
-        *            the ui
-        * 
-        * @return the relation list
-        */
-       @GET
-       public RelationList getRelationList(@Context UriInfo ui) {
-               RelationList relationList = this.getRequestedRelationList(ui, null,
-                               null, null);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with the subject=
-        * 
-        * @param ui
-        *            the ui
-        * @param subjectCsid
-        *            the subject == subjectCsid
-        * 
-        * @return the relation list_ s
-        */
-       @GET
-       @Path("subject/{subjectCsid}")
-       public RelationList getRelationList_S(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid) {
-               RelationList relationList = this.getRequestedRelationList(ui,
-                               subjectCsid, null, null);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with predicate == predicate.
-        * 
-        * @param ui
-        *            the ui
-        * @param predicate
-        *            the predicate
-        * 
-        * @return the relation list of type
-        */
-       @GET
-       @Path("type/{predicate}")
-       public RelationList getRelationList_P(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate) {
-               RelationList relationList = this.getRequestedRelationList(ui, null,
-                               predicate, null);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with object == objectCsid
-        * 
-        * @param ui
-        *            the ui
-        * @param objectCsid
-        *            the object csid
-        * 
-        * @return the relation list_ o
-        */
-       @GET
-       @Path("object/{objectCsid}")
-       public RelationList getRelationList_O(@Context UriInfo ui,
-                       @PathParam("objectCsid") String objectCsid) {
-               RelationList relationList = this.getRequestedRelationList(ui, null,
-                               null, objectCsid);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with predicate == predicate *and* subject ==
-        * subjectCsid
-        * 
-        * @param ui
-        *            the ui
-        * @param predicate
-        *            the predicate
-        * @param subjectCsid
-        *            the subject subjectCsid
-        * 
-        * @return the relation list of type with subject
-        */
-       @GET
-       @Path("type/{predicate}/subject/{subjectCsid}")
-       public RelationList getRelationList_PS(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("subjectCsid") String subjectCsid) {
-               RelationList relationList = this.getRequestedRelationList(ui,
-                               subjectCsid, predicate, null);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with subject == subjectCsid *and* predicate ==
-        * predicate
-        * 
-        * @param ui
-        *            the ui
-        * @param subjectCsid
-        *            the subject csid
-        * @param predicate
-        *            the predicate
-        * 
-        * @return the relation list_ sp
-        */
-       @GET
-       @Path("subject/{subjectCsid}/type/{predicate}")
-       public RelationList getRelationList_SP(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate) {
-               RelationList relationList = this.getRequestedRelationList(ui,
-                               subjectCsid, predicate, null);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with predicate == predicate *and* object ==
-        * objectCsid
-        * 
-        * @param ui
-        *            the ui
-        * @param predicate
-        *            the predicate
-        * @param objectCsid
-        *            the object csid
-        * 
-        * @return the relation list of type with object
-        */
-       @GET
-       @Path("type/{predicate}/object/{objectCsid}")
-       public RelationList getRelationList_PO(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid) {
-               RelationList relationList = this.getRequestedRelationList(ui, null,
-                               predicate, objectCsid);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with object == objectCsid *and* predicate ==
-        * predicate
-        * 
-        * @param ui
-        *            the ui
-        * @param objectCsid
-        *            the object csid
-        * @param predicate
-        *            the predicate
-        * 
-        * @return the relation list_ op
-        */
-       @GET
-       @Path("object/{objectCsid}/type/{predicate}")
-       public RelationList getRelationList_OP(@Context UriInfo ui,
-                       @PathParam("objectCsid") String objectCsid,
-                       @PathParam("predicate") String predicate) {
-               RelationList relationList = this.getRequestedRelationList(ui, null,
-                               predicate, objectCsid);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with predicate == predicate *and* subject ==
-        * subjectCsid *and* object == objectCsid
-        * 
-        * @param ui
-        *            the ui
-        * @param predicate
-        *            the predicate
-        * @param subjectCsid
-        *            the subject csid
-        * @param objectCsid
-        *            the object csid
-        * 
-        * @return the relation list
-        */
-       @GET
-       @Path("type/{predicate}/subject/{subjectCsid}/object/{objectCsid}")
-       public RelationList getRelationList_PSO(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("objectCsid") String objectCsid) {
-               RelationList relationList = this.getRequestedRelationList(ui,
-                               predicate, subjectCsid, objectCsid);
-
-               return relationList;
-       }
-
-       /**
-        * Gets a list of relations with subject == subjectCsid *and* predicate ==
-        * predicate *and* object == objectCsid
-        * 
-        * @param ui
-        *            the ui
-        * @param subjectCsid
-        *            the subject csid
-        * @param predicate
-        *            the predicate
-        * @param objectCsid
-        *            the object csid
-        * 
-        * @return the relation list_ spo
-        */
-       @GET
-       @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}")
-       public RelationList getRelationList_SPO(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid) {
-               RelationList relationList = this.getRequestedRelationList(ui,
-                               subjectCsid, predicate, objectCsid);
-
-               return relationList;
-       }
-
-       /**
-        * 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) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in createRelation", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Index failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-
-               UriBuilder uriBuilder = ui.getAbsolutePathBuilder();
-               uriBuilder.path(csid);
-               URI uri = uriBuilder.build();
-
-               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) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in getRelation", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Index 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);
-               }
-
-               if (logger.isDebugEnabled() == true) {
-                       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) {
-
-               if (logger.isDebugEnabled() == true) {
-                       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) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in updateRelation", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Index 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 {
-                       service.deleteRelation(csid);
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("caught exception in deleteRelation", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND)
-                                       .entity("Delete failed on Relation csid=" + csid)
-                                       .type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in deleteRelation", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Index failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-       }
-
-       /*
-        * Private Methods
-        */
-
-       /**
-        * Gets the relation list common.
-        * 
-        * @param ui
-        *            the ui
-        * @param subjectCsid
-        *            the subject csid
-        * @param predicate
-        *            the predicate
-        * @param objectCsid
-        *            the object csid
-        * 
-        * @return the relation list common
-        * 
-        * @throws WebApplicationException
-        *             the web application exception
-        */
-       private RelationList getRequestedRelationList(@Context UriInfo ui,
-                       String subjectCsid, String predicate, String objectCsid)
-                       throws WebApplicationException {
-
-               URI absoluteURI = ui.getAbsolutePath();
-               String uriString = absoluteURI.toString();
-
-               RelationList relationList = null;
-               try {
-                       relationList = this.getRelationList(subjectCsid, predicate,
-                                       objectCsid);
-               } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in getRelationList", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity(
-                                       "Index failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-
-               return relationList;
-       }
-
-       /**
-        * Gets the relation list.
-        * 
-        * @param subjectCsid
-        *            the subject csid
-        * @param predicate
-        *            the predicate
-        * @param objectCsid
-        *            the object csid
-        * 
-        * @return the relation list
-        * 
-        * @throws DocumentException
-        *             the document exception
-        */
-       private RelationList getRelationList(String subjectCsid, String predicate,
-                       String objectCsid) throws DocumentException {
-               RelationList relationList = new RelationList();
-               try {
-                       Document document = service.getRelationList(subjectCsid, predicate,
-                                       objectCsid);
-                       if (logger.isDebugEnabled() == true) {
-                               System.err.println(document.asXML());
-                       }
-
-                       Element root = document.getRootElement();
-                       List<RelationList.RelationListItem> list = relationList
-                                       .getRelationListItem();
-                       Element node = null;
-                       for (Iterator i = root.elementIterator(); i.hasNext();) {
-                               node = (Element) i.next();
-                               if (logger.isDebugEnabled() == true) {
-                                       System.out.println();
-                                       node.asXML();
-                               }
-
-                               // set the Relation list item entity elements
-                               RelationListItem listItem = new RelationListItem();
-                               listItem.setUri(node
-                                               .attributeValue(RelationListItemJAXBSchema.URI));
-                               listItem.setCsid(node
-                                               .attributeValue(RelationListItemJAXBSchema.CSID));
-                               list.add(listItem);
-                       }
-
-               } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in getRelationListOfType", e);
-                       }
-                       throw new DocumentException(e);
-               }
-
-               return relationList;
-       }
-
-       /**
-        * 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);
-       }
-
-}
diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationService.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/RelationService.java
deleted file mode 100644 (file)
index 4f22911..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/**    \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.relation;\r
-\r
-import java.io.IOException;\r
-import org.dom4j.Document;\r
-//import org.dom4j.DocumentException;\r
-import org.collectionspace.services.common.repository.DocumentException;\r
-\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
-       /**\r
-        * Gets the relation list of type.\r
-        * \r
-        * @param subjectCsid the subject csid\r
-        * @param predicate the predicate\r
-        * @param objectCsid the object csid\r
-        * \r
-        * @return the relation list of type\r
-        * \r
-        * @throws DocumentException the document exception\r
-        * @throws IOException Signals that an I/O exception has occurred.\r
-        */\r
-       Document getRelationList(String subjectCsid,\r
-                       String predicate, String objectCsid)\r
-               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
index 0db9aa60296b24e256fa63185566394e053ff32a..48d8bb4195f1a85a8efda30f9e96c0d8ca0064b4 100644 (file)
@@ -27,17 +27,17 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.collectionspace.services.common.relation.RelationJAXBSchema;
-import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl;
-import org.collectionspace.services.common.relation.RelationsManager;
 
-import org.collectionspace.services.relation.Relation;
-import org.collectionspace.services.relation.RelationList;
-import org.collectionspace.services.relation.RelationList.RelationListItem;
+import org.collectionspace.services.common.relation.IRelationsManager;
+import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
+import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
+import org.collectionspace.services.common.repository.DocumentHandler.Action;
+import org.collectionspace.services.relation.RelationsCommon;
+import org.collectionspace.services.relation.RelationsCommonList;
+import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
 
-import org.collectionspace.services.relation.nuxeo.RelationNuxeoConstants;
 import org.collectionspace.services.common.repository.DocumentWrapper;
-import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
+import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -50,32 +50,31 @@ import org.slf4j.LoggerFactory;
  * $LastChangedDate: $
  */
 public class RelationDocumentModelHandler
-        extends DocumentModelHandler<Relation, RelationList> {
+        extends RemoteDocumentModelHandler<RelationsCommon, RelationsCommonList> {
 
     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
     /**
      * relation is used to stash JAXB object to use when handle is called
      * for Action.CREATE, Action.UPDATE or Action.GET
      */
-    private Relation relation;
+    private RelationsCommon relation;
     /**
      * relationList is stashed when handle is called
      * for ACTION.GET_ALL
      */
-    private RelationList relationList;
+    private RelationsCommonList relationList;
 
     @Override
     public void prepare(Action action) throws Exception {
         //no specific action needed
     }
 
-
     /**
      * getCommonObject get associated Relation
      * @return
      */
     @Override
-    public Relation getCommonObject() {
+    public RelationsCommon getCommonPart() {
         return relation;
     }
 
@@ -84,7 +83,7 @@ public class RelationDocumentModelHandler
      * @param relation
      */
     @Override
-    public void setCommonObject(Relation relation) {
+    public void setCommonPart(RelationsCommon relation) {
         this.relation = relation;
     }
 
@@ -93,78 +92,77 @@ public class RelationDocumentModelHandler
      * @return
      */
     @Override
-    public RelationList getCommonObjectList() {
+    public RelationsCommonList getCommonPartList() {
         return relationList;
     }
 
     @Override
-    public void setCommonObjectList(RelationList relationList) {
+    public void setCommonPartList(RelationsCommonList relationList) {
         this.relationList = relationList;
     }
 
     @Override
-    public Relation extractCommonObject(DocumentWrapper wrapDoc)
+    public RelationsCommon extractCommonPart(DocumentWrapper wrapDoc)
             throws Exception {
-        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
-        Relation theRelation = new Relation();
-        
-        RelationsManagerNuxeoImpl.fillRelationFromDocModel(theRelation, docModel);
-
-        return theRelation;
+        throw new UnsupportedOperationException();
     }
 
     @Override
-    public void fillCommonObject(Relation relation, DocumentWrapper wrapDoc) throws Exception {
-        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
-
-        RelationsManagerNuxeoImpl.fillDocModelFromRelation(relation, docModel);
+    public void fillCommonPart(RelationsCommon relation, DocumentWrapper wrapDoc) throws Exception {
+        throw new UnsupportedOperationException();
     }
 
     @Override
-    public RelationList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
+    public RelationsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
 
         Map propsFromResource = this.getProperties();
-        String subjectCsid = (String)propsFromResource.get(RelationsManager.SUBJECT);
-        String predicate = (String)propsFromResource.get(RelationsManager.PREDICATE);
-        String objectCsid = (String)propsFromResource.get(RelationsManager.OBJECT);
+        String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
+        String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
+        String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
 
-        RelationList coList = new RelationList();
-        List<RelationList.RelationListItem> list = coList.getRelationListItem();
+        RelationsCommonList relList = new RelationsCommonList();
+        List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
 
-        //FIXME: iterating over a long list of documents is not a long term
+        //FIXME: iterating over a long itemList of documents is not a long term
         //strategy...need to change to more efficient iterating in future
         Iterator<DocumentModel> iter = docList.iterator();
         while(iter.hasNext()){
             DocumentModel docModel = iter.next();
-            if (RelationsManager.isQueryMatch(docModel, subjectCsid,
-                                       predicate, objectCsid) == true) {
-                               RelationListItem coListItem = new RelationListItem();
-                               RelationsManagerNuxeoImpl.fillRelationListItemFromDocModel(
-                                               coListItem, docModel);
-                               list.add(coListItem);
-                       }
+            if(RelationsUtils.isQueryMatch(docModel, subjectCsid,
+                    predicate, objectCsid) == true){
+                RelationListItem relListItem = RelationsUtils.getRelationListItem(
+                        docModel, getServiceContextPath());
+                itemList.add(relListItem);
+            }
         }
+        return relList;
+    }
 
-        return coList;
+  
+
+    @Override
+    public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
+        super.fillAllParts(wrapDoc);
+        fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
     }
-    
-    public String getDocumentType() {
-       return RelationNuxeoConstants.NUXEO_DOCTYPE;
+
+    private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
+        DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
+        //FIXME property setter should be dynamically set using schema inspection
+        //so it does not require hard coding
+        // a default title for the Dublin Core schema
+        docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
     }
 
     @Override
-    public void fillCommonObjectList(RelationList obj, DocumentWrapper wrapDoc) throws Exception {
-        throw new UnsupportedOperationException();
+    public String getDocumentType() {
+        return RelationConstants.NUXEO_DOCTYPE;
     }
 
-    /**
-     * getQProperty converts the given property to qualified schema property
-     * @param prop
-     * @return
-     */
-    private String getQProperty(String property) {
-       return RelationsManager.getQPropertyName(property);
+    @Override
+    public String getQProperty(String prop) {
+        return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;
     }
 }
 
index b2f1a5b6065e2b10c7279919735a677900162168..53ac92ff3696ab2427e97bc492bb9d549a6181fb 100644 (file)
@@ -23,7 +23,7 @@
  */
 package org.collectionspace.services.relation.nuxeo;
 
-import org.collectionspace.services.common.NuxeoClientType;
+import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.repository.DocumentHandler;
 import org.collectionspace.services.common.CollectionSpaceHandlerFactory;
 
@@ -46,9 +46,9 @@ public class RelationHandlerFactory implements CollectionSpaceHandlerFactory {
     }
 
     public DocumentHandler getHandler(String clientType) {
-        if(NuxeoClientType.JAVA.toString().equals(clientType)){
+        if(ClientType.JAVA.toString().equals(clientType)){
             return new RelationDocumentModelHandler();
-        } else if(NuxeoClientType.REST.toString().equals(clientType)) {
+//        } else if(ClientType.REST.toString().equals(clientType)) {
 //            return new RelationRepresenationHandler();
         }
         throw new IllegalArgumentException("Not supported client=" + clientType);
diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java
deleted file mode 100644 (file)
index ca09458..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.collectionspace.services.relation.nuxeo;\r
-\r
-import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl;\r
-\r
-public class RelationNuxeoConstants {\r
-       static String NUXEO_DOCTYPE = RelationsManagerNuxeoImpl.REL_NUXEO_DOCTYPE;\r
-}
\ No newline at end of file
diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java
deleted file mode 100644 (file)
index f1e5a9c..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-/**    \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.relation.nuxeo;\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.common.repository.DocumentException;\r
-//import org.collectionspace.services.nuxeo.NuxeoRESTClient;\r
-import org.collectionspace.services.nuxeo.CollectionSpaceServiceNuxeoImpl;\r
-import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl;\r
-import org.collectionspace.services.relation.Relation;\r
-import org.collectionspace.services.relation.RelationService;\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.relation.RelationsManager;\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
- * The Class RelationServiceNuxeoImpl.\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
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.relation.RelationService#deleteRelation(java.lang.String)\r
-        */\r
-       public Document deleteRelation(String csid) throws DocumentException {\r
-               Document result = null;\r
-\r
-//             RepositoryInstance repoSession = null;\r
-//             try {\r
-//                     repoSession = getRepositorySession();\r
-//                     result = deleteDocument(repoSession, csid);\r
-//             } catch (Exception e) {\r
-//                     if (logger.isDebugEnabled()) {\r
-//                             logger.debug("Caught exception ", e);\r
-//                     }\r
-//                     throw new DocumentException(e);\r
-//             } finally {\r
-//                     if (repoSession != null) {\r
-//                             releaseRepositorySession(repoSession);\r
-//                     }\r
-//             }\r
-\r
-               return result;\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.relation.RelationService#getRelation(java.lang.String)\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
-                       if (logger.isDebugEnabled()) {\r
-                               logger.debug("Caught exception ", e);\r
-                       }\r
-                       throw new DocumentException(e);\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
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.relation.RelationService#getRelationList()\r
-        */\r
-       public Document getRelationList()\r
-                       throws DocumentException, IOException {\r
-               Document result = null;\r
-               RepositoryInstance repoSession = null;\r
-\r
-               try {\r
-                       repoSession = getRepositorySession();\r
-                       List<Relation> relationList = RelationsManager.getRelationships(repoSession);\r
-                       \r
-                       result = RelationsManagerNuxeoImpl.getDocument(relationList);\r
-               } catch (Exception e) {\r
-                       if (logger.isDebugEnabled()) {\r
-                               logger.debug("Caught exception ", e);\r
-                       }\r
-                       throw new DocumentException(e);\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
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.RelationService#getRelationList(java.lang.String, java.lang.String, java.lang.String)\r
-        */\r
-       public Document getRelationList(String subjectCsid,\r
-                       String predicate, String objectCsid)\r
-                               throws DocumentException, IOException {\r
-               Document result = null;\r
-               RepositoryInstance repoSession = null;\r
-\r
-               try {\r
-                       repoSession = getRepositorySession();\r
-                       List<Relation> relationList = RelationsManager.getRelationships(repoSession,\r
-                                       subjectCsid, predicate, objectCsid);\r
-                       \r
-                       result = RelationsManagerNuxeoImpl.getDocument(relationList);\r
-               } catch (Exception e) {\r
-                       if (logger.isDebugEnabled()) {\r
-                               logger.debug("Caught exception ", e);\r
-                       }\r
-                       throw new DocumentException(e);\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
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.relation.RelationService#postRelation(org.collectionspace.services.relation.Relation)\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
-            DocumentModel resultDocModel = RelationsManagerNuxeoImpl.createRelationship(repoSession, co);\r
-            repoSession.save();\r
-            result = NuxeoUtils.getDocument(repoSession, resultDocModel);\r
-               } catch (Exception e) {\r
-                       if (logger.isDebugEnabled() == true) {\r
-                               logger.debug("Caught exception ", e);\r
-                       }\r
-                       throw new DocumentException(e);\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
-       /* (non-Javadoc)\r
-        * @see org.collectionspace.services.relation.RelationService#putRelation(java.lang.String, org.collectionspace.services.relation.Relation)\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
-            RelationsManagerNuxeoImpl.fillDocModelFromRelation(theUpdate, documentModel);\r
-            repoSession.saveDocument(documentModel);\r
-            repoSession.save();\r
-            result = NuxeoUtils.getDocument(repoSession, documentModel);\r
-        } catch(Exception e){\r
-                       if (logger.isDebugEnabled()) {\r
-                               logger.debug("Caught exception ", e);\r
-                       }\r
-                       throw new DocumentException(e);\r
-        } finally{\r
-            if(repoSession != null){\r
-                releaseRepositorySession(repoSession);\r
-            }\r
-        }\r
-               \r
-               return result;\r
-       }       \r
-\r
-}\r