chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r956843 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/query/ test/java/org/apache/chemistry/opencmis/inmemory/query/
Date Tue, 22 Jun 2010 10:37:41 GMT
Author: jens
Date: Tue Jun 22 10:37:40 2010
New Revision: 956843

URL: http://svn.apache.org/viewvc?rev=956843&view=rev
Log:
CMIS-216
evaluate parameter searchAllVersions

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java?rev=956843&r1=956842&r2=956843&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
Tue Jun 22 10:37:40 2010
@@ -51,10 +51,12 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl;
 import org.apache.chemistry.opencmis.inmemory.TypeManager;
 import org.apache.chemistry.opencmis.inmemory.query.QueryObject.SortSpec;
+import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Filing;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
+import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
 import org.apache.chemistry.opencmis.inmemory.storedobj.impl.ObjectStoreImpl;
 import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
 import org.apache.chemistry.opencmis.server.support.query.CalendarHelper;
@@ -96,7 +98,7 @@ public class InMemoryQueryProcessor impl
         // iterate over all the objects and check for each if the query matches
         for (String objectId : ((ObjectStoreImpl) objectStore).getIds()) {
             StoredObject so = objectStore.getObjectById(objectId);
-            checkMatch(so);
+            match(so, searchAllVersions==null ? true : searchAllVersions.booleanValue());
         }
 
         ObjectList objList = buildResultList(tm, user, includeAllowableActions, includeRelationships,
renditionFilter,
@@ -155,18 +157,6 @@ public class InMemoryQueryProcessor impl
         // log.debug("onStopProcessing()");
     }
 
-    /**
-     * Check for each object contained in the in-memory repository if it matches the current
query
-     * expression. If yes add it to the list of matched objects.
-     * 
-     * @param so
-     *      object stored in the in-memory repository
-     */
-    public void checkMatch(StoredObject so) {
-        // log.debug("checkMatch() for object: " + so.getId());
-        match(so);
-    }
-
     public ObjectList buildResultList(TypeManager tm, String user, 
             Boolean includeAllowableActions, IncludeRelationships includeRelationships, String
renditionFilter,
             BigInteger maxItems, BigInteger skipCount) {
@@ -257,14 +247,24 @@ public class InMemoryQueryProcessor impl
         
     }
 
-    private void match(StoredObject so) {
-        // log.debug("Tree is: " + (whereTree == null ? "(empty)" : whereTree.toStringTree()));
+    /**
+     * Check for each object contained in the in-memory repository if it matches the current
query
+     * expression. If yes add it to the list of matched objects.
+     * 
+     * @param so
+     *      object stored in the in-memory repository
+     */
+    private void match(StoredObject so, boolean searchAllVersions) {
+        // log.debug("checkMatch() for object: " + so.getId());
         // first check if type is matching...
         String queryName = queryObj.getTypes().values().iterator().next(); // as we don't
support JOINS take first type
         TypeDefinition td = queryObj.getTypeDefinitionFromQueryName(queryName);
+        boolean skip = so instanceof VersionedDocument; // we are only interested in versions
not in the series
         boolean typeMatches = typeMatches(td, so);
+        if (!searchAllVersions && so instanceof DocumentVersion && ((DocumentVersion)so).getParentDocument().getLatestVersion(false)
!= so)
+            skip = true;
         // ... then check expression...
-        if (typeMatches)
+        if (typeMatches && !skip)
             evalWhereTree(whereTree, so);        
     }
     

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java?rev=956843&r1=956842&r2=956843&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.java
Tue Jun 22 10:37:40 2010
@@ -23,10 +23,11 @@ import static org.apache.chemistry.openc
 import static org.apache.chemistry.opencmis.inmemory.UnitTestTypeSystemCreator.PROP_ID_DATETIME;
 import static org.apache.chemistry.opencmis.inmemory.UnitTestTypeSystemCreator.PROP_ID_DECIMAL;
 import static org.apache.chemistry.opencmis.inmemory.UnitTestTypeSystemCreator.PROP_ID_INT;
-import static org.junit.Assert.*;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
@@ -52,7 +53,7 @@ public class EvalQueryTest extends Abstr
         super.setTypeCreatorClass(UnitTestTypeSystemCreator.class.getName());
         super.setUp();
         //create test data
-        dataCreator = new QueryTestDataCreator(fRepositoryId, fRootFolderId, fObjSvc );
+        dataCreator = new QueryTestDataCreator(fRepositoryId, fRootFolderId, fObjSvc, fVerSvc);
         dataCreator.createBasicTestData();
     }
 
