From 5706e129f912a47b00356376024b997366151138 Mon Sep 17 00:00:00 2001 From: Andrei Rebegea Date: Wed, 14 Jun 2017 16:56:49 +0000 Subject: [PATCH] Merged 5.2.N (5.2.2) to HEAD (5.2) 134395 cturlica: REPO-1304: Create a group - updated error message when creating a group with the same name git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137339 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/rest/api/impl/GroupsImpl.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/rest/api/impl/GroupsImpl.java b/source/java/org/alfresco/rest/api/impl/GroupsImpl.java index 58489c39a9..4a682ba7c4 100644 --- a/source/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/source/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -49,6 +49,7 @@ import org.alfresco.rest.antlr.WhereClauseParser; import org.alfresco.rest.api.Groups; import org.alfresco.rest.api.model.Group; import org.alfresco.rest.api.model.GroupMember; +import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; @@ -588,7 +589,7 @@ public class GroupsImpl implements Groups throw new InvalidArgumentException("groupId is null or empty"); } - if (!authorityService.authorityExists(groupId)) + if (!groupAuthorityExists(groupId)) { throw new EntityNotFoundException(groupId); } @@ -605,5 +606,22 @@ public class GroupsImpl implements Groups { throw new InvalidArgumentException("groupId is null or empty"); } + + if (groupAuthorityExists(group.getId())) + { + throw new ConstraintViolatedException("Group '" + group.getId() + "' already exists."); + } + } + + private boolean groupAuthorityExists(String shortName) + { + return authorityExists(AuthorityType.GROUP, shortName); + } + + private boolean authorityExists(AuthorityType authorityType, String shortName) + { + String name = authorityService.getName(authorityType, shortName); + + return (name != null && authorityService.authorityExists(name)); } }