use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.
the class SecurityServiceImpl method createGroup.
@Override
public Group createGroup(final CreateGroupParams createGroup) {
final Group group = Group.create().key(createGroup.getKey()).displayName(createGroup.getDisplayName()).modifiedTime(Instant.now(clock)).description(createGroup.getDescription()).build();
final CreateNodeParams createGroupParams = PrincipalNodeTranslator.toCreateNodeParams(group);
try {
final Node node = callWithContext(() -> {
final Node createdNode = this.nodeService.create(createGroupParams);
this.nodeService.refresh(RefreshMode.SEARCH);
return createdNode;
});
securityAuditLogSupport.createGroup(createGroup);
return PrincipalNodeTranslator.groupFromNode(node);
} catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
throw new PrincipalAlreadyExistsException(createGroup.getKey());
}
}
use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.
the class CreateIssueCommand method doExecute.
private Issue doExecute() {
validateBlockingChecks();
final long index = countTotalIssues() + 1;
final IssueName issueName = IssueNameFactory.create(index);
final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(this.params, this.getCurrentUser(), index, issueName);
final Node createdNode;
try {
createdNode = nodeService.create(createNodeParams);
} catch (NodeAlreadyExistAtPathException e) {
throw new IssueAlreadyExistsException(IssueName.from(createNodeParams.getName()));
}
nodeService.refresh(RefreshMode.SEARCH);
return IssueNodeTranslator.fromNode(createdNode);
}
use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.
the class CreateIssueCommentCommand method doExecute.
private IssueComment doExecute() {
validateBlockingChecks();
final Node issueNode = nodeService.getById(NodeId.from(params.getIssue()));
final String commentName = IssueCommentNameFactory.create(params.getCreated());
final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(this.params, issueNode.name(), commentName);
final Node createdNode;
try {
createdNode = nodeService.create(createNodeParams);
} catch (NodeAlreadyExistAtPathException e) {
throw new IssueAlreadyExistsException(IssueName.from(createNodeParams.getName()));
}
nodeService.refresh(RefreshMode.SEARCH);
return IssueCommentNodeTranslator.fromNode(createdNode);
}
use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.
the class RenameContentCommandTest method test_already_exists.
@Test
void test_already_exists() {
Node mockNode = Node.create().id(NodeId.from("testId")).build();
final RepositoryId repositoryId = RepositoryId.from("some.repo");
final Branch branch = Branch.from("somebranch");
when(nodeService.rename(isA(RenameNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create("/content/mycontent2").build(), repositoryId, branch));
when(nodeService.getById(mockNode.id())).thenReturn(mockNode);
final Content content = createContent(true);
final RenameContentCommand command = createCommand(RenameContentParams.create().contentId(content.getId()).newName(ContentName.from("mycontent2")).build());
final ContentAlreadyExistsException exception = assertThrows(ContentAlreadyExistsException.class, command::execute);
assertEquals(branch, exception.getBranch());
assertEquals(repositoryId, exception.getRepositoryId());
}
use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.
the class DuplicateNodeCommand method execute.
public DuplicateNodeResult execute() {
final Node existingNode = doGetById(params.getNodeId());
if (existingNode == null) {
throw new NodeNotFoundException("Cannot duplicate node with id [" + params.getNodeId() + "]");
}
if (existingNode.isRoot()) {
throw new OperationNotPermittedException("Not allowed to duplicate root-node");
}
final CreateNodeParams.Builder createNodeParams = CreateNodeParams.from(existingNode);
attachBinaries(existingNode, createNodeParams);
Node duplicatedNode = null;
String newNodeName = existingNode.name().toString();
do {
try {
newNodeName = DuplicateValueResolver.name(newNodeName);
final CreateNodeParams processedParams = executeProcessors(createNodeParams.name(newNodeName).build());
duplicatedNode = CreateNodeCommand.create(this).params(processedParams).binaryService(binaryService).build().execute();
} catch (NodeAlreadyExistAtPathException e) {
// try again with other name
LOG.debug(String.format("[%s] node with [%s] parent already exist.", newNodeName, existingNode.parentPath().toString()), e);
}
} while (duplicatedNode == null);
result.node(duplicatedNode);
nodeDuplicated(1);
final NodeReferenceUpdatesHolder.Builder builder = NodeReferenceUpdatesHolder.create().add(existingNode.id(), duplicatedNode.id());
if (params.getIncludeChildren()) {
storeChildNodes(existingNode, duplicatedNode, builder);
}
final NodeReferenceUpdatesHolder nodesToBeUpdated = builder.build();
RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
updateNodeReferences(duplicatedNode, nodesToBeUpdated);
updateChildReferences(duplicatedNode, nodesToBeUpdated);
return result.build();
}
Aggregations