Search in sources :

Example 21 with NodeId

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();
    }
}
Also used : NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) NodeId(com.enonic.xp.node.NodeId) VersionsDumpEntry(com.enonic.xp.repo.impl.dump.model.VersionsDumpEntry) NodeVersionQueryResult(com.enonic.xp.node.NodeVersionQueryResult)

Example 22 with NodeId

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();
}
Also used : Branch(com.enonic.xp.branch.Branch) NodeId(com.enonic.xp.node.NodeId) HashSet(java.util.HashSet)

Example 23 with NodeId

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;
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeAccessException(com.enonic.xp.node.NodeAccessException) NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException)

Example 24 with NodeId

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;
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeId(com.enonic.xp.node.NodeId) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException)

Example 25 with NodeId

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();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) AttachedBinaries(com.enonic.xp.node.AttachedBinaries) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Aggregations

NodeId (com.enonic.xp.node.NodeId)91 Node (com.enonic.xp.node.Node)44 Test (org.junit.jupiter.api.Test)36 NodePath (com.enonic.xp.node.NodePath)23 InternalContext (com.enonic.xp.repo.impl.InternalContext)18 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)15 NodeIds (com.enonic.xp.node.NodeIds)14 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)11 Context (com.enonic.xp.context.Context)10 PropertyTree (com.enonic.xp.data.PropertyTree)10 Branch (com.enonic.xp.branch.Branch)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)9 NodeVersionId (com.enonic.xp.node.NodeVersionId)9 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)8 RefreshMode (com.enonic.xp.node.RefreshMode)8 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 Event (com.enonic.xp.event.Event)6 RenameNodeParams (com.enonic.xp.node.RenameNodeParams)6