]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-119: Added support for rtEither query param to find relationships that with...
authorremillet <remillet@yahoo.com>
Thu, 21 Sep 2017 21:20:40 +0000 (14:20 -0700)
committerremillet <remillet@yahoo.com>
Thu, 21 Sep 2017 21:20:40 +0000 (14:20 -0700)
services/client/src/main/java/org/collectionspace/services/client/IRelationsManager.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryClientImpl.java

index 5482f6e14551b994634053734487993b391c6bd7..62acb7a512dcc393f32aa64326a64392b0a869ca 100644 (file)
@@ -13,6 +13,10 @@ public interface IRelationsManager {
                        + "." + SERVICE_COMMONPART_NAME + ":subjectCsid";
        public final static String CMIS_CSPACE_RELATIONS_OBJECT_ID = IQueryManager.CMIS_RELATIONS_PREFIX
                        + "." + SERVICE_COMMONPART_NAME + ":objectCsid";
+       public final static String CMIS_CSPACE_RELATIONS_EITHER_ID = IQueryManager.CMIS_RELATIONS_PREFIX
+                       + "." + SERVICE_COMMONPART_NAME + ":either";
+       
+       
        public final static String CMIS_CSPACE_RELATIONS_OBJECT_TYPE = IQueryManager.CMIS_RELATIONS_PREFIX
                        + "." + SERVICE_COMMONPART_NAME + ":objectDocumentType";
        public final static String CMIS_CSPACE_RELATIONS_TITLE = IQueryManager.CMIS_RELATIONS_PREFIX
index af44a6cfcce59eb26a5fe2e279442ba23007f10f..24f36c5069993aa77939032dc8fbcac57979c245 100644 (file)
@@ -461,7 +461,7 @@ public abstract class DocumentModelHandler<T, TL>
                MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
                String asSubjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT);
                String asObjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_OBJECT);
-               String asEitherCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_EITHER);
+//             String asEitherCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_EITHER);
                String matchObjDocTypes = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_MATCH_OBJ_DOCTYPES);
                String selectDocType = (String)queryParams.getFirst(IQueryManager.SELECT_DOC_TYPE_FIELD);
 
@@ -478,6 +478,7 @@ public abstract class DocumentModelHandler<T, TL>
                String relTable = IRelationsManager.DOC_TYPE + " " + IQueryManager.CMIS_RELATIONS_PREFIX;
                String relObjectCsidCol = IRelationsManager.CMIS_CSPACE_RELATIONS_OBJECT_ID;
                String relSubjectCsidCol = IRelationsManager.CMIS_CSPACE_RELATIONS_SUBJECT_ID;
+               String relEitherCsidCol = IRelationsManager.CMIS_CSPACE_RELATIONS_EITHER_ID;
                String targetCsidCol = IQueryManager.CMIS_TARGET_CSID;
                String tenantID = this.getServiceContext().getTenantId();
 
@@ -494,11 +495,10 @@ public abstract class DocumentModelHandler<T, TL>
                        // Since our query param is the "object" value, join the tables where the CSID of the document is the other side (the "subject") of the relationship.
                        theOnClause = relSubjectCsidCol + " = " + targetCsidCol; 
                        theWhereClause = relObjectCsidCol + " = " + "'" + asObjectCsid + "'";
