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