Search in sources :

Example 11 with ConstraintViolatedException

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

the class NodesImpl method createNodeImpl.

private NodeRef createNodeImpl(NodeRef parentNodeRef, String nodeName, QName nodeTypeQName, Map<QName, Serializable> props, QName assocTypeQName) {
    NodeRef newNode = null;
    if (props == null) {
        props = new HashMap<>(1);
    }
    props.put(ContentModel.PROP_NAME, nodeName);
    validatePropValues(props);
    QName assocQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
    try {
        newNode = nodeService.createNode(parentNodeRef, assocTypeQName, assocQName, nodeTypeQName, props).getChildRef();
    } catch (DuplicateChildNodeNameException dcne) {
        // duplicate - name clash
        throw new ConstraintViolatedException(dcne.getMessage());
    }
    ActivityInfo activityInfo = getActivityInfo(parentNodeRef, newNode);
    postActivity(Activity_Type.ADDED, activityInfo, false);
    return newNode;
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ActivityInfo(org.alfresco.service.cmr.activities.ActivityInfo) QName(org.alfresco.service.namespace.QName) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 12 with ConstraintViolatedException

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

the class NodesImpl method addChildren.

public List<AssocChild> addChildren(String parentNodeId, List<AssocChild> entities) {
    NodeRef parentNodeRef = validateNode(parentNodeId);
    List<AssocChild> result = new ArrayList<>(entities.size());
    for (AssocChild assoc : entities) {
        String childId = assoc.getChildId();
        if (childId == null) {
            throw new InvalidArgumentException("Missing childId");
        }
        QName assocTypeQName = getAssocType(assoc.getAssocType());
        try {
            NodeRef childNodeRef = validateNode(childId);
            String nodeName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
            QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
            nodeService.addChild(parentNodeRef, childNodeRef, assocTypeQName, assocChildQName);
        } catch (AssociationExistsException aee) {
            throw new ConstraintViolatedException(aee.getMessage());
        } catch (DuplicateChildNodeNameException dcne) {
            throw new ConstraintViolatedException(dcne.getMessage());
        }
        result.add(assoc);
    }
    return result;
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) AssocChild(org.alfresco.rest.api.model.AssocChild) ArrayList(java.util.ArrayList) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 13 with ConstraintViolatedException

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

the class PeopleImpl method create.

@Override
public Person create(Person person) {
    validateCreatePersonData(person);
    if (!isAdminAuthority()) {
        // hence next block would cause 409 to be returned)
        throw new PermissionDeniedException();
    }
    // no sensible way to know that it was thrown due to the user already existing - hence this check here.
    if (personService.personExists(person.getUserName())) {
        throw new ConstraintViolatedException("Person '" + person.getUserName() + "' already exists.");
    }
    // set enabled default value true
    if (person.isEnabled() == null) {
        person.setEnabled(true);
    }
    Map<QName, Serializable> props = person.toProperties();
    MutableAuthenticationService mas = (MutableAuthenticationService) authenticationService;
    mas.createAuthentication(person.getUserName(), person.getPassword().toCharArray());
    mas.setAuthenticationEnabled(person.getUserName(), person.isEnabled());
    // Add custom properties
    if (person.getProperties() != null) {
        Map<String, Object> customProps = person.getProperties();
        props.putAll(nodes.mapToNodeProperties(customProps));
    }
    NodeRef nodeRef = personService.createPerson(props);
    // Add custom aspects
    nodes.addCustomAspects(nodeRef, person.getAspectNames(), EXCLUDED_ASPECTS);
    // and store the content URL in ContentModel.PROP_PERSONDESC
    if (person.getDescription() != null) {
        savePersonDescription(person.getDescription(), nodeRef);
    }
    // Return a fresh retrieval
    return getPerson(person.getUserName());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 14 with ConstraintViolatedException

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

the class QuickShareLinksImpl method create.

/**
 * Create quick share.
 * <p>
 * Requires authenticated access.
 *
 * @param nodeIds
 * @param parameters
 * @return
 */
public List<QuickShareLink> create(List<QuickShareLink> nodeIds, Parameters parameters) {
    checkEnabled();
    List<QuickShareLink> result = new ArrayList<>(nodeIds.size());
    List<String> includeParam = parameters != null ? parameters.getInclude() : Collections.<String>emptyList();
    for (QuickShareLink qs : nodeIds) {
        String nodeId = qs.getNodeId();
        if (nodeId == null) {
            throw new InvalidArgumentException("A valid nodeId must be specified !");
        }
        NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
        try {
            // Note: will throw InvalidNodeRefException (=> 404) if node does not exist
            String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
            if (sharedId != null) {
                throw new ConstraintViolatedException("sharedId already exists: " + nodeId + " [" + sharedId + "]");
            }
            // Note: since we already check node exists above, we can assume that InvalidNodeRefException (=> 404) here means not content (see type check)
            try {
                QuickShareDTO qsDto = quickShareService.shareContent(nodeRef, qs.getExpiresAt());
                result.add(getQuickShareInfo(qsDto.getId(), false, includeParam));
            } catch (InvalidNodeRefException inre) {
                throw new InvalidArgumentException("Unable to create shared link to non-file content: " + nodeId);
            } catch (QuickShareLinkExpiryActionException ex) {
                throw new InvalidArgumentException(ex.getMessage());
            }
        } catch (AccessDeniedException ade) {
            throw new PermissionDeniedException("Unable to create shared link to node that does not exist: " + nodeId);
        } catch (InvalidNodeRefException inre) {
            logger.warn("Unable to create shared link: [" + nodeRef + "]");
            throw new EntityNotFoundException(nodeId);
        }
    }
    return result;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) ArrayList(java.util.ArrayList) QuickShareLinkExpiryActionException(org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QuickShareDTO(org.alfresco.service.cmr.quickshare.QuickShareDTO) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Example 15 with ConstraintViolatedException

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

the class SitesImpl method createSite.

/**
 * Create default/fixed preset (Share) site - with DocLib container/component
 *
 * @param site
 * @return
 */
public Site createSite(Site site, Parameters parameters) {
    // note: if site id is null then will be generated from the site title
    site = validateSite(site);
    SiteInfo siteInfo = null;
    try {
        siteInfo = createSite(site);
    } catch (SiteServiceException sse) {
        if (sse.getMsgId().equals("site_service.unable_to_create")) {
            throw new ConstraintViolatedException(sse.getMessage());
        } else {
            throw sse;
        }
    }
    String siteId = siteInfo.getShortName();
    NodeRef siteNodeRef = siteInfo.getNodeRef();
    // default false (if not provided)
    boolean skipShareSurfConfig = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_SURF_CONFIGURATION));
    if (skipShareSurfConfig == false) {
        // import default/fixed preset Share surf config
        importSite(siteId, siteNodeRef);
    }
    // pre-create doclib
    siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
    // default false (if not provided)
    boolean skipAddToFavorites = Boolean.valueOf(parameters.getParameter(PARAM_SKIP_ADDTOFAVORITES));
    if (skipAddToFavorites == false) {
        String personId = AuthenticationUtil.getFullyAuthenticatedUser();
        // ignore result
        favouritesService.addFavourite(personId, siteNodeRef);
    }
    return getSite(siteInfo, true);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteServiceException(org.alfresco.repo.site.SiteServiceException) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) 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