Search in sources :

Example 21 with NodeNotFoundException

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

the class DuplicateNodeCommand method execute.

public DuplicateNodeResult execute() {
    final Node existingNode = doGetById(params.getNodeId());
    if (existingNode == null) {
        throw new NodeNotFoundException("Cannot duplicate node with id [" + params.getNodeId() + "]");
    }
    if (existingNode.isRoot()) {
        throw new OperationNotPermittedException("Not allowed to duplicate root-node");
    }
    final CreateNodeParams.Builder createNodeParams = CreateNodeParams.from(existingNode);
    attachBinaries(existingNode, createNodeParams);
    Node duplicatedNode = null;
    String newNodeName = existingNode.name().toString();
    do {
        try {
            newNodeName = DuplicateValueResolver.name(newNodeName);
            final CreateNodeParams processedParams = executeProcessors(createNodeParams.name(newNodeName).build());
            duplicatedNode = CreateNodeCommand.create(this).params(processedParams).binaryService(binaryService).build().execute();
        } catch (NodeAlreadyExistAtPathException e) {
            // try again with other name
            LOG.debug(String.format("[%s] node with [%s] parent already exist.", newNodeName, existingNode.parentPath().toString()), e);
        }
    } while (duplicatedNode == null);
    result.node(duplicatedNode);
    nodeDuplicated(1);
    final NodeReferenceUpdatesHolder.Builder builder = NodeReferenceUpdatesHolder.create().add(existingNode.id(), duplicatedNode.id());
    if (params.getIncludeChildren()) {
        storeChildNodes(existingNode, duplicatedNode, builder);
    }
    final NodeReferenceUpdatesHolder nodesToBeUpdated = builder.build();
    RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
    updateNodeReferences(duplicatedNode, nodesToBeUpdated);
    updateChildReferences(duplicatedNode, nodesToBeUpdated);
    return result.build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 22 with NodeNotFoundException

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

the class NodeServiceImpl method executeGetByIdAndVersionId.

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

Example 23 with NodeNotFoundException

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

the class ResolveSyncWorkCommand method getParentIdsFromPaths.

private NodeIds getParentIdsFromPaths(final NodePaths parentPaths) {
    final NodeIds.Builder parentIdBuilder = NodeIds.create();
    for (final NodePath parent : parentPaths) {
        final NodeId parentId = this.nodeStorageService.getIdForPath(parent, InternalContext.from(ContextAccessor.current()));
        if (parentId == null) {
            throw new NodeNotFoundException("Cannot find parent with path [" + parent + "]");
        }
        parentIdBuilder.add(parentId);
    }
    return parentIdBuilder.build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath)

Example 24 with NodeNotFoundException

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

the class SecurityServiceImpl method setPassword.

@Override
public User setPassword(final PrincipalKey key, final String password) {
    Preconditions.checkArgument(key.isUser(), "Expected principal key of type User");
    Preconditions.checkArgument(password != null && password.length() > 0, "Password cannot be empty");
    return callWithContext(() -> {
        final Node node = callWithContext(() -> this.nodeService.getByPath(key.toPath()));
        if (node == null) {
            throw new NodeNotFoundException("setPassword failed, user with key " + key + " not found");
        }
        final User user = PrincipalNodeTranslator.userFromNode(node);
        if (user == null) {
            throw new NodeNotFoundException("setPassword failed, user with key " + key + " not found");
        }
        final String authenticationHash = this.passwordEncoder.encodePassword(password);
        final User userToUpdate = User.create(user).authenticationHash(authenticationHash).build();
        final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.toUpdateNodeParams(userToUpdate);
        final Node updatedNode = nodeService.update(updateNodeParams);
        return PrincipalNodeTranslator.userFromNode(updatedNode);
    });
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) User(com.enonic.xp.security.User) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 25 with NodeNotFoundException

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

the class GetContentByIdAndVersionIdCommand method execute.

public Content execute() {
    final NodeId nodeId = NodeId.from(contentId.toString());
    final NodeVersionId nodeVersionId = NodeVersionId.from(versionId.toString());
    try {
        return getContentByIdAndVersionId(nodeId, nodeVersionId);
    } catch (NodeNotFoundException e) {
        throw createContentNotFoundException();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeId(com.enonic.xp.node.NodeId)

Aggregations

NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)25 Node (com.enonic.xp.node.Node)13 NodeId (com.enonic.xp.node.NodeId)11 Test (org.junit.jupiter.api.Test)5 NodePath (com.enonic.xp.node.NodePath)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 NodeQuery (com.enonic.xp.node.NodeQuery)3 OperationNotPermittedException (com.enonic.xp.node.OperationNotPermittedException)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 Content (com.enonic.xp.content.Content)2 ContentId (com.enonic.xp.content.ContentId)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)2 Nodes (com.enonic.xp.node.Nodes)2 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Principals (com.enonic.xp.security.Principals)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)1 Branch (com.enonic.xp.branch.Branch)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1