use of com.enonic.xp.node.NodeNotFoundException in project xp by enonic.
the class CreateIssueCommentCommandTest method createIssueNotExists.
@Test
public void createIssueNotExists() {
final PrincipalKey creator = PrincipalKey.from("user:store:one");
final CreateIssueCommentParams params = CreateIssueCommentParams.create().creator(creator).issue(IssueId.create()).creatorDisplayName("Creator One").text("Comment text...").build();
final CreateIssueCommentCommand command = createIssueCommentCommand(params);
Mockito.when(this.nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
assertThrows(NodeNotFoundException.class, () -> command.execute());
}
use of com.enonic.xp.node.NodeNotFoundException 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();
}
use of com.enonic.xp.node.NodeNotFoundException 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();
}
use of com.enonic.xp.node.NodeNotFoundException 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);
}
use of com.enonic.xp.node.NodeNotFoundException 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;
}
Aggregations