chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r915357 - in /incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src: main/java/org/apache/opencmis/inmemory/ main/java/org/apache/opencmis/inmemory/clientprovider/ main/java/org/apache/opencmis/inmemory/server/ mai...
Date Tue, 23 Feb 2010 14:32:24 GMT
Author: jens
Date: Tue Feb 23 14:32:23 2010
New Revision: 915357

URL: http://svn.apache.org/viewvc?rev=915357&view=rev
Log:
Prepare code for unfiling and multifiling

Added:
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/MultiFilingServiceImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryMultiFilingService.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/MultiFilingTest.java
Modified:
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/CmisInMemoryProvider.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/clientprovider/CmisInMemorySpi.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Path.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/AbstractPathImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/FolderTest.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/CmisInMemoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/CmisInMemoryProvider.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/CmisInMemoryProvider.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/CmisInMemoryProvider.java
Tue Feb 23 14:32:23 2010
@@ -49,6 +49,7 @@
   protected NavigationService fNavigationService;
   protected ObjectService fObjectService;
   protected VersioningService fVersioningService;
+  protected MultiFilingService fMultiService;
   protected RepositoryInfoData fRepositoryInfo;
 
   public CmisInMemoryProvider(Map<String, String> cfgParams) {
@@ -83,7 +84,7 @@
   }
 
   MultiFilingService getMultiFilingService() {
-    return null;
+    return fMultiService;
   }
 
   AclService getAclService() {
@@ -120,6 +121,7 @@
     fNavigationService = new NavigationServiceImpl(fStoreManager);
     fObjectService = new ObjectServiceImpl(fStoreManager);
     fVersioningService = new VersioningServiceImpl(fStoreManager, fObjectService);    
+    fMultiService = new MultiFilingServiceImpl(fStoreManager);
   }
 
   

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/MultiFilingServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/MultiFilingServiceImpl.java?rev=915357&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/MultiFilingServiceImpl.java
(added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/MultiFilingServiceImpl.java
Tue Feb 23 14:32:23 2010
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.inmemory;
+
+import org.apache.opencmis.commons.api.ExtensionsData;
+import org.apache.opencmis.commons.provider.MultiFilingService;
+import org.apache.opencmis.inmemory.storedobj.api.StoreManager;
+
+public class MultiFilingServiceImpl extends AbstractServiceImpl implements MultiFilingService
{
+
+  public MultiFilingServiceImpl(StoreManager storeManager) {
+    super(storeManager);
+  }
+
+  public void addObjectToFolder(String repositoryId, String objectId, String folderId,
+      Boolean allVersions, ExtensionsData extension) {
+    // TODO Auto-generated method stub
+
+  }
+
+  public void removeObjectFromFolder(String repositoryId, String objectId, String folderId,
+      ExtensionsData extension) {
+    // TODO Auto-generated method stub
+
+  }
+
+}

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/NavigationServiceImpl.java
Tue Feb 23 14:32:23 2010
@@ -45,6 +45,7 @@
 import org.apache.opencmis.commons.provider.ObjectList;
 import org.apache.opencmis.commons.provider.ObjectParentData;
 import org.apache.opencmis.commons.provider.PropertiesData;
+import org.apache.opencmis.inmemory.storedobj.api.Children;
 import org.apache.opencmis.inmemory.storedobj.api.DocumentVersion;
 import org.apache.opencmis.inmemory.storedobj.api.Folder;
 import org.apache.opencmis.inmemory.storedobj.api.ObjectStore;
@@ -207,6 +208,7 @@
   /* (non-Javadoc)
    * @see org.opencmis.client.provider.NavigationService#getObjectParents(java.lang.String,
java.lang.String, java.lang.String, java.lang.Boolean, org.opencmis.commons.enums.IncludeRelationships,
java.lang.String, java.lang.Boolean, org.opencmis.client.provider.ExtensionsData)
    */
+  @SuppressWarnings("unchecked")
   public List<ObjectParentData> getObjectParents(String repositoryId, String objectId,
       String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
       String renditionFilter, Boolean includeRelativePathSegment, ExtensionsData extension)
{
@@ -216,7 +218,7 @@
 
     // for now we have only folders that have a parent and the in-memory provider only has
one
     // parent for each object (no multi-filing)
-    ObjectParentDataImpl result = new ObjectParentDataImpl();
+    ObjectParentDataImpl result = null;
     ObjectStore fs = fStoreManager.getObjectStore(repositoryId);
     
     StoredObject so = fs.getObjectById(objectId);
@@ -229,14 +231,18 @@
           + objectId);
     
     if (null != spo) {
-      result.setObject(getFolderParentIntern(repositoryId, spo, filter));
-      String path = spo.getPath();
-      int beginIndex = path.lastIndexOf(Path.PATH_SEPARATOR)+1; // Note: if / not found results
in 0
-      String relPathSeg = path.substring(beginIndex, path.length());
-      result.setRelativePathSegment(relPathSeg);
+      ObjectData parents = getFolderParentIntern(repositoryId, spo, filter);
+      if (null != parents) {
+        result = new ObjectParentDataImpl();
+        result.setObject(parents);
+        String path = spo.getPath();
+        int beginIndex = path.lastIndexOf(Path.PATH_SEPARATOR)+1; // Note: if / not found
results in 0
+        String relPathSeg = path.substring(beginIndex, path.length());
+        result.setRelativePathSegment(relPathSeg);
+      }
     }
     log.debug("stop getObjectParents()");
-    return Collections.singletonList((ObjectParentData)result);
+    return null == result ? (List<ObjectParentData>) Collections.EMPTY_LIST : Collections.singletonList((ObjectParentData)result);
   }
 
   // private helpers
