]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-332: Added remaining URL paths for symmetry.
authorRichard Millet <richard.millet@berkeley.edu>
Sun, 9 Aug 2009 02:12:42 +0000 (02:12 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Sun, 9 Aug 2009 02:12:42 +0000 (02:12 +0000)
services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java
services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java

index 1148a3aa4562073e33f546ed36516fc6b80dab51..25e0015c668b215961ed8907d5c712896f547dd7 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
 import org.collectionspace.services.common.repository.DocumentException;\r
 import org.collectionspace.services.relation.Relation;\r
 import org.dom4j.Document;\r
+import org.nuxeo.ecm.core.api.DocumentModel;\r
 \r
 /**\r
  * The Interface RelationUtils.\r
@@ -105,4 +106,21 @@ public interface RelationUtils {
         * @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
index 0a944c9c256479385024fa1a2e116aac169a102d..242627ef3efa0c6bdb06aa9d18e05cc64fb9c48a 100644 (file)
@@ -35,12 +35,22 @@ import org.collectionspace.services.relation.Relation;
 import org.collectionspace.services.common.relation.RelationUtils;\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 RelationUtils relationUtils = new RelationUtilsNuxeoImpl();\r
 \r
@@ -120,5 +130,24 @@ public class RelationsManager {
        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
index eb963480f3c8e404330977e665e9fa43252f1bda..d7ef70b3c837abb9587885f97eed95a390674521 100644 (file)
@@ -581,12 +581,13 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
         * \r
         * @throws ClientException the client exception\r
         */\r
-       private boolean isQueryMatch(DocumentModel documentModel,\r
+       public boolean isQueryMatch(DocumentModel documentModel,\r
                        String subjectCsid,\r
                        String predicate,\r
-                       String objectCsid) throws ClientException {\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
@@ -607,6 +608,12 @@ public class RelationUtilsNuxeoImpl implements RelationUtils {
                                }\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
index f77645fb725283087affec7c5087d0ea9ce9ab40..c4874470ab091502320f5dc80956a625b06d0699 100644 (file)
@@ -1,5 +1,33 @@
+/**    
+ * NewRelationResource.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.Map;
+
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -22,6 +50,7 @@ import org.collectionspace.services.relation.nuxeo.RelationNuxeoConstants;
 import org.collectionspace.services.relation.nuxeo.RelationHandlerFactory;
 import org.collectionspace.services.common.NuxeoClientType;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.relation.RelationsManager;
 import org.collectionspace.services.common.repository.DocumentNotFoundException;
 import org.collectionspace.services.common.repository.DocumentHandler;
 import org.collectionspace.services.common.repository.RepositoryClient;
@@ -35,209 +64,334 @@ import org.slf4j.LoggerFactory;
 @Produces("application/xml")
 public class NewRelationResource {
 
-    public final static String SERVICE_NAME = "relations";
-    final Logger logger = LoggerFactory.getLogger(NewRelationResource.class);
-    //FIXME retrieve client type from configuration
-    final static NuxeoClientType CLIENT_TYPE = ServiceMain.getInstance().getNuxeoClientType();
-
-    public NewRelationResource() {
-        // do nothing
-    }
-
-    @POST
-    public Response createRelation(
-            Relation relation) {
-
-        String csid = null;
-        try{
-            RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
-            RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
-            RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
-            DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
-            handler.setCommonObject(relation);
-            csid = client.create(SERVICE_NAME, handler);
-            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);
-        }
-    }
-
-    @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{
-            RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
-            RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
-            RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
-            DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
-            client.get(csid, handler);
-            relation = (Relation) handler.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);
-        }
-
-        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;
-    }
-
-    @GET
-    public RelationList getRelationList(@Context UriInfo ui) {
-        RelationList relationList = new RelationList();
-        try{
-            RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
-            RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
-            RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
-            DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
-            client.getAll(SERVICE_NAME, handler);
-            relationList = (RelationList) handler.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 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{
-            RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
-            RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
-            RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance();
-            DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString());
-            handler.setCommonObject(theUpdate);
-            client.update(csid, handler);
-        }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;
-    }
-
-    @DELETE
-    @Path("{csid}")
-    public Response deleteRelation(@PathParam("csid") String csid) {
-
-        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{
-            RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance();
-            RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString());
-            client.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);
-        }
-
-    }
-
-    private void verbose(String msg, Relation relation) {
-        try{
-            verbose(msg);
-            JAXBContext jc = JAXBContext.newInstance(
-                    Relation.class);
-
-            Marshaller m = jc.createMarshaller();
-            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-            m.marshal(relation, System.out);
-        }catch(Exception e){
-            e.printStackTrace();
-        }
-
-    }
-
-    private void verbose(String msg) {
-        System.out.println("RelationResource. " + msg);
-    }
+       public final static String SERVICE_NAME = "relations";
+       final Logger logger = LoggerFactory.getLogger(NewRelationResource.class);
+       // FIXME retrieve client type from configuration
+       final static NuxeoClientType CLIENT_TYPE = ServiceMain.getInstance()
+                       .getNuxeoClientType();
+
+       public NewRelationResource() {
+               // do nothing
+       }
+
+       @POST
+       public Response createRelation(Relation relation) {
+
+               String csid = null;
+               try {
+                       RepositoryClientFactory clientFactory = RepositoryClientFactory
+                                       .getInstance();
+                       RepositoryClient client = clientFactory.getClient(CLIENT_TYPE
+                                       .toString());
+                       RelationHandlerFactory handlerFactory = RelationHandlerFactory
+                                       .getInstance();
+                       DocumentHandler handler = (DocumentHandler) handlerFactory
+                                       .getHandler(CLIENT_TYPE.toString());
+                       handler.setCommonObject(relation);
+                       csid = client.create(SERVICE_NAME, handler);
+                       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);
+               }
+       }
+
+       @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 {
+                       RepositoryClientFactory clientFactory = RepositoryClientFactory
+                                       .getInstance();
+                       RepositoryClient client = clientFactory.getClient(CLIENT_TYPE
+                                       .toString());
+                       RelationHandlerFactory handlerFactory = RelationHandlerFactory
+                                       .getInstance();
+                       DocumentHandler handler = (DocumentHandler) handlerFactory
+                                       .getHandler(CLIENT_TYPE.toString());
+                       client.get(csid, handler);
+                       relation = (Relation) handler.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);
+               }
+
+               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
+        */
+
+       @GET
+       public RelationList getRelationList(@Context UriInfo ui) {
+               return this.getRelationListRequest(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("object/{objectCsid}")
+       public RelationList getRelationList_O(@Context UriInfo ui,
+                       @PathParam("objectCsid") String objectCsid) {
+               return this.getRelationListRequest(null, null, objectCsid);
+       }
+
+       @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("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 {
+                       RepositoryClientFactory clientFactory = RepositoryClientFactory
+                                       .getInstance();
+                       RepositoryClient client = clientFactory.getClient(CLIENT_TYPE
+                                       .toString());
+                       RelationHandlerFactory handlerFactory = RelationHandlerFactory
+                                       .getInstance();
+                       DocumentHandler handler = (DocumentHandler) handlerFactory
+                                       .getHandler(CLIENT_TYPE.toString());
+                       handler.setCommonObject(theUpdate);
+                       client.update(csid, handler);
+               } 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;
+       }
+
+       @DELETE
+       @Path("{csid}")
+       public Response deleteRelation(@PathParam("csid") String csid) {
+
+               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 {
+                       RepositoryClientFactory clientFactory = RepositoryClientFactory
+                                       .getInstance();
+                       RepositoryClient client = clientFactory.getClient(CLIENT_TYPE
+                                       .toString());
+                       client.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);
+               }
+
+       }
+
+       /*
+        * Private Methods
+        */
+
+       /**
+        * 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 {
+                       RepositoryClientFactory clientFactory = RepositoryClientFactory
+                                       .getInstance();
+                       RepositoryClient client = clientFactory.getClient(CLIENT_TYPE
+                                       .toString());
+                       RelationHandlerFactory handlerFactory = RelationHandlerFactory
+                                       .getInstance();
+                       DocumentHandler handler = (DocumentHandler) handlerFactory
+                                       .getHandler(CLIENT_TYPE.toString());
+
+                       Map propsFromPath = handler.getProperties();
+                       propsFromPath.put(RelationsManager.SUBJECT, subjectCsid);
+                       propsFromPath.put(RelationsManager.PREDICATE, predicate);
+                       propsFromPath.put(RelationsManager.OBJECT, objectCsid);
+
+                       client.getAll(SERVICE_NAME, handler);
+                       relationList = (RelationList) handler.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;
+       }
+
+       private void verbose(String msg, Relation relation) {
+               try {
+                       verbose(msg);
+                       JAXBContext jc = JAXBContext.newInstance(Relation.class);
+
+                       Marshaller m = jc.createMarshaller();
+                       m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+                       m.marshal(relation, System.out);
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+       }
+
+       private void verbose(String msg) {
+               System.out.println("RelationResource. " + msg);
+       }
 }
index 0bb0abe5998d1c9ca7c09495b64ec94c38ec05bb..c6b74c1a65f97cb44268c177385eee8549482390 100644 (file)
@@ -25,6 +25,8 @@ package org.collectionspace.services.relation.nuxeo;
 
 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.RelationUtilsNuxeoImpl;
 import org.collectionspace.services.common.relation.RelationsManager;
@@ -122,6 +124,11 @@ public class RelationDocumentModelHandler
     public RelationList extractCommonObjectList(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);
+
         RelationList coList = new RelationList();
         List<RelationList.RelationListItem> list = coList.getRelationListItem();
 
@@ -130,11 +137,13 @@ public class RelationDocumentModelHandler
         Iterator<DocumentModel> iter = docList.iterator();
         while(iter.hasNext()){
             DocumentModel docModel = iter.next();
-            RelationListItem coListItem = new RelationListItem();
-            
-            RelationUtilsNuxeoImpl.fillRelationListItemFromDocModel(coListItem, docModel);
-            
-            list.add(coListItem);
+            if (RelationsManager.isQueryMatch(docModel, subjectCsid,
+                                       predicate, objectCsid) == true) {
+                               RelationListItem coListItem = new RelationListItem();
+                               RelationUtilsNuxeoImpl.fillRelationListItemFromDocModel(
+                                               coListItem, docModel);
+                               list.add(coListItem);
+                       }
         }
 
         return coList;