-               } else if (asEitherCsid != null && !asEitherCsid.isEmpty()) {
-                       theOnClause = relObjectCsidCol + " = " + targetCsidCol
-                                       + " OR " + relSubjectCsidCol + " = " + targetCsidCol;
-                       theWhereClause = relSubjectCsidCol + " = " + "'" + asEitherCsid + "'"
-                                       + " OR " + relObjectCsidCol + " = " + "'" + asEitherCsid + "'";
+//             } else if (asEitherCsid != null && !asEitherCsid.isEmpty()) {
+//                     theOnClause = relEitherCsidCol + " = " + targetCsidCol; // See https://issues.collectionspace.org/browse/DRYD-119
+//                     theWhereClause = relSubjectCsidCol + " = " + "'" + asEitherCsid + "'"
+//                                     + " OR " + relObjectCsidCol + " = " + "'" + asEitherCsid + "'";
                } else {
                        //Since the call to isCMISQuery() return true, we should never get here.
                        logger.error("Attempt to make CMIS query failed because the HTTP request was missing valid query parameters.");
index 4a5ae318b970137631c3f19036607026c1116fbf..a2950f30b1be4862c78a7467584a34b3955a1423 100644 (file)
@@ -722,7 +722,11 @@ public class RepositoryClientImpl implements RepositoryClient<PoxPayloadIn, PoxP
             if (handler.isCMISQuery() == true) {
                 String inList = buildInListForDocTypes(docTypes);
                 ctx.getQueryParams().add(IQueryManager.SEARCH_RELATED_MATCH_OBJ_DOCTYPES, inList);
-                docList = getFilteredCMIS(repoSession, ctx, handler, queryContext);
+                if (isSubjectOrObjectQuery(ctx)) {
+                       docList = getFilteredCMISForSubjectOrObject(repoSession, ctx, handler, queryContext);
+                } else {
+                       docList = getFilteredCMIS(repoSession, ctx, handler, queryContext);
+                }
             } else {
                 String query = NuxeoUtils.buildNXQLQuery(docTypes, queryContext);
                 if (logger.isDebugEnabled()) {
@@ -743,7 +747,100 @@ public class RepositoryClientImpl implements RepositoryClient<PoxPayloadIn, PoxP
         return wrapDoc;
     }
 
-    /**
+    private DocumentModelList getFilteredCMISForSubjectOrObject(CoreSessionInterface repoSession,
+                       ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, DocumentHandler handler, QueryContext queryContext) throws DocumentNotFoundException, DocumentException {
+       DocumentModelList result = null;
+       
+       if (isSubjectOrObjectQuery(ctx) == true) {
+               MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
+               String asEitherCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_EITHER);
+               
+               queryParams.remove(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT);
+               queryParams.remove(IQueryManager.SEARCH_RELATED_TO_CSID_AS_OBJECT);
+
+               //
+               // First query for subjectCsid results.
+               //
+               queryParams.addFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT, asEitherCsid);
+            DocumentModelList subjectDocList = getFilteredCMIS(repoSession, ctx, handler, queryContext);
+            queryParams.remove(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT);
+            
+               //
+               // Next query for objectCsid results.
+               //
+               queryParams.addFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_OBJECT, asEitherCsid);
+            DocumentModelList objectDocList = getFilteredCMIS(repoSession, ctx, handler, queryContext);
+            queryParams.remove(IQueryManager.SEARCH_RELATED_TO_CSID_AS_OBJECT);
+
+            //
+            // Finally, combine the two results
+            //
+            result = mergeDocumentModelLists(subjectDocList, objectDocList);
+       }
+       
+               return result;
+       }
+
+       private DocumentModelList mergeDocumentModelLists(DocumentModelList subjectDocList,
+                       DocumentModelList objectDocList) {
+               DocumentModelList result = null;
+               
+               if (subjectDocList == null || subjectDocList.isEmpty()) {
+                       return objectDocList;
+               }
+               
+               if (objectDocList == null || objectDocList.isEmpty()) {
+                       return subjectDocList;
+               }
+               
+        result = new DocumentModelListImpl();
+        
+        // Add the subject list
+               Iterator<DocumentModel> iterator = subjectDocList.iterator();
+               while (iterator.hasNext()) {
+                       DocumentModel dm = iterator.next();
+                       addToResults(result, dm);
+               }
+               
+               // Add the object list
+               iterator = objectDocList.iterator();
+               while (iterator.hasNext()) {
+                       DocumentModel dm = iterator.next();
+                       addToResults(result, dm);
+               }
+
+               // Set the 'totalSize' value for book keeping sake
+               ((DocumentModelListImpl) result).setTotalSize(result.size());
+
+               return result;
+       }
+
+       //
+       // Only add if it is not already in the list
+       private void addToResults(DocumentModelList result, DocumentModel dm) {
+               Iterator<DocumentModel> iterator = result.iterator();
+               boolean found = false;
+               
+               while (iterator.hasNext()) {
+                       DocumentModel existingDm = iterator.next();
+                       if (existingDm.getId().equals(dm.getId())) {
+                               found = true;
+                               break;
+                       }
+               }
+               
+               if (found == false) {
+                       result.add(dm);
+               }
+       }
+
+       private boolean isSubjectOrObjectQuery(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx) {
+       MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
+       String asEitherCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_EITHER);
+       return asEitherCsid != null && !asEitherCsid.isEmpty();
+       }
+
+       /**
      * Find a list of documentModels from the Nuxeo repository
      *
      * @param docTypes a list of DocType names to match
@@ -1012,8 +1109,12 @@ public class RepositoryClientImpl implements RepositoryClient<PoxPayloadIn, PoxP
             if (handler.isJDBCQuery() == true) {
                 docList = getFilteredJDBC(repoSession, ctx, handler);
             // CMIS query
-            } else if (handler.isCMISQuery() == true) {
-                docList = getFilteredCMIS(repoSession, ctx, handler, queryContext); //FIXME: REM - Need to deal with paging info in CMIS query
+            } else if (handler.isCMISQuery() == true) { //FIXME: REM - Need to deal with paging info in CMIS query
+                if (isSubjectOrObjectQuery(ctx)) {
+                       docList = getFilteredCMISForSubjectOrObject(repoSession, ctx, handler, queryContext);
+                } else {
+                    docList = getFilteredCMIS(repoSession, ctx, handler, queryContext); 
+                }
             // NXQL query
             } else {
                 String query = NuxeoUtils.buildNXQLQuery(queryContext);