Search in sources :

Example 71 with Node

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

the class HasUnpublishedChildrenCommand method execute.

public boolean execute() {
    final Node parentNode = doGetById(parent);
    if (parentNode == null) {
        return false;
    }
    final SearchResult result = nodeSearchService.query(NodeVersionDiffQuery.create().source(ContextAccessor.current().getBranch()).target(target).nodePath(parentNode.path()).size(0).excludes(ExcludeEntries.create().add(new ExcludeEntry(parentNode.path(), false)).build()).build(), SingleRepoStorageSource.create(ContextAccessor.current().getRepositoryId(), SingleRepoStorageSource.Type.VERSION));
    return result.getTotalHits() > 0;
}
Also used : ExcludeEntry(com.enonic.xp.repo.impl.version.search.ExcludeEntry) Node(com.enonic.xp.node.Node) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult)

Example 72 with Node

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

the class MoveNodeCommand method execute.

public MoveNodeResult execute() {
    final Node existingNode = doGetById(nodeId);
    if (existingNode == null) {
        throw new NodeNotFoundException("cannot move node with id [" + nodeId + "]");
    }
    if (existingNode.isRoot()) {
        throw new OperationNotPermittedException("Not allowed to move root-node");
    }
    final NodeName newNodeName = resolveNodeName(existingNode);
    final NodePath newParentPath = resolvePath(existingNode);
    if (noChanges(existingNode, newParentPath, newNodeName)) {
        return result.build();
    }
    checkNotMovedToSelfOrChild(existingNode, newParentPath, newNodeName);
    checkContextUserPermissionOrAdmin(existingNode, newParentPath);
    verifyNoExistingAtNewPath(newParentPath, newNodeName);
    doMoveNode(newParentPath, newNodeName, nodeId);
    RefreshCommand.create().refreshMode(RefreshMode.ALL).indexServiceInternal(this.indexServiceInternal).build().execute();
    return result.build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeName(com.enonic.xp.node.NodeName) Node(com.enonic.xp.node.Node) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) NodePath(com.enonic.xp.node.NodePath)

Example 73 with Node

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

the class MoveNodeCommand method checkContextUserPermissionOrAdmin.

private void checkContextUserPermissionOrAdmin(final Node existingSourceNode, final NodePath newParentPath) {
    NodePermissionsResolver.requireContextUserPermissionOrAdmin(Permission.MODIFY, existingSourceNode);
    final Node newParentNode = GetNodeByPathCommand.create(this).nodePath(newParentPath).build().execute();
    if (newParentNode == null) {
        throw new NodeNotFoundException("Cannot move node to parent with path '" + newParentPath + "', does not exist");
    }
    NodePermissionsResolver.requireContextUserPermissionOrAdmin(Permission.CREATE, newParentNode);
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node)

Example 74 with Node

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

the class NodeServiceImpl method getById.

@Override
public Node getById(final NodeId id) {
    final Trace trace = Tracer.newTrace("node.getById");
    if (trace == null) {
        return executeGetById(id);
    }
    return Tracer.trace(trace, () -> {
        trace.put("id", id);
        final Node node = executeGetById(id);
        trace.put("path", node.path());
        return node;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) Node(com.enonic.xp.node.Node)

Example 75 with Node

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

the class NodeServiceImpl method executeGetById.

private Node executeGetById(final NodeId id) {
    verifyContext();
    final Node node = doGetById(id);
    if (node == null) {
        throw new NodeNotFoundException("Node with id " + id + " not found in branch " + ContextAccessor.current().getBranch().getValue());
    }
    return node;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16