Search in sources :

Example 1 with ConstraintViolatedException

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);
}
Also used : AuthorityType(org.alfresco.service.cmr.security.AuthorityType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 2 with ConstraintViolatedException

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);
}
Also used : AuthorityType(org.alfresco.service.cmr.security.AuthorityType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 3 with ConstraintViolatedException

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());
    }
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 4 with ConstraintViolatedException

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);
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 5 with ConstraintViolatedException

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;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Aggregations

ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)36 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)20 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)16 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)12 QName (org.alfresco.service.namespace.QName)10 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)9 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)6 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)5 ArrayList (java.util.ArrayList)4 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)4 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)4 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)3 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3 CustomAspect (org.alfresco.rest.api.model.CustomAspect)3 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)3 AuthorityType (org.alfresco.service.cmr.security.AuthorityType)3