catch(Exception e){
throw new DotDataException(e.getMessage());
}
deleteRelatedContent(contentlet, related.getRelationship(), related.isHasParent(), user, respectFrontendRoles);
Tree newTree = null;
Set<Tree> uniqueRelationshipSet = new HashSet<Tree>();
Relationship rel = related.getRelationship();
List<Contentlet> conRels = RelationshipFactory.getAllRelationshipRecords(related.getRelationship(), contentlet, related.isHasParent());
int treePosition = (conRels != null && conRels.size() != 0) ? conRels.size() : 1 ;
int positionInParent = 1;
for (Contentlet c : related.getRecords()) {
if (child) {
newTree = new Tree(c.getIdentifier(), contentlet.getIdentifier(), rel.getRelationTypeValue(), positionInParent);
} else {
newTree = new Tree(contentlet.getIdentifier(), c.getIdentifier(), rel.getRelationTypeValue(), treePosition);
}
positionInParent=positionInParent+1;
if( uniqueRelationshipSet.add(newTree) ) {
int newTreePosistion = newTree.getTreeOrder();
Tree treeToUpdate = TreeFactory.getTree(newTree);
treeToUpdate.setTreeOrder(newTreePosistion);
if(treeToUpdate != null && UtilMethods.isSet(treeToUpdate.getRelationType()))
TreeFactory.saveTree(treeToUpdate);
else
TreeFactory.saveTree(newTree);
treePosition++;