From 4a56714c7fe856a19fa01671008ed93a6619fe5e Mon Sep 17 00:00:00 2001 From: Torsten Simon Date: Fri, 8 Nov 2024 13:12:48 +0100 Subject: [PATCH] fix:fetching org administrators group is slow via loop, try direct match via group name id --- .../OnCreateNodePolicyOrgAdministrators.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/Backend/alfresco/module/src/main/java/org/edu_sharing/alfresco/policy/OnCreateNodePolicyOrgAdministrators.java b/Backend/alfresco/module/src/main/java/org/edu_sharing/alfresco/policy/OnCreateNodePolicyOrgAdministrators.java index 81646061c1..b09c4e2321 100644 --- a/Backend/alfresco/module/src/main/java/org/edu_sharing/alfresco/policy/OnCreateNodePolicyOrgAdministrators.java +++ b/Backend/alfresco/module/src/main/java/org/edu_sharing/alfresco/policy/OnCreateNodePolicyOrgAdministrators.java @@ -1,9 +1,5 @@ package org.edu_sharing.alfresco.policy; -import java.io.Serializable; -import java.util.List; -import java.util.Map; - import org.alfresco.model.ContentModel; import org.alfresco.repo.model.Repository; import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy; @@ -15,14 +11,18 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.ResultSetRow; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; +import org.apache.log4j.Logger; +import org.edu_sharing.alfresco.service.AuthorityService; import org.edu_sharing.repository.client.tools.CCConstants; import org.edu_sharing.repository.server.tools.cache.EduGroupCache; +import java.io.Serializable; +import java.util.List; +import java.util.Map; + public class OnCreateNodePolicyOrgAdministrators implements OnCreateNodePolicy, OnMoveNodePolicy { PermissionService permissionService; @@ -88,15 +88,24 @@ private String getAdminGroup(ChildAssociationRef childRef) { } if(organisationNode != null){ - + Map eduGroupProps = EduGroupCache.getByEduGroupfolder(organisationNode); - NodeRef eduGroupNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, (String)eduGroupProps.get(ContentModel.PROP_NODE_UUID)); - List childGroups = nodeService.getChildAssocs(eduGroupNodeRef); - for(ChildAssociationRef childGroup : childGroups){ - String grouptype = (String)nodeService.getProperty(childGroup.getChildRef(), QName.createQName(CCConstants.CCM_PROP_GROUPEXTENSION_GROUPTYPE)); - if(CCConstants.ADMINISTRATORS_GROUP_TYPE.equals(grouptype)){ - String authorityName = (String)nodeService.getProperty(childGroup.getChildRef(), QName.createQName(CCConstants.CM_PROP_AUTHORITY_AUTHORITYNAME)); - return authorityName; + NodeRef eduGroupNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, (String) eduGroupProps.get(ContentModel.PROP_NODE_UUID)); + try { + String name = PermissionService.GROUP_PREFIX + AuthorityService.getGroupName(AuthorityService.ADMINISTRATORS_GROUP, (String) eduGroupProps.get(ContentModel.PROP_AUTHORITY_NAME)); + String grouptype = (String)nodeService.getProperty(serviceRegistry.getAuthorityService().getAuthorityNodeRef(name), QName.createQName(CCConstants.CCM_PROP_GROUPEXTENSION_GROUPTYPE)); + if(CCConstants.ADMINISTRATORS_GROUP_TYPE.equals(grouptype)) { + return name; + } + } catch (Throwable t) { + Logger.getLogger(OnCreateNodePolicyOrgAdministrators.class).warn(t); + // this is much, much slower + List childGroups = nodeService.getChildAssocs(eduGroupNodeRef); + for(ChildAssociationRef childGroup : childGroups){ + String grouptype = (String)nodeService.getProperty(childGroup.getChildRef(), QName.createQName(CCConstants.CCM_PROP_GROUPEXTENSION_GROUPTYPE)); + if(CCConstants.ADMINISTRATORS_GROUP_TYPE.equals(grouptype)){ + return (String)nodeService.getProperty(childGroup.getChildRef(), QName.createQName(CCConstants.CM_PROP_AUTHORITY_AUTHORITYNAME)); + } } } }