Search in sources :

Example 6 with NodeAlreadyExistAtPathException

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());
    }
}
Also used : Group(com.enonic.xp.security.Group) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 7 with NodeAlreadyExistAtPathException

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);
}
Also used : IssueAlreadyExistsException(com.enonic.xp.issue.IssueAlreadyExistsException) IssueName(com.enonic.xp.issue.IssueName) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 8 with NodeAlreadyExistAtPathException

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);
}
Also used : IssueAlreadyExistsException(com.enonic.xp.issue.IssueAlreadyExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 9 with NodeAlreadyExistAtPathException

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());
}
Also used : Branch(com.enonic.xp.branch.Branch) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test)

Example 10 with NodeAlreadyExistAtPathException

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();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Aggregations

NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)12 Node (com.enonic.xp.node.Node)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)8 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)4 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 ContentAccessException (com.enonic.xp.content.ContentAccessException)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 IssueAlreadyExistsException (com.enonic.xp.issue.IssueAlreadyExistsException)2 NodeAccessException (com.enonic.xp.node.NodeAccessException)2 Test (org.junit.jupiter.api.Test)2 Branch (com.enonic.xp.branch.Branch)1 Content (com.enonic.xp.content.Content)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 MoveContentException (com.enonic.xp.content.MoveContentException)1 MoveContentsResult (com.enonic.xp.content.MoveContentsResult)1 IssueName (com.enonic.xp.issue.IssueName)1 ApplyNodePermissionsParams (com.enonic.xp.node.ApplyNodePermissionsParams)1 MoveNodeException (com.enonic.xp.node.MoveNodeException)1