Search in sources :

Example 21 with NodeBranchEntry

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

the class ProjectServiceImplTest method create_in_non_master_node.

@Test
void create_in_non_master_node() {
    IndexServiceInternal indexServiceInternalMock = mock(IndexServiceInternal.class);
    when(indexServiceInternalMock.waitForYellowStatus()).thenReturn(true);
    indexService.setIndexServiceInternal(indexServiceInternalMock);
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    final Project project = adminContext().callWith(() -> doCreateProject(ProjectName.from(projectRepoId), null, true, null));
    assertNotNull(project);
    assertEquals("test-project", project.getName().toString());
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(Node.ROOT_UUID, InternalContext.create(adminContext()).repositoryId(projectRepoId).build());
    assertNotNull(nodeBranchEntry);
    adminContext().runWith(() -> {
        final Repository pro = repositoryService.get(projectRepoId);
        assertNotNull(pro);
    });
}
Also used : Project(com.enonic.xp.project.Project) Repository(com.enonic.xp.repository.Repository) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 22 with NodeBranchEntry

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

the class GetActiveNodeVersionsCommand method execute.

public GetActiveNodeVersionsResult execute() {
    final GetActiveNodeVersionsResult.Builder builder = GetActiveNodeVersionsResult.create();
    for (final Branch branch : branches) {
        final Context context = ContextAccessor.current();
        final NodeBranchEntry nodeBranchEntry = this.nodeStorageService.getBranchNodeVersion(this.nodeId, InternalContext.create(context).branch(branch).build());
        if (nodeBranchEntry != null) {
            builder.add(branch, this.nodeStorageService.getVersion(nodeBranchEntry.getNodeId(), nodeBranchEntry.getVersionId(), InternalContext.from(context)));
        }
    }
    return builder.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 23 with NodeBranchEntry

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

the class PushNodesCommand method pushNodes.

private InternalPushNodesResult.Builder pushNodes(final Context context, final NodeBranchEntries nodeBranchEntries, final NodeComparisons comparisons) {
    final PushNodeEntries.Builder publishBuilder = PushNodeEntries.create().targetBranch(this.target).targetRepo(context.getRepositoryId());
    final InternalPushNodesResult.Builder builder = InternalPushNodesResult.create();
    final ArrayList<NodeBranchEntry> list = new ArrayList<>(nodeBranchEntries.getSet());
    list.sort(Comparator.comparing(NodeBranchEntry::getNodePath));
    for (final NodeBranchEntry branchEntry : list) {
        final NodeComparison comparison = comparisons.get(branchEntry.getNodeId());
        final NodeBranchEntry nodeBranchEntry = nodeBranchEntries.get(comparison.getNodeId());
        final boolean hasPublishPermission = NodesHasPermissionResolver.create(this).nodeIds(NodeIds.from(nodeBranchEntry.getNodeId())).permission(Permission.PUBLISH).build().execute();
        if (!hasPublishPermission) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ACCESS_DENIED);
            nodePushed(1);
            continue;
        }
        if (comparison.getCompareStatus() == CompareStatus.EQUAL) {
            builder.addSuccess(nodeBranchEntry);
            nodePushed(1);
            continue;
        }
        if ((CompareStatus.NEW == comparison.getCompareStatus() || CompareStatus.MOVED == comparison.getCompareStatus()) && targetAlreadyExists(nodeBranchEntry.getNodePath(), comparisons, context)) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ALREADY_EXIST);
            nodePushed(1);
            continue;
        }
        if (!targetParentExists(nodeBranchEntry.getNodePath(), builder, context)) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.PARENT_NOT_FOUND);
            nodePushed(1);
            continue;
        }
        publishBuilder.add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry).currentTargetPath(comparison.getTargetPath()).build());
        builder.addSuccess(nodeBranchEntry);
        if (comparison.getCompareStatus() == CompareStatus.MOVED) {
            updateTargetChildrenMetaData(nodeBranchEntry, builder);
        }
    }
    final PushNodeEntries pushNodeEntries = publishBuilder.build();
    builder.setPushNodeEntries(pushNodeEntries);
    final InternalContext pushContext = InternalContext.create(context).skipConstraints(true).build();
    this.nodeStorageService.push(pushNodeEntries, pushListener, pushContext);
    return builder;
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) InternalContext(com.enonic.xp.repo.impl.InternalContext) ArrayList(java.util.ArrayList) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) PushNodeEntries(com.enonic.xp.node.PushNodeEntries)

