chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1511117 - in /chemistry/opencmis/branches/inmemory-refactoring/src: main/java/org/apache/chemistry/opencmis/inmemory/server/ main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ test/java/org/apache/chemistry/opencmis/inmemory/
Date Tue, 06 Aug 2013 20:30:34 GMT
Author: jens
Date: Tue Aug  6 20:30:33 2013
New Revision: 1511117

URL: http://svn.apache.org/r1511117
Log:
InMemory: support remove object from all folders, fix [CMIS-696]

Modified:
    chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/BaseServiceValidatorImpl.java
    chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryMultiFilingServiceImpl.java
    chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/InMemoryServiceValidatorImpl.java
    chemistry/opencmis/branches/inmemory-refactoring/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java

Modified: chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/BaseServiceValidatorImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/BaseServiceValidatorImpl.java?rev=1511117&r1=1511116&r2=1511117&view=diff
==============================================================================
--- chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/BaseServiceValidatorImpl.java
(original)
+++ chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/BaseServiceValidatorImpl.java
Tue Aug  6 20:30:33 2013
@@ -161,6 +161,7 @@ public class BaseServiceValidatorImpl im
 
     protected StoredObject[] checkParams(String repositoryId, String objectId1, String objectId2)
{
         StoredObject[] so = new StoredObject[2];
+        checkRepositoryId(repositoryId);
         ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
         so[0] = checkExistingObjectId(objectStore, objectId1);
         so[1] = checkExistingObjectId(objectStore, objectId2);
@@ -450,7 +451,18 @@ public class BaseServiceValidatorImpl im
 	public StoredObject[] removeObjectFromFolder(CallContext context, String repositoryId, String
objectId,
             String folderId, ExtensionsData extension) {
 
-        return checkParams(repositoryId, objectId, folderId);
+        if (folderId != null)
+        {
+            return checkParams(repositoryId, objectId, folderId);
+        }
+        else
+        {
+            StoredObject[] so = new StoredObject[1];
+            checkRepositoryId(repositoryId);
+            ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
+            so[0] = checkExistingObjectId(objectStore, objectId);
+            return so;
+        }        
     }
 
     @Override

Modified: chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryMultiFilingServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryMultiFilingServiceImpl.java?rev=1511117&r1=1511116&r2=1511117&view=diff
==============================================================================
--- chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryMultiFilingServiceImpl.java
(original)
+++ chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryMultiFilingServiceImpl.java
Tue Aug  6 20:30:33 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.chemistry.opencmis.inmemory.server;
 
+import java.util.List;
+
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
@@ -25,6 +27,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.ObjectInfoHandler;
+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.ObjectStoreMultiFiling;
@@ -75,23 +78,38 @@ public class InMemoryMultiFilingServiceI
 
         StoredObject[] sos = validator.removeObjectFromFolder(context, repositoryId, objectId,
folderId, extension);
         StoredObject so = sos[0];
-
-        StoredObject folder = sos[1];
-
-        ObjectStoreMultiFiling osmf = checkObjects(repositoryId, so, folder);
-        Folder parent = (Folder) folder;
-        
-        osmf.removeParent(so, parent);
-
-        // To be able to provide all Atom links in the response we need
-        // additional information:
-        if (context.isObjectInfoRequired()) {
-            ObjectInfoImpl objectInfo = new ObjectInfoImpl();
-            fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
-            fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folder, objectInfo);
-            objectInfos.addObjectInfo(objectInfo);
+        if (null != folderId) {
+            StoredObject folder = sos[1];
+            ObjectStoreMultiFiling osmf = checkObjects(repositoryId, so, folder);
+            Folder parent = (Folder) folder;
+
+            osmf.removeParent(so, parent);
+
+            // To be able to provide all Atom links in the response we need
+            // additional information:
+            if (context.isObjectInfoRequired()) {
+                ObjectInfoImpl objectInfo = new ObjectInfoImpl();
+                fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
+                fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folder, objectInfo);
+                objectInfos.addObjectInfo(objectInfo);
+            }
+        } else {
+            ObjectStoreMultiFiling osmf = checkObjects(repositoryId, so, null);
+            List<String> parentIds = osmf.getParentIds((Filing) so,  context.getUsername());
+            for (String parentId: parentIds) {
+                Folder parent = (Folder) ((ObjectStore)osmf).getObjectById(parentId);
+                osmf.removeParent(so, parent);
+            }
+
+            // To be able to provide all Atom links in the response we need
+            // additional information:
+            if (context.isObjectInfoRequired()) {
+                ObjectInfoImpl objectInfo = new ObjectInfoImpl();
+                fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
+                objectInfos.addObjectInfo(objectInfo);
+            }
         }
