Search in sources :

Example 1 with DuplicateChildNodeNameException

use of org.alfresco.service.cmr.repository.DuplicateChildNodeNameException 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 2 with DuplicateChildNodeNameException

use of org.alfresco.service.cmr.repository.DuplicateChildNodeNameException 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 3 with DuplicateChildNodeNameException

use of org.alfresco.service.cmr.repository.DuplicateChildNodeNameException in project acs-community-packaging by Alfresco.

the class ImportDialog method performImport.

/**
 * Performs the import operation using the current state of the bean
 *
 * @return The outcome
 */
public String performImport(final FacesContext context, String outcome) {
    if (logger.isDebugEnabled())
        logger.debug("Called import for file: " + this.file);
    if (this.file != null && this.file.exists()) {
        // check the file actually has contents
        if (this.file.length() > 0) {
            try {
                RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
                RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

                    public Object execute() throws Throwable {
                        // first of all we need to add the uploaded ACP/ZIP file to the repository
                        NodeRef acpNodeRef = addFileToRepository(context);
                        // build the action params map based on the bean's current state
                        Map<String, Serializable> params = new HashMap<String, Serializable>(2, 1.0f);
                        params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, browseBean.getActionSpace().getNodeRef());
                        params.put(ImporterActionExecuter.PARAM_ENCODING, encoding);
                        // build the action to execute
                        Action action = getActionService().createAction(ImporterActionExecuter.NAME, params);
                        if (action instanceof ImporterActionExecuter) {
                            ((ImporterActionExecuter) action).setHighByteZip(highByteZip);
                        }
                        action.setExecuteAsynchronously(runInBackground);
                        // execute the action on the ACP file
                        getActionService().executeAction(action, acpNodeRef);
                        if (logger.isDebugEnabled()) {
                            logger.debug("Executed import action with action params of " + params);
                        }
                        return null;
                    }
                };
                txnHelper.doInTransaction(callback);
                // reset the bean
                reset();
            } catch (Throwable e) {
                if (e instanceof DuplicateChildNodeNameException) {
                    String name = ((DuplicateChildNodeNameException) e).getName();
                    String err_mess = MessageFormat.format(I18NUtil.getMessage(ERR_DUPLICATE_NAME), name);
                    Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), err_mess), e);
                } else {
                    Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), e.toString()), e);
                }
                outcome = null;
                ReportedException.throwIfNecessary(e);
            }
        } else {
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_EMPTY_FILE));
            outcome = null;
        }
    } else {
        Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_NO_FILE));
        outcome = null;
    }
    return outcome;
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) HashMap(java.util.HashMap) ImporterActionExecuter(org.alfresco.repo.action.executer.ImporterActionExecuter) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 4 with DuplicateChildNodeNameException

use of org.alfresco.service.cmr.repository.DuplicateChildNodeNameException 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 5 with DuplicateChildNodeNameException

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

Aggregations

DuplicateChildNodeNameException (org.alfresco.service.cmr.repository.DuplicateChildNodeNameException)6 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)5 QName (org.alfresco.service.namespace.QName)5 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ImporterActionExecuter (org.alfresco.repo.action.executer.ImporterActionExecuter)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 AssocChild (org.alfresco.rest.api.model.AssocChild)1 NodePermissions (org.alfresco.rest.api.model.NodePermissions)1 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)1 Action (org.alfresco.service.cmr.action.Action)1 ActivityInfo (org.alfresco.service.cmr.activities.ActivityInfo)1 AssociationExistsException (org.alfresco.service.cmr.repository.AssociationExistsException)1