Search in sources :

Example 16 with NodeVersionQueryResult

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

the class DumpServiceImplTest method version_ids_should_stay_the_same_if_no_changes.

@Test
public void version_ids_should_stay_the_same_if_no_changes() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    RenameNodeCommand.create().searchService(this.searchService).storageService(this.storageService).indexServiceInternal(this.indexServiceInternal).params(RenameNodeParams.create().nodeId(node.id()).nodeName(NodeName.from("renamed")).build()).build().execute();
    this.nodeService.push(NodeIds.from(node.id()), WS_OTHER);
    updateNode(node);
    refresh();
    final NodeVersionQueryResult versionsBeforeLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
    refresh();
    final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
    final NodeVersionIds versionIdsBeforeLoad = versionsBeforeLoad.getNodeVersionsMetadata().getAllVersionIds();
    final NodeVersionIds versionIdsAfterLoad = versionsAfterLoad.getNodeVersionsMetadata().getAllVersionIds();
    assertEquals(versionIdsBeforeLoad, versionIdsAfterLoad);
}
Also used : Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) NodeVersionIds(com.enonic.xp.node.NodeVersionIds) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 17 with NodeVersionQueryResult

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

the class DumpServiceImplTest method limit_number_of_versions.

@Test
public void limit_number_of_versions() throws Exception {
    final Node node = createNode(NodePath.ROOT, "myNode");
    for (int i = 0; i < 10; i++) {
        updateNode(node);
    }
    NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true, SystemDumpParams.create().dumpName("myTestDump").maxVersions(5).build()));
    final NodeVersionQueryResult versionsAfterLoad = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).size(-1).build());
    assertEquals(6, versionsAfterLoad.getHits());
}
Also used : Node(com.enonic.xp.node.Node) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 18 with NodeVersionQueryResult

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

the class NodeVersionQueryResultFactory method create.

public static NodeVersionQueryResult create(final NodeVersionQuery query, final SearchResult searchResult) {
    final NodeVersionQueryResult.Builder findNodeVersionsResult = NodeVersionQueryResult.create();
    findNodeVersionsResult.hits(searchResult.getHits().getSize());
    findNodeVersionsResult.totalHits(searchResult.getTotalHits());
    findNodeVersionsResult.from(query.getFrom());
    findNodeVersionsResult.to(query.getSize());
    final NodeVersionsMetadata nodeVersionsMetadata = buildEntityVersions(query, searchResult);
    findNodeVersionsResult.entityVersions(nodeVersionsMetadata);
    return findNodeVersionsResult.build();
}
Also used : NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 19 with NodeVersionQueryResult

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

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

the class VersionTableVacuumTaskTest method assertVersions.

private void assertVersions(final NodeId nodeId, final int versions) {
    final NodeVersionQueryResult result = this.nodeService.findVersions(NodeVersionQuery.create().nodeId(nodeId).size(0).build());
    assertEquals(versions, result.getTotalHits(), "Wrong number of versions found");
}
Also used : NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

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