use of com.enonic.xp.node.NodeId in project xp by enonic.
the class RepoDumper method dumpVersions.
private void dumpVersions(final Collection<NodeId> dumpedNodes) {
writer.openVersionsMeta(repository.getId());
try {
for (NodeId nodeId : dumpedNodes) {
final VersionsDumpEntry.Builder builder = VersionsDumpEntry.create(nodeId);
final NodeVersionQueryResult versions = getVersions(nodeId);
for (final NodeVersionMetadata metaData : versions.getNodeVersionsMetadata()) {
doStoreVersion(builder, metaData, this.dumpResult);
this.dumpResult.addedVersion();
}
writer.writeVersionsEntry(builder.build());
}
} finally {
writer.closeMeta();
}
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class RepoDumper method execute.
public RepoDumpResult execute() {
final Set<NodeId> dumpedNodes = new HashSet<>();
final Consumer<NodeId> nodeIdsAccumulator = includeVersions ? dumpedNodes::add : nodeId -> {
};
for (Branch branch : this.repository.getBranches()) {
setContext(branch).runWith(() -> dumpBranch(nodeIdsAccumulator));
}
if (includeVersions) {
setContext(RepositoryConstants.MASTER_BRANCH).runWith(() -> dumpVersions(dumpedNodes));
}
setContext(RepositoryConstants.MASTER_BRANCH).runWith(this::dumpCommits);
return this.dumpResult.build();
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class AbstractDeleteNodeCommand method deleteNodeWithChildren.
NodeBranchEntries deleteNodeWithChildren(final Node node, final Context context, final DeleteNodeListener deleteNodeListener) {
if (node.isRoot() && !allowDeleteRootNode) {
throw new OperationNotPermittedException("Not allowed to delete root-node");
}
doRefresh();
final NodeBranchEntries nodesToBeDeleted = newResolveNodesToDelete(node);
final NodeIds nodeIds = NodeIds.from(nodesToBeDeleted.getKeys());
final boolean allHasPermissions = NodesHasPermissionResolver.create(this).nodeIds(nodeIds).permission(Permission.DELETE).build().execute();
if (!allHasPermissions) {
throw new NodeAccessException(context.getAuthInfo().getUser(), node.path(), Permission.DELETE);
}
for (final List<NodeId> keysBatch : Iterables.partition(nodeIds, BATCH_SIZE)) {
this.nodeStorageService.delete(NodeIds.from(keysBatch), InternalContext.from(context));
if (deleteNodeListener != null) {
deleteNodeListener.nodesDeleted(keysBatch.size());
}
}
doRefresh();
return nodesToBeDeleted;
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class CheckNodeExistsCommand method execute.
public boolean execute() {
final InternalContext context = InternalContext.create(ContextAccessor.current()).searchPreference(Mode.ACCURACY.equals(mode) ? SearchPreference.PRIMARY : SearchPreference.LOCAL).build();
if (Mode.ACCURACY.equals(mode)) {
RefreshCommand.create().indexServiceInternal(this.indexServiceInternal).refreshMode(RefreshMode.STORAGE).build().execute();
}
final NodeId found = nodeStorageService.getIdForPath(nodePath, context);
if (found != null && throwIfExists) {
throw new NodeAlreadyExistAtPathException(nodePath, context.getRepositoryId(), context.getBranch());
}
return found != null;
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class CreateNodeCommand method execute.
public Node execute() {
Preconditions.checkNotNull(params.getParent(), "Path of parent Node must be specified");
Preconditions.checkArgument(params.getParent().isAbsolute(), "Path to parent Node must be absolute: " + params.getParent());
NodeHelper.runAsAdmin(this::verifyNotExistsAlready);
final Node parentNode = NodeHelper.runAsAdmin(this::verifyParentExists);
if (parentNode == null) {
throw new NodeNotFoundException("Parent node to node with name '" + params.getName() + "' with parent path '" + params.getParent() + "' not found");
}
requireContextUserPermission(Permission.CREATE, parentNode);
final PrincipalKey user = getCurrentPrincipalKey();
final AccessControlList permissions = getAccessControlEntries(user);
final Long manualOrderValue = NodeHelper.runAsAdmin(() -> resolvePotentialManualOrderValue(parentNode));
final AttachedBinaries attachedBinaries = storeAndAttachBinaries();
final Node.Builder nodeBuilder = Node.create().id(this.params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).manualOrderValue(manualOrderValue).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).attachedBinaries(attachedBinaries).timestamp(this.timestamp != null ? this.timestamp : Instant.now(CLOCK));
final Node newNode = nodeBuilder.build();
return StoreNodeCommand.create(this).node(newNode).updateMetadataOnly(false).build().execute();
}
Aggregations