Search in sources :

Example 1 with AssociationExistsException

use of org.alfresco.service.cmr.repository.AssociationExistsException 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)

Example 2 with AssociationExistsException

use of org.alfresco.service.cmr.repository.AssociationExistsException 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)

Aggregations

ArrayList (java.util.ArrayList)2 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 AssociationExistsException (org.alfresco.service.cmr.repository.AssociationExistsException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 QName (org.alfresco.service.namespace.QName)2 AssocChild (org.alfresco.rest.api.model.AssocChild)1 AssocTarget (org.alfresco.rest.api.model.AssocTarget)1 DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)1