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();
}
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;
}
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();
}
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);
});
}
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();
}
}
Aggregations