Search in sources :

Example 1 with NodeVersionsMetadata

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

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

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

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

the class NodeServiceImplTest method test_commit.

@Test
public void test_commit() {
    // Create and update node
    final Node createdNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
    final NodeId nodeId = createdNode.id();
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(nodeId).editor(toBeEdited -> {
        toBeEdited.data.addString("newField", "fisk");
    }).build();
    final Node updatedNode = updateNode(updateNodeParams);
    nodeService.refresh(RefreshMode.STORAGE);
    // Check that the two versions have no commit ID by default
    final NodeVersionsMetadata versionsMetadata = getVersionsMetadata(nodeId);
    assertEquals(2, versionsMetadata.size());
    final Iterator<NodeVersionMetadata> versionMetadataIterator = versionsMetadata.iterator();
    final NodeVersionMetadata latestVersionMetadata = versionMetadataIterator.next();
    final NodeVersionMetadata firstVersionMetadata = versionMetadataIterator.next();
    assertNull(latestVersionMetadata.getNodeCommitId());
    assertNull(firstVersionMetadata.getNodeCommitId());
    // Call commit with node ID
    final NodeCommitEntry commitEntry = NodeCommitEntry.create().message("Commit message").build();
    final NodeCommitEntry returnedCommitEntry = nodeService.commit(commitEntry, NodeIds.from(nodeId));
    nodeService.refresh(RefreshMode.STORAGE);
    // Check created commit entry
    final NodeCommitId nodeCommitId = returnedCommitEntry.getNodeCommitId();
    assertNotNull(nodeCommitId);
    assertEquals("Commit message", returnedCommitEntry.getMessage());
    assertNotNull(returnedCommitEntry.getTimestamp());
    assertEquals("user:system:test-user", returnedCommitEntry.getCommitter().toString());
    // Check that only the latest version has a commit ID
    final NodeVersionsMetadata versionsMetadata2 = getVersionsMetadata(nodeId);
    assertEquals(2, versionsMetadata2.size());
    final Iterator<NodeVersionMetadata> versionMetadataIterator2 = versionsMetadata2.iterator();
    final NodeVersionMetadata latestVersionMetadata2 = versionMetadataIterator2.next();
    final NodeVersionMetadata firstVersionMetadata2 = versionMetadataIterator2.next();
    assertEquals(nodeCommitId, latestVersionMetadata2.getNodeCommitId());
    assertNull(firstVersionMetadata2.getNodeCommitId());
    // Call commit with the node version ID of the first version
    final NodeCommitEntry commitEntry2 = NodeCommitEntry.create().message("Commit message 2").build();
    final RoutableNodeVersionId routableNodeVersionId = RoutableNodeVersionId.from(nodeId, firstVersionMetadata2.getNodeVersionId());
    final NodeCommitEntry returnedCommitEntry2 = nodeService.commit(commitEntry, RoutableNodeVersionIds.from(routableNodeVersionId));
    nodeService.refresh(RefreshMode.STORAGE);
    // Check that only the first version has been impacted
    final NodeVersionsMetadata versionsMetadata3 = getVersionsMetadata(nodeId);
    assertEquals(2, versionsMetadata3.size());
    final Iterator<NodeVersionMetadata> versionMetadataIterator3 = versionsMetadata3.iterator();
    final NodeVersionMetadata latestVersionMetadata3 = versionMetadataIterator3.next();
    final NodeVersionMetadata firstVersionMetadata3 = versionMetadataIterator3.next();
    assertEquals(nodeCommitId, latestVersionMetadata3.getNodeCommitId());
    assertEquals(returnedCommitEntry2.getNodeCommitId(), firstVersionMetadata3.getNodeCommitId());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Permission(com.enonic.xp.security.acl.Permission) NodeCommitId(com.enonic.xp.node.NodeCommitId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) ContextBuilder(com.enonic.xp.context.ContextBuilder) BinaryReference(com.enonic.xp.util.BinaryReference) User(com.enonic.xp.security.User) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeId(com.enonic.xp.node.NodeId) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitId(com.enonic.xp.node.NodeCommitId) Test(org.junit.jupiter.api.Test)

Example 5 with NodeVersionsMetadata

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

the class FindVersionsHandlerTest method testFindVersionsHandler.

@Test
public void testFindVersionsHandler() {
    final NodeVersionMetadata newNodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionNew")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(1000)).build();
    final NodeVersionMetadata oldNodeVersionMeta = NodeVersionMetadata.create().nodeId(NodeId.from("nodeId1")).nodeVersionId(NodeVersionId.from("nodeVersionOld")).nodePath(NodePath.ROOT).timestamp(Instant.ofEpochSecond(500)).build();
    final NodeVersionsMetadata nodeVersionsMetadata = NodeVersionsMetadata.create(NodeId.from("nodeId1")).add(newNodeVersionMeta).add(oldNodeVersionMeta).build();
    final NodeVersionQueryResult result = NodeVersionQueryResult.create().entityVersions(nodeVersionsMetadata).from(0).to(2).hits(2).totalHits(40).build();
    final ArgumentCaptor<GetNodeVersionsParams> getNodeVersionsParamsCaptor = ArgumentCaptor.forClass(GetNodeVersionsParams.class);
    Mockito.when(nodeService.findVersions(Mockito.any(GetNodeVersionsParams.class))).thenReturn(result);
    runScript("/lib/xp/examples/node/findVersions.js");
    Mockito.verify(nodeService).findVersions(getNodeVersionsParamsCaptor.capture());
    assertEquals("nodeId", getNodeVersionsParamsCaptor.getValue().getNodeId().toString());
    assertEquals(0, getNodeVersionsParamsCaptor.getValue().getFrom());
    assertEquals(2, getNodeVersionsParamsCaptor.getValue().getSize());
}
Also used : NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) Test(org.junit.jupiter.api.Test)

Aggregations

NodeVersionsMetadata (com.enonic.xp.node.NodeVersionsMetadata)5 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)4 NodeVersionQueryResult (com.enonic.xp.node.NodeVersionQueryResult)4 Node (com.enonic.xp.node.Node)3 Instant (java.time.Instant)3 Test (org.junit.jupiter.api.Test)3 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 NodeId (com.enonic.xp.node.NodeId)2 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)2 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)2 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)2 OrderExpr (com.enonic.xp.query.expr.OrderExpr)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