Merged 5.2.N (5.2.2) to HEAD (5.2)

134418 cturlica: REPO-1303: Update a group
      - added update group capabilities.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137346 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrei Rebegea
2017-06-14 16:57:46 +00:00
parent b74efb3846
commit c708379824
7 changed files with 170 additions and 10 deletions

View File

@@ -58,6 +58,21 @@ public interface Groups
*/
Group create(Group group, Parameters parameters);
/**
* Update the given group. Not all fields are used, only those as defined in
* the Open API spec.
*
* @param groupId
* the group ID
* @param group
* details to use for the update
* @param parameters
* the {@link Parameters} object to get the parameters passed
* into the request including: - include param (parentIds, zones)
* @return Updated group
*/
Group update(String groupId, Group group, Parameters parameters);
/**
* Get a group by it's id.
*

View File

@@ -47,7 +47,8 @@ import java.util.List;
* @author cturlica
*/
@EntityResource(name = "groups", title = "Groups")
public class GroupsEntityResource implements EntityResourceAction.Read<Group>, EntityResourceAction.ReadById<Group>, EntityResourceAction.Create<Group>, InitializingBean
public class GroupsEntityResource
implements EntityResourceAction.Read<Group>, EntityResourceAction.ReadById<Group>, EntityResourceAction.Create<Group>, EntityResourceAction.Update<Group>, InitializingBean
{
private Groups groups;
@@ -86,4 +87,11 @@ public class GroupsEntityResource implements EntityResourceAction.Read<Group>, E
result.add(groups.create(entity.get(0), parameters));
return result;
}
@Override
@WebApiDescription(title = "Update group", description = "Update group")
public Group update(String groupId, Group group, Parameters parameters)
{
return groups.update(groupId, group, parameters);
}
}

View File

@@ -114,7 +114,7 @@ public class GroupsImpl implements Groups
public Group create(Group group, Parameters parameters)
{
validateGroup(group);
validateGroup(group, false);
// Create authority with default zones.
final Set<String> authorityZones = authorityService.getDefaultZones();
@@ -136,6 +136,16 @@ public class GroupsImpl implements Groups
return getGroup(authority, parameters);
}
public Group update(String groupId, Group group, Parameters parameters)
{
validateGroupId(groupId);
validateGroup(group, true);
authorityService.setAuthorityDisplayName(groupId, group.getDisplayName());
return getGroup(groupId, parameters);
}
public Group getGroup(String groupId, Parameters parameters) throws EntityNotFoundException
{
AuthorityInfo authorityInfo = getAuthorityInfo(groupId);
@@ -649,21 +659,46 @@ public class GroupsImpl implements Groups
}
}
private void validateGroup(Group group)
private void validateGroup(Group group, boolean isUpdate)
{
if (group == null)
{
throw new InvalidArgumentException("group is null");
}
if (group.getId() == null || group.getId().isEmpty())
if (!isUpdate)
{
throw new InvalidArgumentException("groupId is null or empty");
}
if (group.getId() == null || group.getId().isEmpty())
{
throw new InvalidArgumentException("groupId is null or empty");
}
if (groupAuthorityExists(group.getId()))
if (groupAuthorityExists(group.getId()))
{
throw new ConstraintViolatedException("Group '" + group.getId() + "' already exists.");
}
}
else
{
throw new ConstraintViolatedException("Group '" + group.getId() + "' already exists.");
if (group.wasSet(Group.ID))
{
throw new InvalidArgumentException("Group update does not support field: id");
}
if (group.wasSet(Group.IS_ROOT))
{
throw new InvalidArgumentException("Group update does not support field: isRoot");
}
if (group.wasSet(Group.PARENT_IDS))
{
throw new InvalidArgumentException("Group update does not support field: parentIds");
}
if (group.wasSet(Group.ZONES))
{
throw new InvalidArgumentException("Group update does not support field: zones");
}
}
}

View File

@@ -25,6 +25,8 @@
*/
package org.alfresco.rest.api.model;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.rest.framework.resource.UniqueId;
@@ -44,6 +46,14 @@ public class Group implements Comparable<Group>
protected Set<String> parentIds;
protected Set<String> zones;
private Map<String, Boolean> setFields = new HashMap<>(7);
public static final String ID = "id";
public static final String DISPLAY_NAME = "displayName";
public static final String IS_ROOT = "isRoot";
public static final String PARENT_IDS = "parentIds";
public static final String ZONES = "zones";
public Group()
{
}
@@ -57,6 +67,7 @@ public class Group implements Comparable<Group>
public void setId(String id)
{
this.id = id;
setFields.put(ID, true);
}
public String getDisplayName()
@@ -67,6 +78,7 @@ public class Group implements Comparable<Group>
public void setDisplayName(String displayName)
{
this.displayName = displayName;
setFields.put(DISPLAY_NAME, true);
}
public Boolean getIsRoot()
@@ -77,6 +89,7 @@ public class Group implements Comparable<Group>
public void setIsRoot(Boolean isRoot)
{
this.isRoot = isRoot;
setFields.put(IS_ROOT, true);
}
public Set<String> getParentIds()
@@ -87,6 +100,7 @@ public class Group implements Comparable<Group>
public void setParentIds(Set<String> parentIds)
{
this.parentIds = parentIds;
setFields.put(PARENT_IDS, true);
}
public Set<String> getZones()
@@ -97,6 +111,7 @@ public class Group implements Comparable<Group>
public void setZones(Set<String> zones)
{
this.zones = zones;
setFields.put(ZONES, true);
}
@Override
@@ -141,4 +156,10 @@ public class Group implements Comparable<Group>
{
return "Group [id=" + id + ", displayName=" + displayName + ", isRoot=" + isRoot + "]";
}
public boolean wasSet(String fieldName)
{
Boolean b = setFields.get(fieldName);
return (b != null ? b : false);
}
}