chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1521367 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/server/ main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ main/java/org...
Date Tue, 10 Sep 2013 08:26:44 GMT
Author: jens
Date: Tue Sep 10 08:26:43 2013
New Revision: 1521367

URL: http://svn.apache.org/r1521367
Log:
Minor InMemory changes

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
Tue Sep 10 08:26:43 2013
@@ -530,7 +530,7 @@ public class InMemoryObjectServiceImpl e
             throw new CmisNotSupportedException("Destination of a move cannot be a subfolder
of the source");
         }
 
-        objectStore.move(so, sourceFolder, targetFolder);
+        objectStore.move(so, sourceFolder, targetFolder, user);
         objectId.setValue(so.getId());
 
         LOG.debug("stop moveObject()");
@@ -617,7 +617,7 @@ public class InMemoryObjectServiceImpl e
 
         isCheckedOut = isCheckedOut(so, user);
 
-        Map<String, PropertyData<?>> oldProperties = so.getProperties();
+        Map<String, PropertyData<?>> oldProperties = new HashMap<String, PropertyData<?>>();
 
         // check properties for validity
         boolean cmis11 = context.getCmisVersion() != CmisVersion.CMIS_1_0;
@@ -651,7 +651,7 @@ public class InMemoryObjectServiceImpl e
             List<String> propertiesIdToDelete = getListOfPropertiesToDeleteFromRemovedSecondaryTypes(repositoryId,
so,
                     newSecondaryTypeIds);
             for (String propIdToRemove : propertiesIdToDelete) {
-                so.getProperties().remove(propIdToRemove);
+                oldProperties.put(propIdToRemove, null);
             }
         }
 
@@ -684,7 +684,7 @@ public class InMemoryObjectServiceImpl e
                             "updateProperties failed, following property can't be deleted,
because it is required: "
                                     + key);
                 }
-                oldProperties.remove(key);
+                oldProperties.put(key, null);
                 hasUpdatedProp = true;
             } else {
                 if (propDef.getUpdatability() == Updatability.WHENCHECKEDOUT) {
@@ -702,7 +702,7 @@ public class InMemoryObjectServiceImpl e
                 hasUpdatedProp = true;
             }
         }
-
+        
         // get name from properties and perform special rename to check if
         // path already exists
         PropertyData<?> pd = properties.getProperties().get(PropertyIds.NAME);
@@ -720,18 +720,11 @@ public class InMemoryObjectServiceImpl e
             }
             // Note: the test for duplicated name in folder is left to the
             // object store
-            objStore.rename((Fileable) so, (String) pd.getFirstValue());
+            objStore.rename((Fileable) so, (String) pd.getFirstValue(), user);
             hasUpdatedProp = true;
         }
 
