Search in sources :

Example 6 with Repository

use of com.enonic.xp.repository.Repository in project xp by enonic.

the class NodeServiceImpl method verifyRepositoryExists.

private void verifyRepositoryExists() {
    NodeHelper.runAsAdmin(() -> {
        final RepositoryId repoId = ContextAccessor.current().getRepositoryId();
        final Repository repository = this.repositoryService.get(repoId);
        if (repository == null) {
            throw new RepositoryNotFoundException(repoId);
        }
    });
}
Also used : Repository(com.enonic.xp.repository.Repository) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 7 with Repository

use of com.enonic.xp.repository.Repository in project xp by enonic.

the class DumpServiceImplTest method dumpDeleteAndLoad.

private SystemLoadResult dumpDeleteAndLoad(final boolean clearBlobStore, final SystemDumpParams params) {
    doDump(params);
    doListRepositories().stream().map(Repository::getId).filter(Predicate.isEqual(SystemConstants.SYSTEM_REPO_ID).or(Predicate.isEqual(AUDIT_LOG_REPO_ID)).or(Predicate.isEqual(SCHEDULER_REPO_ID)).negate()).forEach(this::doDeleteRepository);
    // Then delete all system repositories
    doDeleteRepository(AUDIT_LOG_REPO_ID);
    doDeleteRepository(SCHEDULER_REPO_ID);
    // system-repo must be deleted last
    doDeleteRepository(SystemConstants.SYSTEM_REPO_ID);
    if (clearBlobStore) {
        this.blobStore.clear();
    }
    bootstrap();
    final SystemLoadResult result = doLoad();
    refresh();
    return result;
}
Also used : Repository(com.enonic.xp.repository.Repository) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult)

Example 8 with Repository

use of com.enonic.xp.repository.Repository in project xp by enonic.

the class DumpServiceImplTest method number_of_versions_in_other_repo.

@Test
public void number_of_versions_in_other_repo() {
    final Repository myRepo = NodeHelper.runAsAdmin(() -> doCreateRepository(RepositoryId.from("myrepo"), AccessControlList.create().add(AccessControlEntry.create().principal(ctxDefault().getAuthInfo().getUser().getKey()).allowAll().build()).build(), null));
    final Context myRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(myRepo.getId()).branch(RepositoryConstants.MASTER_BRANCH).build();
    final Node myNode = myRepoContext.callWith(() -> createNode(NodePath.ROOT, "myNode"));
    myRepoContext.runWith(() -> updateNode(myNode));
    myRepoContext.runWith(() -> updateNode(myNode));
    myRepoContext.runWith(() -> updateNode(myNode));
    final SystemLoadResult dumpResult = NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true, SystemDumpParams.create().dumpName("myTestDump").build()));
    final RepoLoadResult repoLoadResult = getRepoLoadResult(dumpResult, myRepo.getId());
    final VersionsLoadResult versionsLoadResult = repoLoadResult.getVersionsLoadResult();
    assertNotNull(versionsLoadResult);
    // One for root, 4 for myNode
    assertEquals(5, versionsLoadResult.getSuccessful());
}
Also used : BundleContext(org.osgi.framework.BundleContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext) Repository(com.enonic.xp.repository.Repository) SystemLoadResult(com.enonic.xp.dump.SystemLoadResult) Node(com.enonic.xp.node.Node) VersionsLoadResult(com.enonic.xp.dump.VersionsLoadResult) RepoLoadResult(com.enonic.xp.dump.RepoLoadResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 9 with Repository

use of com.enonic.xp.repository.Repository in project xp by enonic.

the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search_different_branches.

@Test
public void multi_repo_search_different_branches() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    // Create new branch in repo1
    final Branch otherBranch = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createBranch("otherBranch"));
    final Node repo1MasterNode1 = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo1Node"));
    final Node repo1OtherNode1 = callInContext(REPO_USER_1, repo1.getId(), otherBranch, () -> createNode(NodePath.ROOT, "repo1Node"));
    final Node repo2MasterNode1 = callInContext(REPO_USER_2, repo2.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo2Node"));
    final SearchTargets targets = SearchTargets.create().add(createTarget(otherBranch, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
    final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
    final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
    assertEquals(2L, result.getTotalHits());
    assertRepos(result, repo1.getId(), repo2.getId());
    assertBranches(result, MASTER_BRANCH, otherBranch);
    assertNodes(result, repo1OtherNode1.id(), repo2MasterNode1.id());
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) SearchTargets(com.enonic.xp.node.SearchTargets) Test(org.junit.jupiter.api.Test)

Example 10 with Repository

use of com.enonic.xp.repository.Repository in project xp by enonic.

the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search.

@Test
public void multi_repo_search() throws Exception {
    final Repository repo1 = createRepo(REPO_USER_1, "repo1");
    final Repository repo2 = createRepo(REPO_USER_2, "repo2");
    runInContext(REPO_USER_1, repo1.getId(), () -> createNode(NodePath.ROOT, "repo1Node"));
    runInContext(REPO_USER_2, repo2.getId(), () -> createNode(NodePath.ROOT, "repo2Node"));
    final SearchTargets targets = SearchTargets.create().add(createTarget(MASTER_BRANCH, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
    final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
    final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
    assertEquals(2L, result.getTotalHits());
    assertRepos(result, repo1.getId(), repo2.getId());
    assertBranches(result, MASTER_BRANCH);
}
Also used : FindNodesByMultiRepoQueryResult(com.enonic.xp.node.FindNodesByMultiRepoQueryResult) Repository(com.enonic.xp.repository.Repository) MultiRepoNodeQuery(com.enonic.xp.node.MultiRepoNodeQuery) NodeQuery(com.enonic.xp.node.NodeQuery) SearchTargets(com.enonic.xp.node.SearchTargets) Test(org.junit.jupiter.api.Test)

Aggregations

Repository (com.enonic.xp.repository.Repository)40 Test (org.junit.jupiter.api.Test)21 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)15 RepositoryId (com.enonic.xp.repository.RepositoryId)10 Node (com.enonic.xp.node.Node)9 Branch (com.enonic.xp.branch.Branch)8 PropertyTree (com.enonic.xp.data.PropertyTree)7 Context (com.enonic.xp.context.Context)6 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)5 MultiRepoNodeQuery (com.enonic.xp.node.MultiRepoNodeQuery)5 NodeQuery (com.enonic.xp.node.NodeQuery)5 SearchTargets (com.enonic.xp.node.SearchTargets)5 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 ContextBuilder (com.enonic.xp.context.ContextBuilder)4 CreateRepositoryParams (com.enonic.xp.repository.CreateRepositoryParams)4 RepositoryService (com.enonic.xp.repository.RepositoryService)4 SystemLoadResult (com.enonic.xp.dump.SystemLoadResult)3 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)3 NodeService (com.enonic.xp.node.NodeService)3 Project (com.enonic.xp.project.Project)3