]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2607: Relation service should support query params of "subType", "objType...
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 9 Aug 2010 21:24:04 +0000 (21:24 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 9 Aug 2010 21:24:04 +0000 (21:24 +0000)
services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java
services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java
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/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java

index 3703c5cfea7da09c11af15d5dbc555f216acff25..4a07ac09a7e1668fbcdbefbece547017be142f21 100644 (file)
@@ -135,8 +135,10 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest {
            String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value();
            ClientResponse<RelationsCommonList> resultResponse = relationClient.readList(
                        collectionObjectCsid,
+                       CollectionobjectsCommon.class.getSimpleName(),
                        predicate,
-                       intakeCsid);
+                       intakeCsid,
+                       IntakesCommon.class.getSimpleName());
         RelationsCommonList relationList = null;
            try {
                Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
index 726d69783d12297688c549a5b177a237d574b074..988fb35405aa91080fcf8134f11ae8cf078ab0d4 100644 (file)
@@ -41,6 +41,8 @@ public interface IRelationsManager {
     /** The Constant SUBJECT. */\r
     static public final String SUBJECT = "subjectCsid";\r
     static public final String SUBJECT_QP = "sbj";\r
+    static public final String SUBJECT_TYPE = "subjectType";\r
+    static public final String SUBJECT_TYPE_QP = SUBJECT_QP + "Type";\r
     \r
     /** The Constant PREDICATE. */\r
     static public final String PREDICATE = "predicate";\r
@@ -49,6 +51,8 @@ public interface IRelationsManager {
     /** The Constant OBJECT. */\r
     static public final String OBJECT = "objectCsid";\r
     static public final String OBJECT_QP = "obj";\r
+    static public final String OBJECT_TYPE = "objectType";\r
+    static public final String OBJECT_TYPE_QP = OBJECT_QP + "Type";\r
 \r
     /**\r
      * Gets the relationships for the entity corresponding to the CSID=csid.\r
index 311fc42e6a0e91e70cf36995819f885b75d7ca50..f4c026ad58aecc01a9d95f5de675e6bc9574037e 100644 (file)
@@ -50,7 +50,9 @@ public class RelationsUtils {
      * @param object the object
      * @return the string
      */
-    public static String buildWhereClause(String subject, String predicate, String object) {
+    public static String buildWhereClause(String subject, String subjectType,
+               String predicate,
+               String object, String objectType) {
        String result = null;
        
        StringBuilder stringBuilder = new StringBuilder();
@@ -59,6 +61,14 @@ public class RelationsUtils {
                                RelationJAXBSchema.DOCUMENT_ID_1 + " = " + "'" + subject + "'");
        }
        
+       if (subjectType != null) {
+               if (stringBuilder.length() > 0) {
+                       stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
+               }
+               stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.DOCUMENT_TYPE_1 + " = " + "'" + subjectType + "'");
+       }
+       
        if (predicate != null) {
                if (stringBuilder.length() > 0) {
                        stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
@@ -75,6 +85,14 @@ public class RelationsUtils {
                                RelationJAXBSchema.DOCUMENT_ID_2 + " = " + "'" + object + "'");
        }
        
+       if (objectType != null) {
+               if (stringBuilder.length() > 0) {
+                       stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
+               }
+               stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.DOCUMENT_TYPE_2 + " = " + "'" + objectType + "'");
+       }
+       
        if (stringBuilder.length() > 0) {
                result = stringBuilder.toString();
        }
index 4dd699bf71f146d6270b2780700cc49525f54e74..38aafe195b34b9f721df51c5eaafc386a3827a0c 100644 (file)
@@ -67,21 +67,15 @@ public class RelationClient extends AbstractServiceClientImpl {
                setProxy();
        }
 
-//     /* (non-Javadoc)
-//      * @see org.collectionspace.services.client.CollectionSpaceClient#getProxy()
-//      */
-//     @Override
-//     public CollectionSpaceProxy getProxy() {
-//             return this.relationProxy;
-//     }
-
-    public CollectionSpaceProxy getProxy() {
+    @Override
+       public CollectionSpaceProxy getProxy() {
        return this.relationProxy;
     }
 
     /**
         * Sets the proxy.
         */
+       @Override
        public void setProxy() {
                if (useAuth()) {
                        relationProxy = ProxyFactory.create(RelationProxy.class,
@@ -105,30 +99,20 @@ public class RelationClient extends AbstractServiceClientImpl {
         * Read list.
         *
         * @param subjectCsid the subject csid
+        * @param subjectType 
         * @param predicate the predicate
         * @param objectCsid the object csid
+        * @param objectType 
         * @return the client response
         */
        public ClientResponse<RelationsCommonList> readList(String subjectCsid,
+                       String subjectType,
                        String predicate,
-                       String objectCsid) {
-               return relationProxy.readList(subjectCsid, predicate, objectCsid);
+                       String objectCsid,
+                       String objectType) {
+               return relationProxy.readList(subjectCsid, subjectType, predicate, objectCsid, objectType);
        }
 
-//     /**
-//      * Read list_ spo.
-//      *
-//      * @param subjectCsid the subject csid
-//      * @param predicate the predicate
-//      * @param objectCsid the object csid
-//      * @return the client response
-//      */
-//     @Deprecated
-//     public ClientResponse<RelationsCommonList> readList_SPO(String subjectCsid,
-//                     String predicate, String objectCsid) {
-//             return relationProxy.readList_SP0(subjectCsid, predicate, objectCsid);
-//     }
-
        /**
         * Read.
         *
index 19eaaf1315a75270966473b0a10f8b7da42c4b15..1533cb4298e8e85592e35b475d3f269293cbe680 100644 (file)
@@ -34,18 +34,11 @@ public interface RelationProxy extends CollectionSpaceProxy {
     @Produces({"application/xml"})
     ClientResponse<RelationsCommonList> readList(
                @QueryParam(IRelationsManager.SUBJECT_QP) String subjectCsid,
+               @QueryParam(IRelationsManager.SUBJECT_TYPE_QP) String subjectType,
                @QueryParam(IRelationsManager.PREDICATE_QP) String predicate,
-               @QueryParam(IRelationsManager.OBJECT_QP) String objectCsid);
+               @QueryParam(IRelationsManager.OBJECT_QP) String objectCsid,
+               @QueryParam(IRelationsManager.OBJECT_TYPE_QP) String objectType);
     
-//    @GET
-//    @Produces({"application/xml"})
-//    @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}")
-//    @Deprecated
-//    ClientResponse<RelationsCommonList> readList_SPO(
-//             @PathParam("subjectCsid") String subjectCsid,
-//            @PathParam("predicate") String predicate,
-//            @PathParam("objectCsid") String objectCsid);
-
     //(C)reate
     @POST
     ClientResponse<Response> create(MultipartOutput multipart);
index a87835b17ca46191f50b6f75f3a8e2fc8749430c..fad74f7b2c671147b7ccf6cb4a009ae9f403e9c7 100644 (file)
@@ -195,9 +195,6 @@ public class NewRelationResource extends
                return result;
        }
 
-       /*
-        * BEGIN OF GET LIST
-        */
        /**
         * Gets the relation list.
         * 
@@ -212,185 +209,16 @@ public class NewRelationResource extends
        @Produces("application/xml")
        public RelationsCommonList getRelationList(@Context UriInfo ui,
                        @QueryParam(IRelationsManager.SUBJECT_QP) String subjectCsid,
+                       @QueryParam(IRelationsManager.SUBJECT_TYPE_QP) String subjectType,
                        @QueryParam(IRelationsManager.PREDICATE_QP) String predicate,
-                       @QueryParam(IRelationsManager.OBJECT_QP) String objectCsid) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, subjectCsid, predicate, objectCsid);
-       }
-
-       /**
-        * Gets the relation list_ s.
-        * 
-        * @param ui the ui
-        * @param subjectCsid the subject csid
-        * 
-        * @return the relation list_ s
-        */
-       @GET
-       @Path("subject/{subjectCsid}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_S(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, subjectCsid, null, null);
-       }
-
-       /**
-        * Gets the relation list_ p.
-        * 
-        * @param ui the ui
-        * @param predicate the predicate
-        * 
-        * @return the relation list_ p
-        */
-       @GET
-       @Path("type/{predicate}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_P(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, null, predicate, null);
-       }
-
-       /**
-        * Gets the relation list_ o.
-        * 
-        * @param ui the ui
-        * @param objectCsid the object csid
-        * 
-        * @return the relation list_ o
-        */
-       @GET
-       @Path("object/{objectCsid}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_O(@Context UriInfo ui,
-                       @PathParam("objectCsid") String objectCsid) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, null, null, objectCsid);
-       }
-
-       /**
-        * Gets the relation list_ ps.
-        * 
-        * @param ui the ui
-        * @param predicate the predicate
-        * @param subjectCsid the subject csid
-        * 
-        * @return the relation list_ ps
-        */
-       @GET
-       @Path("type/{predicate}/subject/{subjectCsid}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_PS(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("subjectCsid") String subjectCsid) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, subjectCsid, predicate, null);
-       }
-
-       /**
-        * Gets the relation list_ sp.
-        * 
-        * @param ui the ui
-        * @param subjectCsid the subject csid
-        * @param predicate the predicate
-        * 
-        * @return the relation list_ sp
-        */
-       @GET
-       @Path("subject/{subjectCsid}/type/{predicate}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_SP(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, subjectCsid, predicate, null);
-       }
-
-       /**
-        * Gets the relation list_ po.
-        * 
-        * @param ui the ui
-        * @param predicate the predicate
-        * @param objectCsid the object csid
-        * 
-        * @return the relation list_ po
-        */
-       @GET
-       @Path("type/{predicate}/object/{objectCsid}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_PO(@Context UriInfo ui,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, null, predicate, objectCsid);
-       }
-
-       /**
-        * Gets the relation list_ op.
-        * 
-        * @param ui the ui
-        * @param objectCsid the object csid
-        * @param predicate the predicate
-        * 
-        * @return the relation list_ op
-        */
-       @GET
-       @Path("object/{objectCsid}/type/{predicate}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_OP(@Context UriInfo ui,
-                       @PathParam("objectCsid") String objectCsid,
-                       @PathParam("predicate") String predicate) {
+                       @QueryParam(IRelationsManager.OBJECT_QP) String objectCsid,
+                       @QueryParam(IRelationsManager.OBJECT_TYPE_QP) String objectType) {
                MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, null, predicate, objectCsid);
+               return this.getRelationList(queryParams, subjectCsid, subjectType,
+                               predicate,
+                               objectCsid, objectType);
        }
 
-       /**
-        * Gets the relation list_ pso.
-        * 
-        * @param ui the ui
-        * @param predicate the predicate
-        * @param subjectCsid the subject csid
-        * @param objectCsid the object csid
-        * 
-        * @return the relation list_ pso
-        */
-       @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) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, subjectCsid, predicate, objectCsid);
-       }
-
-       /**
-        * Gets the relation list_ spo.
-        * 
-        * @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}")
-       @Produces("application/xml")
-       public RelationsCommonList getRelationList_SPO(@Context UriInfo ui,
-                       @PathParam("subjectCsid") String subjectCsid,
-                       @PathParam("predicate") String predicate,
-                       @PathParam("objectCsid") String objectCsid) {
-               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-               return this.getRelationList(queryParams, subjectCsid, predicate, objectCsid);
-       }
-
-       /*
-        * END OF GET LIST
-        */
-
        /**
         * Update relation.
         * 
@@ -501,13 +329,16 @@ public class NewRelationResource extends
        public RelationsCommonList getRelationList(
                        MultivaluedMap<String, String> queryParams,
                        String subjectCsid,
+                       String subjectType,
                        String predicate, 
-                       String objectCsid) throws WebApplicationException {
+                       String objectCsid,
+                       String objectType) throws WebApplicationException {
                RelationsCommonList relationList = new RelationsCommonList();
                try {
                        ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
                        DocumentHandler handler = createDocumentHandler(ctx);
-                       String relationClause = RelationsUtils.buildWhereClause(subjectCsid, predicate, objectCsid);
+                       String relationClause = RelationsUtils.buildWhereClause(subjectCsid, subjectType, predicate,
+                                       objectCsid, objectType);
                        handler.getDocumentFilter().appendWhereClause(relationClause, IQueryManager.SEARCH_QUALIFIER_AND);                      
                        getRepositoryClient(ctx).getFiltered(ctx, handler);
                        relationList = (RelationsCommonList)handler.getCommonPartList();