View Javadoc
1   /*
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.cms.taxonomy.impl;
18  
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.HashSet;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Set;
25  
26  import javax.jcr.AccessDeniedException;
27  import javax.jcr.ItemExistsException;
28  import javax.jcr.ItemNotFoundException;
29  import javax.jcr.Node;
30  import javax.jcr.NodeIterator;
31  import javax.jcr.PathNotFoundException;
32  import javax.jcr.RepositoryException;
33  import javax.jcr.Session;
34  import javax.jcr.UnsupportedRepositoryOperationException;
35  import javax.jcr.Workspace;
36  import javax.jcr.query.Query;
37  import javax.jcr.query.QueryManager;
38  import javax.jcr.query.QueryResult;
39  
40  import org.apache.commons.lang.StringUtils;
41  import org.exoplatform.container.component.ComponentPlugin;
42  import org.exoplatform.container.xml.InitParams;
43  import org.exoplatform.container.xml.ObjectParameter;
44  import org.exoplatform.container.xml.ValueParam;
45  import org.exoplatform.services.cms.BasePath;
46  import org.exoplatform.services.cms.impl.DMSConfiguration;
47  import org.exoplatform.services.cms.impl.DMSRepositoryConfiguration;
48  import org.exoplatform.services.cms.jcrext.activity.ActivityCommonService;
49  import org.exoplatform.services.cms.link.LinkManager;
50  import org.exoplatform.services.cms.taxonomy.TaxonomyService;
51  import org.exoplatform.services.jcr.RepositoryService;
52  import org.exoplatform.services.jcr.access.AccessControlEntry;
53  import org.exoplatform.services.jcr.access.PermissionType;
54  import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
55  import org.exoplatform.services.jcr.core.ExtendedNode;
56  import org.exoplatform.services.jcr.core.ManageableRepository;
57  import org.exoplatform.services.jcr.ext.app.SessionProviderService;
58  import org.exoplatform.services.jcr.ext.common.SessionProvider;
59  import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
60  import org.exoplatform.services.listener.ListenerService;
61  import org.exoplatform.services.log.ExoLogger;
62  import org.exoplatform.services.log.Log;
63  import org.exoplatform.services.security.IdentityConstants;
64  import org.exoplatform.services.wcm.core.NodetypeConstant;
65  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
66  import org.picocontainer.Startable;
67  
68  /**
69   * Created by The eXo Platform SARL Author : Ly Dinh Quang
70   * quang.ly@exoplatform.com xxx5669@gmail.com Mar 31, 2009
71   */
72  public class TaxonomyServiceImpl implements TaxonomyService, Startable {
73    private SessionProviderService providerService_;
74  
75    private NodeHierarchyCreator   nodeHierarchyCreator_;
76  
77    private RepositoryService      repositoryService_;
78  
79    private static final String    TAXONOMY_LINK   = "exo:taxonomyLink";
80  
81    private static final String    EXOSYMLINK_LINK = "exo:symlink";
82  
83    private static final String    EXO_WORKSPACE   = "exo:workspace";
84  
85    private static final String    EXO_UUID        = "exo:uuid";
86  
87    private LinkManager            linkManager_;
88    private ListenerService        listenerService;
89    private ActivityCommonService  activityService;
90  
91    private final String           SQL_QUERY       = "Select * from exo:taxonomyLink where jcr:path like '$0/%' "
92        + "and exo:uuid = '$1' "
93        + "and exo:workspace = '$2' "
94        + "order by exo:dateCreated DESC";
95  
96    private final String SQL_QUERY_EXACT_PATH = "Select * from exo:taxonomyLink where jcr:path like '$0/%' "
97        + "and not jcr:path like '$0/%/%' "
98        + "and exo:uuid = '$1' "
99        + "and exo:workspace = '$2' "
100       + "order by exo:dateCreated DESC";
101 
102 
103   List<TaxonomyPlugin>           plugins_        = new ArrayList<>();
104 
105   private DMSConfiguration       dmsConfiguration_;
106 
107   private Map<String, String[]>  taxonomyTreeDefaultUserPermissions_;
108 
109   private static final Log       LOG             = ExoLogger.getLogger(TaxonomyServiceImpl.class.getName());
110   private String categoryNameLength;
111 
112   /**
113    * Constructor method
114    * @param providerService         create session
115    * @param nodeHierarchyCreator    get path by alias name
116    * @param repoService             manage repository
117    * @param linkManager             create and reach link
118    * @param dmsConfiguration        get dms-system workspace
119    * @throws Exception
120    */
121   public TaxonomyServiceImpl(InitParams initParams, SessionProviderService providerService,
122                              NodeHierarchyCreator nodeHierarchyCreator, RepositoryService repoService,
123                              LinkManager linkManager, DMSConfiguration dmsConfiguration) throws Exception {
124     providerService_ = providerService;
125     nodeHierarchyCreator_ = nodeHierarchyCreator;
126     repositoryService_ = repoService;
127     linkManager_ = linkManager;
128     dmsConfiguration_ = dmsConfiguration;
129     ValueParam valueParam = initParams.getValueParam("categoryNameLength");
130     if(valueParam!=null) {
131       categoryNameLength = valueParam.getValue();
132     } else {
133       categoryNameLength = "150";
134     }
135     ObjectParameter objectParam = initParams.getObjectParam("defaultPermission.configuration");
136     if (objectParam != null)
137       taxonomyTreeDefaultUserPermissions_
138       = getPermissions(((TaxonomyTreeDefaultUserPermission)objectParam.getObject()).getPermissions());
139     activityService = WCMCoreUtils.getService(ActivityCommonService.class);
140   }
141 
142   public String getCategoryNameLength() {
143     return categoryNameLength;
144   }
145 
146   public void init() throws Exception {
147     for (TaxonomyPlugin plugin : plugins_) {
148       plugin.init();
149     }
150   }
151 
152   /**
153    * {@inheritDoc}
154    */
155   public void addTaxonomyPlugin(ComponentPlugin plugin) {
156     if (plugin instanceof TaxonomyPlugin) {
157       plugins_.add((TaxonomyPlugin) plugin);
158     }
159   }
160 
161   public List<Node> getAllTaxonomyTrees() throws RepositoryException {
162     return getAllTaxonomyTrees(false);
163   }
164 
165   /**
166    * {@inheritDoc}
167    */
168   public List<Node> getAllTaxonomyTrees(boolean system)
169       throws RepositoryException {
170     List<Node> listNode = new ArrayList<>();
171     try {
172       Node taxonomyDef = getRootTaxonomyDef();
173       NodeIterator nodeIter = taxonomyDef.getNodes();
174       while (nodeIter.hasNext()) {
175         Node node = (Node) nodeIter.next();
176         if (node.isNodeType(EXOSYMLINK_LINK)) {
177           try {
178             Node target = linkManager_.getTarget(node, system);
179             if (target != null)
180               listNode.add(target);
181           } catch (ItemNotFoundException ex) {
182             continue;
183           }
184           catch (AccessDeniedException adex) {
185             continue;
186           }
187         }
188       }
189     } catch (RepositoryConfigurationException e) {
190       throw new RepositoryException(e);
191     }
192     return listNode;
193   }
194 
195   /**
196    * {@inheritDoc}
197    */
198   public Node getTaxonomyTree(String taxonomyName) throws RepositoryException {
199     return getTaxonomyTree(taxonomyName, false);
200   }
201 
202   /**
203    * {@inheritDoc}
204    */
205   public Node getTaxonomyTree(String taxonomyName, boolean system)
206       throws RepositoryException {
207     try {
208       Node taxonomyDef = getRootTaxonomyDef();
209       try {
210         Node taxonomyTree = taxonomyDef.getNode(taxonomyName);
211         if (taxonomyTree.isNodeType(EXOSYMLINK_LINK))
212           return linkManager_.getTarget(taxonomyTree, system);
213       }catch (PathNotFoundException pne) {
214         throw new RepositoryException(pne);
215       }
216     } catch (RepositoryConfigurationException e1) {
217       throw new RepositoryException(e1);
218     } catch (PathNotFoundException e2) {
219       throw new RepositoryException(e2);
220     }
221     return null;
222   }
223 
224   /**
225    * {@inheritDoc}
226    */
227   public boolean hasTaxonomyTree(String taxonomyName) throws RepositoryException {
228     SessionProvider systemProvider = SessionProvider.createSystemProvider();
229     try {
230       Node taxonomyTree = getRootTaxonomyDef(systemProvider).getNode(taxonomyName);
231       return taxonomyTree.isNodeType(EXOSYMLINK_LINK);
232     } catch (RepositoryConfigurationException e1) {
233       throw new RepositoryException(e1);
234     } catch (PathNotFoundException e2) {
235       //ignore this exception
236     } finally {
237       systemProvider.close();
238     }
239     return false;
240   }
241 
242   /**
243    * {@inheritDoc}
244    */
245   public void addTaxonomyTree(Node taxonomyTree) throws RepositoryException,
246   TaxonomyAlreadyExistsException {
247     if (hasTaxonomyTree(taxonomyTree.getName())) {
248       throw new TaxonomyAlreadyExistsException();
249     }
250     SessionProvider systemProvider = SessionProvider.createSystemProvider();
251     try {
252       Node taxonomyDef = getRootTaxonomyDef(systemProvider);
253       linkManager_.createLink(taxonomyDef, EXOSYMLINK_LINK, taxonomyTree, taxonomyTree.getName());
254     } catch (RepositoryConfigurationException e) {
255       throw new RepositoryException(e);
256     } finally {
257       systemProvider.close();
258     }
259   }
260 
261   /**
262    * {@inheritDoc}
263    */
264   public void updateTaxonomyTree(String taxonomyName, Node taxonomyTree) throws RepositoryException {
265     try {
266       if (hasTaxonomyTree(taxonomyName)) {
267         Node taxonomyTreeLink = getRootTaxonomyDef().getNode(taxonomyName);
268         linkManager_.updateLink(taxonomyTreeLink, taxonomyTree);
269       }
270     } catch (RepositoryConfigurationException e) {
271       throw new RepositoryException(e);
272     }
273   }
274 
275   /**
276    * {@inheritDoc}
277    */
278   public void removeTaxonomyTree(String taxonomyName) throws RepositoryException {
279     Session session = null;
280     try {
281       if (hasTaxonomyTree(taxonomyName)) {
282         Node targetNode = getTaxonomyTree(taxonomyName, true);
283         session = targetNode.getSession();
284         targetNode.remove();
285         session.save();
286         Node taxonomyDef = getRootTaxonomyDef();
287         if (taxonomyDef.hasNode(taxonomyName)) {
288           Node taxonomyTree = taxonomyDef.getNode(taxonomyName);
289           taxonomyTree.remove();
290           taxonomyDef.getSession().save();
291         }
292       }
293     } catch (RepositoryConfigurationException e) {
294       throw new RepositoryException(e);
295     }
296   }
297 
298   /**
299    * {@inheritDoc}
300    */
301   public void addTaxonomyNode(String workspace, String parentPath, String taxoNodeName,
302                               String creatorUser) throws RepositoryException, TaxonomyNodeAlreadyExistsException {
303     Session systemSession = null;
304     try {
305       ManageableRepository manaRepo = repositoryService_.getCurrentRepository();
306       systemSession = getSession(manaRepo, workspace, true);
307       Node parentNode = (Node) systemSession.getItem(parentPath);
308       if (parentNode.hasNode(taxoNodeName))
309         throw new TaxonomyNodeAlreadyExistsException();
310       ExtendedNode node = (ExtendedNode) parentNode.addNode(taxoNodeName, "exo:taxonomy");
311       if (node.canAddMixin("exo:privilegeable")) {
312         if(node.hasProperty("exo:owner")) {
313           String owner = node.getProperty("exo:owner").getString();
314           node.addMixin("exo:privilegeable");
315           node.setPermission(owner, PermissionType.ALL);
316           if (creatorUser != null)
317             node.setPermission(creatorUser, PermissionType.ALL);
318           for(Map.Entry<String, String[]> entry : taxonomyTreeDefaultUserPermissions_.entrySet()) {
319             node.setPermission(entry.getKey(), entry.getValue());
320           }
321         }
322         if (!node.isNodeType("exo:privilegeable"))
323           node.addMixin("exo:privilegeable");
324         String systemUser = IdentityConstants.SYSTEM;
325         if (!containsUser(node.getACL().getPermissionEntries(), systemUser))
326           node.setPermission(systemUser, PermissionType.ALL);
327       }
328       systemSession.save();
329     } catch (PathNotFoundException e2) {
330       throw new RepositoryException(e2);
331     }
332   }
333 
334   private boolean containsUser(List<AccessControlEntry> entries, String userName) {
335     if (userName == null) return false;
336     for (AccessControlEntry entry : entries)
337       if (userName.equals(entry.getIdentity()))
338         return true;
339     return false;
340   }
341 
342   /**
343    * {@inheritDoc}
344    */
345   public void removeTaxonomyNode(String workspace, String absPath) throws RepositoryException {
346     Session systemSession = null;
347     try {
348       ManageableRepository manaRepo = repositoryService_.getCurrentRepository();
349       systemSession = getSession(manaRepo, workspace, true);
350       Node taxonomyNode = (Node) systemSession.getItem(absPath);
351       taxonomyNode.remove();
352       systemSession.save();
353     } catch (PathNotFoundException e2) {
354       throw new RepositoryException(e2);
355     }
356   }
357 
358   /**
359    * {@inheritDoc}
360    */
361   public List<Node> getCategories(Node node, String taxonomyName) throws RepositoryException {
362     return getCategories(node, taxonomyName, false);
363   }
364 
365   /**
366    * {@inheritDoc}
367    */
368   public List<Node> getCategories(Node node, String taxonomyName, boolean system) throws RepositoryException {
369     List<Node> listCate = new ArrayList<>();
370     Session session = null;
371     try {
372       if (node.isNodeType("mix:referenceable")) {
373         Node rootNodeTaxonomy = getTaxonomyTree(taxonomyName, system);
374         if (rootNodeTaxonomy != null) {
375           String sql = null;
376           sql = StringUtils.replace(SQL_QUERY, "$0", rootNodeTaxonomy.getPath());
377           sql = StringUtils.replace(sql, "$1", node.getUUID());
378           sql = StringUtils.replace(sql, "$2", node.getSession().getWorkspace().getName());
379           session =
380               repositoryService_.getCurrentRepository().login(rootNodeTaxonomy.getSession().getWorkspace().getName());
381           QueryManager queryManager = session.getWorkspace().getQueryManager();
382           Query query = queryManager.createQuery(sql, Query.SQL);
383           QueryResult result = query.execute();
384           NodeIterator iterate = result.getNodes();
385           Set<String> addedNode = new HashSet<>();
386           while (iterate.hasNext()) {
387             Node parentCate = iterate.nextNode().getParent();
388             // We need filtering duplicated result to fix the problem of ECMS-3282.
389             if (!addedNode.contains(parentCate.getSession().getWorkspace().getName() + ":/" + parentCate.getPath())) {
390               listCate.add(parentCate);
391               addedNode.add(parentCate.getSession().getWorkspace().getName() + ":/" + parentCate.getPath());
392             }
393           }
394         }
395       }
396     } catch (Exception e) {
397       throw new RepositoryException(e);
398     } finally {
399       if(session != null) session.logout();
400     }
401     return listCate;
402   }
403   /**
404    * {@inheritDoc}
405    */
406   public List<Node> getAllCategories(Node node) throws RepositoryException {
407     return getAllCategories(node, false);
408   }
409 
410   /**
411    * {@inheritDoc}
412    */
413   public List<Node> getAllCategories(Node node, boolean system) throws RepositoryException {
414     List<Node> listCategories = new ArrayList<>();
415     List<Node> allTrees = getAllTaxonomyTrees(system);
416     for (Node tree : allTrees) {
417       List<Node> categories = getCategories(node, tree.getName(), system);
418       for (Node category : categories) listCategories.add(category);
419     }
420     return listCategories;
421   }
422 
423   /**
424    * {@inheritDoc}
425    */
426   public void addCategory(Node node, String taxonomyName, String categoryPath)
427       throws RepositoryException {
428     addCategories(node, taxonomyName, new String[] { categoryPath });
429   }
430 
431   /**
432    * {@inheritDoc}
433    */
434   public void addCategory(Node node, String taxonomyName, String categoryPath, boolean system)
435       throws RepositoryException {
436     addCategories(node, taxonomyName, new String[] { categoryPath }, system);
437   }
438 
439   /**
440    * {@inheritDoc}
441    */
442   public void addCategories(Node node, String taxonomyName, String[] categoryPaths)
443       throws RepositoryException {
444     addCategories(node, taxonomyName, categoryPaths, false);
445   }
446 
447   /**
448    * {@inheritDoc}
449    */
450   public void addCategories(Node node, String taxonomyName, String[] categoryPaths, boolean system)
451       throws RepositoryException {
452     if (listenerService ==null) {
453       listenerService = WCMCoreUtils.getService(ListenerService.class);
454     }
455     String category = "";
456     try {
457       Node rootNodeTaxonomy = getTaxonomyTree(taxonomyName, system);
458       for (String categoryPath : categoryPaths) {
459         //get category path
460         if (rootNodeTaxonomy.getPath().equals("/")) {
461           category = categoryPath;
462         } else if (categoryPath.length() != 0) {
463           if (!categoryPath.startsWith("/"))
464             category = rootNodeTaxonomy.getPath() + "/" + categoryPath;
465           else
466             category = rootNodeTaxonomy.getPath() + categoryPath;
467         } else {
468           category = rootNodeTaxonomy.getPath();
469         }
470         //get category node
471         Node categoryNode;
472         if (categoryPath.startsWith(rootNodeTaxonomy.getPath())) {
473           categoryNode = (Node) rootNodeTaxonomy.getSession().getItem(categoryPath);
474         } else if (categoryPath.equals("")) {
475           categoryNode = rootNodeTaxonomy;
476         } else {
477           categoryNode = (Node) rootNodeTaxonomy.getSession().getItem(category);
478         }
479         String categoryName = categoryNode.getName();
480         if (categoryNode.hasProperty("exo:title")) {
481           categoryName = categoryNode.getProperty("exo:title").getString();
482         }
483         //add mix referenceable for node
484         if (node.canAddMixin("mix:referenceable")) {
485           node.addMixin("mix:referenceable");
486           node.getSession().save();
487         }
488         //generate unique linkName
489         String nodeUUID = node.getUUID();
490         String nodeWS = node.getSession().getWorkspace().getName();
491         String linkName = node.getName();
492         int index = 1;
493         while (categoryNode.hasNode(linkName)) {
494           Node taxonomyNode = categoryNode.getNode(linkName);
495           if (nodeUUID.equals(taxonomyNode.getProperty(EXO_UUID).getString()) &&
496               nodeWS.equals(taxonomyNode.getProperty(EXO_WORKSPACE).getString())) {
497             throw new ItemExistsException();
498           }
499           linkName = node.getName() + index++;
500         }
501 
502         //create link
503         linkManager_.createLink(categoryNode, TAXONOMY_LINK, node, linkName);
504         if (listenerService!=null) {
505           try {
506             if (activityService.isAcceptedNode(node) || (node.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE) &&
507                 activityService.isBroadcastNTFileEvents(node))) {
508               listenerService.broadcast(ActivityCommonService.CATEGORY_ADDED_ACTIVITY, node, categoryName);
509             }
510           } catch (Exception e) {
511             if (LOG.isErrorEnabled()) {
512               LOG.error("Can not notify CategoryAddedActivity because of: " + e.getMessage());
513             }
514           }
515         }
516       }
517     } catch (PathNotFoundException e) {
518       throw new RepositoryException(e);
519     }
520 
521   }
522 
523   /**
524    * {@inheritDoc}
525    */
526   public boolean hasCategories(Node node, String taxonomyName) throws RepositoryException {
527     return hasCategories(node, taxonomyName, false);
528   }
529 
530   /**
531    * {@inheritDoc}
532    */
533   public boolean hasCategories(Node node, String taxonomyName, boolean system) throws RepositoryException {
534     List<Node> listCate = getCategories(node, taxonomyName, system);
535     if (listCate != null && listCate.size() > 0)
536       return true;
537     return false;
538   }
539 
540   public void moveTaxonomyNode(String workspace, String srcPath, String destPath, String type) throws RepositoryException {
541     Session systemSession = null;
542     try {
543       ManageableRepository manaRepo = repositoryService_.getCurrentRepository();
544       systemSession = getSession(manaRepo, workspace, true);
545       if ("cut".equals(type)) {
546         systemSession.move(srcPath, destPath);
547         systemSession.save();
548       } else if ("copy".equals(type)) {
549         Workspace wspace = systemSession.getWorkspace();
550         wspace.copy(srcPath, destPath);
551         systemSession.save();
552       } else
553         throw new UnsupportedRepositoryOperationException();
554     } finally {
555     }
556   }
557 
558   /**
559    * {@inheritDoc}
560    */
561   public void removeCategory(Node node, String taxonomyName, String categoryPath)
562       throws RepositoryException {
563     removeCategory(node, taxonomyName, categoryPath, false);
564   }
565 
566   /**
567    * {@inheritDoc}
568    */
569   public void removeCategory(Node node, String taxonomyName, String categoryPath, boolean system)
570       throws RepositoryException {
571     try {
572       //get category node
573       String category = "";
574       Node rootNodeTaxonomy = getTaxonomyTree(taxonomyName, system);
575       if (rootNodeTaxonomy.getPath().equals("/")) {
576         category = categoryPath;
577       } else if (!categoryPath.startsWith("/")) {
578         category = rootNodeTaxonomy.getPath() + "/" + categoryPath;
579       } else {
580         category = rootNodeTaxonomy.getPath() + categoryPath;
581       }
582       Node categoryNode = ((Node) rootNodeTaxonomy.getSession().getItem(category));
583       String categoryName = categoryNode.getName();
584       //get taxonomyLink node
585       String sql = StringUtils.replace(SQL_QUERY_EXACT_PATH, "$0", categoryNode.getPath());
586       sql = StringUtils.replace(sql, "$1", node.getUUID());
587       sql = StringUtils.replace(sql, "$2", node.getSession().getWorkspace().getName());
588 
589       QueryManager queryManager = categoryNode.getSession().getWorkspace().getQueryManager();
590       Query query = queryManager.createQuery(sql, Query.SQL);
591       QueryResult result = query.execute();
592       NodeIterator iterate = result.getNodes();
593 
594       Node nodeTaxonomyLink = null;
595       if (iterate != null && iterate.hasNext()) {
596         nodeTaxonomyLink = iterate.nextNode();
597       }
598 
599       //remove taxonomyLink node
600       if (nodeTaxonomyLink == null) {
601         throw new RepositoryException("canot found taxonomy link node");
602       }
603       nodeTaxonomyLink.remove();
604       categoryNode.save();
605       node.getSession().save();
606       if (listenerService!=null) {
607         try {
608           if (activityService.isAcceptedNode(node) || (node.getPrimaryNodeType().getName().equals(NodetypeConstant.NT_FILE) &&
609               activityService.isBroadcastNTFileEvents(node))) {
610             listenerService.broadcast(ActivityCommonService.CATEGORY_REMOVED_ACTIVITY, node, categoryName);
611           }
612         } catch (Exception e) {
613           if (LOG.isErrorEnabled()) {
614             LOG.error("Can not notify Activity because of: " + e.getMessage());
615           }
616         }
617       }
618     } catch (PathNotFoundException e) {
619       throw new RepositoryException(e);
620     }
621   }
622 
623   /**
624    * {@inheritDoc}
625    */
626   public Map<String, String[]> getTaxonomyTreeDefaultUserPermission() {
627     return taxonomyTreeDefaultUserPermissions_;
628   }
629 
630   public Map<String, String[]> getPermissions(List<TaxonomyTreeDefaultUserPermission.Permission> permissions) {
631     Map<String, String[]> permissionsMap = new HashMap<>();
632     for (TaxonomyTreeDefaultUserPermission.Permission permission : permissions) {
633       StringBuilder strPer = new StringBuilder();
634       if ("true".equals(permission.getRead()))
635         strPer.append(PermissionType.READ);
636       if ("true".equals(permission.getAddNode()))
637         strPer.append(",").append(PermissionType.ADD_NODE);
638       if ("true".equals(permission.getSetProperty()))
639         strPer.append(",").append(PermissionType.SET_PROPERTY);
640       if ("true".equals(permission.getRemove()))
641         strPer.append(",").append(PermissionType.REMOVE);
642       permissionsMap.put(permission.getIdentity(), strPer.toString().split(","));
643     }
644     return permissionsMap;
645   }
646 
647   /**
648    * Get node as root of all taxonomy in the repository that is in TAXONOMIES_TREE_DEFINITION_PATH
649    * @param systemProvider System Provider
650    * @return
651    * @throws RepositoryException
652    * @throws RepositoryConfigurationException
653    */
654   private Node getRootTaxonomyDef(SessionProvider systemProvider) throws RepositoryException,
655       RepositoryConfigurationException {
656     ManageableRepository manaRepository = repositoryService_.getCurrentRepository();
657     DMSRepositoryConfiguration dmsRepoConfig = dmsConfiguration_.getConfig();
658     Session systemSession = systemProvider.getSession(dmsRepoConfig.getSystemWorkspace(), manaRepository);
659     String taxonomiesTreeDef = nodeHierarchyCreator_
660         .getJcrPath(BasePath.TAXONOMIES_TREE_DEFINITION_PATH);
661     Node taxonomyRootDef = (Node) systemSession.getItem(taxonomiesTreeDef);
662     return taxonomyRootDef;
663   }
664   
665   /**
666    * Get node as root of all taxonomy in the repository that is in TAXONOMIES_TREE_DEFINITION_PATH
667    * @return
668    * @throws RepositoryException
669    * @throws RepositoryConfigurationException
670    */
671   private Node getRootTaxonomyDef() throws RepositoryException,
672   RepositoryConfigurationException {
673     ManageableRepository manaRepository = repositoryService_.getCurrentRepository();
674     DMSRepositoryConfiguration dmsRepoConfig = dmsConfiguration_.getConfig();
675     Session systemSession = getSession(manaRepository, dmsRepoConfig.getSystemWorkspace(), true);
676     String taxonomiesTreeDef = nodeHierarchyCreator_
677         .getJcrPath(BasePath.TAXONOMIES_TREE_DEFINITION_PATH);
678     Node taxonomyRootDef = (Node) systemSession.getItem(taxonomiesTreeDef);
679     return taxonomyRootDef;
680   }
681 
682   /**
683    * Get session by workspace and ManageableRepository
684    * @param manageRepository
685    * @param workspaceName
686    * @param system
687    * @return          System session if system = true, else return session of current user
688    * @throws RepositoryException
689    */
690   private Session getSession(ManageableRepository manageRepository, String workspaceName,
691                              boolean system) throws RepositoryException {
692     if (system)
693       return providerService_.getSystemSessionProvider(null).getSession(workspaceName,
694                                                                         manageRepository);
695     return providerService_.getSessionProvider(null).getSession(workspaceName, manageRepository);
696   }
697 
698   /**
699    * {@inheritDoc}
700    */
701   public void start() {
702     try {
703       for (TaxonomyPlugin plugin : plugins_) {
704         plugin.init() ;
705       }
706     } catch (Exception e) {
707       if (LOG.isErrorEnabled()) {
708         LOG.error("Unexpected error", e);
709       }
710     }
711   }
712 
713   /**
714    * {@inheritDoc}
715    */
716   public void stop() {
717   }
718 }