]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5664 - Added support to services config to use the Nuxeo versioning support...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 26 Oct 2012 17:05:15 +0000 (10:05 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Fri, 26 Oct 2012 17:05:15 +0000 (10:05 -0700)
services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java
services/common/src/main/cspace/config/services/tenants/lifesci/tenant-bindings.delta.xml
services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandlerImpl.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/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/config/src/main/resources/service.xsd

index 3f227cd7b3ff7b470794836dab38957bfa4b7b7b..ddcb4d24589cd43a031e4ffb0d9e2c11d1ecec5a 100644 (file)
@@ -42,6 +42,18 @@ public interface IQueryManager {
     final static String SEARCH_TYPE_INVOCATION = "inv";\r
        final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR;\r
        final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;\r
+\r
+       //\r
+       // Nuxeo pseudo-values (and filters) for special document properties.\r
+       //\r
+       final static String NUXEO_IS_PROXY = "ecm:isProxy";\r
+       final static String NUXEO_IS_PROXY_FILTER = NUXEO_IS_PROXY + " = 0";\r
+       final static String NUXEO_IS_VERSION = "ecm:isCheckedInVersion";\r
+       final static String NUXEO_IS_VERSION_FILTER = NUXEO_IS_VERSION + " = 0";\r
+       // In the CMIS context, the prefix is nuxeo, not ecm\r
+       final static String NUXEO_CMIS_IS_VERSION = "nuxeo:isVersion";\r
+       final static String NUXEO_CMIS_IS_VERSION_FILTER = NUXEO_CMIS_IS_VERSION + " = false";\r
+       \r
        //\r
        // Query params for CMIS queries on the relationship (Relation) table.\r
        //\r
@@ -70,6 +82,10 @@ public interface IQueryManager {
        // Relations CMIS property mapping constants\r
        final static String CMIS_RELATIONS_PREFIX = "REL";\r
        \r
+       final static String CMIS_JOIN_NUXEO_IS_VERSION_FILTER = \r
+                       IQueryManager.CMIS_TARGET_PREFIX + "." + IQueryManager.NUXEO_CMIS_IS_VERSION_FILTER;\r
+\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
index b9c0a76e31c7a54b65634ac542f39b2c87163ce6..6938663af05cef94aa6a3cc0ec0f76a1c4f88d7a 100644 (file)
 
        </tenant:serviceBindings>
 
+       <tenant:serviceBindings merge:matcher="id" id="Movements">
+               <service:DocHandlerParams xmlns:service="http://collectionspace.org/services/config/service">
+                       <service:params>
+                               <service:SupportsVersioning>true</service:SupportsVersioning>
+                                       <service:ListResultsFields merge:action="preserve" />
+                       </service:params>
+               </service:DocHandlerParams>
+       </tenant:serviceBindings>
+
        <tenant:serviceBindings merge:matcher="id" id="Persons">
     <service:DocHandlerParams xmlns:service="http://collectionspace.org/services/config/service">
                        <service:params>
index a30a45eef19d084d0a0d93490213b51477f495d6..6436951f4a4e0696ef86ee84ac5fa5d3e3dda30d 100644 (file)
@@ -56,6 +56,13 @@ public abstract class AbstractMultipartDocumentHandlerImpl<T, TL, WT, WTL>
        return false;
     }
     
+    /*
+     * By default we won't support object versioning
+     */
+    public boolean supportsVersioning() {
+       return false;
+    }
+    
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
      */
index 1000f7b7a70acca80a57bd3d49b3575810b898c1..a11a0b9d582c8a895553122b00392027cd2f15f9 100644 (file)
@@ -517,6 +517,10 @@ public abstract class DocumentModelHandler<T, TL>
                                                                + " IN " + matchObjDocTypes + ")";
                }
                
+               // This could later be in control of a queryParam, to omit if we want to see versions, or to
+               // only see old versions.
+               theWhereClause += IQueryManager.SEARCH_QUALIFIER_AND + IQueryManager.CMIS_JOIN_NUXEO_IS_VERSION_FILTER;
+               
                StringBuilder query = new StringBuilder();
                // assemble the query from the string arguments
                query.append("SELECT ");
index 5af6540c670af4a70690284b324abc19a659203f..7fd63f622d56bfdfbf606a38ea31102568f2c835 100644 (file)
@@ -170,6 +170,30 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
        
        return result;
     }
+    
+    @Override
+    public boolean supportsVersioning() {
+       boolean result = false;
+       
+       DocHandlerParams.Params params = null;
+       try {
+               ServiceContext ctx = this.getServiceContext();
+                       params = ServiceConfigUtils.getDocHandlerParams(ctx);
+                       Boolean bool = params.isSupportsVersioning();
+                       if (bool != null) {
+                               result = bool.booleanValue();
+                       }
+               } catch (DocumentException e) {
+                       // TODO Auto-generated catch block
+                       String errMsg = String.format("Could not get document handler params from config bindings for class %s", this.getClass().getName());
+                       if (logger.isWarnEnabled() == true) {
+                               logger.warn(errMsg);
+                       }
+               }
+       
+       return result;
+    }
+    
 
        @Override
        public void handleWorkflowTransition(DocumentWrapper<DocumentModel> wrapDoc, TransitionDef transitionDef)
