From 1f72faa90c51e7b82f937bea911c2c826524c40d Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 17 Jan 2024 09:14:58 +0100 Subject: [PATCH] ACS-5506 Add proper exception handling --- .../alfresco/rest/api/impl/GroupsImpl.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 7c344cb551..e657e44357 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -71,6 +71,7 @@ import org.alfresco.rest.framework.resource.parameters.where.Query; import org.alfresco.rest.framework.resource.parameters.where.QueryHelper; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported; +import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AuthorityService; @@ -79,6 +80,7 @@ import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.util.AlfrescoCollator; import org.alfresco.util.Pair; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.extensions.surf.util.I18NUtil; @@ -613,12 +615,26 @@ public class GroupsImpl implements Groups group.setDisplayName(authorityDisplayName); group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); - group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); + + Set containedAuthorities; + try { + containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); + } catch (UnknownAuthorityException e) + { + containedAuthorities = Collections.emptySet(); + } + group.setHasSubgroups(CollectionUtils.isNotEmpty(containedAuthorities)); NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); - String description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? - nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : - null; + String description; + try { + description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? + nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : + null; + } catch (InvalidNodeRefException e) + { + description = null; + } group.setDescription(description); // Optionally include