Example 24 with NodeBranchEntry

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

the class PushNodesCommand method updateTargetChildrenMetaData.

private void updateTargetChildrenMetaData(final NodeBranchEntry nodeBranchEntry, PushNodesResult.Builder resultBuilder) {
    final Context context = ContextAccessor.current();
    final Context targetContext = ContextBuilder.create().authInfo(context.getAuthInfo()).branch(this.target).repositoryId(context.getRepositoryId()).build();
    final FindNodesByParentResult result = FindNodesByParentCommand.create(this).params(FindNodesByParentParams.create().parentPath(nodeBranchEntry.getNodePath()).childOrder(ChildOrder.from(NodeIndexPath.PATH + " asc")).build()).build().execute();
    final NodeBranchEntries childEntries = this.nodeStorageService.getBranchNodeVersions(result.getNodeIds(), false, InternalContext.from(ContextAccessor.current()));
    for (final NodeBranchEntry child : childEntries) {
        final NodeBranchEntry targetNodeEntry = this.nodeStorageService.getBranchNodeVersion(child.getNodeId(), InternalContext.from(targetContext));
        if (targetNodeEntry != null) {
            final Node childNode = GetNodeByIdCommand.create(this).id(child.getNodeId()).build().execute();
            this.nodeStorageService.move(StoreMovedNodeParams.create().nodeVersionId(child.getVersionId()).node(childNode).build(), InternalContext.from(targetContext));
            resultBuilder.addSuccess(child);
            updateTargetChildrenMetaData(child, resultBuilder);
        }
    }
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Example 25 with NodeBranchEntry

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

the class MoveNodeCommand method doMoveNode.

private Node doMoveNode(final NodePath newParentPath, final NodeName newNodeName, final NodeId id) {
    final Node persistedNode = doGetById(id);
    final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(persistedNode.path()).from(0).size(NodeSearchService.GET_ALL_SIZE_FLAG).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
    final NodeBranchEntries nodeBranchEntries = this.nodeStorageService.getBranchNodeVersions(NodeIds.from(result.getIds()), false, InternalContext.from(ContextAccessor.current()));
    final Node.Builder nodeToMoveBuilder = Node.create(persistedNode).name(newNodeName).data(processor.process(persistedNode.data())).parentPath(newParentPath).indexConfigDocument(persistedNode.getIndexConfigDocument()).timestamp(Instant.now(CLOCK));
    final Node movedNode;
    final boolean isTheOriginalMovedNode = persistedNode.id().equals(this.nodeId);
    if (isTheOriginalMovedNode) {
        final boolean isRenaming = newParentPath.equals(persistedNode.parentPath());
        if (!isRenaming) {
            updateStoredNodeProperties(newParentPath, nodeToMoveBuilder);
        }
    }
    movedNode = doStore(nodeToMoveBuilder.build());
    this.result.addMovedNode(MoveNodeResult.MovedNode.create().previousPath(persistedNode.path()).node(movedNode).build());
    nodeMoved(1);
    for (final NodeBranchEntry nodeBranchEntry : nodeBranchEntries) {
        doMoveNode(nodeToMoveBuilder.build().path(), getNodeName(nodeBranchEntry), nodeBranchEntry.getNodeId());
    }
    return movedNode;
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)25 InternalContext (com.enonic.xp.repo.impl.InternalContext)9 Test (org.junit.jupiter.api.Test)8 Node (com.enonic.xp.node.Node)7 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)6 NodeId (com.enonic.xp.node.NodeId)5 NodePath (com.enonic.xp.node.NodePath)5 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)4 NodeVersion (com.enonic.xp.node.NodeVersion)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 PushNodeEntries (com.enonic.xp.node.PushNodeEntries)4 RoutableNodeVersionId (com.enonic.xp.node.RoutableNodeVersionId)4 Event (com.enonic.xp.event.Event)3 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)3 PushNodeEntry (com.enonic.xp.node.PushNodeEntry)3 Branch (com.enonic.xp.branch.Branch)2 Context (com.enonic.xp.context.Context)2 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)2 NodeComparison (com.enonic.xp.node.NodeComparison)2 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)2