Search in sources :

Example 11 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)

Example 12 with NodeAlreadyExistAtPathException

use of com.enonic.xp.node.NodeAlreadyExistAtPathException in project xp by enonic.

the class SchedulerServiceActivatorTest method initWithExistJob.

@Test
void initWithExistJob() {
    final CreateScheduledJobParams jobParams = CreateScheduledJobParams.create().name(ScheduledJobName.from("name")).descriptor(DescriptorKey.from("appKey:descriptorName")).calendar(calendarService.cron("* * * * *", TimeZone.getDefault())).config(new PropertyTree()).build();
    when(schedulerConfig.jobs()).thenReturn(Set.of(jobParams));
    when(nodeService.create(isA(CreateNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create(NodePath.ROOT, jobParams.getName().getValue()).build(), RepositoryId.from("repo"), Branch.from("branch")));
    activator.activate(bundleContext);
    verify(nodeService, times(1)).create(isA(CreateNodeParams.class));
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) PropertyTree(com.enonic.xp.data.PropertyTree) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

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