]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5036: Final support for CMIS query to list all items/resources in a relationsh...
authorRichard Millet <remillet@berkeley.edu>
Thu, 24 May 2012 22:03:15 +0000 (15:03 -0700)
committerRichard Millet <remillet@berkeley.edu>
Thu, 24 May 2012 22:03:15 +0000 (15:03 -0700)
services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java
services/common/pom.xml
services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.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/RepositoryJavaClientImpl.java
services/dimension/service/src/main/java/org/collectionspace/services/dimension/nuxeo/DimensionDocumentModelHandler.java
services/movement/service/src/main/java/org/collectionspace/services/movement/MovementResource.java
services/movement/service/src/main/java/org/collectionspace/services/movement/nuxeo/MovementDocumentModelHandler.java
services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java

index a5a143f1295e21018492c53e577bfc194b62ccec..384b43b9971b20f100faf791d1f08ec8c3126506 100644 (file)
@@ -45,8 +45,29 @@ public interface IQueryManager {
        //\r
        // Query params for CMIS queries on the relationship (Relation) table.\r
        //\r
-       final static String SEARCH_RELATED_TO_CSID_SUBJECT = "rt_sbj";\r
-       final static String SEARCH_RELATED_TO_CSID_OBJECT = "rd_obj";\r
+       final static String SEARCH_RELATED_TO_CSID_SUBJECT = "rtSbj";\r
+       final static String SEARCH_RELATED_TO_CSID_OBJECT = "rtObj";\r
+       \r
+       //\r
+       // Generic CMIS property mapping constants\r
+       //\r
+       final static String CMIS_OBJECT_ID = "cmis:objectId";\r
+       final static String CMIS_NAME = "cmis:name";\r
+       //\r
+       // Nuxeo related CMIS property mapping constants\r
+       final static String CMIS_NUXEO_ID = CMIS_OBJECT_ID;\r
+       final static String CMIS_NUXEO_NAME = CMIS_NAME;\r
+       final static String CMIS_NUXEO_TITLE = "dc:title";\r
+       \r
+       // CollectionSpace CMIS property mapping constants\r
+       final static String CMIS_TARGET_PREFIX = "DOC";\r
+       // Relations CMIS property mapping constants\r
+       final static String CMIS_RELATIONS_PREFIX = "REL";\r
+       \r
+       final static String CMIS_TARGET_NUXEO_ID = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_ID;\r
+       final static String CMIS_TARGET_CSID = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_NAME;\r
+       final static String CMIS_TARGET_TITLE = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_TITLE;\r
+       final static String CMIS_TARGET_NAME = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_NAME;\r
 \r
        public void execQuery(String queryString);\r
        \r
index a892bfeec9e3b75de94f503bbaa9b5bb7a0bdae5..ddd7fa93e9d6e49bb6639c4f4e4ec08a3887f483 100644 (file)
             <artifactId>org.collectionspace.services.client</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.relation.client</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.authentication.jaxb</artifactId>\r
index 53e556bec58dc5b8686a1aff8375774882fcbdb0..64b4a7fe9ae7a5d625009f3bbe4564da6b9e8cd0 100644 (file)
@@ -423,4 +423,8 @@ public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
        //
        return null;
     }
+    
+    public boolean isCMISQuery() {
+       return false;
+    }
 }
index f938b2140e29be3b25ff7b0da6fcc237dd7fe014..b7a6657bb6751fdd24fb2067a16ea5c93e32b60e 100644 (file)
@@ -335,4 +335,6 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      * information in the current service context -which includes things like the query parameters, etc.
      */
     public String getCMISQuery();
+    
+    public boolean isCMISQuery();
 }
index e9a2d8ebe989e41f47a544fd0043d25d2549764f..72fa04f48a6ee2a386ab87b4ab6617436057ba06 100644 (file)
@@ -26,8 +26,12 @@ package org.collectionspace.services.nuxeo.client.java;
 import java.util.Collection;
 import java.util.List;
 
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.RelationClient;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
@@ -346,4 +350,68 @@ public abstract class DocumentModelHandler<T, TL>
                     COLLECTIONSPACE_CORE_UPDATED_BY, userId);
        }
     }
