1 17 package org.alfresco.repo.admin.patch.impl; 18 19 import java.util.List ; 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 36 public class CategoryRootPermissionPatch extends AbstractPatch 37 { 38 private static final String MSG_RESULT = "patch.categoryRootPermission.result"; 39 private static final String 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 75 protected String applyInternal() throws Exception 76 { 77 String categoryRootPath = "/cm:categoryRoot"; 78 79 NodeRef rootNodeRef = nodeService.getRootNode(spacesBootstrap.getStoreRef()); 81 List <NodeRef> nodeRefs = searchService.selectNodes(rootNodeRef, categoryRootPath, null, namespaceService, false); 82 if (nodeRefs.size() == 0) 83 { 84 String msg = I18NUtil.getMessage(ERR_NOT_FOUND, categoryRootPath); 85 throw new PatchException(msg); 86 } 87 NodeRef categoryRootRef = nodeRefs.get(0); 88 89 permissionService.setPermission(categoryRootRef, PermissionService.GUEST_AUTHORITY, PermissionService.READ, true); 91 92 String msg = I18NUtil.getMessage(MSG_RESULT, categoryRootPath); 94 return msg; 95 } 96 } 97 | Popular Tags |