Search in sources :

Example 6 with NodeVersionQuery

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

the class FindNodeVersionsCommandTest method get_single_version.

@Test
void get_single_version() {
    final Node node = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
    final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).build();
    final NodeVersionQueryResult result = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
    assertEquals(1, result.getHits());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test)

Example 7 with NodeVersionQuery

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

the class VersionTableVacuumCommand method createQuery.

private NodeVersionQuery createQuery(NodeVersionId lastVersionId) {
    final NodeVersionQuery.Builder builder = NodeVersionQuery.create();
    if (lastVersionId != null) {
        final RangeFilter versionIdFilter = RangeFilter.create().fieldName(VersionIndexPath.VERSION_ID.getPath()).gt(ValueFactory.newString(lastVersionId.toString())).build();
        builder.addQueryFilter(versionIdFilter);
    }
    final RangeFilter mustBeOlderThanFilter = RangeFilter.create().fieldName(VersionIndexPath.TIMESTAMP.getPath()).to(ValueFactory.newDateTime(until)).build();
    return builder.addQueryFilter(mustBeOlderThanFilter).addOrderBy(FieldOrderExpr.create(VersionIndexPath.VERSION_ID, OrderExpr.Direction.ASC)).size(batchSize).build();
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) RangeFilter(com.enonic.xp.query.filter.RangeFilter)

Example 8 with NodeVersionQuery

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

the class DumpServiceImplTest method checkCommitUpgrade.

private void checkCommitUpgrade(final NodeId nodeId) {
    nodeService.refresh(RefreshMode.ALL);
    final NodeCommitQuery nodeCommitQuery = NodeCommitQuery.create().build();
    final NodeCommitQueryResult nodeCommitQueryResult = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("master")).build().callWith(() -> nodeService.findCommits(nodeCommitQuery));
    assertEquals(1, nodeCommitQueryResult.getTotalHits());
    final NodeCommitEntry commitEntry = nodeCommitQueryResult.getNodeCommitEntries().iterator().next();
    final NodeCommitId nodeCommitId = commitEntry.getNodeCommitId();
    assertEquals("Dump upgrade", commitEntry.getMessage());
    assertEquals("user:system:node-su", commitEntry.getCommitter().toString());
    final GetActiveNodeVersionsParams activeNodeVersionsParams = GetActiveNodeVersionsParams.create().nodeId(nodeId).branches(Branches.from(ContentConstants.BRANCH_DRAFT, ContentConstants.BRANCH_MASTER)).build();
    final GetActiveNodeVersionsResult activeNodeVersionsResult = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("master")).build().callWith(() -> nodeService.getActiveVersions(activeNodeVersionsParams));
    final NodeVersionMetadata draftNodeVersion = activeNodeVersionsResult.getNodeVersions().get(ContentConstants.BRANCH_DRAFT);
    assertNull(draftNodeVersion.getNodeCommitId());
    final NodeVersionMetadata masterNodeVersion = activeNodeVersionsResult.getNodeVersions().get(ContentConstants.BRANCH_MASTER);
    assertEquals(nodeCommitId, masterNodeVersion.getNodeCommitId());
    final NodeVersionQuery nodeVersionQuery = NodeVersionQuery.create().nodeId(nodeId).build();
    final NodeVersionQueryResult versionQueryResult = ContextBuilder.from(ContextAccessor.current()).branch(Branch.from("draft")).build().callWith(() -> nodeService.findVersions(nodeVersionQuery));
    assertEquals(16, versionQueryResult.getTotalHits());
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeCommitQuery(com.enonic.xp.node.NodeCommitQuery) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitQueryResult(com.enonic.xp.node.NodeCommitQueryResult) NodeCommitId(com.enonic.xp.node.NodeCommitId) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetActiveNodeVersionsParams(com.enonic.xp.node.GetActiveNodeVersionsParams)

Example 9 with NodeVersionQuery

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

the class FindNodeVersionsCommandTest method get_multiple_version.

@Test
void get_multiple_version() {
    PropertyTree data = new PropertyTree();
    final Node node = createNode(CreateNodeParams.create().data(data).name("my-node").parent(NodePath.ROOT).build());
    final int updateCount = 4;
    updateNode(node.id(), updateCount);
    refresh();
    final NodeVersionQuery query = NodeVersionQuery.create().size(100).from(0).nodeId(node.id()).addOrderBy(FieldOrderExpr.create(VersionIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).build();
    final NodeVersionQueryResult result = FindNodeVersionsCommand.create().query(query).searchService(this.searchService).build().execute();
    assertEquals(updateCount + 1, result.getHits());
    final NodeVersionsMetadata nodeVersionsMetadata = result.getNodeVersionsMetadata();
    Instant previousTimestamp = null;
    for (final NodeVersionMetadata nodeVersionMetadata : nodeVersionsMetadata) {
        final Instant currentNodeTimestamp = nodeVersionMetadata.getTimestamp();
        if (previousTimestamp != null) {
            if (currentNodeTimestamp.isAfter(previousTimestamp)) {
                fail(String.format("expected timestamp of current item to be before or equal to previous. Previous: [%s], current: [%s]", previousTimestamp, currentNodeTimestamp));
            }
        }
        previousTimestamp = currentNodeTimestamp;
    }
}
Also used : NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Instant(java.time.Instant) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test)

Example 10 with NodeVersionQuery

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

the class AbstractBlobVacuumTaskTest method setUp.

public void setUp() throws Exception {
    this.blobStore = new MemoryBlobStore();
    this.nodeService = Mockito.mock(NodeService.class);
    Mockito.when(nodeService.findVersions(Mockito.any(NodeVersionQuery.class))).thenAnswer((invocation) -> {
        final NodeVersionQuery query = invocation.getArgument(0);
        final ValueFilter valueFilter = (ValueFilter) query.getQueryFilters().first();
        if (valueFilter.getValues().contains(ValueFactory.newString(createBlobKey('a').toString()))) {
            return NodeVersionQueryResult.empty(1);
        }
        return NodeVersionQueryResult.empty(0);
    });
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeService(com.enonic.xp.node.NodeService) ValueFilter(com.enonic.xp.query.filter.ValueFilter) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore)

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