Search in sources :

Example 26 with Branch

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

the class RenameContentCommandTest method test_already_exists.

@Test
void test_already_exists() {
    Node mockNode = Node.create().id(NodeId.from("testId")).build();
    final RepositoryId repositoryId = RepositoryId.from("some.repo");
    final Branch branch = Branch.from("somebranch");
    when(nodeService.rename(isA(RenameNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create("/content/mycontent2").build(), repositoryId, branch));
    when(nodeService.getById(mockNode.id())).thenReturn(mockNode);
    final Content content = createContent(true);
    final RenameContentCommand command = createCommand(RenameContentParams.create().contentId(content.getId()).newName(ContentName.from("mycontent2")).build());
    final ContentAlreadyExistsException exception = assertThrows(ContentAlreadyExistsException.class, command::execute);
    assertEquals(branch, exception.getBranch());
    assertEquals(repositoryId, exception.getRepositoryId());
}
Also used : Branch(com.enonic.xp.branch.Branch) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test)

Example 27 with Branch

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

the class RepoDumper method getActiveVersion.

private NodeVersionMetadata getActiveVersion(final NodeId nodeId) {
    final Branch branch = ContextAccessor.current().getBranch();
    final GetActiveNodeVersionsParams params = GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(Branches.from(branch)).build();
    return this.nodeService.getActiveVersions(params).getNodeVersions().get(branch);
}
Also used : Branch(com.enonic.xp.branch.Branch) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Example 28 with Branch

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

the class RepoLoader method doExecute.

private void doExecute(final RepoLoadResult.Builder result) {
    final Branch currentBranch = ContextAccessor.current().getBranch();
    verifyOrCreateBranch(currentBranch);
    final BranchLoadResult branchLoadResult = this.reader.loadBranch(repositoryId, currentBranch, this.branchEntryProcessor);
    result.add(branchLoadResult);
}
Also used : Branch(com.enonic.xp.branch.Branch) BranchLoadResult(com.enonic.xp.dump.BranchLoadResult)

Example 29 with Branch

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

the class AbstractMetaDumpUpgrader method doUpgrade.

@Override
public void doUpgrade(final String dumpName) {
    super.doUpgrade(dumpName);
    final String timeMillis = Long.toString(System.currentTimeMillis());
    FilePaths tmpFilePaths = new DefaultFilePaths() {

        @Override
        public PathRef branchMetaPath(final RepositoryId repositoryId, final Branch branch) {
            return branchRootPath(repositoryId).resolve(branch.toString()).resolve("meta-" + timeMillis + ".tar.gz");
        }

        @Override
        public PathRef versionMetaPath(final RepositoryId repositoryId) {
            return branchRootPath(repositoryId).resolve("versions-" + timeMillis + ".tar.gz");
        }
    };
    tmpDumpReader = FileDumpReader.create(null, basePath, dumpName, tmpFilePaths);
    tmpDumpWriter = FileDumpWriter.create(basePath, dumpName, null, tmpFilePaths);
    try {
        dumpReader.getRepositories().forEach(this::upgradeRepository);
        overwriteSourceFiles();
    } catch (Exception e) {
        try {
            deleteBufferFiles();
        } catch (Exception e2) {
            LOG.error("Error while deleting buffer files", e);
        }
        throw new DumpUpgradeException("Error while upgrading dump [" + dumpName + "]", e);
    } finally {
        try {
            tmpDumpReader.close();
            tmpDumpWriter.close();
        } catch (IOException e) {
            LOG.error("Error while closing dump writer", e);
        }
    }
}
Also used : FilePaths(com.enonic.xp.repo.impl.dump.FilePaths) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) Branch(com.enonic.xp.branch.Branch) DefaultFilePaths(com.enonic.xp.repo.impl.dump.DefaultFilePaths) IOException(java.io.IOException) RepositoryId(com.enonic.xp.repository.RepositoryId) IOException(java.io.IOException)

Example 30 with Branch

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

the class ReindexExecutor method execute.

public ReindexResult execute() {
    final ReindexResult.Builder builder = ReindexResult.create();
    final long start = System.currentTimeMillis();
    builder.startTime(Instant.ofEpochMilli(start));
    builder.branches(this.branches);
    builder.repositoryId(this.repositoryId);
    if (listener != null) {
        listener.totalBranches(this.branches.getSize());
    }
    for (final Branch branch : this.branches) {
        doReindexBranchNew(repositoryId, builder, branch);
    }
    final long stop = System.currentTimeMillis();
    builder.endTime(Instant.ofEpochMilli(stop));
    builder.duration(Duration.ofMillis(stop - start));
    return builder.build();
}
Also used : ReindexResult(com.enonic.xp.index.ReindexResult) Branch(com.enonic.xp.branch.Branch)

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