Search in sources :

Example 86 with Node

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

the class UpdateNodeCommand method doExecute.

private Node doExecute() {
    final Node persistedNode = getPersistedNode();
    requireContextUserPermissionOrAdmin(Permission.MODIFY, persistedNode);
    final EditableNode editableNode = new EditableNode(persistedNode);
    params.getEditor().edit(editableNode);
    if (editableNode.inheritPermissions != persistedNode.inheritsPermissions() || !persistedNode.getPermissions().equals(editableNode.permissions)) {
        requireContextUserPermissionOrAdmin(Permission.WRITE_PERMISSIONS, persistedNode);
    }
    final AttachedBinaries updatedBinaries = UpdatedAttachedBinariesResolver.create().editableNode(editableNode).persistedNode(persistedNode).binaryAttachments(this.params.getBinaryAttachments()).binaryService(this.binaryService).build().resolve();
    final Node editedNode = editableNode.build();
    if (editedNode.equals(persistedNode) && updatedBinaries.equals(persistedNode.getAttachedBinaries())) {
        return persistedNode;
    }
    final Node updatedNode = createUpdatedNode(Node.create(editedNode).timestamp(Instant.now(CLOCK)).attachedBinaries(updatedBinaries).build());
    if (!this.params.isDryRun()) {
        StoreNodeCommand.create(this).node(updatedNode).build().execute();
    }
    return updatedNode;
}
Also used : Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) EditableNode(com.enonic.xp.node.EditableNode) AttachedBinaries(com.enonic.xp.node.AttachedBinaries)

Example 87 with Node

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

the class UpdateNodeCommand method createUpdatedNode.

private Node createUpdatedNode(final Node editedNode) {
    final NodePath parentPath = editedNode.path().getParentPath();
    final AccessControlList permissions = evaluatePermissions(parentPath, editedNode.inheritsPermissions(), editedNode.getPermissions());
    final Node.Builder updateNodeBuilder = Node.create(editedNode).permissions(permissions);
    return updateNodeBuilder.build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) NodePath(com.enonic.xp.node.NodePath)

Example 88 with Node

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

the class SetActiveVersionCommand method execute.

public NodeVersionId execute() {
    final InternalContext context = InternalContext.from(ContextAccessor.current());
    final Node node = this.nodeStorageService.get(nodeId, nodeVersionId, context);
    if (node == null) {
        throw new NodeNotFoundException("Cannot find nodeVersion [" + this.nodeVersionId + "] in branch " + context.getBranch().getValue());
    }
    if (!node.id().equals(nodeId)) {
        throw new NodeNotFoundException("NodeVersionId [" + nodeVersionId + "] not a version of Node with id [" + nodeId + "]");
    }
    NodePermissionsResolver.requireContextUserPermissionOrAdmin(REQUIRED_PERMISSION, node);
    this.nodeStorageService.updateVersion(node, nodeVersionId, context);
    return nodeVersionId;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node)

Example 89 with Node

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

the class SetNodeStateCommand method execute.

public SetNodeStateResult execute() {
    final Node node = doGetById(this.params.getNodeId());
    final SetNodeStateResult.Builder setNodeStateResultBuilder = SetNodeStateResult.create();
    if (this.params.isRecursive()) {
        setNodeStateWithChildren(node, setNodeStateResultBuilder);
    } else {
        setNodeState(node, setNodeStateResultBuilder);
    }
    return setNodeStateResultBuilder.build();
}
Also used : SetNodeStateResult(com.enonic.xp.node.SetNodeStateResult) Node(com.enonic.xp.node.Node)

Example 90 with Node

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

the class RepositoryEntryServiceImpl method updateRepositoryNode.

private Repository updateRepositoryNode(final UpdateNodeParams updateNodeParams) {
    final Node updatedNode = createContext().callWith(() -> UpdateNodeCommand.create().params(updateNodeParams).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).binaryService(this.binaryService).build().execute());
    eventPublisher.publish(NodeEvents.updated(updatedNode));
    refresh();
    Repository repository = RepositoryNodeTranslator.toRepository(updatedNode);
    eventPublisher.publish(RepositoryEvents.updated(repository.getId()));
    return repository;
}
Also used : Repository(com.enonic.xp.repository.Repository) 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