From: Richard Millet Date: Mon, 9 Aug 2010 21:24:04 +0000 (+0000) Subject: CSPACE-2607: Relation service should support query params of "subType", "objType... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=6edc186506a4352174b49cd31b1734e02c57c000;p=tmp%2Fjakarta-migration.git CSPACE-2607: Relation service should support query params of "subType", "objType" for subject type and object type --- diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java index 3703c5cfe..4a07ac09a 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java @@ -135,8 +135,10 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value(); ClientResponse 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()); diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java index 726d69783..988fb3540 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java @@ -41,6 +41,8 @@ public interface IRelationsManager { /** The Constant SUBJECT. */ static public final String SUBJECT = "subjectCsid"; static public final String SUBJECT_QP = "sbj"; + static public final String SUBJECT_TYPE = "subjectType"; + static public final String SUBJECT_TYPE_QP = SUBJECT_QP + "Type"; /** The Constant PREDICATE. */ static public final String PREDICATE = "predicate"; @@ -49,6 +51,8 @@ public interface IRelationsManager { /** The Constant OBJECT. */ static public final String OBJECT = "objectCsid"; static public final String OBJECT_QP = "obj"; + static public final String OBJECT_TYPE = "objectType"; + static public final String OBJECT_TYPE_QP = OBJECT_QP + "Type"; /** * Gets the relationships for the entity corresponding to the CSID=csid. 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 index 311fc42e6..f4c026ad5 100644 --- 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 @@ -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(); } diff --git a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java index 4dd699bf7..38aafe195 100644 --- a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java +++ b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java @@ -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 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 readList_SPO(String subjectCsid, -// String predicate, String objectCsid) { -// return relationProxy.readList_SP0(subjectCsid, predicate, objectCsid); -// } - /** * Read. * diff --git a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java index 19eaaf131..1533cb429 100644 --- a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java +++ b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java @@ -34,18 +34,11 @@ public interface RelationProxy extends CollectionSpaceProxy { @Produces({"application/xml"}) ClientResponse 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 readList_SPO( -// @PathParam("subjectCsid") String subjectCsid, -// @PathParam("predicate") String predicate, -// @PathParam("objectCsid") String objectCsid); - //(C)reate @POST ClientResponse create(MultipartOutput multipart); diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java index a87835b17..fad74f7b2 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java @@ -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 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 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 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 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 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 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 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 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 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 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 queryParams, String subjectCsid, + String subjectType, String predicate, - String objectCsid) throws WebApplicationException { + String objectCsid, + String objectType) throws WebApplicationException { RelationsCommonList relationList = new RelationsCommonList(); try { ServiceContext 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();