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());
}
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();
}
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());
}
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;
}
}
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);
});
}
Aggregations