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