Search in sources :

Example 31 with NodeId

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

the class VersionTableVacuumCommand method findVersionsInBranches.

private BRANCH_CHECK_RESULT findVersionsInBranches(final Repository repository, final NodeVersionMetadata versionMetadata) {
    final NodeId nodeId = versionMetadata.getNodeId();
    final NodeVersionId versionId = versionMetadata.getNodeVersionId();
    boolean nodeFound = false;
    for (final Branch branch : repository.getBranches()) {
        try {
            final Node node = ContextBuilder.from(ContextAccessor.current()).branch(branch).repositoryId(repository.getId()).build().callWith(() -> this.nodeService.getById(nodeId));
            if (versionId.equals(node.getNodeVersionId())) {
                return BRANCH_CHECK_RESULT.SAME_VERSION_FOUND;
            }
            nodeFound = true;
        } catch (NodeNotFoundException e) {
        // Ignore
        }
    }
    return nodeFound ? BRANCH_CHECK_RESULT.OTHER_VERSION_FOUND : BRANCH_CHECK_RESULT.NO_VERSION_FOUND;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Example 32 with NodeId

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

the class DumpServiceImplTest method binaries_in_versions.

@Test
public void binaries_in_versions() throws Exception {
    final PropertyTree data = new PropertyTree();
    final BinaryReference binaryRef = BinaryReference.from("binaryRef");
    data.addBinaryReference("myBinary", binaryRef);
    final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myNode").data(data).attachBinary(binaryRef, ByteSource.wrap("this is binary data".getBytes())).build());
    final BinaryReference binaryRef2 = BinaryReference.from("anotherBinary");
    final Node updatedNode = updateNode(UpdateNodeParams.create().id(node.id()).editor(n -> n.data.setBinaryReference("myBinary", binaryRef2)).attachBinary(binaryRef2, ByteSource.wrap("anotherBinary".getBytes())).build());
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    final NodeVersionQueryResult versions = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    assertEquals(2, versions.getHits());
    verifyBinaries(node, updatedNode, versions);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) RepositoryIds(com.enonic.xp.repository.RepositoryIds) BranchDumpResult(com.enonic.xp.dump.BranchDumpResult) UpgradeListener(com.enonic.xp.upgrade.UpgradeListener) Version(com.enonic.xp.util.Version) RenameNodeCommand(com.enonic.xp.repo.impl.node.RenameNodeCommand) Branch(com.enonic.xp.branch.Branch) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) NodeCommitId(com.enonic.xp.node.NodeCommitId) RepositoryId(com.enonic.xp.repository.RepositoryId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) ContextBuilder(com.enonic.xp.context.ContextBuilder) URI(java.net.URI) Bundle(org.osgi.framework.Bundle) SystemConstants(com.enonic.xp.security.SystemConstants) Path(java.nio.file.Path) BinaryReference(com.enonic.xp.util.BinaryReference) FileDumpReader(com.enonic.xp.repo.impl.dump.reader.FileDumpReader) Pre5ContentConstants(com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre5.Pre5ContentConstants) ImmutableMap(com.google.common.collect.ImmutableMap) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Assertions.assertIterableEquals(org.junit.jupiter.api.Assertions.assertIterableEquals) Predicate(java.util.function.Predicate) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) BundleContext(org.osgi.framework.BundleContext) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) List(java.util.List) Repositories(com.enonic.xp.repository.Repositories) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) NodeVersion(com.enonic.xp.node.NodeVersion) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) SystemDumpParams(com.enonic.xp.dump.SystemDumpParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Repository(com.enonic.xp.repository.Repository) Mockito.mock(org.mockito.Mockito.mock) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) SystemDumpListener(com.enonic.xp.dump.SystemDumpListener) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) IndexConfig(com.enonic.xp.index.IndexConfig) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) TreeSet(java.util.TreeSet) RepoLoadResult(com.enonic.xp.dump.RepoLoadResult) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionIds(com.enonic.xp.node.NodeVersionIds) ImmutableList(com.google.common.collect.ImmutableList) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) RepoDumpResult(com.enonic.xp.dump.RepoDumpResult) StreamSupport(java.util.stream.StreamSupport) PropertyPath(com.enonic.xp.data.PropertyPath) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) DumpUpgradeResult(com.enonic.xp.dump.DumpUpgradeResult) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) InternalContext(com.enonic.xp.repo.impl.InternalContext) PropertySet(com.enonic.xp.data.PropertySet) NodePath(com.enonic.xp.node.NodePath) SystemLoadListener(com.enonic.xp.dump.SystemLoadListener) Mockito.when(org.mockito.Mockito.when) Branches(com.enonic.xp.branch.Branches) SystemDumpUpgradeParams(com.enonic.xp.dump.SystemDumpUpgradeParams) UpdateRepositoryEntryParams(com.enonic.xp.repo.impl.repository.UpdateRepositoryEntryParams) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) NodeName(com.enonic.xp.node.NodeName) Reference(com.enonic.xp.util.Reference) SystemLoadParams(com.enonic.xp.dump.SystemLoadParams) DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) VersionsLoadResult(com.enonic.xp.dump.VersionsLoadResult) NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 33 with NodeId

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

the class MoveNodeCommandTest method move_to_manually_ordered_parent.