@@ -333,9 +339,13 @@
 
     Folder parentFolder = sop.getParent();
 
-    if (parentFolder == null)
-      throw new CmisInvalidArgumentException("Cannot get parent of a root folder");
-
+    if (null == parentFolder) {
+      if (sop instanceof Children) // a folder without a parent
+        throw new CmisInvalidArgumentException("Cannot get parent of a root folder");
+      else
+        return null; // an unfiled document
+    }
+    
     List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter);
     PropertiesData props = PropertyCreationHelper.getPropertiesFromObject(repositoryId,
         parentFolder, fStoreManager, requestedIds);

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/ObjectServiceImpl.java
Tue Feb 23 14:32:23 2010
@@ -92,7 +92,7 @@
       AccessControlList addACEs, AccessControlList removeACEs, ExtensionsData extension)
{
 
     log.debug("start createDocument()");
-    checkStandardParameters(repositoryId, folderId);
+    checkRepositoryId(repositoryId);
 
     ObjectStore folderStore = fStoreManager.getObjectStore(repositoryId);
 
@@ -101,22 +101,26 @@
     String name = (String) pd.getFirstValue();
 
     // Validation stuff
-    StoredObject so = folderStore.getObjectById(folderId);
-    Folder folder = null;
-
-    if (null == so)
-      throw new CmisInvalidArgumentException(" Cannot create document, folderId: " + folderId
-          + " is invalid");
-
-    if (so instanceof Folder)
-      folder = (Folder) so;
-    else
-      throw new CmisInvalidArgumentException(
-          "Can't creat document, folderId does not refer to a folder: " + folderId);
-
     TypeValidator.validateRequiredSystemProperties(properties);
     TypeDefinition typeDef = getTypeDefinition(repositoryId, properties);
-    TypeValidator.validateAllowedChildObjectTypes(typeDef, folder.getAllowedChildObjectTypeIds());
+
+    Folder folder = null;
+    if (null != folderId) {
+      StoredObject so = folderStore.getObjectById(folderId);
+  
+      if (null == so)
+        throw new CmisInvalidArgumentException(" Cannot create document, folderId: " + folderId
+            + " is invalid");
+  
+      if (so instanceof Folder)
+        folder = (Folder) so;
+      else
+        throw new CmisInvalidArgumentException(
+            "Can't creat document, folderId does not refer to a folder: " + folderId);
+      
+      TypeValidator.validateAllowedChildObjectTypes(typeDef, folder.getAllowedChildObjectTypeIds());
+    }
+    
 
     // check if the given type is a document type
     if (!typeDef.getBaseId().equals(
@@ -139,8 +143,10 @@
       verDoc.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
       verDoc.setCustomProperties(properties.getProperties());
       DocumentVersion version = verDoc.addVersion(contentStream, versioningState, user);
-      // add document to folder
-      folder.addChildDocument(verDoc); // sets parent in doc
+      if (null != folder)
+        folder.addChildDocument(verDoc); // add document to folder and set parent in doc
+      else
+        verDoc.persist();      
       version.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
       version.setCustomProperties(properties.getProperties());
       version.persist();
@@ -151,7 +157,10 @@
       // add document to folder
       doc.createSystemBasePropertiesWhenCreated(properties.getProperties(), user);
       doc.setCustomProperties(properties.getProperties());
-      folder.addChildDocument(doc); // sets parent in doc
+      if (null != folder)
+        folder.addChildDocument(doc); // add document to folder and set parent in doc
+      else
+        doc.persist();
       resId = doc.getId();
     }
         
@@ -585,6 +594,7 @@
     log.debug("start moveObject()");
     checkStandardParameters(repositoryId, objectId.getValue());
     Folder targetFolder = null;
+    Folder sourceFolder = null;
     ObjectStore folderStore = fStoreManager.getObjectStore(repositoryId);
     StoredObject so = folderStore.getObjectById(objectId.getValue());
     Path spo = null;
@@ -598,16 +608,30 @@
           + objectId.getValue());
 
     StoredObject soTarget = folderStore.getObjectById(targetFolderId);
-    if (soTarget instanceof Folder)
+    if (null == soTarget)
+      throw new CmisObjectNotFoundException("Unknown target folder: " + targetFolderId);
+    else if (soTarget instanceof Folder)
       targetFolder = (Folder) soTarget;
     else
-      throw new CmisNotSupportedException("Destination of a move operation must be a folder");
+      throw new CmisNotSupportedException("Destination " + targetFolderId + " of a move operation
must be a folder");
 
+    StoredObject soSource = folderStore.getObjectById(sourceFolderId);
+    if (null == soSource)
+      throw new CmisObjectNotFoundException("Unknown source folder: " + sourceFolderId);
+    else if (soSource instanceof Folder)
+      sourceFolder = (Folder) soSource;
+    else
+      throw new CmisNotSupportedException("Source " + sourceFolderId + " of a move operation
must be a folder");
+
+    if (spo.getParent() != soSource)
+      throw new CmisNotSupportedException("Cannot move object, source folder " + sourceFolderId
+ "is not a parent of object " + objectId.getValue());
+      
     if (so instanceof Folder && hasDescendant((Folder) so, targetFolder)) {
       throw new CmisNotSupportedException(
           "Destination of a move cannot be a subfolder of the source");
     }
-    spo.move(targetFolder);
+    
+    spo.move(sourceFolder, targetFolder);
     objectId.setValue(so.getId());
     log.debug("stop moveObject()");
   }

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/clientprovider/CmisInMemorySpi.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/clientprovider/CmisInMemorySpi.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/clientprovider/CmisInMemorySpi.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/clientprovider/CmisInMemorySpi.java
Tue Feb 23 14:32:23 2010
@@ -107,8 +107,7 @@
    * @see org.apache.opencmis.client.provider.spi.CMISSPI#getMultiFilingService()
    */
   public MultiFilingService getMultiFilingService() {
-    // TODO to be completed if multi-filing implemented
-    return null;
+    return fMultiService;
   }
 
   /*

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryMultiFilingService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryMultiFilingService.java?rev=915357&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryMultiFilingService.java
(added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryMultiFilingService.java
Tue Feb 23 14:32:23 2010
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.inmemory.server;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.opencmis.commons.api.ExtensionsData;
+import org.apache.opencmis.commons.enums.IncludeRelationships;
+import org.apache.opencmis.commons.provider.MultiFilingService;
+import org.apache.opencmis.commons.provider.ObjectData;
+import org.apache.opencmis.commons.provider.ObjectService;
+import org.apache.opencmis.inmemory.MultiFilingServiceImpl;
+import org.apache.opencmis.inmemory.storedobj.api.StoreManager;
+import org.apache.opencmis.server.spi.CallContext;
+import org.apache.opencmis.server.spi.CmisMultiFilingService;
+import org.apache.opencmis.server.spi.ObjectInfoHolder;
+
+public class InMemoryMultiFilingService implements CmisMultiFilingService {
+
+  private static final Log LOG = LogFactory.getLog(InMemoryMultiFilingService.class.getName());
+
+  MultiFilingService fMultiService;
+  ObjectService fObjectService;
+  AtomLinkInfoProvider fAtomLinkProvider;
+
+  public InMemoryMultiFilingService(StoreManager storeMgr, ObjectService objService) {
+    fAtomLinkProvider = new AtomLinkInfoProvider(storeMgr);
+    fMultiService = new MultiFilingServiceImpl(storeMgr);
+    fObjectService = objService;
+  }
+
+  public ObjectData addObjectToFolder(CallContext context, String repositoryId, String objectId,
+      String folderId, Boolean allVersions, ExtensionsData extension, ObjectInfoHolder objectInfos)
{
+
+    LOG.debug("Begin addObjectToFolder()");
+
+    // Attach the CallContext to a thread local context that can be accessed from everywhere
+    RuntimeContext.getRuntimeConfig().attachCfg(context);
+
+    fMultiService.addObjectToFolder(repositoryId, objectId, folderId, allVersions, extension);
+
+    // Make a call to getObject to convert the resulting id into an ObjectData
+    ObjectData res = fObjectService.getObject(repositoryId, objectId, "*", false,
+        IncludeRelationships.NONE, null, false, false, extension);
+
+    // To be able to provide all Atom links in the response we need additional information:
+    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, objectId, objectInfos);
+    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folderId, objectInfos);
+
+    LOG.debug("End addObjectToFolder()");
+    return res;
+  }
+
+  public ObjectData removeObjectFromFolder(CallContext context, String repositoryId,
+      String objectId, String folderId, ExtensionsData extension, ObjectInfoHolder objectInfos)
{
+
+    LOG.debug("Begin removeObjectFromFolder()");
+    // Attach the CallContext to a thread local context that can be accessed from everywhere
+    RuntimeContext.getRuntimeConfig().attachCfg(context);
+
+    fMultiService.removeObjectFromFolder(repositoryId, objectId, folderId, extension);
+
+    // Make a call to getObject to convert the resulting id into an ObjectData
+    ObjectData res = fObjectService.getObject(repositoryId, objectId, "*", false,
+        IncludeRelationships.NONE, null, false, false, extension);
+
+    // To be able to provide all Atom links in the response we need additional information:
+    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, objectId, objectInfos);
+    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, folderId, objectInfos);
+
+    LOG.debug("End removeObjectFromFolder()");
+
+    return res;
+  }
+
+}

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Path.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Path.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Path.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/api/Path.java
Tue Feb 23 14:32:23 2010
@@ -60,6 +60,6 @@
    * @param newParent
    *    new parent folder for the object
    */
-  public void move(Folder newParent);
+  public void move(Folder oldParent, Folder newParent);
   
 }
\ No newline at end of file

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/AbstractPathImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/AbstractPathImpl.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/AbstractPathImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/AbstractPathImpl.java
Tue Feb 23 14:32:23 2010
@@ -99,7 +99,7 @@
 //    fObjStore.changePath(this, oldPath, newPath);    
   }
   
