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;
}
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;
}
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;
}
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());
}
}
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);
}
Aggregations