-
+        
         LOG.debug("End removeObjectFromFolder()");
     }
 
@@ -106,7 +124,7 @@ public class InMemoryMultiFilingServiceI
                     + " is a folder and folders are not multi-filed.");
         }
 
-        if (!(folder instanceof Folder)) {
+        if (folder != null && !(folder instanceof Folder)) {
             throw new CmisConstraintException("Cannot add object to folder, folder id " +
folder.getId()
                     + " does not refer to a folder.");
         }

Modified: chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/InMemoryServiceValidatorImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/InMemoryServiceValidatorImpl.java?rev=1511117&r1=1511116&r2=1511117&view=diff
==============================================================================
--- chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/InMemoryServiceValidatorImpl.java
(original)
+++ chemistry/opencmis/branches/inmemory-refactoring/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/InMemoryServiceValidatorImpl.java
Tue Aug  6 20:30:33 2013
@@ -832,7 +832,8 @@ public class InMemoryServiceValidatorImp
 
         StoredObject[] sos = super.removeObjectFromFolder(context, repositoryId, objectId,
folderId, extension);
         checkWriteAccess(repositoryId, context.getUsername(), sos[0]);
-        checkWriteAccess(repositoryId, context.getUsername(), sos[1]);
+        if (null != folderId)
+            checkWriteAccess(repositoryId, context.getUsername(), sos[1]);
         return sos;
     }
 

Modified: chemistry/opencmis/branches/inmemory-refactoring/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/inmemory-refactoring/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java?rev=1511117&r1=1511116&r2=1511117&view=diff
==============================================================================
--- chemistry/opencmis/branches/inmemory-refactoring/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java
(original)
+++ chemistry/opencmis/branches/inmemory-refactoring/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java
Tue Aug  6 20:30:33 2013
@@ -178,6 +178,16 @@ public class MultiFilingTest extends Abs
         LOG.debug("End testRenameMultiFiledDocument()");
     }
 
+        
+    @Test
+    public void testRemoveDocumentFromAllFolders() {
+        LOG.debug("Begin testRemoveDocumentFromAllFolders()");
+
+        String docId = createUnfiledDocument();
+        removeDocumentFromAllFolders(docId);
+        LOG.debug("End testRemoveDocumentFromAllFolders()");
+    }
+    
     @Test
     public void testAddVersionedDocumentToFolder() {
         LOG.debug("Begin testAddVersionedDocumentToFolder()");
@@ -195,6 +205,15 @@ public class MultiFilingTest extends Abs
         LOG.debug("End testRemoveVersionedDocumentFromFolder()");
     }
 
+    @Test
+    public void testRemoveVersionedDocumentFromAllFolders() {
+        LOG.debug("Begin testRemoveVersionedDocumentFromAllFolders()");
+
+        String docId = createVersionedDocument();
+        removeDocumentFromAllFolders(docId);
+        LOG.debug("End testRemoveVersionedDocumentFromAllFolders()");
+    }
+    
     private void createFolders() {
         fId1 = createFolder("folder1", fRootFolderId, FOLDER_TYPE_ID);
         fId2 = createFolder("folder2", fRootFolderId, FOLDER_TYPE_ID);
@@ -249,6 +268,15 @@ public class MultiFilingTest extends Abs
         assertEquals(0, parents.size());
     }
 
+    private void removeDocumentFromAllFolders(String docId) {
+        prepareMultiFiledDocument(docId);
+
+        fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, null, null);
+        List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId,
"*", false,
+                IncludeRelationships.NONE, null, true, null);
+        assertEquals(0, parents.size());
+    }
+    
     private String createUnfiledDocument() {
         return createDocument(UNFILED_DOC_NAME, null, DOCUMENT_TYPE_ID, true);
     }



Mime
View raw message