@Test
public void move_to_manually_ordered_parent() throws Exception {
    final Node originalRoot = createNode(NodePath.ROOT, "a1");
    final Node a1_1 = createNode(originalRoot.path(), "a1_1");
    final Node a1_2 = createNode(originalRoot.path(), "a1_2");
    final Node newParent = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("a2").childOrder(ChildOrder.manualOrder()).build());
    final Node a2_1 = createNode(newParent.path(), "a2_1");
    final Node a2_2 = createNode(newParent.path(), "a2_2");
    doMoveNode(newParent.path(), a1_1.id());
    doMoveNode(newParent.path(), a1_2.id());
    final FindNodesByParentResult result = findByParent(FindNodesByParentParams.create().parentId(newParent.id()).build());
    final Iterator<NodeId> iterator = result.getNodeIds().iterator();
    assertEquals(a1_2.id(), iterator.next());
    assertEquals(a1_1.id(), iterator.next());
    assertEquals(a2_2.id(), iterator.next());
    assertEquals(a2_1.id(), iterator.next());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 34 with NodeId

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

the class NodeServiceImplTest method testReorderChildren.

@Test
public void testReorderChildren() {
    final Node parent = createNode(CreateNodeParams.create().name("my-parent").parent(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).build());
    final Node child1 = createNode(CreateNodeParams.create().name("my-child-1").parent(parent.path()).build());
    final Node child2 = createNode(CreateNodeParams.create().name("my-child-2").parent(parent.path()).build());
    final Node child3 = createNode(CreateNodeParams.create().name("my-child-3").parent(parent.path()).build());
    final ReorderChildNodesParams params = ReorderChildNodesParams.create().add(ReorderChildNodeParams.create().nodeId(child1.id()).moveBefore(child2.id()).build()).add(ReorderChildNodeParams.create().nodeId(child3.id()).moveBefore(child1.id()).build()).processor(data -> {
        data.addString("processedValue", "value");
        return data;
    }).build();
    final ReorderChildNodesResult result = this.nodeService.reorderChildren(params);
    assertThat(result.getNodeIds()).containsExactly(child1.id(), child3.id());
    assertThat(result.getParentNodes().getIds()).containsExactly(parent.id());
    assertThat(nodeService.findByParent(FindNodesByParentParams.create().parentId(parent.id()).build()).getNodeIds()).containsExactly(child3.id(), child1.id(), child2.id());
    nodeService.refresh(RefreshMode.ALL);
    final Node processedParent = this.nodeService.getById(parent.id());
    assertEquals("value", processedParent.data().getString("processedValue"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Permission(com.enonic.xp.security.acl.Permission) NodeCommitId(com.enonic.xp.node.NodeCommitId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) ContextBuilder(com.enonic.xp.context.ContextBuilder) BinaryReference(com.enonic.xp.util.BinaryReference) User(com.enonic.xp.security.User) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) Node(com.enonic.xp.node.Node) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Test(org.junit.jupiter.api.Test)

Example 35 with NodeId

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

the class NodeServiceImplTest method test_duplicate_with_children.

@Test
public void test_duplicate_with_children() {
    final PropertyTree data = new PropertyTree();
    final Node node_1 = this.nodeService.create(CreateNodeParams.create().name("parent").parent(NodePath.ROOT).data(data).build());
    final Node node_1_2 = this.nodeService.create(CreateNodeParams.create().name("child").parent(node_1.path()).data(data).build());
    final Node node_1_2_3 = this.nodeService.create(CreateNodeParams.create().name("child_of_child").parent(node_1_2.path()).data(data).build());
    this.nodeService.refresh(RefreshMode.SEARCH);
    final Node duplicatedNode = this.nodeService.duplicate(DuplicateNodeParams.create().nodeId(node_1.id()).build());
    final NodeId node_1_2_dup_id = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(duplicatedNode.id()).build()).getNodeIds().first();
    final Node node_1_2_dup = this.nodeService.getById(node_1_2_dup_id);
    assertEquals(node_1_2.name(), node_1_2_dup.name());
    final NodeId node_1_2_3_dup_id = this.nodeService.findByParent(FindNodesByParentParams.create().parentPath(node_1_2_dup.path()).build()).getNodeIds().first();
    final Node node_1_2_3_dup = this.nodeService.getById(node_1_2_3_dup_id);
    assertEquals(node_1_2_3.name(), node_1_2_3_dup.name());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Aggregations

NodeId (com.enonic.xp.node.NodeId)91 Node (com.enonic.xp.node.Node)44 Test (org.junit.jupiter.api.Test)36 NodePath (com.enonic.xp.node.NodePath)23 InternalContext (com.enonic.xp.repo.impl.InternalContext)18 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)15 NodeIds (com.enonic.xp.node.NodeIds)14 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)11 Context (com.enonic.xp.context.Context)10 PropertyTree (com.enonic.xp.data.PropertyTree)10 Branch (com.enonic.xp.branch.Branch)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)9 NodeVersionId (com.enonic.xp.node.NodeVersionId)9 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)8 RefreshMode (com.enonic.xp.node.RefreshMode)8 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 Event (com.enonic.xp.event.Event)6 RenameNodeParams (com.enonic.xp.node.RenameNodeParams)6