Search in sources :

Example 1 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class FindContentVersionsCommand method doGetContentVersions.

private FindContentVersionsResult doGetContentVersions() {
    this.nodeService.refresh(RefreshMode.STORAGE);
    final NodeId nodeId = NodeId.from(this.contentId);
    final NodeVersionQueryResult nodeVersionQueryResult = nodeService.findVersions(GetNodeVersionsParams.create().nodeId(nodeId).from(this.from).size(this.size).build());
    final FindContentVersionsResult.Builder findContentVersionsResultBuilder = FindContentVersionsResult.create().hits(nodeVersionQueryResult.getHits()).totalHits(nodeVersionQueryResult.getTotalHits()).from(nodeVersionQueryResult.getFrom()).size(nodeVersionQueryResult.getSize());
    final ContentVersionFactory contentVersionFactory = new ContentVersionFactory(this.nodeService);
    final ContentVersions contentVersions = contentVersionFactory.create(nodeId, nodeVersionQueryResult.getNodeVersionsMetadata());
    findContentVersionsResultBuilder.contentVersions(contentVersions);
    return findContentVersionsResultBuilder.build();
}
Also used : ContentVersions(com.enonic.xp.content.ContentVersions) FindContentVersionsResult(com.enonic.xp.content.FindContentVersionsResult) NodeId(com.enonic.xp.node.NodeId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 2 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class RepoDumper method dumpVersions.

private void dumpVersions(final Collection<NodeId> dumpedNodes) {
    writer.openVersionsMeta(repository.getId());
    try {
        for (NodeId nodeId : dumpedNodes) {
            final VersionsDumpEntry.Builder builder = VersionsDumpEntry.create(nodeId);
            final NodeVersionQueryResult versions = getVersions(nodeId);
            for (final NodeVersionMetadata metaData : versions.getNodeVersionsMetadata()) {
                doStoreVersion(builder, metaData, this.dumpResult);
                this.dumpResult.addedVersion();
            }
            writer.writeVersionsEntry(builder.build());
        }
    } finally {
        writer.closeMeta();
    }
}
Also used : NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeId(com.enonic.xp.node.NodeId) VersionsDumpEntry(com.enonic.xp.repo.impl.dump.model.VersionsDumpEntry) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 3 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class IsBlobUsedByVersionCommand method execute.

public boolean execute() {
    final NodeVersionQuery query = createQuery();
    final NodeVersionQueryResult versions = nodeService.findVersions(query);
    return versions.getTotalHits() > 0;
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 4 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class SegmentVacuumCommand method isRepositoryToKeep.

private boolean isRepositoryToKeep(final RepositoryId repositoryId) {
    return repositoryPresenceMap.computeIfAbsent(repositoryId, key -> {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository [" + repositoryId + "] not found in the list of current repository");
        }
        // If repository is not present, find if there is an old version more recent than the threshold
        final Context systemContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(SystemConstants.SYSTEM_REPO_ID).branch(SystemConstants.BRANCH_SYSTEM).build();
        final Instant since = Instant.now().minusMillis(params.getAgeThreshold());
        final NodeVersionQuery findRecentVersionsQuery = NodeVersionQuery.create().nodeId(NodeId.from(repositoryId.toString())).addQueryFilter(RangeFilter.create().fieldName(VersionIndexPath.TIMESTAMP.getPath()).from(ValueFactory.newDateTime(since)).build()).size(0).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
        final NodeVersionQueryResult result = systemContext.callWith(() -> nodeService.findVersions(findRecentVersionsQuery));
        if (result.getTotalHits() > 0 && LOG.isDebugEnabled()) {
            LOG.debug("Recent versions of the repository entry found");
        }
        return result.getTotalHits() > 0;
    });
}
Also used : Context(com.enonic.xp.context.Context) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Instant(java.time.Instant) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 5 with NodeVersionQueryResult

use of com.enonic.xp.node.NodeVersionQueryResult in project xp by enonic.

the class VersionTableVacuumCommand method doProcessRepository.

private void doProcessRepository(final Repository repository) {
    int counter = 0;
    NodeVersionId lastVersionId = null;
    NodeVersionQuery query = createQuery(lastVersionId);
    NodeVersionQueryResult versionsResult = nodeService.findVersions(query);
    long hits = versionsResult.getHits();
    final long totalHits = versionsResult.getTotalHits();
    if (listener != null) {
        listener.stepBegin(repository.getId().toString(), totalHits);
    }
    while (hits > 0) {
        final List<NodeVersionId> versionsToDelete = new ArrayList<>();
        final Set<BlobKey> nodeBlobToCheckSet = new HashSet<>();
        final Set<BlobKey> binaryBlobToCheckSet = new HashSet<>();
        final NodeVersionsMetadata versions = versionsResult.getNodeVersionsMetadata();
        for (NodeVersionMetadata version : versions) {
            final boolean toDelete = processVersion(repository, version);
            if (toDelete) {
                result.deleted();
                versionsToDelete.add(version.getNodeVersionId());
                nodeBlobToCheckSet.add(version.getNodeVersionKey().getNodeBlobKey());
                binaryBlobToCheckSet.addAll(version.getBinaryBlobKeys().getSet());
            } else {
                result.inUse();
            }
            lastVersionId = version.getNodeVersionId();
            counter++;
        }
        versionService.delete(versionsToDelete, InternalContext.from(ContextAccessor.current()));
        nodeBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.NODE_BLOB_KEY)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.NODE_SEGMENT_LEVEL, blobKey));
        binaryBlobToCheckSet.stream().filter(blobKey -> !isBlobKeyUsed(blobKey, VersionIndexPath.BINARY_BLOB_KEYS)).forEach(blobKey -> removeNodeBlobRecord(repository.getId(), NodeConstants.BINARY_SEGMENT_LEVEL, blobKey));
        query = createQuery(lastVersionId);
        versionsResult = nodeService.findVersions(query);
        hits = versionsResult.getHits();
    }
    if (listener != null) {
        listener.processed(counter);
    }
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) IsBlobUsedByVersionCommand(com.enonic.xp.repo.impl.vacuum.blob.IsBlobUsedByVersionCommand) RepositoryService(com.enonic.xp.repository.RepositoryService) Node(com.enonic.xp.node.Node) VersionService(com.enonic.xp.repo.impl.version.VersionService) LoggerFactory(org.slf4j.LoggerFactory) NodeConstants(com.enonic.xp.repo.impl.node.NodeConstants) Segment(com.enonic.xp.blob.Segment) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) BlobKey(com.enonic.xp.blob.BlobKey) Branch(com.enonic.xp.branch.Branch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentLevel(com.enonic.xp.blob.SegmentLevel) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) BlobStore(com.enonic.xp.blob.BlobStore) NodeService(com.enonic.xp.node.NodeService) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) ContextBuilder(com.enonic.xp.context.ContextBuilder) RangeFilter(com.enonic.xp.query.filter.RangeFilter) VersionIndexPath(com.enonic.xp.repo.impl.version.VersionIndexPath) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Logger(org.slf4j.Logger) IndexPath(com.enonic.xp.index.IndexPath) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) InternalContext(com.enonic.xp.repo.impl.InternalContext) Set(java.util.Set) ValueFactory(com.enonic.xp.data.ValueFactory) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) VacuumListener(com.enonic.xp.vacuum.VacuumListener) OrderExpr(com.enonic.xp.query.expr.OrderExpr) List(java.util.List) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) VacuumTaskParams(com.enonic.xp.repo.impl.vacuum.VacuumTaskParams) Repository(com.enonic.xp.repository.Repository) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) ArrayList(java.util.ArrayList) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) BlobKey(com.enonic.xp.blob.BlobKey) HashSet(java.util.HashSet)

Aggregations

NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)22 Node (com.enonic.xp.node.Node)12 Test (org.junit.jupiter.api.Test)11 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)9 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)8 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)8 NodeId (com.enonic.xp.node.NodeId)5 Instant (java.time.Instant)4 Branch (com.enonic.xp.branch.Branch)3 GetActiveNodeVersionsResult (com.enonic.xp.node.GetActiveNodeVersionsResult)3 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)3 Context (com.enonic.xp.context.Context)2 ContextAccessor (com.enonic.xp.context.ContextAccessor)2 ContextBuilder (com.enonic.xp.context.ContextBuilder)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)2 NodeVersionId (com.enonic.xp.node.NodeVersionId)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Repository (com.enonic.xp.repository.Repository)2 RepositoryConstants (com.enonic.xp.repository.RepositoryConstants)2