-  public void move(Folder newParent) {
+  public void move(Folder oldParent, Folder newParent) {
     // we delegate this to the folder class because we need access to the global map to move
     if (this instanceof Document || this instanceof VersionedDocument)
       fParent.moveChildDocument(this, newParent);    

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.java
Tue Feb 23 14:32:23 2010
@@ -203,8 +203,8 @@
     return fContainer.getPath();
   }
 
-  public void move(Folder newParent) {
-    fContainer.move(newParent);
+  public void move(Folder oldParent, Folder newParent) {
+    fContainer.move(oldParent, newParent);
   }
 
   public void setParent(Folder parent) {

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
Tue Feb 23 14:32:23 2010
@@ -23,6 +23,7 @@
 import org.apache.opencmis.commons.provider.AccessControlList;
 import org.apache.opencmis.commons.provider.CmisProvider;
 import org.apache.opencmis.commons.provider.ContentStreamData;
+import org.apache.opencmis.commons.provider.MultiFilingService;
 import org.apache.opencmis.commons.provider.NavigationService;
 import org.apache.opencmis.commons.provider.ObjectData;
 import org.apache.opencmis.commons.provider.ObjectParentData;
@@ -47,6 +48,8 @@
   protected NavigationService fNavSvc;
   protected RepositoryService fRepSvc;
   protected VersioningService fVerSvc;
+  protected MultiFilingService fMultiSvc;
+  
   private String fTypeCreatorClassName;
   private boolean fUseClientProviderInterface;
   
@@ -319,6 +322,7 @@
     fObjSvc = inMemSpi.getObjectService();
     fNavSvc = inMemSpi.getNavigationService();    
     fVerSvc = inMemSpi.getVersioningService();
+    fMultiSvc = inMemSpi.getMultiFilingService();
   }
   
   /**
@@ -338,6 +342,14 @@
     fObjSvc = provider.getObjectService();
     fNavSvc = provider.getNavigationService();
     fVerSvc = provider.getVersioningService();
+    fMultiSvc = provider.getMultiFilingService();
+  }
+
+  protected String getStringProperty(ObjectData objData, String propertyKey) {
+    PropertyData<? extends Object> pd = (PropertyData<? extends Object>) objData.getProperties()
+        .getProperties().get(PropertyIds.CMIS_PATH);
+    assertNotNull(pd.getFirstValue());
+    assertTrue(pd.getFirstValue() instanceof String);
+    return (String)pd.getFirstValue();
   }
-  
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/FolderTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/FolderTest.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/FolderTest.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/FolderTest.java
Tue Feb 23 14:32:23 2010
@@ -126,14 +126,16 @@
   
   public void testMoveFolder() {
     String oldPath = f1.getPath();
-    f1.move(f3);
+    Folder f1Parent = f1.getParent();
+    f1.move(f1Parent, f3);
     assertNull(fStore.getObjectByPath(oldPath));
     assertEquals(f1.getPath(), "/Folder 3/Folder 1");
     assertEquals(f1, fStore.getObjectByPath("/Folder 3/Folder 1"));
     
     f2.rename("Folder 1");
     try {
-      f2.move(f3);
+      Folder f2Parent = f2.getParent();
+      f2.move(f2Parent, f3);
       fail("Should not be possible to move folder to a folder that has a child with same
name");
     } catch (Exception e) {            
     }
@@ -149,8 +151,6 @@
       fail("Should not be possible to move folder that has children");
     } catch (Exception e) {            
     }
-    
-    
   }
 
   private void createFolders() {

Added: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/MultiFilingTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/MultiFilingTest.java?rev=915357&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/MultiFilingTest.java
(added)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/MultiFilingTest.java
Tue Feb 23 14:32:23 2010
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.inmemory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.opencmis.commons.PropertyIds;
+import org.apache.opencmis.commons.enums.BaseObjectTypeIds;
+import org.apache.opencmis.commons.enums.IncludeRelationships;
+import org.apache.opencmis.commons.exceptions.CmisNotSupportedException;
+import org.apache.opencmis.commons.provider.ObjectParentData;
+import org.apache.opencmis.inmemory.types.InMemoryFolderTypeDefinition;
+
+public class MultiFilingTest extends AbstractServiceTst {
+
+  private static Log LOG = LogFactory.getLog(MultiFilingTest.class);
+  private static final String DOCUMENT_TYPE_ID = UnitTestTypeSystemCreator.COMPLEX_TYPE;
+  private static final String FOLDER_TYPE_ID =  InMemoryFolderTypeDefinition.getRootFolderType().getId();
+  
+  private String fId1;
+  private String fId2;
+  private String fId11;
+
+  protected void setUp() throws Exception {
+    super.setUp();
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  public void testCreateUnfiledDocument() {
+    LOG.debug("Begin testCreatUnfiledDocument()");
+    String docId = createUnfiledDocument();    
+    String docId2 = getDocument(docId);
+    assertEquals(docId, docId2);
+    
+    // get object parents, must be empty
+    List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*",
false,
+        IncludeRelationships.NONE, null, true, null);
+    
+    assertNotNull(res);
+    assertEquals(res.size(), 0);
+    
+    LOG.debug("End testCreatUnfiledDocument()");    
+  }
+  
+  public void xtestMakeFiledDocumentUnfiled() {
+    LOG.debug("Begin testMakeFiledDocumentUnfiled()");
+    
+    String docId = createDocument("Filed document", fRootFolderId, DOCUMENT_TYPE_ID, true);
+
+    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fRootFolderId,  null);
+    List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId,
"*", false,
+        IncludeRelationships.NONE, null, true, null);
+    assertEquals(0, parents.size());
+
+    LOG.debug("End testMakeFiledDocumentUnfiled()");    
+  }
+
+  public void xtestAddDocumentToFolder() {
+    LOG.debug("Begin testAddDocumentToFolder()");
+    
+    String docId = createUnfiledDocument();
+    List<String> folderIds = prepareMultiFiledDocument(docId);
+    
+    // get object parents, must contain all folders
+    List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*",
false,
+        IncludeRelationships.NONE, null, true, null);
+    assertEquals(3, res.size());
+    for (ObjectParentData opd : res) {
+      assertTrue(folderIds.contains(opd.getObject().getId()));
+      assertEquals(BaseObjectTypeIds.CMIS_FOLDER.value(), opd.getObject().getBaseTypeId());
+      String name = getStringProperty(opd.getObject(), PropertyIds.CMIS_NAME);
+      assertEquals(name, opd.getRelativePathSegment());      
+    }
+    
+    // try version specific filing, should fail
+    try {
+      fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, false, null);
+      fail("Adding not all versions to a folder should fail.");
+    } catch (Exception e) {
+      assertTrue(e instanceof CmisNotSupportedException);
+    }
+    LOG.debug("End testAddDocumentToFolder()");    
+  }
+  
+  public void xtestRemoveDocumentFromFolder() {
+    LOG.debug("Begin testRemoveDocumentFromFolder()");
+
+    String docId = createUnfiledDocument();
+    prepareMultiFiledDocument(docId);
+    
+    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId1,  null);
+    List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId,
"*", false,
+        IncludeRelationships.NONE, null, true, null);
+    assertEquals(2, parents.size());
+    for (ObjectParentData opd : parents) {
+      assertFalse(fId1.equals(opd.getObject().getId()));
+    }
+    
+    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId2,  null);
+    parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+        IncludeRelationships.NONE, null, true, null);
+    assertEquals(1, parents.size());
+    for (ObjectParentData opd : parents) {
+      assertFalse(fId1.equals(opd.getObject().getId()));
+    }
+
+    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId11,  null);
+    parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+        IncludeRelationships.NONE, null, true, null);
+    assertEquals(0, parents.size());
+
+    LOG.debug("End testRemoveDocumentFromFolder()");    
+  }
+  
+  private void createFolders() {
+    fId1 = createFolder("folder1", fRootFolderId, FOLDER_TYPE_ID);
+    fId2 = createFolder("folder2", fRootFolderId, FOLDER_TYPE_ID);
+    fId11 = createFolder("folder1.1", fId1, FOLDER_TYPE_ID);    
+  }
+  
+  private String createUnfiledDocument() {
+    return createDocument("Unfiled document", null, DOCUMENT_TYPE_ID, true);
+  }
+  
+  private List<String> prepareMultiFiledDocument(String docId) {
+    createFolders();
+    
+    // add the document to three folders
+    fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, true, null);
+    fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId2, true, null);
+    fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId11, true, null);
+    
+    List<String> folderIds = new ArrayList<String>();
+    folderIds.add(fId1);
+    folderIds.add(fId2);
+    folderIds.add(fId11);
+    
+    return folderIds;
+  }
+}

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java?rev=915357&r1=915356&r2=915357&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/ObjectServiceTest.java
Tue Feb 23 14:32:23 2010
@@ -694,8 +694,9 @@
     if (!isFolder) // get first document in this folder
       sourceIdToMove = gen.getDocumentId(sourceIdToMove, 0);
     holder.setValue(sourceIdToMove); // "/Folder_1/My Folder 0/My Folder 1");
+    String sourceFolderId = getSourceFolder(sourceIdToMove);
     log.info("Id before moveObject: " + holder.getValue());
-    fObjSvc.moveObject(fRepositoryId, holder, rootFolderId, null, null);
+    fObjSvc.moveObject(fRepositoryId, holder, rootFolderId, sourceFolderId, null);
     log.info("Id after moveObject: " + holder.getValue());
     gen.dumpFolder(fRootFolderId, propertyFilter);
 
@@ -709,8 +710,9 @@
       ObjectInFolderList ch = fNavSvc.getChildren(fRepositoryId, holder.getValue(), propertyFilter,
null,
           false, IncludeRelationships.NONE, null, false, null, null, null);
       String subFolderId = ch.getObjects().get(0).getObject().getId();
+      
       try {
-        fObjSvc.moveObject(fRepositoryId, holder, subFolderId, null, null);
+        fObjSvc.moveObject(fRepositoryId, holder, subFolderId, sourceFolderId, null);
         fail("moveObject to a folder that is a descendant of the source must fail.");
       } catch (Exception e) {
         assertTrue(e instanceof CmisNotSupportedException );
@@ -812,6 +814,12 @@
     return id;
   }
   
+  private String getSourceFolder(String objectId) {
+    // return the first parent found in the result list of all parents
+    List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, objectId,
"*", false,
+        IncludeRelationships.NONE, null, true, null);
+    return parents.get(0).getObject().getId();
+  }
   
   // Helper class to create some type for testing the ObjectService
   



Mime
View raw message