index 7c186f17d916b53fe83b57817581ddf1af6b9038..154c429a55c0c25ee5cdaefaa557b4675196f0ab 100644 (file)
@@ -53,6 +53,7 @@ import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.IterableQueryResult;
+import org.nuxeo.ecm.core.api.VersioningOption;
 import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl;
 import org.nuxeo.ecm.core.api.DocumentRef;
 import org.nuxeo.ecm.core.api.IdRef;
@@ -163,6 +164,13 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             String id = IdUtils.generateId(UUID.randomUUID().toString());
             // create document model
             DocumentModel doc = repoSession.createDocumentModel(wspacePath, id, docType);
+            /* Check for a versioned document, and check In and Out before we proceed.
+             * This does not work as we do not have the uid schema on our docs.
+            if(((DocumentModelHandler) handler).supportsVersioning()) {
+                   doc.setProperty("uid","major_version",1);
+                   doc.setProperty("uid","minor_version",0);
+            }
+            */
             ((DocumentModelHandler) handler).setRepositorySession(repoSession);
             DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
             handler.handle(Action.CREATE, wrapDoc);
@@ -985,6 +993,27 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                String msg = logException(ce, "Could not find document to update with CSID=" + csid);
                 throw new DocumentNotFoundException(msg, ce);
             }
+            // Check for a versioned document, and check In and Out before we proceed.
+            if(((DocumentModelHandler) handler).supportsVersioning()) {
+               /* Once we advance to 5.5 or later, we can add this. 
+                * See also https://jira.nuxeo.com/browse/NXP-8506
+               if(!doc.isVersionable()) {
+                       throw new DocumentException("Configuration for: "
+                                       +handler.getServiceContextPath()+" supports versioning, but Nuxeo config does not!");
+               }
+                */
+               /* Force a version number - Not working. Apparently we need to configure the uid schema??
+                   if(doc.getProperty("uid","major_version") == null) {
+                           doc.setProperty("uid","major_version",1);
+                   }
+                   if(doc.getProperty("uid","minor_version") == null) {
+                           doc.setProperty("uid","minor_version",0);
+                   }
+                   */
+               doc.checkIn(VersioningOption.MINOR, null); 
+               doc.checkOut();
+            }
+            
             //
             // Set reposession to handle the document
             //
index c6219809f0b88314c1d19c2cc4353dbaea50c562..f6ed2623ebd27b4b9c2fcca8f8ad5c552fe79962 100644 (file)
@@ -365,6 +365,14 @@ public class NuxeoUtils {
      * @param queryContext  The query context, which provides the WHERE clause to append.
      */
     static private final void appendNXQLWhere(StringBuilder query, QueryContext queryContext) {
+
+       // Filter documents that are proxies (speeds up the query) and filter checked in versions
+       // for services that are using versioning.
+       // TODO This should really be handled as a default query param so it can be overridden, 
+       // allowing clients to find versions, just as they can find soft-deleted items.
+       final String PROXY_AND_VERSION_FILTER = 
+                         IQueryManager.SEARCH_QUALIFIER_AND + IQueryManager.NUXEO_IS_PROXY_FILTER
+                       + IQueryManager.SEARCH_QUALIFIER_AND + IQueryManager.NUXEO_IS_VERSION_FILTER;
         //
         // Restrict search to a specific Nuxeo domain
         // TODO This is a slow method for tenant-filter
@@ -388,9 +396,9 @@ public class NuxeoUtils {
             query.append(IQueryManager.SEARCH_QUALIFIER_AND + "(" + whereClause + ")");
         }
         //
-        // Please lookup this use in Nuxeo support and document here
+        // See "Special NXQL Properties" at http://doc.nuxeo.com/display/NXDOC/NXQL
         //
-        query.append(IQueryManager.SEARCH_QUALIFIER_AND + "ecm:isProxy = 0");
+        query.append(PROXY_AND_VERSION_FILTER);
     }
 
     /**
index 09895ae19fa6fc58528360b61f96cb62ffddb411..446d12c3441fa9854dfe0ca7174e406a227a751c 100644 (file)
                         <xs:element name="SchemaName" type="xs:string" minOccurs="0" maxOccurs="1"/>
                         <xs:element name="RefnameDisplayNameField" type="ListResultField" minOccurs="0" maxOccurs="1"/>  <!-- Should rename 'ListResultField' to a more generic name -->
                         <xs:element name="SupportsHierarchy" type="xs:boolean" minOccurs="0" maxOccurs="1" default="false"/>
+                        <xs:element name="SupportsVersioning" type="xs:boolean" minOccurs="0" maxOccurs="1" default="false"/>
                         <xs:element name="DublinCoreTitle" type="xs:string" minOccurs="0" maxOccurs="1"/>
                         <xs:element name="SummaryFields" type="xs:string" minOccurs="0" maxOccurs="1"/>
                         <xs:element name="AbstractCommonListClassname" type="xs:string" minOccurs="0" maxOccurs="1"/>