-        if (hasUpdatedProp) {
-            // set user, creation date, etc.
-            if (user == null) {
-                user = UNKNOWN_USER;
-            }
-            so.updateSystemBasePropertiesWhenModified(properties.getProperties(), user);
-            // set changeToken
-        }
+        objStore.updateObject(so, oldProperties, user);
 
         if (hasUpdatedProp) {
             objectId.setValue(so.getId()); // might have a new id

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
Tue Sep 10 08:26:43 2013
@@ -290,8 +290,10 @@ public interface ObjectStore {
      *            old parent folder for the object
      * @param newParent
      *            new parent folder for the object
+     * @param user
+     *            user performing the operation
      */
-    void move(StoredObject so, Folder oldParent, Folder newParent);
+    void move(StoredObject so, Folder oldParent, Folder newParent, String user);
 
     /**
      * Rename an object.
@@ -300,8 +302,10 @@ public interface ObjectStore {
      *            object to be renamed
      * @param newName
      *            new name to be assigned
+     * @param user
+     *            user performing the operation
      */
-    void rename(Fileable so, String newName);
+    void rename(StoredObject so, String newName, String user);
 
     /**
      * Persist a new version in the store (created from a check-out).
@@ -320,12 +324,14 @@ public interface ObjectStore {
     void deleteVersion(DocumentVersion version);
 
     /**
-     * Persist an object after modifying the properties.
+     * Modify and store the properties of an object.
      * 
      * @param so
-     *            object to be updated
+     *            object to update
+     * @param properties
+     *            map containing properties to be updated
      */
-    void upateObject(StoredObject so);
+    void updateObject(StoredObject so, Map<String, PropertyData<?>> properties,
String user);
 
     /**
      * get the path of this folder (for folder in CMIS path is unique).

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
Tue Sep 10 08:26:43 2013
@@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.Ace;
 import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
@@ -438,8 +439,24 @@ public class ObjectStoreImpl implements 
     }
 
     @Override
-    public void upateObject(StoredObject so) {
+    public void updateObject(StoredObject so, Map<String, PropertyData<?>> newProperties,
String user) {
         // nothing to do
+        Map<String, PropertyData<?>> properties = so.getProperties();
+        for (String key : newProperties.keySet()) {
+            PropertyData<?> value = newProperties.get(key);
+
+            if (key.equals(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
+                properties.put(key, value); // preserve it even if it is empty!
+            } else  if (null == value || value.getValues() == null || value.getFirstValue()
== null) {
+                // delete property
+                properties.remove(key);
+            } else {
+                properties.put(key, value);
+            }
+        }
+        // update system properties and secondary object type ids
+        so.updateSystemBasePropertiesWhenModified(properties, user);
+        properties.remove(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
     }
 
     @Override
@@ -699,7 +716,7 @@ public class ObjectStoreImpl implements 
     }
 
     @Override
-    public void move(StoredObject so, Folder oldParent, Folder newParent) {
+    public void move(StoredObject so, Folder oldParent, Folder newParent, String user) {
         try {
             if (hasChild(newParent, so.getName())) {
                 throw new CmisInvalidArgumentException("Cannot move object " + so.getName()
+ " to folder "
@@ -719,17 +736,19 @@ public class ObjectStoreImpl implements 
     }
 
     @Override
-    public void rename(Fileable so, String newName) {
+    public void rename(StoredObject so, String newName, String user) {
         try {
             lock();
             if (so.getId().equals(fRootFolder.getId())) {
                 throw new CmisInvalidArgumentException("Root folder cannot be renamed.");
             }
-            for (String folderId : so.getParentIds()) {
-                Folder folder = (Folder) getObjectById(folderId);
-                if (hasChild(folder, newName)) {
-                    throw new CmisNameConstraintViolationException("Cannot rename object
to " + newName
-                            + ". This path already exists in parent " + getFolderPath(folder.getId())
+ ".");
+            if (so instanceof Fileable) {
+                for (String folderId : ((Fileable)so).getParentIds()) {
+                    Folder folder = (Folder) getObjectById(folderId);
+                    if (hasChild(folder, newName)) {
+                        throw new CmisNameConstraintViolationException("Cannot rename object
to " + newName
+                                + ". This path already exists in parent " + getFolderPath(folder.getId())
+ ".");
+                    }
                 }
             }
             so.setName(newName);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoredObjectImpl.java
Tue Sep 10 08:26:43 2013
@@ -343,10 +343,12 @@ public class StoredObjectImpl implements
                 setDescription((String) properties.get(PropertyIds.DESCRIPTION).getFirstValue());
             }
 
-            if (null != properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
+            if (properties.containsKey(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)) {
                 secondaryTypeIds.clear();
-                secondaryTypeIds.addAll((List<String>) properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS)
-                        .getValues());
+            }
+            PropertyData<?> secondaryTypeProp = properties.get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
+            if (null != secondaryTypeProp) {
+                secondaryTypeIds.addAll((List<String>) secondaryTypeProp.getValues());
             }
         }
         if (isCreated) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java
Tue Sep 10 08:26:43 2013
@@ -260,8 +260,8 @@ public final class PropertyCreationHelpe
 
         List<PropertyData<?>> propertiesList = new ArrayList<PropertyData<?>>(properties.values());
 
-        if (fillOptionalPropertyData) { // add query name, local name, display
-                                        // name
+        // add query name, local name, display name
+        if (fillOptionalPropertyData) {
             fillOptionalPropertyData(td, propertiesList);
         }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java
Tue Sep 10 08:26:43 2013
@@ -87,33 +87,33 @@ public class FolderTest extends TestCase
         // rename top level folder
         String newName = "Folder B";
         String oldPath = getPath(f2);
-        fStore.rename(f2, newName);
+        fStore.rename(f2, newName, USER);
         assertEquals(f2.getName(), newName);
         assertEquals(getPath(f2), Filing.PATH_SEPARATOR + newName);
         assertNull(fStore.getObjectByPath(oldPath, USER));
         assertEquals(f2, fStore.getObjectByPath(Filing.PATH_SEPARATOR + newName, USER));
         try {
-            fStore.rename(f2, "Folder 3");
+            fStore.rename(f2, "Folder 3", USER);
             fail("Should not allow to rename a folder to an existing name");
         } catch (Exception e) {
         }
 
         // rename sub folder
         oldPath = getPath(f11);
-        fStore.rename(f11, newName);
+        fStore.rename(f11, newName, USER);
         assertEquals(f11.getName(), newName);
         assertEquals(getPath(f11), "/Folder 1/Folder B");
         assertNull(fStore.getObjectByPath(oldPath, USER));
         assertEquals(f11, fStore.getObjectByPath("/Folder 1/Folder B", USER));
         try {
-            fStore.rename(f2, newName);
+            fStore.rename(f2, newName, USER);
             fail("Should not allow to rename a folder to an existing name");
         } catch (Exception e) {
         }
 
         // rename root folder
         try {
-            fStore.rename(fRoot, "abc");
+            fStore.rename(fRoot, "abc", USER);
             fail("Should not be possible to rename root folder");
         } catch (Exception e) {
         }
@@ -123,15 +123,15 @@ public class FolderTest extends TestCase
     public void testMoveFolder() {
         String oldPath = getPath(f1);
         Folder f1Parent = fRoot;
-        fStore.move(f1, f1Parent, f3);
+        fStore.move(f1, f1Parent, f3, USER);
         assertNull(fStore.getObjectByPath(oldPath, USER));
         assertEquals(getPath(f1), "/Folder 3/Folder 1");
         assertEquals(f1, fStore.getObjectByPath("/Folder 3/Folder 1", USER));
 
-        fStore.rename(f2, "Folder 1");
+        fStore.rename(f2, "Folder 1", USER);
         try {
             Folder f2Parent = fRoot;
-            fStore.move(f2, f2Parent, f3);
+            fStore.move(f2, f2Parent, f3, USER);
             fail("Should not be possible to move folder to a folder that has a child with
same name");
         } catch (Exception e) {
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=1521367&r1=1521366&r2=1521367&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
Tue Sep 10 08:26:43 2013
@@ -808,6 +808,7 @@ public class ObjectServiceTest extends A
                 fObjSvc.updateProperties(fRepositoryId, idHolder, changeTokenHolder, newProps,
null);
                 fail("Update with an invalid name should fail.");
             } catch (Exception e) {
+                log.error("Wrong exception: "+ e);
                 assertTrue(e instanceof CmisInvalidArgumentException);
             }
 



Mime
View raw message