Author: nfilotto
Date: 2011-04-11 13:42:26 -0400 (Mon, 11 Apr 2011)
New Revision: 4227
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/hierarchy/
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/hierarchy/TestNodeHierarchyCreator.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/NodeHierarchyCreator.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/HierarchyConfig.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewGroupListener.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewUserListener.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java
Log:
EXOJCR-1136: Improve the NodeHierarchyCreator to better scale in term of users
New NodeHierarchyCreator based on the data distribution service
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/NodeHierarchyCreator.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/NodeHierarchyCreator.java 2011-04-11
17:40:26 UTC (rev 4226)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/NodeHierarchyCreator.java 2011-04-11
17:42:26 UTC (rev 4227)
@@ -24,21 +24,73 @@
import javax.jcr.Node;
/**
+ * This service is used as an helper to initialize the JCR
+ *
* Created by The eXo Platform SAS Author : Dang Van Minh minh.dang(a)exoplatform.com Nov
15, 2007
* 10:10:10 AM
*/
public interface NodeHierarchyCreator
{
- public String getJcrPath(String alias);
+ /**
+ * Gets the JCR path corresponding to the given alias
+ * @param alias the alias of the path to retrieve
+ * @return the corresponding JCR path
+ */
+ String getJcrPath(String alias);
- public void init(String repository) throws Exception;
+ /**
+ * Initialize the given repository thanks to all the registered plugins
+ * @param repository the repository to initialize
+ * @throws Exception if an exception occurs
+ * @deprecated use init() instead
+ */
+ void init(String repository) throws Exception;
- public Node getUserNode(SessionProvider sessionProvider, String userName) throws
Exception;
+ /**
+ * Initialize the current repository thanks to all the registered plugins
+ * @param repository the repository to initialize
+ * @throws Exception if an exception occurs
+ */
+ void init() throws Exception;
- public Node getUserApplicationNode(SessionProvider sessionProvider, String userName)
throws Exception;
+ /**
+ * Remove the JCR node corresponding to the root node of the user workspace
+ * @param sessionProvider the session provider to use to remove the root node
+ * @param userName the user name for which we want to remove the root node of his
workspace
+ * @throws Exception if an exception occurs
+ */
+ void removeUserNode(SessionProvider sessionProvider, String userName) throws
Exception;
- public Node getPublicApplicationNode(SessionProvider sessionProvider) throws
Exception;
+ /**
+ * Gets the JCR node corresponding to the root node of the user workspace
+ * @param sessionProvider the session provider to use to get the root node
+ * @param userName the user name for which we want to find the root node of his
workspace
+ * @return the root node of the workspace of the given user
+ * @throws Exception if an exception occurs
+ */
+ Node getUserNode(SessionProvider sessionProvider, String userName) throws Exception;
- public void addPlugin(ComponentPlugin plugin);
+ /**
+ * Gets the JCR node corresponding to the root node of the user's applications
+ * @param sessionProvider the session provider to use to get the root node
+ * @param userName the user name for which we want to find the root node of his
applications
+ * @return the root node of the user's applications of the given user
+ * @throws Exception if an exception occurs
+ */
+ Node getUserApplicationNode(SessionProvider sessionProvider, String userName) throws
Exception;
+
+ /**
+ * Gets the JCR node corresponding to the root node of the public applications
+ * @param sessionProvider the session provider to use to get the root node
+ * @return the root node of the public applications
+ * @throws Exception if an exception occurs
+ */
+ Node getPublicApplicationNode(SessionProvider sessionProvider) throws Exception;
+
+ /**
+ * Registers a new plugins
+ * @param plugin the plugin to register
+ */
+ void addPlugin(ComponentPlugin plugin);
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/HierarchyConfig.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/HierarchyConfig.java 2011-04-11
17:40:26 UTC (rev 4226)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/HierarchyConfig.java 2011-04-11
17:42:26 UTC (rev 4227)
@@ -18,8 +18,12 @@
*/
package org.exoplatform.services.jcr.ext.hierarchy.impl;
+import org.exoplatform.services.jcr.access.PermissionType;
+
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Created by The eXo Platform SAS Author : Dang Van Minh minh.dang(a)exoplatform.com Nov
15, 2007
@@ -101,6 +105,30 @@
return this.permissions;
}
+ public Map<String, String[]> getPermissions(String identityToAdd)
+ {
+ Map<String, String[]> permissionsMap = new HashMap<String,
String[]>();
+ if (identityToAdd != null && !identityToAdd.isEmpty())
+ {
+ permissionsMap.put(identityToAdd, PermissionType.ALL);
+ }
+ for (Permission permission : permissions)
+ {
+ List<String> lPermissions = new ArrayList<String>(4);
+ if ("true".equalsIgnoreCase(permission.getRead()))
+ lPermissions.add(PermissionType.READ);
+ if ("true".equalsIgnoreCase(permission.getAddNode()))
+ lPermissions.add(PermissionType.ADD_NODE);
+ if ("true".equalsIgnoreCase(permission.getSetProperty()))
+ lPermissions.add(PermissionType.SET_PROPERTY);
+ if ("true".equalsIgnoreCase(permission.getRemove()))
+ lPermissions.add(PermissionType.REMOVE);
+ permissionsMap.put(permission.getIdentity(),
+ (String[])lPermissions.toArray(new String[lPermissions.size()]));
+ }
+ return permissionsMap;
+ }
+
public void setPermissions(List<Permission> list)
{
this.permissions = list;
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewGroupListener.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewGroupListener.java 2011-04-11
17:40:26 UTC (rev 4226)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewGroupListener.java 2011-04-11
17:42:26 UTC (rev 4227)
@@ -20,22 +20,21 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.jcr.RepositoryService;
-import org.exoplatform.services.jcr.access.PermissionType;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionManager;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionMode;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionType;
import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
import org.exoplatform.services.jcr.ext.hierarchy.impl.HierarchyConfig.JcrPath;
-import org.exoplatform.services.jcr.ext.hierarchy.impl.HierarchyConfig.Permission;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.GroupEventListener;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
import javax.jcr.Session;
/**
@@ -44,22 +43,24 @@
*/
public class NewGroupListener extends GroupEventListener
{
+ private static final Log log =
ExoLogger.getLogger("exo.jcr.component.ext.NewGroupListener");
- private HierarchyConfig config_;
+ private static final String GROUPS_PATH = "groupsPath";
- private RepositoryService jcrService_;
+ private final HierarchyConfig config_;
- private String groupsPath_;
+ private final RepositoryService jcrService_;
+
+ private final DataDistributionType dataDistributionType_;
+
+ private final String groupsPath_;
- final static private String NT_UNSTRUCTURED = "nt:unstructured".intern();
-
- final static private String GROUPS_PATH = "groupsPath";
-
public NewGroupListener(RepositoryService jcrService, NodeHierarchyCreator
nodeHierarchyCreatorService,
- InitParams params) throws Exception
+ DataDistributionManager dataDistributionManager, InitParams params) throws
Exception
{
jcrService_ = jcrService;
config_ =
(HierarchyConfig)params.getObjectParamValues(HierarchyConfig.class).get(0);
+ dataDistributionType_ =
dataDistributionManager.getDataDistributionType(DataDistributionMode.NONE);
groupsPath_ = nodeHierarchyCreatorService.getJcrPath(GROUPS_PATH);
}
@@ -81,13 +82,9 @@
else
groupId = parentId + "/" + group.getGroupName();
}
- List<RepositoryEntry> repositories =
jcrService_.getConfig().getRepositoryConfigurations();
if (isNew)
{
- for (RepositoryEntry repo : repositories)
- {
- buildGroupStructure(repo.getName(), groupId);
- }
+ buildGroupStructure(jcrService_.getCurrentRepository(), groupId);
}
}
@@ -109,103 +106,66 @@
else
groupId = parentId + "/" + group.getGroupName();
}
- List<RepositoryEntry> repositories =
jcrService_.getConfig().getRepositoryConfigurations();
- for (RepositoryEntry repo : repositories)
- {
- try
- {
- removeGroup(repo.getName(), groupId);
- }
- catch (Exception e)
- {
- continue;
- }
- }
+ removeGroup(jcrService_.getCurrentRepository(), groupId);
}
- private void removeGroup(String repoName, String groupId) throws Exception
+ private void removeGroup(ManageableRepository manageableRepository, String groupId)
throws Exception
{
- ManageableRepository manageableRepository = jcrService_.getRepository(repoName);
- String systemWorkspace =
manageableRepository.getConfiguration().getDefaultWorkspaceName();
- Session session = manageableRepository.getSystemSession(systemWorkspace);
- Node groupNode = (Node)session.getItem(groupsPath_ + groupId);
- groupNode.remove();
- session.save();
- session.logout();
- }
-
- @SuppressWarnings("unchecked")
- private void buildGroupStructure(String repository, String groupId) throws Exception
- {
- ManageableRepository manageableRepository = jcrService_.getRepository(repository);
- String systemWorkspace =
manageableRepository.getConfiguration().getDefaultWorkspaceName();
- Session session = manageableRepository.getSystemSession(systemWorkspace);
- Node groupsHome = (Node)session.getItem(groupsPath_);
- List jcrPaths = config_.getJcrPaths();
- Node groupNode = null;
+ Session session = null;
try
{
- groupNode = groupsHome.getNode(groupId.substring(1, groupId.length()));
+ String systemWorkspace =
manageableRepository.getConfiguration().getDefaultWorkspaceName();
+ session = manageableRepository.getSystemSession(systemWorkspace);
+ Node groupsHome = (Node)session.getItem(groupsPath_);
+ dataDistributionType_.removeDataNode(groupsHome, groupId);
}
- catch (PathNotFoundException e)
+ catch (Exception e)
{
- groupNode = groupsHome.addNode(groupId.substring(1, groupId.length()));
+ log.error("An error occurs while removing the group directory of
'" + groupId + "'", e);
}
- for (JcrPath jcrPath : (List<JcrPath>)jcrPaths)
+ finally
{
- createNode(groupNode, jcrPath.getPath(), jcrPath.getNodeType(),
jcrPath.getMixinTypes(), getPermissions(
- jcrPath.getPermissions(), groupId));
+ if (session != null)
+ {
+ session.logout();
+ }
}
- session.save();
- session.logout();
}
@SuppressWarnings("unchecked")
- private void createNode(Node groupNode, String path, String nodeType,
List<String> mixinTypes, Map permissions)
- throws Exception
+ private void buildGroupStructure(ManageableRepository manageableRepository, String
groupId) throws Exception
{
- if (nodeType == null || nodeType.length() == 0)
- nodeType = NT_UNSTRUCTURED;
+ Session session = null;
try
{
- groupNode = groupNode.getNode(path);
+ String systemWorkspace =
manageableRepository.getConfiguration().getDefaultWorkspaceName();
+ session = manageableRepository.getSystemSession(systemWorkspace);
+ Node groupsHome = (Node)session.getItem(groupsPath_);
+ Node groupNode = dataDistributionType_.getOrCreateDataNode(groupsHome,
groupId);
+ @SuppressWarnings("rawtypes")
+ List jcrPaths = config_.getJcrPaths();
+ for (JcrPath jcrPath : (List<JcrPath>)jcrPaths)
+ {
+ createNode(groupNode, jcrPath.getPath(), jcrPath.getNodeType(),
jcrPath.getMixinTypes(),
+ jcrPath.getPermissions("*:".concat(groupId)));
+ }
}
- catch (PathNotFoundException e)
+ catch (Exception e)
{
- groupNode = groupNode.addNode(path, nodeType);
+ log.error("An error occurs while initializing the group directory of
'" + groupId + "'", e);
}
- if (groupNode.canAddMixin("exo:privilegeable"))
- groupNode.addMixin("exo:privilegeable");
- if (permissions != null && !permissions.isEmpty())
- ((ExtendedNode)groupNode).setPermissions(permissions);
- if (mixinTypes.size() > 0)
+ finally
{
- for (String mixin : mixinTypes)
+ if (session != null)
{
- if (groupNode.canAddMixin(mixin))
- groupNode.addMixin(mixin);
+ session.logout();
}
}
}
- private Map getPermissions(List<Permission> permissions, String groupId)
+ private void createNode(Node groupNode, String path, String nodeType,
List<String> mixinTypes, Map<String, String[]> permissions)
+ throws Exception
{
- Map<String, String[]> permissionsMap = new HashMap<String,
String[]>();
- String groupIdentity = "*:".concat(groupId);
- permissionsMap.put(groupIdentity, PermissionType.ALL);
- for (Permission permission : permissions)
- {
- StringBuilder strPer = new StringBuilder();
- if ("true".equals(permission.getRead()))
- strPer.append(PermissionType.READ);
- if ("true".equals(permission.getAddNode()))
- strPer.append(",").append(PermissionType.ADD_NODE);
- if ("true".equals(permission.getSetProperty()))
- strPer.append(",").append(PermissionType.SET_PROPERTY);
- if ("true".equals(permission.getRemove()))
- strPer.append(",").append(PermissionType.REMOVE);
- permissionsMap.put(permission.getIdentity(),
strPer.toString().split(","));
- }
- return permissionsMap;
+ dataDistributionType_.getOrCreateDataNode(groupNode, path, nodeType, mixinTypes,
permissions);
}
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewUserListener.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewUserListener.java 2011-04-11
17:40:26 UTC (rev 4226)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NewUserListener.java 2011-04-11
17:42:26 UTC (rev 4227)
@@ -20,23 +20,22 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.jcr.RepositoryService;
-import org.exoplatform.services.jcr.access.PermissionType;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionManager;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionMode;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionType;
import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
import org.exoplatform.services.jcr.ext.hierarchy.impl.HierarchyConfig.JcrPath;
-import org.exoplatform.services.jcr.ext.hierarchy.impl.HierarchyConfig.Permission;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.exoplatform.services.organization.User;
import org.exoplatform.services.organization.UserEventListener;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Session;
/**
* Created by The eXo Platform SAS Author : Dang Van Minh minh.dang(a)exoplatform.com Nov
15, 2007
@@ -44,137 +43,81 @@
*/
public class NewUserListener extends UserEventListener
{
+ private static final Log log =
ExoLogger.getLogger("exo.jcr.component.ext.NewUserListener");
- private HierarchyConfig config_;
+ private final HierarchyConfig config_;
- private RepositoryService jcrService_;
+ private final RepositoryService jcrService_;
- private NodeHierarchyCreator nodeHierarchyCreatorService_;
+ private final NodeHierarchyCreator nodeHierarchyCreatorService_;
+
+ private final DataDistributionType dataDistributionType_;
- private String userPath_;
-
- final static private String USERS_PATH = "usersPath";
-
- final static private String NT_UNSTRUCTURED = "nt:unstructured".intern();
-
public NewUserListener(RepositoryService jcrService, NodeHierarchyCreator
nodeHierarchyCreatorService,
- InitParams params) throws Exception
+ DataDistributionManager dataDistributionManager, InitParams params) throws
Exception
{
jcrService_ = jcrService;
- nodeHierarchyCreatorService_ = nodeHierarchyCreatorService;
+ dataDistributionType_ =
dataDistributionManager.getDataDistributionType(DataDistributionMode.NONE);
config_ =
(HierarchyConfig)params.getObjectParamValues(HierarchyConfig.class).get(0);
- nodeHierarchyCreatorService_.addPlugin(new AddPathPlugin(params));
- userPath_ = nodeHierarchyCreatorService.getJcrPath(USERS_PATH);
+ nodeHierarchyCreatorService.addPlugin(new AddPathPlugin(params));
+ nodeHierarchyCreatorService_ = nodeHierarchyCreatorService;
}
public void preSave(User user, boolean isNew) throws Exception
{
- String userName = user.getUserName();
- List<RepositoryEntry> repositories =
jcrService_.getConfig().getRepositoryConfigurations();
- // TODO [PN, 12.02.08] only default repository should contains user structure
if (isNew)
{
- for (RepositoryEntry repo : repositories)
- {
- processUserStructure(repo.getName(), userName);
- }
+ processUserStructure(jcrService_.getCurrentRepository(), user.getUserName());
}
}
- @SuppressWarnings("unchecked")
- private void processUserStructure(String repository, String userName) throws
Exception
+ private void processUserStructure(ManageableRepository manageableRepository, String
userName) throws Exception
{
- ManageableRepository manageableRepository = jcrService_.getRepository(repository);
- String systemWorkspace =
manageableRepository.getConfiguration().getDefaultWorkspaceName();
- Session session = manageableRepository.getSystemSession(systemWorkspace);
- Node usersHome = (Node)session.getItem(userPath_);
- List<JcrPath> jcrPaths = config_.getJcrPaths();
- Node userNode = null;
- try
+ SessionProvider sessionProvider = SessionProvider.createSystemProvider();
+ try
{
- userNode = usersHome.getNode(userName);
+ Node userNode = nodeHierarchyCreatorService_.getUserNode(sessionProvider,
userName);
+ List<JcrPath> jcrPaths = config_.getJcrPaths();
+ for (JcrPath jcrPath : jcrPaths)
+ {
+ createNode(userNode, jcrPath.getPath(), jcrPath.getNodeType(),
jcrPath.getMixinTypes(),
+ jcrPath.getPermissions(userName));
+ }
}
- catch (PathNotFoundException e)
+ catch (Exception e)
{
- userNode = usersHome.addNode(userName);
+ log.error("An error occurs while initializing the user directory of
'" + userName + "'", e);
}
- for (JcrPath jcrPath : jcrPaths)
+ finally
{
- createNode(userNode, jcrPath.getPath(), jcrPath.getNodeType(),
jcrPath.getMixinTypes(), getPermissions(jcrPath
- .getPermissions(), userName));
+ sessionProvider.close();
+ sessionProvider = null;
}
- session.save();
- session.logout();
}
public void preDelete(User user)
{
// use a anonymous connection for the configuration as the user is not
// authentified at that time
- List<RepositoryEntry> repositories =
jcrService_.getConfig().getRepositoryConfigurations();
- for (RepositoryEntry repo : repositories)
- {
- try
- {
- ManageableRepository manaRepo = jcrService_.getRepository(repo.getName());
- Session session =
manaRepo.getSystemSession(manaRepo.getConfiguration().getDefaultWorkspaceName());
- Node usersHome =
(Node)session.getItem(nodeHierarchyCreatorService_.getJcrPath(USERS_PATH));
- usersHome.getNode(user.getUserName()).remove();
- session.save();
- session.logout();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private void createNode(Node userNode, String path, String nodeType,
List<String> mixinTypes, Map permissions)
- throws Exception
- {
- if (nodeType == null || nodeType.length() == 0)
- nodeType = NT_UNSTRUCTURED;
+ SessionProvider sessionProvider = SessionProvider.createSystemProvider();
try
{
- userNode = userNode.getNode(path);
+ nodeHierarchyCreatorService_.removeUserNode(sessionProvider,
user.getUserName());
}
- catch (PathNotFoundException e)
+ catch (Exception e)
{
- userNode = userNode.addNode(path, nodeType);
+ log.error("An error occurs while removing the user directory of '"
+ user.getUserName() + "'", e);
}
- if (userNode.canAddMixin("exo:privilegeable"))
- userNode.addMixin("exo:privilegeable");
- if (permissions != null && !permissions.isEmpty())
- ((ExtendedNode)userNode).setPermissions(permissions);
- if (mixinTypes.size() > 0)
+ finally
{
- for (String mixin : mixinTypes)
- {
- if (userNode.canAddMixin(mixin))
- userNode.addMixin(mixin);
- }
+ sessionProvider.close();
+ sessionProvider = null;
}
}
- private Map getPermissions(List<Permission> permissions, String userId)
+ private void createNode(Node userNode, String path, String nodeType,
List<String> mixinTypes, Map<String, String[]> permissions)
+ throws Exception
{
- Map<String, String[]> permissionsMap = new HashMap<String,
String[]>();
- permissionsMap.put(userId, PermissionType.ALL);
- for (Permission permission : permissions)
- {
- StringBuilder strPer = new StringBuilder();
- if ("true".equals(permission.getRead()))
- strPer.append(PermissionType.READ);
- if ("true".equals(permission.getAddNode()))
- strPer.append(",").append(PermissionType.ADD_NODE);
- if ("true".equals(permission.getSetProperty()))
- strPer.append(",").append(PermissionType.SET_PROPERTY);
- if ("true".equals(permission.getRemove()))
- strPer.append(",").append(PermissionType.REMOVE);
- permissionsMap.put(permission.getIdentity(),
strPer.toString().split(","));
- }
- return permissionsMap;
+ dataDistributionType_.getOrCreateDataNode(userNode, path, nodeType, mixinTypes,
permissions);
}
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java 2011-04-11
17:40:26 UTC (rev 4226)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java 2011-04-11
17:42:26 UTC (rev 4227)
@@ -18,23 +18,27 @@
*/
package org.exoplatform.services.jcr.ext.hierarchy.impl;
+import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.container.component.ComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
import org.exoplatform.services.jcr.RepositoryService;
-import org.exoplatform.services.jcr.access.PermissionType;
-import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionManager;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionMode;
+import org.exoplatform.services.jcr.ext.distribution.DataDistributionType;
import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
import org.exoplatform.services.jcr.ext.hierarchy.impl.HierarchyConfig.JcrPath;
-import org.exoplatform.services.jcr.ext.hierarchy.impl.HierarchyConfig.Permission;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.picocontainer.Startable;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@@ -42,33 +46,65 @@
import javax.jcr.Session;
/**
+ *
* Created by The eXo Platform SAS Author : Dang Van Minh minh.dang(a)exoplatform.com Nov
15, 2007
* 2:21:57 PM
*/
public class NodeHierarchyCreatorImpl implements NodeHierarchyCreator, Startable
{
- final static private String NT_UNSTRUCTURED = "nt:unstructured".intern();
+ private static final Log log =
ExoLogger.getLogger("exo.jcr.component.ext.NodeHierarchyCreatorImpl");
- final static private String USERS_PATH = "usersPath";
+ private static final String USERS_PATH = "usersPath";
- final static private String USER_APPLICATION = "userApplicationData";
+ private static final String USER_APPLICATION = "userApplicationData";
- final static private String PUBLIC_APPLICATION = "eXoApplications";
+ private static final String PUBLIC_APPLICATION = "eXoApplications";
- final static private String USER_PRIVATE = "userPrivate";
+ private static final String USER_PRIVATE = "userPrivate";
- final static private String USER_PUBLIC = "userPublic";
+ private static final String USER_PUBLIC = "userPublic";
- private RepositoryService jcrService_;
+ private final RepositoryService jcrService_;
- List<AddPathPlugin> pathPlugins_ = new ArrayList<AddPathPlugin>();
+ private final DataDistributionManager dataDistributionManager_;
- public NodeHierarchyCreatorImpl(RepositoryService jcrService) throws Exception
+ private final List<AddPathPlugin> pathPlugins_ = new
ArrayList<AddPathPlugin>();
+
+ private final Map<String, String> paths_ = new HashMap<String, String>();
+
+ private final boolean oldDistribution;
+
+ public NodeHierarchyCreatorImpl(RepositoryService jcrService, InitParams params)
{
+ this(jcrService, null, params);
+ }
+
+ public NodeHierarchyCreatorImpl(RepositoryService jcrService, DataDistributionManager
dataDistributionManager,
+ InitParams params)
+ {
+ if (dataDistributionManager == null)
+ {
+ throw new IllegalArgumentException("The DataDistributionManager is now
mandatory if you use the "
+ + "NodeHierarchyCreator, so please define it in your configuration
"
+ + "as described in the JCR documentation");
+ }
jcrService_ = jcrService;
+ dataDistributionManager_ = dataDistributionManager;
+ oldDistribution =
+ params != null &&
params.getValueParam("old-user-distribution") != null
+ &&
Boolean.valueOf(params.getValueParam("old-user-distribution").getValue());
+ if (PropertyManager.isDevelopping() && !oldDistribution)
+ {
+ log.info("The NodeHierarchyCreator is configured to use the new
distribution mechanism for the"
+ + " users directories, if you prefer to use the old mechanism set the
value parameter "
+ + "'old-user-distribution' to 'true'.");
+ }
}
+ /**
+ * {@inheritDoc}
+ */
public void start()
{
try
@@ -77,112 +113,102 @@
}
catch (Exception e)
{
- e.printStackTrace();
+ log.error("An error occurs while processing the plugins", e);
}
}
+ /**
+ * {@inheritDoc}
+ */
public void stop()
{
}
+ /**
+ * {@inheritDoc}
+ */
public void init(String repository) throws Exception
{
- initBasePath(repository);
+ init();
}
- @SuppressWarnings("unchecked")
- private void createNode(Node rootNode, String path, String nodeType,
List<String> mixinTypes, Map permissions)
- throws Exception
+ /**
+ * {@inheritDoc}
+ */
+ public void init() throws Exception
{
- Node node = rootNode;
- for (String token : path.split("/"))
- {
- if (token.length() > 0)
- {
- try
- {
- node = node.getNode(token);
- }
- catch (PathNotFoundException e)
- {
- if (nodeType == null || nodeType.length() == 0)
- nodeType = NT_UNSTRUCTURED;
- node = node.addNode(token, nodeType);
- if (node.canAddMixin("exo:privilegeable"))
- node.addMixin("exo:privilegeable");
- if (permissions != null && !permissions.isEmpty())
- ((ExtendedNode)node).setPermissions(permissions);
- if (mixinTypes.size() > 0)
- {
- for (String mixin : mixinTypes)
- {
- if (node.canAddMixin(mixin))
- node.addMixin(mixin);
- }
- }
- }
- }
- }
+ initBasePath();
}
- public Map getPermissions(List<Permission> permissions)
+ private void createNode(Node rootNode, String path, String nodeType,
List<String> mixinTypes,
+ Map<String, String[]> permissions) throws Exception
{
- Map<String, String[]> permissionsMap = new HashMap<String,
String[]>();
- for (Permission permission : permissions)
- {
- StringBuilder strPer = new StringBuilder();
- if ("true".equals(permission.getRead()))
- strPer.append(PermissionType.READ);
- if ("true".equals(permission.getAddNode()))
- strPer.append(",").append(PermissionType.ADD_NODE);
- if ("true".equals(permission.getSetProperty()))
- strPer.append(",").append(PermissionType.SET_PROPERTY);
- if ("true".equals(permission.getRemove()))
- strPer.append(",").append(PermissionType.REMOVE);
- permissionsMap.put(permission.getIdentity(),
strPer.toString().split(","));
- }
- return permissionsMap;
+
dataDistributionManager_.getDataDistributionType(DataDistributionMode.NONE).getOrCreateDataNode(rootNode,
path,
+ nodeType, mixinTypes, permissions);
}
- @SuppressWarnings("unchecked")
private void processAddPathPlugin() throws Exception
{
Session session = null;
+ ManageableRepository currentRepo = jcrService_.getCurrentRepository();
for (AddPathPlugin pathPlugin : pathPlugins_)
{
HierarchyConfig hierarchyConfig = pathPlugin.getPaths();
- String repository = hierarchyConfig.getRepository();
+ if (hierarchyConfig == null)
+ {
+ continue;
+ }
List<JcrPath> jcrPaths = hierarchyConfig.getJcrPaths();
- for (String workspaceName : hierarchyConfig.getWorkspaces())
+ if (jcrPaths == null)
{
- session =
jcrService_.getRepository(repository).getSystemSession(workspaceName);
- Node rootNode = session.getRootNode();
- for (JcrPath jcrPath : jcrPaths)
+ continue;
+ }
+ Set<String> workspaceNames = new LinkedHashSet<String>();
+ if (hierarchyConfig.getWorkspaces() != null)
+ {
+ workspaceNames.addAll(hierarchyConfig.getWorkspaces());
+ }
+ workspaceNames.add(currentRepo.getConfiguration().getDefaultWorkspaceName());
+ for (String workspaceName : workspaceNames)
+ {
+ JcrPath currentjcrPath = null;
+ try
{
- String nodeType = jcrPath.getNodeType();
- if (nodeType == null || nodeType.length() == 0)
- nodeType = NT_UNSTRUCTURED;
- List<String> mixinTypes = jcrPath.getMixinTypes();
- if (mixinTypes == null)
- mixinTypes = new ArrayList<String>();
- if (!jcrPath.getAlias().equals(USER_APPLICATION) &&
!jcrPath.getAlias().startsWith(USER_PRIVATE)
- && !jcrPath.getAlias().startsWith(USER_PUBLIC))
+ session = currentRepo.getSystemSession(workspaceName);
+ Node rootNode = session.getRootNode();
+ for (JcrPath jcrPath : jcrPaths)
{
- createNode(rootNode, jcrPath.getPath(), nodeType, mixinTypes,
- getPermissions(jcrPath.getPermissions()));
+ currentjcrPath = jcrPath;
+ if (!jcrPath.getAlias().equals(USER_APPLICATION) &&
!jcrPath.getAlias().startsWith(USER_PRIVATE)
+ && !jcrPath.getAlias().startsWith(USER_PUBLIC))
+ {
+ createNode(rootNode, jcrPath.getPath(), jcrPath.getNodeType(),
jcrPath.getMixinTypes(),
+ jcrPath.getPermissions(null));
+ }
}
}
- session.save();
- session.logout();
+ catch (Exception e)
+ {
+ log.error("An error occurs while processing the JCR path which alias
is "
+ + (currentjcrPath == null ? null : currentjcrPath.getAlias()) + "
with the workspace "
+ + workspaceName, e);
+ }
+ finally
+ {
+ if (session != null)
+ {
+ session.logout();
+ session = null;
+ }
+ }
}
}
}
- @SuppressWarnings("unchecked")
- private void initBasePath(String repository) throws Exception
+ private void initBasePath() throws Exception
{
Session session = null;
- ManageableRepository manageableRepository = jcrService_.getRepository(repository);
+ ManageableRepository manageableRepository = jcrService_.getCurrentRepository();
String defaultWorkspace =
manageableRepository.getConfiguration().getDefaultWorkspaceName();
String systemWorkspace =
manageableRepository.getConfiguration().getSystemWorkspaceName();
boolean isSameWorksapce = defaultWorkspace.equalsIgnoreCase(systemWorkspace);
@@ -190,123 +216,142 @@
for (AddPathPlugin pathPlugin : pathPlugins_)
{
HierarchyConfig hierarchyConfig = pathPlugin.getPaths();
+ if (hierarchyConfig == null)
+ {
+ continue;
+ }
List<JcrPath> jcrPaths = hierarchyConfig.getJcrPaths();
+ if (jcrPaths == null)
+ {
+ continue;
+ }
for (String workspaceName : workspaceNames)
{
if (!isSameWorksapce &&
workspaceName.equalsIgnoreCase(systemWorkspace))
continue;
- session = manageableRepository.getSystemSession(workspaceName);
- Node rootNode = session.getRootNode();
- for (JcrPath jcrPath : jcrPaths)
+ JcrPath currentjcrPath = null;
+ try
{
- String nodeType = jcrPath.getNodeType();
- if (nodeType == null || nodeType.length() == 0)
- nodeType = NT_UNSTRUCTURED;
- List<String> mixinTypes = jcrPath.getMixinTypes();
- if (mixinTypes == null)
- mixinTypes = new ArrayList<String>();
- if (!jcrPath.getAlias().equals(USER_APPLICATION) &&
!jcrPath.getAlias().startsWith(USER_PRIVATE)
- && !jcrPath.getAlias().startsWith(USER_PUBLIC))
+ session = manageableRepository.getSystemSession(workspaceName);
+ Node rootNode = session.getRootNode();
+ for (JcrPath jcrPath : jcrPaths)
{
- createNode(rootNode, jcrPath.getPath(), nodeType, mixinTypes,
- getPermissions(jcrPath.getPermissions()));
+ currentjcrPath = jcrPath;
+ if (!jcrPath.getAlias().equals(USER_APPLICATION) &&
!jcrPath.getAlias().startsWith(USER_PRIVATE)
+ && !jcrPath.getAlias().startsWith(USER_PUBLIC))
+ {
+ createNode(rootNode, jcrPath.getPath(), jcrPath.getNodeType(),
jcrPath.getMixinTypes(),
+ jcrPath.getPermissions(null));
+ }
}
}
- session.save();
- session.logout();
+ catch (Exception e)
+ {
+ log.error("An error occurs while processing the JCR path which alias
is "
+ + (currentjcrPath == null ? null : currentjcrPath.getAlias()) + "
with the workspace "
+ + workspaceName, e);
+ }
+ finally
+ {
+ if (session != null)
+ {
+ session.logout();
+ session = null;
+ }
+ }
}
}
}
+ /**
+ * {@inheritDoc}
+ */
public Node getUserApplicationNode(SessionProvider sessionProvider, String userName)
throws Exception
{
Node userNode = getUserNode(sessionProvider, userName);
- Node userAppNode = null;
- try
- {
- userAppNode = userNode.getNode(getJcrPath(USER_APPLICATION));
- }
- catch (PathNotFoundException e)
- {
- userAppNode = userNode.addNode(getJcrPath(USER_APPLICATION));
- userNode.save();
- }
- return userAppNode;
+ return
dataDistributionManager_.getDataDistributionType(DataDistributionMode.NONE).getOrCreateDataNode(userNode,
+ getJcrPath(USER_APPLICATION));
}
+ /**
+ * {@inheritDoc}
+ */
public Node getPublicApplicationNode(SessionProvider sessionProvider) throws
Exception
{
- ManageableRepository currentRepo = jcrService_.getCurrentRepository();
- Session session =
- getSession(sessionProvider, currentRepo,
currentRepo.getConfiguration().getDefaultWorkspaceName());
+ Session session = getSession(sessionProvider);
Node rootNode = session.getRootNode();
- String publicApplication = getJcrPath(PUBLIC_APPLICATION);
- session.logout();
- return rootNode.getNode(publicApplication.substring(1,
publicApplication.length()));
+ return
dataDistributionManager_.getDataDistributionType(DataDistributionMode.NONE).getDataNode(rootNode,
+ getJcrPath(PUBLIC_APPLICATION));
}
+ /**
+ * {@inheritDoc}
+ */
public Node getUserNode(SessionProvider sessionProvider, String userName) throws
Exception
{
String userPath = getJcrPath(USERS_PATH);
- ManageableRepository currentRepo = jcrService_.getCurrentRepository();
- Session session =
- getSession(sessionProvider, currentRepo,
currentRepo.getConfiguration().getDefaultWorkspaceName());
+ Session session = getSession(sessionProvider);
Node usersNode = (Node)session.getItem(userPath);
- Node userNode = null;
+ DataDistributionType type =
+ dataDistributionManager_.getDataDistributionType(oldDistribution ?
DataDistributionMode.NONE
+ : DataDistributionMode.READABLE);
+ return type.getOrCreateDataNode(usersNode, userName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeUserNode(SessionProvider sessionProvider, String userName) throws
Exception
+ {
+ String userPath = getJcrPath(USERS_PATH);
+ Session session = getSession(sessionProvider);
try
{
- userNode = usersNode.getNode(userName);
+ Node usersNode = (Node)session.getItem(userPath);
+ DataDistributionType type =
+ dataDistributionManager_.getDataDistributionType(oldDistribution ?
DataDistributionMode.NONE
+ : DataDistributionMode.READABLE);
+ type.removeDataNode(usersNode, userName);
}
catch (PathNotFoundException e)
{
- userNode = usersNode.addNode(userName);
- usersNode.save();
+ // ignore me
}
- finally
- {
- session.logout();
- }
- return userNode;
}
- private Session getSession(SessionProvider sessionProvider, ManageableRepository repo,
String defaultWorkspace)
- throws RepositoryException
+ private Session getSession(SessionProvider sessionProvider) throws
RepositoryException
{
- return sessionProvider.getSession(defaultWorkspace, repo);
+ ManageableRepository repo = jcrService_.getCurrentRepository();
+ return
sessionProvider.getSession(repo.getConfiguration().getDefaultWorkspaceName(), repo);
}
+ /**
+ * {@inheritDoc}
+ */
public String getJcrPath(String alias)
{
- for (int j = 0; j < pathPlugins_.size(); j++)
+ return paths_.get(alias);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addPlugin(ComponentPlugin plugin)
+ {
+ if (plugin instanceof AddPathPlugin)
{
- HierarchyConfig config = pathPlugins_.get(j).getPaths();
- List jcrPaths = config.getJcrPaths();
- for (Iterator iter = jcrPaths.iterator(); iter.hasNext();)
+ AddPathPlugin app = (AddPathPlugin)plugin;
+ pathPlugins_.add(app);
+ if (app.getPaths() != null && app.getPaths().getJcrPaths() != null)
{
- HierarchyConfig.JcrPath jcrPath = (HierarchyConfig.JcrPath)iter.next();
- if (jcrPath.getAlias().equals(alias))
+ for (JcrPath jcrPath : app.getPaths().getJcrPaths())
{
- return jcrPath.getPath();
+ if (jcrPath.getAlias() != null && jcrPath.getPath() != null)
+ {
+ paths_.put(jcrPath.getAlias(), jcrPath.getPath());
+ }
}
}
}
- return null;
}
-
- public void addPlugin(ComponentPlugin plugin)
- {
- if (plugin instanceof AddPathPlugin)
- pathPlugins_.add((AddPathPlugin)plugin);
- }
-
- @SuppressWarnings("unused")
- public ComponentPlugin removePlugin(String name)
- {
- return null;
- }
-
- public Collection getPlugins()
- {
- return null;
- }
}
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/hierarchy/TestNodeHierarchyCreator.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/hierarchy/TestNodeHierarchyCreator.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/hierarchy/TestNodeHierarchyCreator.java 2011-04-11
17:42:26 UTC (rev 4227)
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.hierarchy;
+
+import org.exoplatform.services.jcr.core.ExtendedNode;
+import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
+import org.exoplatform.services.jcr.ext.common.SessionProvider;
+import org.exoplatform.services.jcr.ext.hierarchy.impl.NewGroupListener;
+import org.exoplatform.services.jcr.ext.hierarchy.impl.NewUserListener;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.impl.GroupImpl;
+import org.exoplatform.services.organization.impl.UserImpl;
+import org.exoplatform.services.security.ConversationState;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Session;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas
Filotto</a>
+ * @version $Id$
+ *
+ */
+public class TestNodeHierarchyCreator extends BaseStandaloneTest
+{
+ private NodeHierarchyCreator creator;
+ private SessionProvider sessionProvider;
+ private NewUserListener userListener;
+ private NewGroupListener groupListener;
+ private Session session;
+
+ /**
+ * @see org.exoplatform.services.jcr.ext.BaseStandaloneTest#setUp()
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ creator =
(NodeHierarchyCreator)container.getComponentInstanceOfType(NodeHierarchyCreator.class);
+ userListener =
(NewUserListener)container.getComponentInstanceOfType(NewUserListener.class);
+ groupListener =
(NewGroupListener)container.getComponentInstanceOfType(NewGroupListener.class);
+ sessionProvider = new SessionProvider(ConversationState.getCurrent());
+ session = sessionProvider.getSession("ws1", repository);
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.ext.BaseStandaloneTest#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception
+ {
+ creator = null;
+ userListener = null;
+ groupListener = null;
+ if (session != null)
+ {
+ session.logout();
+ session = null;
+ }
+ if (sessionProvider != null)
+ {
+ sessionProvider.close();
+ sessionProvider = null;
+ }
+ super.tearDown();
+ }
+
+ public void testGetJcrPath() throws Exception
+ {
+ assertEquals("/exo:applications",
creator.getJcrPath("eXoApplications"));
+ assertEquals("/exo:services",
creator.getJcrPath("eXoServices"));
+ assertEquals("/Users", creator.getJcrPath("usersPath"));
+ assertEquals("/Groups/Path/Home",
creator.getJcrPath("groupsPath"));
+ }
+
+ public void testInit() throws Exception
+ {
+ Node node = (Node)session.getItem("/exo:services");
+ assertNotNull(node);
+ assertTrue(node.isNodeType("nt:folder"));
+ assertTrue(node.canAddMixin("mix:referenceable"));
+ assertTrue(node.canAddMixin("exo:privilegeable"));
+
+ node = (Node)session.getItem("/exo:applications");
+ assertNotNull(node);
+ assertFalse(node.isNodeType("nt:folder"));
+ assertFalse(node.canAddMixin("mix:referenceable"));
+ assertTrue(node.canAddMixin("exo:privilegeable"));
+
+ node = (Node)session.getItem("/Users");
+ assertNotNull(node);
+ assertFalse(node.isNodeType("nt:folder"));
+ assertTrue(node.canAddMixin("mix:referenceable"));
+ assertFalse(node.canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node).getACL().getPermissions("*:/platform/administrators"));
+
+ node = (Node)session.getItem("/Groups/Path/Home");
+ assertNotNull(node);
+ assertTrue(node.isNodeType("nt:unstructured"));
+ assertFalse(node.canAddMixin("mix:referenceable"));
+ assertFalse(node.canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node).getACL().getPermissions("*:/platform/administrators"));
+ assertTrue(node.getParent().isNodeType("nt:unstructured"));
+ assertFalse(node.getParent().canAddMixin("mix:referenceable"));
+ assertFalse(node.getParent().canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node.getParent()).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node.getParent()).getACL().getPermissions("*:/platform/administrators"));
+ assertTrue(node.getParent().getParent().isNodeType("nt:unstructured"));
+
assertFalse(node.getParent().getParent().canAddMixin("mix:referenceable"));
+
assertFalse(node.getParent().getParent().canAddMixin("exo:privilegeable"));
+
assertTrue(((ExtendedNode)node.getParent().getParent()).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node.getParent().getParent()).getACL().getPermissions("*:/platform/administrators"));
+ }
+
+ public void testGetUserNode() throws Exception
+ {
+ Node node = creator.getUserNode(sessionProvider, "foo");
+ assertNotNull(node);
+ assertTrue(node.getPath().startsWith("/Users"));
+ }
+
+ public void testGetUserApplicationNode() throws Exception
+ {
+ User user = new UserImpl("foo");
+ userListener.preSave(user, true);
+ Node node = creator.getUserApplicationNode(sessionProvider, "foo");
+ assertNotNull(node);
+ assertTrue(node.isNodeType("nt:folder"));
+ assertFalse(node.canAddMixin("mix:referenceable"));
+ assertFalse(node.canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node).getACL().getPermissions("*:/platform/administrators"));
+ Node parentNode = creator.getUserNode(sessionProvider, "foo");
+ assertNotNull(parentNode);
+ assertTrue(node.getPath().startsWith(parentNode.getPath()));
+ assertNotNull(session.getItem(node.getPath()));
+ userListener.preDelete(user);
+ try
+ {
+ session.getItem(node.getPath());
+ fail("A PathNotFoundException is expected");
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore me
+ }
+ }
+
+ public void testGroupsNode() throws Exception
+ {
+ GroupImpl group1 = new GroupImpl("platform");
+ GroupImpl group2 = new GroupImpl();
+ group2.setId("/platform/users");
+ GroupImpl group3 = new GroupImpl("my-group-name2");
+ group3.setParentId("/platform");
+
+ groupListener.preSave(group1, true);
+ Node node = (Node)session.getItem("/Groups/Path/Home/" +
group1.getGroupName());
+ assertNotNull(node);
+ node = node.getNode("ApplicationData");
+ assertTrue(node.isNodeType("nt:folder"));
+ assertFalse(node.canAddMixin("mix:referenceable"));
+ assertFalse(node.canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node).getACL().getPermissions("*:/platform/administrators"));
+
+ groupListener.preSave(group2, true);
+ node = (Node)session.getItem("/Groups/Path/Home" + group2.getId());
+ assertNotNull(node);
+ node = node.getNode("ApplicationData");
+ assertTrue(node.isNodeType("nt:folder"));
+ assertFalse(node.canAddMixin("mix:referenceable"));
+ assertFalse(node.canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node).getACL().getPermissions("*:/platform/administrators"));
+ groupListener.preDelete(group2);
+ try
+ {
+ session.getItem("/Groups/Path/Home" + group2.getId());
+ fail("A PathNotFoundException is expected");
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore me
+ }
+ groupListener.preSave(group3, true);
+ node = (Node)session.getItem("/Groups/Path/Home" + group3.getParentId() +
"/" + group3.getGroupName());
+ assertNotNull(node);
+ node = node.getNode("ApplicationData");
+ assertTrue(node.isNodeType("nt:folder"));
+ assertFalse(node.canAddMixin("mix:referenceable"));
+ assertFalse(node.canAddMixin("exo:privilegeable"));
+ assertTrue(((ExtendedNode)node).getACL().hasPermissions());
+
assertNotNull(((ExtendedNode)node).getACL().getPermissions("*:/platform/administrators"));
+ groupListener.preDelete(group3);
+ try
+ {
+ session.getItem("/Groups/Path/Home" + group3.getParentId() +
"/" + group3.getGroupName());
+ fail("A PathNotFoundException is expected");
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore me
+ }
+ groupListener.preDelete(group1);
+ try
+ {
+ session.getItem("/Groups/Path/Home/" + group1.getGroupName());
+ fail("A PathNotFoundException is expected");
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore me
+ }
+ }
+}