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
This commit is contained in:
Andrei Rebegea
2017-06-14 16:56:49 +00:00
parent c3748a5ba7
commit 5706e129f9

View File

@@ -49,6 +49,7 @@ import org.alfresco.rest.antlr.WhereClauseParser;
import org.alfresco.rest.api.Groups; import org.alfresco.rest.api.Groups;
import org.alfresco.rest.api.model.Group; import org.alfresco.rest.api.model.Group;
import org.alfresco.rest.api.model.GroupMember; 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.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; 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"); throw new InvalidArgumentException("groupId is null or empty");
} }
if (!authorityService.authorityExists(groupId)) if (!groupAuthorityExists(groupId))
{ {
throw new EntityNotFoundException(groupId); throw new EntityNotFoundException(groupId);
} }
@@ -605,5 +606,22 @@ public class GroupsImpl implements Groups
{ {
throw new InvalidArgumentException("groupId is null or empty"); 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));
} }
} }