Search in sources :

Example 31 with Branch

use of com.enonic.xp.branch.Branch 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 32 with Branch

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

the class RepositoryServiceImpl method doDeleteBranch.

private Repository doDeleteBranch(final DeleteBranchParams params, final RepositoryId repositoryId, Repository previousRepository) {
    // If the repository entry does not exist, throws an exception
    previousRepository = previousRepository == null ? repositoryEntryService.getRepositoryEntry(repositoryId) : previousRepository;
    if (previousRepository == null) {
        throw new RepositoryNotFoundException(repositoryId);
    }
    // If the branch does not exist, throws an exception
    final Branch branch = params.getBranch();
    if (!previousRepository.getBranches().contains(branch)) {
        throw new BranchNotFoundException(branch);
    }
    // If the root node exists, deletes it
    if (getRootNode(previousRepository.getId(), branch) != null) {
        deleteRootNode(branch);
    }
    // Updates the repository entry
    return repositoryEntryService.removeBranchFromRepositoryEntry(repositoryId, branch);
}
Also used : Branch(com.enonic.xp.branch.Branch) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException)

Example 33 with Branch

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

the class DumpServiceImplTest method branch_created_if_missing.

@Test
public void branch_created_if_missing() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    final Branch branch = WS_DEFAULT;
    final RepositoryId currentRepoId = TEST_REPO_ID;
    NodeHelper.runAsAdmin(() -> {
        doDump(SystemDumpParams.create().dumpName("testDump").build());
        this.repositoryEntryService.removeBranchFromRepositoryEntry(currentRepoId, branch);
        assertFalse(this.repositoryEntryService.getRepositoryEntry(currentRepoId).getBranches().contains(branch));
        this.dumpService.load(SystemLoadParams.create().dumpName("testDump").build());
        assertTrue(this.repositoryEntryService.getRepositoryEntry(currentRepoId).getBranches().contains(branch));
        assertNotNull(this.nodeService.getById(node.id()));
    });
}
Also used : Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 34 with Branch

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

the class SegmentVacuumTaskTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.blobStore = new MemoryBlobStore();
    this.repositoryId = RepositoryId.from("test");
    this.repositoryId2 = RepositoryId.from("test2");
    this.segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.NODE_SEGMENT_LEVEL);
    this.segment2 = RepositorySegmentUtils.toSegment(repositoryId2, NodeConstants.NODE_SEGMENT_LEVEL);
    this.repositoryService = Mockito.mock(RepositoryService.class);
    final Branch branch = Branch.from("master");
    final Repository repository = Repository.create().id(repositoryId).branches(branch).build();
    final Repository repository2 = Repository.create().id(repositoryId).branches(branch).build();
    Mockito.when(repositoryService.list()).thenReturn(Repositories.from(repository, repository2));
    this.nodeService = Mockito.mock(NodeService.class);
    Mockito.when(nodeService.findVersions(Mockito.any(NodeVersionQuery.class))).thenReturn(NodeVersionQueryResult.empty(0));
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) NodeService(com.enonic.xp.node.NodeService) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore) RepositoryService(com.enonic.xp.repository.RepositoryService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with Branch

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

the class RepositoryServiceImplTest method create_branch_with_node_in_root.

@Test
void create_branch_with_node_in_root() {
    doCreateRepo("fisk");
    Branch branch = Branch.from("myBranch");
    final var mockCurrentContext = ContextBuilder.create().branch("myBranch").repositoryId("fisk").authInfo(REPO_TEST_DEFAULT_USER_AUTHINFO).build();
    mockCurrentContext.callWith(() -> repositoryService.createBranch(CreateBranchParams.from(branch)));
    assertDoesNotThrow(() -> mockCurrentContext.callWith(() -> nodeService.create(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).data(new PropertyTree()).build())));
}
Also used : Branch(com.enonic.xp.branch.Branch) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

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