Search in sources :

Example 6 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method validateTypeAspectParent.

private void validateTypeAspectParent(AbstractClassModel typeAspect, CustomModel existingModel) {
    String parentPrefixedName = typeAspect.getParentName();
    if (StringUtils.isBlank(parentPrefixedName)) {
        return;
    }
    Pair<String, String> prefixLocaNamePair = splitPrefixedQName(parentPrefixedName);
    String parentPrefix = prefixLocaNamePair.getFirst();
    String parentLocalName = prefixLocaNamePair.getSecond();
    // Validate parent prefix and localName
    // We know that the values are not null, we just check against the defined RegEx
    validateName(parentPrefix, null);
    validateName(parentLocalName, null);
    final boolean isAspect = (typeAspect instanceof CustomAspect);
    ClassDefinition classDefinition = null;
    QName qname = null;
    if (existingModel.getNamespacePrefix().equals(parentPrefix)) {
        // Check for types/aspects within the model
        qname = QName.createQName(existingModel.getNamespaceUri(), parentLocalName);
        classDefinition = (isAspect) ? customModelService.getCustomAspect(qname) : customModelService.getCustomType(qname);
    } else {
        // Make sure the namespace URI and Prefix are registered
        Pair<String, String> uriPrefixPair = resolveToUriAndPrefix(parentPrefixedName);
        qname = QName.createQName(uriPrefixPair.getFirst(), parentLocalName);
        classDefinition = (isAspect) ? dictionaryService.getAspect(qname) : dictionaryService.getType(qname);
    }
    if (classDefinition == null) {
        String msgId = (isAspect) ? "cmm.rest_api.aspect_parent_not_exist" : "cmm.rest_api.type_parent_not_exist";
        throw new ConstraintViolatedException(I18NUtil.getMessage(msgId, parentPrefixedName));
    } else {
        checkCircularDependency(classDefinition.getModel(), existingModel, parentPrefixedName);
    }
}
Also used : QName(org.alfresco.service.namespace.QName) CustomAspect(org.alfresco.rest.api.model.CustomAspect) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 7 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.

the class DeletedNodesImpl method restoreArchivedNode.

@Override
public Node restoreArchivedNode(String archivedId, NodeTargetAssoc nodeTargetAssoc) {
    // First check the node is valid and has been archived.
    NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
    RestoreNodeReport restored = null;
    if (nodeTargetAssoc != null) {
        NodeRef targetNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeTargetAssoc.getTargetParentId());
        QName assocType = nodes.getAssocType(nodeTargetAssoc.getAssocType());
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef, targetNodeRef, assocType, null);
    } else {
        restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
    }
    switch(restored.getStatus()) {
        case SUCCESS:
            return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
        case FAILURE_PERMISSION:
            throw new PermissionDeniedException();
        case FAILURE_INTEGRITY:
            throw new IntegrityException("Restore failed due to an integrity error", null);
        case FAILURE_DUPLICATE_CHILD_NODE_NAME:
            throw new ConstraintViolatedException("Name already exists in target");
        case FAILURE_INVALID_ARCHIVE_NODE:
            throw new EntityNotFoundException(archivedId);
        case FAILURE_INVALID_PARENT:
            throw new NotFoundException("Invalid parent id " + restored.getTargetParentNodeRef());
        default:
            throw new ApiException("Unable to restore node " + archivedId);
    }
}
Also used : RestoreNodeReport(org.alfresco.repo.node.archive.RestoreNodeReport) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 8 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 9 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 10 with ConstraintViolatedException

use of org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException in project alfresco-remote-api by Alfresco.

the class NodesImpl method addTargets.

public List<AssocTarget> addTargets(String sourceNodeId, List<AssocTarget> entities) {
    List<AssocTarget> result = new ArrayList<>(entities.size());
    NodeRef srcNodeRef = validateNode(sourceNodeId);
    for (AssocTarget assoc : entities) {
        String targetNodeId = assoc.getTargetId();
        if (targetNodeId == null) {
            throw new InvalidArgumentException("Missing targetId");
        }
        String assocTypeStr = assoc.getAssocType();
        QName assocTypeQName = getAssocType(assocTypeStr);
        try {
            NodeRef tgtNodeRef = validateNode(targetNodeId);
            nodeAssocService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
        } catch (AssociationExistsException aee) {
            throw new ConstraintViolatedException("Node association '" + assocTypeStr + "' already exists from " + sourceNodeId + " to " + targetNodeId);
        } catch (IllegalArgumentException iae) {
            // note: for now, we assume it is invalid assocType - alternatively, we could attempt to pre-validate via dictionary.getAssociation
            throw new InvalidArgumentException(sourceNodeId + "," + assocTypeStr + "," + targetNodeId);
        }
        result.add(assoc);
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) AssocTarget(org.alfresco.rest.api.model.AssocTarget) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Aggregations

ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)31 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)20 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)12 QName (org.alfresco.service.namespace.QName)10 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)7 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)7 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)7 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)4 CustomModelConstraintException (org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException)4 InvalidCustomModelException (org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException)4 AssociationExistsException (org.alfresco.service.cmr.repository.AssociationExistsException)4 ArrayList (java.util.ArrayList)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3 CustomModel (org.alfresco.rest.api.model.CustomModel)3 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)3 InsufficientStorageException (org.alfresco.rest.framework.core.exceptions.InsufficientStorageException)3