KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > admin > patch > impl > CategoryRootPermissionPatch


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.admin.patch.impl;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.i18n.I18NUtil;
22 import org.alfresco.repo.admin.patch.AbstractPatch;
23 import org.alfresco.repo.importer.ImporterBootstrap;
24 import org.alfresco.service.cmr.admin.PatchException;
25 import org.alfresco.service.cmr.repository.NodeRef;
26 import org.alfresco.service.cmr.repository.NodeService;
27 import org.alfresco.service.cmr.search.SearchService;
28 import org.alfresco.service.cmr.security.PermissionService;
29 import org.alfresco.service.namespace.NamespaceService;
30
31 /**
32  * Grant <b>Consumer</b> role to <b>Guest</b> in <b>Category Root</b> folder.
33  * <p>
34  * This patch expects the folder to be present.
35  */

36 public class CategoryRootPermissionPatch extends AbstractPatch
37 {
38     private static final String JavaDoc MSG_RESULT = "patch.categoryRootPermission.result";
39     private static final String JavaDoc ERR_NOT_FOUND = "patch.categoryRootPermission.err.not_found";
40     
41     private PermissionService permissionService;
42     private ImporterBootstrap spacesBootstrap;
43     private SearchService searchService;
44     private NamespaceService namespaceService;
45     private NodeService nodeService;
46     
47     
48     public void setPermissionService(PermissionService permissionService)
49     {
50         this.permissionService = permissionService;
51     }
52
53     public void setSpacesBootstrap(ImporterBootstrap spacesBootstrap)
54     {
55         this.spacesBootstrap = spacesBootstrap;
56     }
57     
58     public void setNodeService(NodeService nodeService)
59     {
60         this.nodeService = nodeService;
61     }
62     
63     public void setSearchService(SearchService searchService)
64     {
65         this.searchService = searchService;
66     }
67     
68     public void setNamespaceService(NamespaceService namespaceService)
69     {
70         this.namespaceService = namespaceService;
71     }
72     
73     
74     @Override JavaDoc
75     protected String JavaDoc applyInternal() throws Exception JavaDoc
76     {
77         String JavaDoc categoryRootPath = "/cm:categoryRoot";
78
79         // find category root
80
NodeRef rootNodeRef = nodeService.getRootNode(spacesBootstrap.getStoreRef());
81         List JavaDoc<NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, categoryRootPath, null, namespaceService, false);
82         if (nodeRefs.size() == 0)
83         {
84             String JavaDoc msg = I18NUtil.getMessage(ERR_NOT_FOUND, categoryRootPath);
85             throw new PatchException(msg);
86         }
87         NodeRef categoryRootRef = nodeRefs.get(0);
88         
89         // apply permission
90
permissionService.setPermission(categoryRootRef, PermissionService.GUEST_AUTHORITY, PermissionService.READ, true);
91
92         // done
93
String JavaDoc msg = I18NUtil.getMessage(MSG_RESULT, categoryRootPath);
94         return msg;
95     }
96 }
97
Popular Tags