Search in sources :

Example 26 with Nodes

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

the class SecurityServiceImpl method duplicateEmailValidation.

private void duplicateEmailValidation(final PrincipalKey key, final String email) {
    if (email == null) {
        return;
    }
    final CompareExpr idProviderExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.ID_PROVIDER_KEY), CompareExpr.Operator.EQ, ValueExpr.string(key.getIdProviderKey().toString()));
    final CompareExpr emailExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.EMAIL_KEY), CompareExpr.Operator.EQ, ValueExpr.string(email));
    final QueryExpr query = QueryExpr.from(LogicalExpr.and(idProviderExpr, emailExpr));
    final Nodes nodes = callWithContext(() -> {
        final FindNodesByQueryResult result = nodeService.findByQuery(NodeQuery.create().query(query).build());
        return this.nodeService.getByIds(result.getNodeIds());
    });
    final User user = nodes.isEmpty() ? null : PrincipalNodeTranslator.userFromNode(nodes.first());
    if (nodes.getSize() > 1 || (user != null && !user.getKey().equals(key))) {
        throw new IllegalArgumentException("A user with email '" + email + "' already exists in id provider '" + key.getIdProviderKey() + "'");
    }
}
Also used : User(com.enonic.xp.security.User) CompareExpr(com.enonic.xp.query.expr.CompareExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Nodes(com.enonic.xp.node.Nodes)

Example 27 with Nodes

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

the class ApplicationServiceImpl method doInstallStoredApplications.

private void doInstallStoredApplications(final ApplicationInstallationParams params) {
    LOG.info("Searching for installed applications");
    final Nodes applicationNodes = repoService.getApplications();
    LOG.info("Found [" + applicationNodes.getSize() + "] installed applications");
    for (final Node applicationNode : applicationNodes) {
        try {
            final Application application = doInstallStoredApplication(applicationNode.id());
            if (application == null) {
                continue;
            }
            final ApplicationKey applicationKey = application.getKey();
            LOG.info("Stored application [{}] installed successfully", applicationKey);
            if (params.isTriggerEvent()) {
                doPublishInstalledEvent(applicationNode);
            }
            if (params.isStart() && storedApplicationIsStarted(applicationNode)) {
                doStartApplication(applicationKey, params.isTriggerEvent(), false);
            }
        } catch (Exception e) {
            LOG.error("Cannot install application [{}]", applicationNode.name(), e);
        }
    }
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Node(com.enonic.xp.node.Node) Application(com.enonic.xp.app.Application) Nodes(com.enonic.xp.node.Nodes) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException)

Example 28 with Nodes

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

the class GetContentByPathsCommand method doExecute.

private Contents doExecute() {
    final NodePaths paths = ContentNodeHelper.translateContentPathsToNodePaths(contentPaths);
    final Nodes nodes = nodeService.getByPaths(paths);
    return this.translator.fromNodes(nodes, true);
}
Also used : NodePaths(com.enonic.xp.node.NodePaths) Nodes(com.enonic.xp.node.Nodes)

Example 29 with Nodes

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

the class FindIssueCommentsCommand method execute.

public FindIssueCommentsResult execute() {
    validateBlockingChecks();
    final Node issue = nodeService.getById(NodeId.from(this.query.getIssue()));
    final NodeQuery nodeQuery = IssueCommentQueryNodeQueryTranslator.translate(this.query, issue.name());
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final Nodes foundNodes = this.nodeService.getByIds(result.getNodeIds());
    final List<IssueComment> issues = IssueCommentNodeTranslator.fromNodes(foundNodes);
    return FindIssueCommentsResult.create().comments(issues).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) IssueComment(com.enonic.xp.issue.IssueComment) Nodes(com.enonic.xp.node.Nodes)

Example 30 with Nodes

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

the class FindIssuesCommand method execute.

public FindIssuesResult execute() {
    final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(this.query);
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final Nodes foundNodes = this.nodeService.getByIds(result.getNodeIds());
    final List<Issue> issues = IssueNodeTranslator.fromNodes(foundNodes);
    return FindIssuesResult.create().issues(issues).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
Also used : Issue(com.enonic.xp.issue.Issue) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Aggregations

Nodes (com.enonic.xp.node.Nodes)31 Node (com.enonic.xp.node.Node)14 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)9 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)9 Test (org.junit.jupiter.api.Test)8 NodeQuery (com.enonic.xp.node.NodeQuery)5 Contents (com.enonic.xp.content.Contents)4 NodeIds (com.enonic.xp.node.NodeIds)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 QueryExpr (com.enonic.xp.query.expr.QueryExpr)3 Branch (com.enonic.xp.branch.Branch)2 Content (com.enonic.xp.content.Content)2 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)2 NodePaths (com.enonic.xp.node.NodePaths)2 Principals (com.enonic.xp.security.Principals)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Application (com.enonic.xp.app.Application)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 BlobKey (com.enonic.xp.blob.BlobKey)1