Search in sources :

Example 1 with NodeVersionQuery

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

the class NodeServiceImpl method findVersions.

@Override
public NodeVersionQueryResult findVersions(final GetNodeVersionsParams params) {
    verifyContext();
    final NodeVersionQuery query = NodeVersionQuery.create().size(params.getSize()).from(params.getFrom()).nodeId(params.getNodeId()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
    return FindNodeVersionsCommand.create().query(query).searchService(this.nodeSearchService).build().execute();
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery)

Example 2 with NodeVersionQuery

use of com.enonic.xp.node.NodeVersionQuery 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 3 with NodeVersionQuery

use of com.enonic.xp.node.NodeVersionQuery 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 4 with NodeVersionQuery

use of com.enonic.xp.node.NodeVersionQuery 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)

Example 5 with NodeVersionQuery

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

the class ApplyNodePermissionsCommandTest method assertVersions.

private void assertVersions(final Node node) {
    final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
    final NodeVersionQueryResult versions = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
    assertEquals(2, versions.getHits());
    final Iterator<NodeVersionMetadata> iterator = versions.getNodeVersionsMetadata().iterator();
    assertTrue(iterator.next().getTimestamp().isAfter(iterator.next().getTimestamp()));
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Aggregations

NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)10 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)7 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)4 Node (com.enonic.xp.node.Node)3 Instant (java.time.Instant)3 NodeService (com.enonic.xp.node.NodeService)2 NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)2 RangeFilter (com.enonic.xp.query.filter.RangeFilter)2 BlobKey (com.enonic.xp.blob.BlobKey)1 BlobStore (com.enonic.xp.blob.BlobStore)1 Segment (com.enonic.xp.blob.Segment)1 SegmentLevel (com.enonic.xp.blob.SegmentLevel)1 Branch (com.enonic.xp.branch.Branch)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 ValueFactory (com.enonic.xp.data.ValueFactory)1 IndexPath (com.enonic.xp.index.IndexPath)1 MemoryBlobStore (com.enonic.xp.internal.blobstore.MemoryBlobStore)1