+    
+    /*
+     * If we see the "rtSbj" query param then we need to perform a CMIS query.  Currently, we have only one
+     * CMIS query, but we could add more.  If we do, this method should look at the incoming request and corresponding
+     * query params to determine if we need to do a CMIS query
+     * (non-Javadoc)
+     * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#isCMISQuery()
+     */
+    public boolean isCMISQuery() {
+       boolean result = false;
+       
+       MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
+       //
+       // Look the query params to see if we need to make a CMSIS query.
+       //
+       String subjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);        
+       if (subjectCsid != null) {
+               result = true;
+       }
+       
+       return result;
+    }
+    
+    /**
+     * Creates the CMIS query from the service context.  Each document handler is responsible for returning a valid CMIS query using the
+     * information in the current service context -which includes things like the query parameters, etc.
+     */
+    @Override
+    public String getCMISQuery() {
+       String result = null;
+       
+       if (isCMISQuery() == true) {
+               MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
+               String subjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
+               String docType = this.getServiceContext().getDocumentType();
+               
+               String selectFields = IQueryManager.CMIS_TARGET_NAME + ", "
+                               + IQueryManager.CMIS_TARGET_TITLE + ", "
+                               + RelationClient.CMIS_CSPACE_RELATIONS_TITLE + ", "
+                               + RelationClient.CMIS_CSPACE_RELATIONS_SUBJECT_ID;
+               String targetTable = docType + " " + IQueryManager.CMIS_TARGET_PREFIX;
+               String relationTable = RelationClient.SERVICE_DOC_TYPE + " " + IQueryManager.CMIS_RELATIONS_PREFIX;
+               String relationObjectCsid = RelationClient.CMIS_CSPACE_RELATIONS_OBJECT_ID;
+               String relationSubjectCsid = RelationClient.CMIS_CSPACE_RELATIONS_SUBJECT_ID;
+               String targetCsid = IQueryManager.CMIS_TARGET_CSID;
+               
+               result = "SELECT " + selectFields
+                               + " FROM "      + targetTable + " JOIN " + relationTable
+                               + " ON " + relationObjectCsid + " = " + targetCsid
+                               + " WHERE " + relationSubjectCsid + " = " + "'" + subjectCsid + "'";
+               
+               // SELECT D.cmis:name, D.dc:title, R.dc:title, R.relations_common:subjectCsid
+               // FROM Dimension D JOIN Relation R
+               // ON R.relations_common:objectCsid = D.cmis:name
+               // WHERE R.relations_common:subjectCsid = '737527ec-a560-4776-99de'
+               
+               if (logger.isDebugEnabled() == true && result != null) {
+                       logger.debug("The CMIS query for the Movement service is: " + result);
+               }
+       }
+        
+        return result;
+    }
+    
 }
index aad37e2e44b42a6bcde713e096c81d5e72653ad9..cd9e3dbbd486d18a5dffebdf04f2637ab16670bf 100644 (file)
@@ -27,6 +27,7 @@ import java.util.UUID;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MultivaluedMap;
 
