Search in sources :

Example 6 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class GetActiveContentVersionsParamsTest method testEquals.

@Test
public void testEquals() {
    Branch branch = Branch.create().value("branchName").build();
    Branches branches = Branches.from(branch);
    GetActiveContentVersionsParams params = GetActiveContentVersionsParams.create().contentId(contentId).branches(branches).build();
    assertEquals(params, params);
    assertEquals(params.getContentId(), contentId);
    assertEquals(params.getBranches().getSet(), branches.getSet());
}
Also used : Branch(com.enonic.xp.branch.Branch) Branches(com.enonic.xp.branch.Branches) Test(org.junit.jupiter.api.Test)

Example 7 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class DeleteContentCommand method getCompareStatus.

private CompareStatus getCompareStatus(final NodeId nodeToDelete) {
    final Context context = ContextAccessor.current();
    final Branch currentBranch = context.getBranch();
    final NodeComparison compare;
    if (currentBranch.equals(ContentConstants.BRANCH_DRAFT)) {
        compare = this.nodeService.compare(nodeToDelete, ContentConstants.BRANCH_MASTER);
    } else {
        compare = this.nodeService.compare(nodeToDelete, ContentConstants.BRANCH_DRAFT);
    }
    return compare.getCompareStatus();
}
Also used : Context(com.enonic.xp.context.Context) NodeComparison(com.enonic.xp.node.NodeComparison) Branch(com.enonic.xp.branch.Branch)

Example 8 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class GetActiveContentVersionsCommand method execute.

public GetActiveContentVersionsResult execute() {
    this.nodeService.refresh(RefreshMode.STORAGE);
    final NodeId nodeId = NodeId.from(contentId.toString());
    final GetActiveNodeVersionsResult activeNodeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(this.branches).build());
    final ContentVersionFactory contentVersionFactory = new ContentVersionFactory(this.nodeService);
    final GetActiveContentVersionsResult.Builder builder = GetActiveContentVersionsResult.create();
    final ImmutableMap<Branch, NodeVersionMetadata> nodeVersionsMap = activeNodeVersions.getNodeVersions();
    for (final Branch branch : nodeVersionsMap.keySet()) {
        final NodeVersionMetadata nodeVersionMetadata = nodeVersionsMap.get(branch);
        builder.add(ActiveContentVersionEntry.from(branch, contentVersionFactory.create(nodeVersionMetadata)));
    }
    return builder.build();
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) GetActiveContentVersionsResult(com.enonic.xp.content.GetActiveContentVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeId(com.enonic.xp.node.NodeId)

Example 9 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class UnpublishContentCommand method removePendingDeleteFromDraft.

private void removePendingDeleteFromDraft(final UnpublishContentsResult result) {
    final Branch currentBranch = ContextAccessor.current().getBranch();
    if (!currentBranch.equals(ContentConstants.BRANCH_DRAFT)) {
        final Context draftContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_DRAFT).build();
        draftContext.callWith(() -> {
            final Nodes draftNodes = this.nodeService.getByIds(NodeIds.from(result.getUnpublishedContents().asStrings()));
            for (final Node draftNode : draftNodes) {
                if (draftNode.getNodeState().value().equalsIgnoreCase(ContentState.PENDING_DELETE.toString())) {
                    this.nodeService.deleteById(draftNode.id());
                }
            }
            return null;
        });
    }
}
Also used : Context(com.enonic.xp.context.Context) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) Nodes(com.enonic.xp.node.Nodes)

Example 10 with Branch

use of com.enonic.xp.branch.Branch in project xp by enonic.

the class RepoDumper method dumpBranch.

private void dumpBranch(final BranchDumpResult.Builder dumpResult, Consumer<NodeId> nodeIdsAccumulator) {
    final Node rootNode = this.nodeService.getRoot();
    final FindNodesByParentResult children = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(rootNode.id()).recursive(true).childOrder(ChildOrder.from("_path asc")).build());
    final Branch branch = ContextAccessor.current().getBranch();
    this.listener.dumpingBranch(repository.getId(), branch, children.getTotalHits() + 1);
    LOG.info("Dumping repository [{}], branch [{}]", repository.getId(), branch);
    doDumpNode(rootNode.id(), dumpResult);
    nodeIdsAccumulator.accept(rootNode.id());
    for (final NodeId child : children.getNodeIds()) {
        doDumpNode(child, dumpResult);
        nodeIdsAccumulator.accept(child);
    }
}
Also used : Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Aggregations

Branch (com.enonic.xp.branch.Branch)52 Test (org.junit.jupiter.api.Test)19 Node (com.enonic.xp.node.Node)13 RepositoryId (com.enonic.xp.repository.RepositoryId)12 Context (com.enonic.xp.context.Context)10 NodeId (com.enonic.xp.node.NodeId)8 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 Repository (com.enonic.xp.repository.Repository)7 ContextAccessor (com.enonic.xp.context.ContextAccessor)5 ContextBuilder (com.enonic.xp.context.ContextBuilder)5 ContentId (com.enonic.xp.content.ContentId)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 CreateBranchParams (com.enonic.xp.repository.CreateBranchParams)4 ContentConstants (com.enonic.xp.content.ContentConstants)3 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)3 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)3 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodePath (com.enonic.xp.node.NodePath)3 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)3