Search in sources :

Example 11 with Branch

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

the class RepoDumper method dumpBranch.

private void dumpBranch(Consumer<NodeId> nodeIdsAccumulator) {
    this.nodeService.refresh(RefreshMode.ALL);
    final Branch branch = ContextAccessor.current().getBranch();
    final BranchDumpResult.Builder branchDumpResult = BranchDumpResult.create(branch);
    writer.openBranchMeta(repository.getId(), branch);
    try {
        dumpBranch(branchDumpResult, nodeIdsAccumulator);
        this.dumpResult.add(branchDumpResult.build());
    } catch (Exception e) {
        throw new RepoDumpException("Error occurred when dumping repository " + repository.getId(), e);
    } finally {
        writer.closeMeta();
    }
}
Also used : BranchDumpResult(com.enonic.xp.dump.BranchDumpResult) Branch(com.enonic.xp.branch.Branch)

Example 12 with Branch

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

the class RepoDumper method execute.

public RepoDumpResult execute() {
    final Set<NodeId> dumpedNodes = new HashSet<>();
    final Consumer<NodeId> nodeIdsAccumulator = includeVersions ? dumpedNodes::add : nodeId -> {
    };
    for (Branch branch : this.repository.getBranches()) {
        setContext(branch).runWith(() -> dumpBranch(nodeIdsAccumulator));
    }
    if (includeVersions) {
        setContext(RepositoryConstants.MASTER_BRANCH).runWith(() -> dumpVersions(dumpedNodes));
    }
    setContext(RepositoryConstants.MASTER_BRANCH).runWith(this::dumpCommits);
    return this.dumpResult.build();
}
Also used : Branch(com.enonic.xp.branch.Branch) NodeId(com.enonic.xp.node.NodeId) HashSet(java.util.HashSet)

Example 13 with Branch

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

the class AbstractDumpReader method loadBranch.

@Override
public BranchLoadResult loadBranch(final RepositoryId repositoryId, final Branch branch, final LineProcessor<EntryLoadResult> processor) {
    final PathRef tarFile = filePaths.branchMetaPath(repositoryId, branch);
    listener.loadingBranch(repositoryId, branch, getBranchSuccessfulCountFromMeta(repositoryId, branch));
    final BranchLoadResult.Builder builder = BranchLoadResult.create(branch);
    if (!exists(tarFile)) {
        return builder.build();
    }
    final EntriesLoadResult result = doLoadEntries(processor, tarFile);
    return builder.successful(result.getSuccessful()).errors(result.getErrors().stream().map(error -> LoadError.error(error.getMessage())).collect(Collectors.toList())).build();
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DumpBlobStore(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobStore) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) FilePaths(com.enonic.xp.repo.impl.dump.FilePaths) RepositoryIds(com.enonic.xp.repository.RepositoryIds) BranchDumpResult(com.enonic.xp.dump.BranchDumpResult) Segment(com.enonic.xp.blob.Segment) BlobKey(com.enonic.xp.blob.BlobKey) Branch(com.enonic.xp.branch.Branch) RepoLoadException(com.enonic.xp.repo.impl.dump.RepoLoadException) RepositoryId(com.enonic.xp.repository.RepositoryId) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) RepoDumpResult(com.enonic.xp.dump.RepoDumpResult) DumpMetaJsonSerializer(com.enonic.xp.repo.impl.dump.serializer.json.DumpMetaJsonSerializer) ByteSource(com.google.common.io.ByteSource) DumpConstants(com.enonic.xp.repo.impl.dump.DumpConstants) CommitsLoadResult(com.enonic.xp.dump.CommitsLoadResult) ImmutableSet(com.google.common.collect.ImmutableSet) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) IOException(java.io.IOException) SystemLoadListener(com.enonic.xp.dump.SystemLoadListener) Branches(com.enonic.xp.branch.Branches) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) LineProcessor(com.google.common.io.LineProcessor) SystemDumpResult(com.enonic.xp.dump.SystemDumpResult) LoadError(com.enonic.xp.dump.LoadError) Stream(java.util.stream.Stream) DumpMeta(com.enonic.xp.repo.impl.dump.model.DumpMeta) NodeVersion(com.enonic.xp.node.NodeVersion) VersionsLoadResult(com.enonic.xp.dump.VersionsLoadResult) PathRef(com.enonic.xp.repo.impl.dump.PathRef) DumpBlobRecord(com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord) NullSystemLoadListener(com.enonic.xp.repo.impl.dump.NullSystemLoadListener) BranchLoadResult(com.enonic.xp.dump.BranchLoadResult) RepoDumpException(com.enonic.xp.repo.impl.dump.RepoDumpException) InputStream(java.io.InputStream) PathRef(com.enonic.xp.repo.impl.dump.PathRef) BranchLoadResult(com.enonic.xp.dump.BranchLoadResult)

Example 14 with Branch

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

the class AbstractMetaDumpUpgrader method deleteBufferFiles.

private void deleteBufferFiles() throws IOException {
    Path bufferFile;
    for (RepositoryId repositoryId : dumpReader.getRepositories()) {
        bufferFile = tmpDumpReader.getVersionsFile(repositoryId);
        Files.deleteIfExists(bufferFile);
        for (Branch branch : dumpReader.getBranches(repositoryId)) {
            bufferFile = tmpDumpReader.getBranchEntriesFile(repositoryId, branch);
            Files.deleteIfExists(bufferFile);
        }
    }
}
Also used : Path(java.nio.file.Path) Branch(com.enonic.xp.branch.Branch) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 15 with Branch

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

the class AbstractNodeEventHandler method createNodeContext.

InternalContext createNodeContext(final Map<Object, Object> map, final InternalContext context) {
    final InternalContext.Builder nodeContext = InternalContext.create(context);
    final RepositoryId repositoryId = getRepositoryId(map);
    if (repositoryId != null) {
        nodeContext.repositoryId(repositoryId);
    }
    final Branch branch = getBranch(map);
    if (branch != null) {
        nodeContext.branch(branch);
    }
    return nodeContext.build();
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Branch(com.enonic.xp.branch.Branch) RepositoryId(com.enonic.xp.repository.RepositoryId)

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