+import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.workflow.WorkflowClient;
@@ -700,6 +701,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * See CSPACE-5036 - How to make CMISQL queries from Nuxeo
      */
        private IterableQueryResult makeCMISQLQuery(RepositoryInstance repoSession, String query) {
+               IterableQueryResult result = null;
+               
                // the NuxeoRepository should be constructed only once, then cached
                // (its construction is expensive)
                try {
@@ -716,21 +719,14 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                        NuxeoCmisService cmisService = new NuxeoCmisService(repo,
                                        callContext, repoSession);
 
-                       IterableQueryResult result = repoSession.queryAndFetch(query,
+                       result = repoSession.queryAndFetch(query,
                                        "CMISQL", cmisService);
-                       for (Map<String, Serializable> row : result) {
-                               logger.debug(
-                               // "dc:title is: " + (String)row.get("dc:title")
-                               "" + " Hierarchy Table ID is:" + row.get("cmis:objectId")
-                                               + " cmis:name is: " + row.get("cmis:name")
-                               // + " nuxeo:lifecycleState is: " +
-                               // row.get("nuxeo:lifecycleState")
-                               );
-                       }
                } catch (ClientException e) {
                        // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       logger.error("Encounter trouble making the following CMIS query: " + query, e);
                }
+               
+               return result;
        }
      
     /**
@@ -769,8 +765,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                Profiler profiler = new Profiler(this, 2);
                profiler.log("Executing NXQL query: " + query.toString());
                profiler.start();
-               if (handler.getCMISQuery() != null) {
-                       docList = getFilteredCMIS(ctx, handler, queryContext);
+               if (handler.isCMISQuery() == true) {
+                       docList = getFilteredCMIS(repoSession, ctx, handler, queryContext); //FIXME: REM - Need to deal with paging info in CMIS query
                } else if ((queryContext.getDocFilter().getOffset() > 0) || (queryContext.getDocFilter().getPageSize() > 0)) {
                 docList = repoSession.query(query, null,
                         queryContext.getDocFilter().getPageSize(), queryContext.getDocFilter().getOffset(), true);
@@ -816,18 +812,22 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                profiler.start();
                //
                IterableQueryResult queryResult = makeCMISQLQuery(repoSession, query);
-                       for (Map<String, Serializable> row : queryResult) {
-                               logger.debug(
-                               // "dc:title is: " + (String)row.get("dc:title")
-                               "" + " Hierarchy Table ID is:" + row.get("cmis:objectId")
-                                               + " cmis:name is: " + row.get("cmis:name")
-                               // + " nuxeo:lifecycleState is: " +
-                               // row.get("nuxeo:lifecycleState")
-                               );
-                               String nuxeoId = (String) row.get("cmis:objectId");
-                               DocumentModel docModel = NuxeoUtils.getDocumentModel(repoSession, nuxeoId);
-                               result.add(docModel);
-                       }               
+               try {
+                               for (Map<String, Serializable> row : queryResult) {
+                                       logger.debug(
+                                       // "dc:title is: " + (String)row.get("dc:title")
+                                       "" + " Hierarchy Table ID is:" + row.get(IQueryManager.CMIS_TARGET_NUXEO_ID)
+                                                       + " cmis:name is: " + row.get(IQueryManager.CMIS_TARGET_NAME)
+                                       // + " nuxeo:lifecycleState is: " +
+                                       // row.get("nuxeo:lifecycleState")
+                                       );
+                                       String nuxeoId = (String) row.get(IQueryManager.CMIS_TARGET_NUXEO_ID);
+                                       DocumentModel docModel = NuxeoUtils.getDocumentModel(repoSession, nuxeoId);
+                                       result.add(docModel);
+                               }
+               } finally {
+                       queryResult.close();
+               }
                //
             profiler.stop();
 
@@ -836,10 +836,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                 logger.debug("Caught exception ", e);
             }
             throw new DocumentException(e);
-        } finally {
-            if (repoSession != null) {
-                releaseRepositorySession(repoSession);
-            }
         }
         
         return result;
index 43b647473010607692fe83d67b2b66a54d0ed340..65cc55f675eced9b80c2e3b5bfe326b363bbfe0b 100644 (file)
@@ -26,8 +26,11 @@ package org.collectionspace.services.dimension.nuxeo;
 import java.util.Iterator;
 import java.util.List;
 
+import javax.ws.rs.core.MultivaluedMap;
+
 import org.collectionspace.services.dimension.DimensionJAXBSchema;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.client.IQueryManager;
+import org.collectionspace.services.client.RelationClient;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.dimension.DimensionsCommon;
 import org.collectionspace.services.dimension.DimensionsCommonList;
@@ -35,7 +38,6 @@ import org.collectionspace.services.dimension.DimensionsCommonList.DimensionList
 
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.slf4j.Logger;
@@ -136,6 +138,6 @@ public class DimensionDocumentModelHandler
     public String getQProperty(String prop) {
         return DimensionConstants.NUXEO_SCHEMA_NAME + ":" + prop;
     }
-
+    
 }
 
index b6c31705c2bb6f47ef44fcab69f7cbd3c290b93f..75172b9198cf795947aea7072d852f508e8d601f 100644 (file)
@@ -78,30 +78,30 @@ public class MovementResource extends ResourceBase {
        return result;
     }
 
-    @Override
-    protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {
-        if (isSet(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT, queryParams) == false) {
-               //
-               // It's not a "related to" query so we can use our normal call to getList and not our CMIS query
-               //
-               return super.getList(queryParams);
-        } else {
-               //
-               // We need to use CMIS query method since we'll be doing a join with the Relation table
-               //
-               try {
-                   ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
-                   DocumentHandler handler = createDocumentHandler(ctx);
-                       String relationToCsid = queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
-                                           
-                       getRepositoryClient(ctx).getFilteredCMIS(ctx, handler);
-
-                   AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
-                   return list;
-               } catch (Exception e) {
-                   throw bigReThrow(e, ServiceMessages.LIST_FAILED);
-               }
-        }
-    }
+//    @Override
+//    protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {
+//        if (isSet(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT, queryParams) == false) {
+//             //
+//             // It's not a "related to" query so we can use our normal call to getList and not our CMIS query
+//             //
+//             return super.getList(queryParams);
+//        } else {
+//             //
+//             // We need to use CMIS query method since we'll be doing a join with the Relation table
+//             //
+//             try {
+//                 ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
+//                 DocumentHandler handler = createDocumentHandler(ctx);
+//                     String relationToCsid = queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
+//                                         
+//                     getRepositoryClient(ctx).getFilteredCMIS(ctx, handler);
+//
+//                 AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
+//                 return list;
+//             } catch (Exception e) {
+//                 throw bigReThrow(e, ServiceMessages.LIST_FAILED);
+//             }
+//        }
+//    }
     
 }
index b210545116f861167d39376ccc7c3a93617d5f99..8d0d62fa5edd3c2041606c7f28deac16bc496975 100644 (file)
  */
 package org.collectionspace.services.movement.nuxeo;
 
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.collectionspace.services.client.IQueryManager;
-import org.collectionspace.services.movement.MovementResource;
 import org.collectionspace.services.movement.MovementsCommon;
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
 import org.slf4j.Logger;
@@ -42,37 +38,5 @@ public class MovementDocumentModelHandler
         extends DocHandlerBase<MovementsCommon> {
 
     final Logger logger = LoggerFactory.getLogger(MovementDocumentModelHandler.class);
-       
-    /**
-     * Creates the CMIS query from the service context.  Each document handler is responsible for returning a valid CMIS query using the
-     * information in the current service context -which includes things like the query parameters, etc.
-     */
-    @Override
-    public String getCMISQuery() {
-       String result = null;
-       
-       String subjectCsid = (String)getServiceContext().getQueryParams().get(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
-       
-       //
-       // For Debugging purposes only
-       //
-        String cmis_movement = System.getenv("CMIS_MOVEMENT");
-
-        if (cmis_movement != null && !cmis_movement.isEmpty()) {
-               result = cmis_movement;
-        } else {
-               result = "SELECT M.cmis:name, M.dc:title, R.dc:title, R.relations_common:subjectCsid "
-                               + "FROM Movement M JOIN Relation R ON R.relations_common:objectCsid = M.cmis:name "
-                               + "WHERE R.relations_common:subjectCsid = "
-                               + "'" + subjectCsid + "'";
-        }
-        
-        if (logger.isDebugEnabled() == true) {
-               logger.debug("The CMIS query for the Movement service is: " + result);
-        }
-        
-        return result;
-    }
-       
 }
 
index 8ace93f91296f858529846fa5d0f77be23da82c5..7949c3345d2e869343ef39bb308974adbafec8de 100644 (file)
@@ -34,6 +34,7 @@ import org.collectionspace.services.relation.RelationsCommonList;
  * The Class RelationClient.
  */
 public class RelationClient extends AbstractPoxServiceClientImpl<RelationsCommonList, RelationProxy> {
+       public static final String SERVICE_DOC_TYPE = "Relation"; // Used for CMIS queries only -should be the same as what's in the tenant bindings
        public static final String SERVICE_NAME = "relations";
        public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;       
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
@@ -43,6 +44,14 @@ public class RelationClient extends AbstractPoxServiceClientImpl<RelationsCommon
 
     public static final String SERVICE_COMMONPART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
 
+       // Relations CMIS property mapping constants
+       public final static String CMIS_CSPACE_RELATIONS_SUBJECT_ID = IQueryManager.CMIS_RELATIONS_PREFIX
+                       + "." + 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_TITLE = IQueryManager.CMIS_RELATIONS_PREFIX
+                       + "." + IQueryManager.CMIS_NUXEO_TITLE;
+    
        @Override
        public String getServiceName() {
                return SERVICE_NAME;