]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-127: Add an API to delete relations given a subject, object, and/or predicate
authorremillet <remillet@yahoo.com>
Wed, 4 Oct 2017 10:20:42 +0000 (03:20 -0700)
committerremillet <remillet@yahoo.com>
Wed, 4 Oct 2017 10:20:42 +0000 (03:20 -0700)
services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java
services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java

index 1339e678685fadd48e40adce7155c978ce469220..53be9d6b88f77638de2a954efb3b4fd8acc78cf1 100644 (file)
@@ -39,16 +39,20 @@ import org.collectionspace.services.client.IRelationsManager;
 import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
 import org.collectionspace.services.relation.RelationsCommon;
 import org.collectionspace.services.relation.RelationsCommonList;
+import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 @Path("/relations")
@@ -128,6 +132,17 @@ public class RelationResource extends NuxeoBasedResource {
         }
     }
 
+    @DELETE
+    public Response delete(@Context UriInfo uriInfo) {
+       Response result = Response.status(200).build();
+       
+       RelationsCommonList relationsList = this.getList(null, uriInfo);
+       for (RelationListItem relation : relationsList.getRelationListItem()) {
+               Response deleteResponse = this.delete(relation.getCsid());
+       }
+       
+       return result;
+    }
 
 }
 
index 1f93a349bd96ba12a475576d5874381aa600b095..30211583d22b7269c920e29eb22365cb94fc066d 100644 (file)
@@ -58,13 +58,13 @@ public class RelationsUtils {
        
        StringBuilder stringBuilder = new StringBuilder();
        
-       //
-       // (subectCsid = ${csid} OR objectCsid = ${csid}) overrides the individual subject or object query params
-       // (Example,    ((rel.subjectcsid = subject AND rel.objectcsid = target)
-       //                                      OR 
-       //                              (rel.subjectcsid = target AND rel.objectcsid = subject))
-       //
-       if (subjectOrObject != null) {
+       if (subjectOrObject != null && object != null) {
+               // Used for GET requests like: cspace-services/collectionobjects?mkRtSbjOrObj=cf5db000-4e65-42d5-8117
+               //
+               // (Example,    ((rel.subjectcsid = subject AND rel.objectcsid = target)
+               //                                      OR 
+               //                              (rel.subjectcsid = target AND rel.objectcsid = subject))
+               //
                String target = object;
                stringBuilder.append("(");
                stringBuilder.append("(" + RelationConstants.NUXEO_SCHEMA_NAME + ":" +
@@ -77,8 +77,21 @@ public class RelationsUtils {
                stringBuilder.append(" AND " + RelationConstants.NUXEO_SCHEMA_NAME + ":" +
                                RelationJAXBSchema.OBJECT_CSID + " = " + "'" + subjectOrObject + "'" + ")");
                stringBuilder.append(")");
-
+       } else if (subjectOrObject != null) {
+               // Used for GET requests like: cspace-services/relations?sbjOrObj=cf5db000-4e65-42d5-8117
+               //
+               // (subectCsid = ${csid} OR objectCsid = ${csid}) overrides the individual subject or object query params
+               // (Example,    (rel.subjectcsid = subjectOrObject      OR rel.objectcsid = subjectOrObject)
+               //
+               stringBuilder.append("(" + RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.SUBJECT_CSID + " = " + "'" + subjectOrObject + "'");
+               stringBuilder.append(" OR ");
+               stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+                               RelationJAXBSchema.OBJECT_CSID + " = " + "'" + subjectOrObject + "')");
        } else {
+               // Used for GET requests like: cspace-services/relations?sbj=cf5db000-4e65-42d5-8117
+               // and cspace-services/relations?obj=cf5db000-4e65-42d5-8117
+               //
                if (subject != null) {
                        if (stringBuilder.length() > 0) {
                                stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);