@@ -730,6 +731,24 @@ public class EvalQueryTest extends Abstr
         }
     }
     
+    @Test 
+    public void testVersionsWithQuery() {
+        String id = dataCreator.createVersionedDocument();
+        assertNotNull(id);
+        String statement = "SELECT * FROM " + UnitTestTypeSystemCreator.VERSION_DOCUMENT_TYPE_ID;
+        ObjectList res = doQueryAllVersions(statement);
+        assertEquals(2, res.getObjects().size());
+        assertTrue(resultContains("ver123", UnitTestTypeSystemCreator.VERSION_PROPERTY_ID,
res));
+        assertTrue(resultContains("ver456", UnitTestTypeSystemCreator.VERSION_PROPERTY_ID,
res));
+        assertTrue(resultContains("V 1.0", PropertyIds.VERSION_LABEL, res));
+        assertTrue(resultContains("V 2.0", PropertyIds.VERSION_LABEL, res));
+        
+        res = doQuery(statement);
+        assertEquals(1, res.getObjects().size());
+        assertFalse(resultContains("V 1.0", PropertyIds.VERSION_LABEL, res));    
+        assertTrue(resultContains("V 2.0", PropertyIds.VERSION_LABEL, res));
+    }
+    
     private ObjectList doQuery(String queryString) {
         log.debug("\nExecuting query: " + queryString);
         ObjectList res = fDiscSvc.query(fRepositoryId, queryString, false, false,
@@ -740,15 +759,29 @@ public class EvalQueryTest extends Abstr
         return res;
     }
 
-    private boolean resultContains(String name, ObjectList results) {
+    private ObjectList doQueryAllVersions(String queryString) {
+        log.debug("\nExecuting query: " + queryString);
+        ObjectList res = fDiscSvc.query(fRepositoryId, queryString, true, false,
+                IncludeRelationships.NONE, null, null, null, null);
+        log.debug("Query result, number of matching objects: " + res.getNumItems());
+        for (ObjectData od : res.getObjects())
+            log.debug("Found matching object: " + od.getProperties().getProperties().get(PropertyIds.NAME).getFirstValue());
+        return res;
+    }
+
+    private boolean resultContains(String name, String propId, ObjectList results) {
         for (ObjectData od : results.getObjects()) {
-            String nameProp = (String) od.getProperties().getProperties().get(PropertyIds.NAME).getFirstValue();
+            String nameProp = (String) od.getProperties().getProperties().get(propId).getFirstValue();
             if (name.equals(nameProp))
                 return true;
         }
         return false;
     }
 
+    private boolean resultContains(String name, ObjectList results) {
+        return resultContains(name, PropertyIds.NAME, results);
+    }
+
     private boolean resultContainsAtPos(String name, int index, ObjectList results) {
         String nameProp = (String) results.getObjects().get(index).getProperties().getProperties().get(PropertyIds.NAME).getFirstValue();
         return name.equals(nameProp);

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java?rev=956843&r1=956842&r2=956843&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java
Tue Jun 22 10:37:40 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.chemistry.opencmis.inmemory.query;
 
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import java.math.BigDecimal;
@@ -33,12 +34,20 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
 import org.apache.chemistry.opencmis.commons.data.Properties;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.BindingsObjectFactoryImpl;
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
+import org.apache.chemistry.opencmis.commons.spi.Holder;
 import org.apache.chemistry.opencmis.commons.spi.ObjectService;
+import org.apache.chemistry.opencmis.commons.spi.VersioningService;
+import org.apache.chemistry.opencmis.inmemory.UnitTestTypeSystemCreator;
+import org.apache.chemistry.opencmis.inmemory.VersioningTest.VersionTestTypeSystemCreator;
+
 import static org.apache.chemistry.opencmis.inmemory.UnitTestTypeSystemCreator.*;
 
 /**
@@ -68,16 +77,18 @@ public class QueryTestDataCreator {
     private String rootFolderId;
     private String repositoryId;
     private ObjectService fObjSvc;
+    private VersioningService fVerSvc;
     private String doc1, doc2, doc3, doc4, doc5;
     private String folder1;
     private String folder2;
     private String folder11;
     private static final TimeZone TZ = TimeZone.getTimeZone("Zulu");
     
-    public QueryTestDataCreator(String repositoryId, String rootFolderId, ObjectService objSvc)
{
+    public QueryTestDataCreator(String repositoryId, String rootFolderId, ObjectService objSvc,
VersioningService verSvc) {
         this.rootFolderId = rootFolderId;
         this.repositoryId = repositoryId;
         fObjSvc = objSvc;
+        fVerSvc = verSvc;
     }
     
     public String getFolder1() {
@@ -269,6 +280,41 @@ public class QueryTestDataCreator {
         createDocument("likedoc3", folderId, COMPLEX_TYPE, propertyMap3);
     }
     
+    @SuppressWarnings("serial")
+    public String createVersionedDocument() {
+        final Map<String, Object> propertyMap1 = 
+            new HashMap<String, Object>() {
+            { 
+                put(VERSION_PROPERTY_ID, "ver123");
+            }};           
+        
+        String verIdV1 = createDocument("verdoc1", rootFolderId, UnitTestTypeSystemCreator.VERSION_DOCUMENT_TYPE_ID,
propertyMap1, VersioningState.MAJOR);
+        ObjectData version = fObjSvc.getObject(repositoryId, verIdV1, "*", false, IncludeRelationships.NONE,
null,
+                false, false, null);
+
+        // get version series id
+        String verIdSer = (String) version.getProperties().getProperties().get(PropertyIds.VERSION_SERIES_ID).getFirstValue();
+
+        // create second version 
+        final Map<String, Object> propertyMap2 = 
+            new HashMap<String, Object>() {
+            { 
+                put(VERSION_PROPERTY_ID, "ver456");
+            }};           
+        Properties propsV2 = createDocumentProperties("dummy", UnitTestTypeSystemCreator.VERSION_DOCUMENT_TYPE_ID,
propertyMap2);
+
+        Holder<String> idHolder = new Holder<String>(verIdV1);
+        Holder<Boolean> contentCopied = new Holder<Boolean>(false);
+        fVerSvc.checkOut(repositoryId, idHolder, null, contentCopied);
+
+        idHolder = new Holder<String>(verIdV1);
+        // Test check-in and pass content and properties
+        String checkinComment = "Here comes next version.";
+        fVerSvc.checkIn(repositoryId, idHolder, true, propsV2, null, checkinComment, null,
null, null, null);
+        // String verIdV2 = idHolder.getValue();
+        return verIdSer;
+    }
+    
     private String createFolder(String folderName, String parentFolderId, String typeId,
Map<String, Object> properties) {
         Properties props = createFolderProperties(folderName, typeId, properties);
         String id = null;
@@ -283,6 +329,10 @@ public class QueryTestDataCreator {
     }
 
     private String createDocument(String name, String folderId, String typeId, Map<String,
Object> properties) {
+        return createDocument(name, folderId, typeId, properties, VersioningState.NONE);
+    }
+
+    private String createDocument(String name, String folderId, String typeId, Map<String,
Object> properties, VersioningState verState) {
         ContentStream contentStream = null;
         List<String> policies = null;
         Acl addACEs = null;
@@ -293,7 +343,7 @@ public class QueryTestDataCreator {
 
         String id = null;
         try {
-            id = fObjSvc.createDocument(repositoryId, props, folderId, contentStream, VersioningState.NONE,
policies,
+            id = fObjSvc.createDocument(repositoryId, props, folderId, contentStream, verState,
policies,
                     addACEs, removeACEs, extension);
             if (null == id)
                 fail("createDocument failed.");



Mime
View raw message