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