Author: jens
Date: Mon Aug  6 20:12:37 2012
New Revision: 1369967

URL: http://svn.apache.org/viewvc?rev=1369967&view=rev
Log:
InMemory bug fixes: support alias cmis:user; allowable actions: consistent 
canCancelCheckin and canCheckIn; query: return only properties of xyz type in 
select * from xyz  

Modified:
    
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java
    
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
    
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
    
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryAclService.java
    
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/server/InMemoryVersioningServiceImpl.java
    
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.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/DataObjectCreator.java?rev=1369967&r1=1369966&r2=1369967&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java
 Mon Aug  6 20:12:37 2012
@@ -116,10 +116,8 @@ public class DataObjectCreator {
             if (canCheckOut) {
                 set.add(Action.CAN_CHECK_OUT);
             }
-            if (isCheckedOut) {
-                set.add(Action.CAN_CANCEL_CHECK_OUT);
-            }
             if (canCheckIn) {
+                set.add(Action.CAN_CANCEL_CHECK_OUT);
                 set.add(Action.CAN_CHECK_IN);
             }
             set.add(Action.CAN_GET_ALL_VERSIONS);

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.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/TypeValidator.java?rev=1369967&r1=1369966&r2=1369967&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
 Mon Aug  6 20:12:37 2012
@@ -18,14 +18,20 @@
  */
 package org.apache.chemistry.opencmis.inmemory;
 
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.List;
 
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import 
org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
 import 
org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
 import 
org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import 
org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
+import 
org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
+import 
org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
 import org.apache.chemistry.opencmis.server.support.TypeManager;
 
 /**
@@ -36,7 +42,9 @@ import org.apache.chemistry.opencmis.ser
  */
 public class TypeValidator {
     
-    public static void checkType(TypeManager tm, TypeDefinition td) {
+    private static final Object CMIS_USER = "cmis:user";
+
+       public static void checkType(TypeManager tm, TypeDefinition td) {
 
         if (null == tm.getTypeById(td.getParentTypeId())) {
             throw new CmisInvalidArgumentException("Cannot add type, because 
parent with id " + td.getParentTypeId()
@@ -90,6 +98,39 @@ public class TypeValidator {
         }        
     }
     
+    public static Acl expandAclMakros(String user, Acl acl) {
+       boolean mustCopy = false;
+       
+       if (user == null || acl == null || acl.getAces() == null)
+               return acl;
+       
+       for (Ace ace: acl.getAces()) {
+               String principal = ace.getPrincipalId();
+               if (principal != null && principal.equals(CMIS_USER)) {
+                       mustCopy = true;
+               }
+       }
+       
+       if (mustCopy) {
+               AccessControlListImpl result = new AccessControlListImpl();
+               List<Ace> list = new ArrayList<Ace>(acl.getAces().size());
+               for (Ace ace: acl.getAces()) {
+                       String principal = ace.getPrincipalId();
+                       if (principal != null && principal.equals(CMIS_USER)) {
+                               AccessControlEntryImpl ace2 = new 
AccessControlEntryImpl();
+                               ace2.setPermissions(ace.getPermissions());
+                               ace2.setExtensions(ace.getExtensions());
+                               ace2.setPrincipal(new 
AccessControlPrincipalDataImpl(user));
+                               list.add(ace2);
+                       } else
+                               list.add(ace);                  
+               }               
+               result.setAces(list);
+               return result;
+       } else
+               return acl;
+    }
+    
     private static void checkTypeId(TypeManager tm, String typeId) {
 
         if (null == typeId) {

Modified: 
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/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java?rev=1369967&r1=1369966&r2=1369967&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
 Mon Aug  6 20:12:37 2012
@@ -144,10 +144,12 @@ public class InMemoryQueryProcessor {
         List<ObjectData> objDataList = new ArrayList<ObjectData>();
         Map<String, String> props = queryObj.getRequestedPropertiesByAlias();
         Map<String, String> funcs = queryObj.getRequestedFuncsByAlias();
+        TypeDefinition fromType = queryObj.getMainFromName();
+        
         for (StoredObject so : matches) {
             TypeDefinition td = 
tm.getTypeById(so.getTypeId()).getTypeDefinition();
             ObjectData od = 
PropertyCreationHelper.getObjectDataQueryResult(td, so, user, props, funcs,
-                    includeAllowableActions, includeRelationships, 
renditionFilter);
+                    fromType, includeAllowableActions, includeRelationships, 
renditionFilter);
 
             objDataList.add(od);
         }

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryAclService.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/InMemoryAclService.java?rev=1369967&r1=1369966&r2=1369967&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryAclService.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryAclService.java
 Mon Aug  6 20:12:37 2012
@@ -24,6 +24,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.TypeValidator;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
@@ -62,7 +63,10 @@ public class InMemoryAclService extends 
     public Acl applyAcl(CallContext context, String repositoryId, String 
objectId, Acl addAces, Acl removeAces, AclPropagation aclPropagation,
             ExtensionsData extension, ObjectInfoHandler objectInfos) {
 
-        StoredObject so = validator.applyAcl(context, repositoryId, objectId, 
aclPropagation, extension);
+       addAces  = TypeValidator.expandAclMakros(context.getUsername(), 
addAces);
+       removeAces  = TypeValidator.expandAclMakros(context.getUsername(), 
removeAces);
+        
+       StoredObject so = validator.applyAcl(context, repositoryId, objectId, 
aclPropagation, extension);
         Acl acl = fStoreManager.getObjectStore(repositoryId).applyAcl(so, 
addAces, removeAces, aclPropagation, context.getUsername());
         
         if (context.isObjectInfoRequired()) {
@@ -75,7 +79,9 @@ public class InMemoryAclService extends 
     
     public Acl applyAcl(CallContext context, String repositoryId, String 
objectId, Acl aces, AclPropagation aclPropagation) {
         
-        StoredObject so = validator.applyAcl(context, repositoryId, objectId);
+       aces  = TypeValidator.expandAclMakros(context.getUsername(), aces);
+
+       StoredObject so = validator.applyAcl(context, repositoryId, objectId);
         return fStoreManager.getObjectStore(repositoryId).applyAcl(so, aces, 
aclPropagation, context.getUsername());        
     }
 

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=1369967&r1=1369966&r2=1369967&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
 Mon Aug  6 20:12:37 2012
@@ -699,7 +699,10 @@ public class InMemoryObjectServiceImpl e
             ContentStream contentStream, VersioningState versioningState, 
List<String> policies, Acl addACEs,
             Acl removeACEs, ExtensionsData extension) {
 
-        validator.createDocument(context, repositoryId, folderId, extension);
+       addACEs  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 addACEs);
+       removeACEs  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 removeACEs);
+
+       validator.createDocument(context, repositoryId, folderId, extension);
 
         // Validation stuff
         TypeValidator.validateRequiredSystemProperties(properties);
@@ -802,7 +805,10 @@ public class InMemoryObjectServiceImpl e
     private Folder createFolderIntern(CallContext context, String 
repositoryId, Properties properties, String folderId,
             List<String> policies, Acl addACEs, Acl removeACEs, ExtensionsData 
extension) {
 
-        validator.createFolder(context, repositoryId, folderId, extension);
+       addACEs  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 addACEs);
+       removeACEs  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 removeACEs);
+
+       validator.createFolder(context, repositoryId, folderId, extension);
         TypeValidator.validateRequiredSystemProperties(properties);
         String user = context.getUsername();
 
@@ -871,6 +877,8 @@ public class InMemoryObjectServiceImpl e
     private StoredObject createPolicyIntern(CallContext context, String 
repositoryId, Properties properties, String folderId,
             List<String> policies, Acl addAces, Acl removeAces, ExtensionsData 
extension) {
 
+       addAces  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 addAces);
+       removeAces  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 removeAces);
         validator.createPolicy(context, repositoryId, folderId, extension);
         throw new CmisNotSupportedException("createPolicy is not supported.");
     }
@@ -883,7 +891,10 @@ public class InMemoryObjectServiceImpl e
 
         String user = context.getUsername();
         
-        // get required properties
+       addACEs  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 addACEs);
+       removeACEs  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 removeACEs);
+
+       // get required properties
         PropertyData<?> pd = 
properties.getProperties().get(PropertyIds.SOURCE_ID);
         String sourceId = (String) pd.getFirstValue();
         if (null == sourceId || sourceId.length() == 0)

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryVersioningServiceImpl.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/InMemoryVersioningServiceImpl.java?rev=1369967&r1=1369966&r2=1369967&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java
 Mon Aug  6 20:12:37 2012
@@ -79,7 +79,10 @@ public class InMemoryVersioningServiceIm
             Properties properties, ContentStream contentStream, String 
checkinComment, List<String> policies,
             Acl addAces, Acl removeAces, ExtensionsData extension, 
ObjectInfoHandler objectInfos) {
 
-        StoredObject so = validator.checkIn(context, repositoryId, objectId, 
addAces, removeAces, extension);
+       addAces  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 addAces);
+       removeAces  = 
org.apache.chemistry.opencmis.inmemory.TypeValidator.expandAclMakros(context.getUsername(),
 removeAces);
+
+       StoredObject so = validator.checkIn(context, repositoryId, objectId, 
addAces, removeAces, extension);
 
         String user = context.getUsername();
         VersionedDocument verDoc = testHasProperCheckedOutStatus(so, user);

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=1369967&r1=1369966&r2=1369967&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
 Mon Aug  6 20:12:37 2012
@@ -243,8 +243,9 @@ public class PropertyCreationHelper {
         return props;
     }
 
-    public static Properties getPropertiesFromObject(StoredObject so, 
TypeDefinition td,
-            Map<String, String> requestedIds, Map<String, String> 
requestedFuncs) {
+       public static Properties getPropertiesFromObject(StoredObject so,
+                       TypeDefinition td, TypeDefinition fromType,
+                       Map<String, String> requestedIds, Map<String, String> 
requestedFuncs) {
         // build properties collection
 
         List<String> idList = new ArrayList<String>(requestedIds.values());
@@ -267,30 +268,34 @@ public class PropertyCreationHelper {
         Map<String, PropertyData<?>> mappedProperties = new HashMap<String, 
PropertyData<?>>();
         if (requestedIds.containsValue("*")) {
             for (Map.Entry<String, PropertyData<?>> prop : 
properties.entrySet()) {
-                // map property id to property query name
-                String queryName = 
td.getPropertyDefinitions().get(prop.getKey()).getQueryName();
-                String localName = 
td.getPropertyDefinitions().get(prop.getKey()).getLocalName();
-                String displayName = 
td.getPropertyDefinitions().get(prop.getKey()).getDisplayName();
-                AbstractPropertyData<?> ad = 
clonePropertyData(prop.getValue()); 
-                
-                ad.setQueryName(queryName);
-                ad.setLocalName(localName);
-                ad.setDisplayName(displayName);
-                mappedProperties.put(queryName, ad);
+               if 
(fromType.getPropertyDefinitions().containsKey(prop.getKey())) {
+                       // map property id to property query name
+                       String queryName = 
td.getPropertyDefinitions().get(prop.getKey()).getQueryName();
+                       String localName = 
td.getPropertyDefinitions().get(prop.getKey()).getLocalName();
+                       String displayName = 
td.getPropertyDefinitions().get(prop.getKey()).getDisplayName();
+                       AbstractPropertyData<?> ad = 
clonePropertyData(prop.getValue()); 
+
+                       ad.setQueryName(queryName);
+                       ad.setLocalName(localName);
+                       ad.setDisplayName(displayName);
+                       mappedProperties.put(queryName, ad);
+               }
             }
         } else {
             // replace all ids with query names or alias:
             for (Entry<String, String> propAlias : requestedIds.entrySet()) {
-                String queryNameOrAlias = propAlias.getKey();
-                PropertyData<?> prop = properties.get(propAlias.getValue());
-                String localName = 
td.getPropertyDefinitions().get(prop.getId()).getLocalName();
-                String displayName = 
td.getPropertyDefinitions().get(prop.getId()).getDisplayName();
-                AbstractPropertyData<?> ad = clonePropertyData(prop); 
-                
-                ad.setQueryName(queryNameOrAlias);
-                ad.setLocalName(localName);
-                ad.setDisplayName(displayName);
-                mappedProperties.put(queryNameOrAlias, ad);
+               String queryNameOrAlias = propAlias.getKey();
+               PropertyData<?> prop = properties.get(propAlias.getValue());
+               if 
(fromType.getPropertyDefinitions().containsKey(prop.getId())) {
+                       String localName = 
td.getPropertyDefinitions().get(prop.getId()).getLocalName();
+                       String displayName = 
td.getPropertyDefinitions().get(prop.getId()).getDisplayName();
+                       AbstractPropertyData<?> ad = clonePropertyData(prop); 
+
+                       ad.setQueryName(queryNameOrAlias);
+                       ad.setLocalName(localName);
+                       ad.setDisplayName(displayName);
+                       mappedProperties.put(queryNameOrAlias, ad);
+               }
             }
         }
         // add functions:
@@ -350,13 +355,13 @@ public class PropertyCreationHelper {
     }
 
     public static ObjectData getObjectDataQueryResult(TypeDefinition typeDef, 
StoredObject so, String user,
-            Map<String, String> requestedProperties, Map<String, String> 
requestedFuncs,
+            Map<String, String> requestedProperties, Map<String, String> 
requestedFuncs, TypeDefinition fromType,
             Boolean includeAllowableActions, IncludeRelationships 
includeRelationships, String renditionFilter) {
 
         ObjectDataImpl od = new ObjectDataImpl();
 
         // build properties collection
-        Properties props = getPropertiesFromObject(so, typeDef, 
requestedProperties, requestedFuncs);
+        Properties props = getPropertiesFromObject(so, typeDef, fromType, 
requestedProperties, requestedFuncs);
 
         // fill output object
         if (null != includeAllowableActions && includeAllowableActions) {


Reply via email to