use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class GroupsImpl method createGroupMember.
@Override
public GroupMember createGroupMember(String groupId, GroupMember groupMember) {
validateGroupId(groupId, false);
// Not allowed to modify a GROUP_EVERYONE member.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
}
validateGroupMember(groupMember);
AuthorityType authorityType = getAuthorityType(groupMember.getMemberType());
if (!authorityService.authorityExists(groupMember.getId())) {
throw new EntityNotFoundException(groupMember.getId());
}
AuthorityType existingAuthorityType = AuthorityType.getAuthorityType(groupMember.getId());
if (existingAuthorityType != authorityType) {
throw new IllegalArgumentException("Incorrect group member type, " + (AuthorityType.USER.equals(existingAuthorityType) ? Groups.PARAM_MEMBER_TYPE_PERSON : existingAuthorityType) + " exists with the given id");
}
authorityService.addAuthority(groupId, groupMember.getId());
String authority = authorityService.getName(authorityType, groupMember.getId());
return getGroupMember(authority);
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class GroupsImpl method deleteGroupMembership.
public void deleteGroupMembership(String groupId, String groupMemberId) {
validateGroupId(groupId, false);
// Not allowed to modify a GROUP_EVERYONE member.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
}
validateGroupMemberId(groupMemberId);
// Verify if groupMemberId is member of groupId
AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId);
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true);
if (!parents.contains(groupId)) {
throw new NotFoundException(groupMemberId + " is not member of " + groupId);
}
authorityService.removeAuthority(groupId, groupMemberId);
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project records-management by Alfresco.
the class FilePlanComponentsApiUtils method updateTransferContainer.
/**
* Utility method that updates a transfer container's name and properties
*
* @param nodeRef the node to update
* @param transferContainerInfo information to update the transfer container with
* @param parameters request parameters
*/
public void updateTransferContainer(NodeRef nodeRef, TransferContainer transferContainerInfo, Parameters parameters) {
Map<QName, Serializable> props = new HashMap<>(0);
if (transferContainerInfo.getProperties() != null) {
props = mapToNodeProperties(transferContainerInfo.getProperties());
}
String name = transferContainerInfo.getName();
if ((name != null) && (!name.isEmpty())) {
// update node name if needed
props.put(ContentModel.PROP_NAME, name);
}
try {
// update node properties - note: null will unset the specified property
nodeService.addProperties(nodeRef, props);
} catch (DuplicateChildNodeNameException dcne) {
throw new ConstraintViolatedException(dcne.getMessage());
}
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project records-management by Alfresco.
the class FilePlanComponentsApiUtils method updateNode.
/**
* Utility method that updates a node's name and properties
* @param nodeRef the node to update
* @param updateInfo information to update the record with
* @param parameters request parameters
*/
public void updateNode(NodeRef nodeRef, RMNode updateInfo, Parameters parameters) {
Map<QName, Serializable> props = new HashMap<>(0);
if (updateInfo.getProperties() != null) {
props = mapToNodeProperties(updateInfo.getProperties());
}
String name = updateInfo.getName();
if ((name != null) && (!name.isEmpty())) {
// update node name if needed
props.put(ContentModel.PROP_NAME, name);
}
try {
// update node properties - note: null will unset the specified property
nodeService.addProperties(nodeRef, props);
} catch (DuplicateChildNodeNameException dcne) {
throw new ConstraintViolatedException(dcne.getMessage());
}
// update aspects
List<String> aspectNames = updateInfo.getAspectNames();
nodes.updateCustomAspects(nodeRef, aspectNames, ApiNodesModelFactory.EXCLUDED_ASPECTS);
}
use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.
the class SitesImpl method addSiteMember.
public SiteMember addSiteMember(String siteId, SiteMember siteMember) {
String personId = people.validatePerson(siteMember.getPersonId());
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
logger.debug("addSiteMember: site does not exist " + siteId + " person " + personId);
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
String role = siteMember.getRole();
if (role == null) {
logger.debug("addSiteMember: Must provide a role " + siteMember);
throw new InvalidArgumentException("Must provide a role");
}
if (siteService.isMember(siteId, personId)) {
logger.debug("addSiteMember: " + personId + " is already a member of site " + siteId);
throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
}
if (!siteService.canAddMember(siteId, personId, role)) {
logger.debug("addSiteMember: PermissionDeniedException " + siteId + " person " + personId + " role " + role);
throw new PermissionDeniedException();
}
try {
siteService.setMembership(siteId, personId, role);
} catch (UnknownAuthorityException e) {
logger.debug("addSiteMember: UnknownAuthorityException " + siteId + " person " + personId + " role " + role);
throw new InvalidArgumentException("Unknown role '" + role + "'");
}
return siteMember;
}
Aggregations