Search in sources :

Example 16 with Branch

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

the class RepositoryServiceImpl method doCreateBranch.

private Repository doCreateBranch(final CreateBranchParams createBranchParams, 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 already exists, throws an exception
    final Branch newBranch = createBranchParams.getBranch();
    if (previousRepository.getBranches().contains(newBranch)) {
        throw new BranchAlreadyExistException(newBranch);
    }
    // If the root node does not exist, creates it
    if (getRootNode(previousRepository.getId(), newBranch) == null) {
        pushRootNode(previousRepository, newBranch);
        RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.ALL).build().execute();
    }
    // Updates the repository entry
    return repositoryEntryService.addBranchToRepositoryEntry(repositoryId, newBranch);
}
Also used : Branch(com.enonic.xp.branch.Branch) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException)

Example 17 with Branch

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

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

the class DumpServiceImplTest method active_versions_in_versions_list.

@Test
public void active_versions_in_versions_list() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
    updateNode(node);
    refresh();
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    refresh();
    final GetActiveNodeVersionsResult activeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().branches(Branches.from(WS_DEFAULT, WS_OTHER)).nodeId(node.id()).build());
    final ImmutableMap<Branch, NodeVersionMetadata> activeVersionsMap = activeVersions.getNodeVersions();
    final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    activeVersionsMap.values().forEach(key -> assertTrue(versionsAfterLoad.getNodeVersionsMetadata().getAllVersionIds().contains(key.getNodeVersionId())));
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 19 with Branch

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

the class DumpServiceImplTest method active_versions_after_load.

@Test
public void active_versions_after_load() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
    updateNode(node);
    refresh();
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    refresh();
    final GetActiveNodeVersionsResult activeVersions = this.nodeService.getActiveVersions(GetActiveNodeVersionsParams.create().branches(Branches.from(WS_DEFAULT, WS_OTHER)).nodeId(node.id()).build());
    final Node defaultBranchNode = ctxDefault().callWith(() -> this.nodeService.getById(node.id()));
    final Node otherBranchNode = ctxOther().callWith(() -> this.nodeService.getById(node.id()));
    final ImmutableMap<Branch, NodeVersionMetadata> activeVersionsMap = activeVersions.getNodeVersions();
    assertEquals(2, activeVersionsMap.size());
    assertEquals(defaultBranchNode.getNodeVersionId(), activeVersionsMap.get(WS_DEFAULT).getNodeVersionId());
    assertEquals(otherBranchNode.getNodeVersionId(), activeVersionsMap.get(WS_OTHER).getNodeVersionId());
}
Also used : GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) Branch(com.enonic.xp.branch.Branch) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 20 with Branch

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

the class BranchAclEntryTest method not_equals.

@Test
public void not_equals() throws Exception {
    final Branch branch = Branch.from("fisk");
    final BranchAclEntry entry1 = new BranchAclEntry(branch, PrincipalKeys.from(PrincipalKey.ofRole("fisk")));
    final BranchAclEntry entry2 = new BranchAclEntry(branch, PrincipalKeys.from(PrincipalKey.ofRole("ost")));
    assertNotEquals(entry1, entry2);
}
Also used : Branch(com.enonic.xp.branch.Branch) Test(org.junit.jupiter.api.Test)

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