Search in sources :

Example 11 with NodeVersionId

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

the class NodeStorageServiceImplTest method testGetNode_ByPath.

@Test
public void testGetNode_ByPath() {
    final NodeBranchEntry nodeBranchEntry = NodeBranchEntry.create().nodeId(nodeId).nodePath(nodePath).nodeState(NodeState.DEFAULT).build();
    final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
    final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
    when(branchService.get(any(NodePath.class), any(InternalContext.class))).thenReturn(nodeBranchEntry);
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
    final Node result = instance.getNode(nodePath, nodeVersionId, context);
    assertNotNull(result);
    verify(branchService, times(1)).get(any(NodePath.class), any(InternalContext.class));
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(branchService, versionService, nodeVersionService);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 12 with NodeVersionId

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

the class GetContentByIdAndVersionIdCommand method execute.

public Content execute() {
    final NodeId nodeId = NodeId.from(contentId.toString());
    final NodeVersionId nodeVersionId = NodeVersionId.from(versionId.toString());
    try {
        return getContentByIdAndVersionId(nodeId, nodeVersionId);
    } catch (NodeNotFoundException e) {
        throw createContentNotFoundException();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeId(com.enonic.xp.node.NodeId)

Example 13 with NodeVersionId

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

the class NodeServiceImpl method setActiveVersion.

@Override
public NodeVersionId setActiveVersion(final NodeId nodeId, final NodeVersionId nodeVersionId) {
    verifyContext();
    final NodeVersionId result = SetActiveVersionCommand.create().nodeVersionId(nodeVersionId).nodeId(nodeId).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute();
    final Node node = this.getById(nodeId);
    if (node != null) {
        this.eventPublisher.publish(NodeEvents.updated(node));
    }
    return result;
}
Also used : RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionId(com.enonic.xp.node.NodeVersionId) Node(com.enonic.xp.node.Node)

Example 14 with NodeVersionId

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

the class DumpServiceImplTest method loadWithUpgrade.

@Test
public void loadWithUpgrade() throws Exception {
    final String dumpName = "testDump";
    createIncompatibleDump(dumpName);
    NodeHelper.runAsAdmin(() -> {
        this.dumpService.load(SystemLoadParams.create().dumpName(dumpName).upgrade(true).includeVersions(true).build());
        FileDumpReader reader = FileDumpReader.create(null, temporaryFolder, dumpName);
        final DumpMeta updatedMeta = reader.getDumpMeta();
        assertEquals(DumpConstants.MODEL_VERSION, updatedMeta.getModelVersion());
        final NodeId nodeId = NodeId.from("f0fb822c-092d-41f9-a961-f3811d81e55a");
        final NodeId fragmentNodeId = NodeId.from("7ee16649-85c6-4a76-8788-74be03be6c7a");
        final NodeId postNodeId = NodeId.from("1f798176-5868-411b-8093-242820c20620");
        final NodePath nodePath = NodePath.create("/content/mysite").build();
        final NodeVersionId draftNodeVersionId = NodeVersionId.from("f3765655d5f0c7c723887071b517808dae00556c");
        final NodeVersionId masterNodeVersionId = NodeVersionId.from("02e61f29a57309834d96bbf7838207ac456bbf5c");
        ContextBuilder.from(ContextAccessor.current()).repositoryId("com.enonic.cms.default").build().runWith(() -> {
            final Node draftNode = nodeService.getById(nodeId);
            assertNotNull(draftNode);
            assertEquals(draftNodeVersionId, draftNode.getNodeVersionId());
            assertEquals(nodePath, draftNode.path());
            assertEquals("2019-02-20T14:44:06.883Z", draftNode.getTimestamp().toString());
            final Node masterNode = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("master")).build().callWith(() -> nodeService.getById(nodeId));
            assertNotNull(masterNode);
            assertEquals(masterNodeVersionId, masterNode.getNodeVersionId());
            assertEquals(nodePath, masterNode.path());
            assertEquals("2018-11-23T11:14:21.662Z", masterNode.getTimestamp().toString());
            checkCommitUpgrade(nodeId);
            checkPageFlatteningUpgradePage(draftNode);
            final Node fragmentNode = nodeService.getById(fragmentNodeId);
            checkPageFlatteningUpgradeFragment(fragmentNode);
            checkRepositoryUpgrade(updatedMeta);
            final Node postNode = nodeService.getById(postNodeId);
            checkHtmlAreaUpgrade(draftNode, postNode);
            checkLanguageUpgrade(draftNode);
        });
    });
}
Also used : DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) NodeVersionId(com.enonic.xp.node.NodeVersionId) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath) FileDumpReader(com.enonic.xp.repo.impl.dump.reader.FileDumpReader) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 15 with NodeVersionId

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

the class NodeStorageServiceImpl method move.

@Override
public Node move(final StoreMovedNodeParams params, final InternalContext context) {
    final NodeVersionKey nodeVersionKey;
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(params.getNode().id(), context);
    if (params.isUpdateMetadataOnly()) {
        nodeVersionKey = nodeBranchEntry.getNodeVersionKey();
    } else {
        nodeVersionKey = nodeVersionService.store(NodeVersion.from(params.getNode()), context);
    }
    NodeVersionId nodeVersionId = params.getNodeVersionId();
    if (nodeVersionId == null) {
        nodeVersionId = new NodeVersionId();
        storeVersionMetadata(params.getNode(), nodeVersionId, nodeVersionKey, context);
    }
    return moveInBranchAndReIndex(params.getNode(), nodeVersionId, nodeVersionKey, nodeBranchEntry.getNodePath(), context);
}
Also used : NodeVersionId(com.enonic.xp.node.NodeVersionId) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

NodeVersionId (com.enonic.xp.node.NodeVersionId)15 Node (com.enonic.xp.node.Node)10 NodeId (com.enonic.xp.node.NodeId)9 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)7 Test (org.junit.jupiter.api.Test)6 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)5 RoutableNodeVersionId (com.enonic.xp.node.RoutableNodeVersionId)5 InternalContext (com.enonic.xp.repo.impl.InternalContext)5 NodePath (com.enonic.xp.node.NodePath)4 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 NodeVersion (com.enonic.xp.node.NodeVersion)3 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)3 Branch (com.enonic.xp.branch.Branch)2 BlobKey (com.enonic.xp.blob.BlobKey)1 BlobStore (com.enonic.xp.blob.BlobStore)1 Segment (com.enonic.xp.blob.Segment)1 SegmentLevel (com.enonic.xp.blob.SegmentLevel)1 Content (com.enonic.xp.content.Content)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1