Search in sources :

Example 6 with NodeVersionId

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

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

the class VersionTableVacuumCommand method findVersionsInBranches.

private BRANCH_CHECK_RESULT findVersionsInBranches(final Repository repository, final NodeVersionMetadata versionMetadata) {
    final NodeId nodeId = versionMetadata.getNodeId();
    final NodeVersionId versionId = versionMetadata.getNodeVersionId();
    boolean nodeFound = false;
    for (final Branch branch : repository.getBranches()) {
        try {
            final Node node = ContextBuilder.from(ContextAccessor.current()).branch(branch).repositoryId(repository.getId()).build().callWith(() -> this.nodeService.getById(nodeId));
            if (versionId.equals(node.getNodeVersionId())) {
                return BRANCH_CHECK_RESULT.SAME_VERSION_FOUND;
            }
            nodeFound = true;
        } catch (NodeNotFoundException e) {
        // Ignore
        }
    }
    return nodeFound ? BRANCH_CHECK_RESULT.OTHER_VERSION_FOUND : BRANCH_CHECK_RESULT.NO_VERSION_FOUND;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Example 8 with NodeVersionId

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

the class NodeStorageServiceImplTest method testGetNode.

@Test
public void testGetNode() {
    final NodePath nodePath = NodePath.create("path").build();
    final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
    final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
    final Node result = instance.getNode(nodeId, nodeVersionId, context);
    assertNotNull(result);
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(versionService, nodeVersionService);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) NodeVersionId(com.enonic.xp.node.NodeVersionId) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 9 with NodeVersionId

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

the class NodeServiceImpl method setActiveVersion.

@Override
public NodeVersionId setActiveVersion(final NodeId nodeId, final NodeVersionId nodeVersionId) {
    verifyContext();
    final NodeVersionId result = SetActiveVersionCommand.create().nodeVersionId(nodeVersionId).nodeId(nodeId).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute();
    final Node node = this.getById(nodeId);
    if (node != null) {
        this.eventPublisher.publish(NodeEvents.updated(node));
    }
    return result;
}
Also used : RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionId(com.enonic.xp.node.NodeVersionId) Node(com.enonic.xp.node.Node)

Example 10 with NodeVersionId

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

the class NodeStorageServiceImpl method move.

@Override
public Node move(final StoreMovedNodeParams params, final InternalContext context) {
    final NodeVersionKey nodeVersionKey;
    final NodeBranchEntry nodeBranchEntry = this.branchService.get(params.getNode().id(), context);
    if (params.isUpdateMetadataOnly()) {
        nodeVersionKey = nodeBranchEntry.getNodeVersionKey();
    } else {
        nodeVersionKey = nodeVersionService.store(NodeVersion.from(params.getNode()), context);
    }
    NodeVersionId nodeVersionId = params.getNodeVersionId();
    if (nodeVersionId == null) {
        nodeVersionId = new NodeVersionId();
        storeVersionMetadata(params.getNode(), nodeVersionId, nodeVersionKey, context);
    }
    return moveInBranchAndReIndex(params.getNode(), nodeVersionId, nodeVersionKey, nodeBranchEntry.getNodePath(), context);
}
Also used : NodeVersionId(com.enonic.xp.node.NodeVersionId) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry)

Aggregations

NodeVersionId (com.enonic.xp.node.NodeVersionId)15 Node (com.enonic.xp.node.Node)10 NodeId (com.enonic.xp.node.NodeId)9 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)7 Test (org.junit.jupiter.api.Test)6 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)5 RoutableNodeVersionId (com.enonic.xp.node.RoutableNodeVersionId)5 InternalContext (com.enonic.xp.repo.impl.InternalContext)5 NodePath (com.enonic.xp.node.NodePath)4 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 NodeVersion (com.enonic.xp.node.NodeVersion)3 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)3 Branch (com.enonic.xp.branch.Branch)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 Content (com.enonic.xp.content.Content)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1