Search in sources :

Example 11 with Nodes

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

the class SecurityServiceImpl method query.

@Override
public PrincipalQueryResult query(final PrincipalQuery query) {
    try {
        final NodeQuery nodeQueryBuilder = PrincipalQueryNodeQueryTranslator.translate(query);
        final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
        final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
        final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
        return PrincipalQueryResult.create().addPrincipals(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
    } catch (NodeNotFoundException e) {
        return PrincipalQueryResult.create().build();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Principals(com.enonic.xp.security.Principals) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 12 with Nodes

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

the class SecurityServiceImpl method findByUsername.

private User findByUsername(final IdProviderKey idProvider, final String username) {
    final CompareExpr idProviderExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.ID_PROVIDER_KEY), CompareExpr.Operator.EQ, ValueExpr.string(idProvider.toString()));
    final CompareExpr userNameExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.LOGIN_KEY), CompareExpr.Operator.EQ, ValueExpr.string(username));
    final QueryExpr query = QueryExpr.from(LogicalExpr.and(idProviderExpr, userNameExpr));
    final Nodes nodes = callWithContext(() -> {
        final FindNodesByQueryResult result = nodeService.findByQuery(NodeQuery.create().query(query).build());
        return this.nodeService.getByIds(result.getNodeIds());
    });
    if (nodes.getSize() > 1) {
        throw new IllegalArgumentException("Expected at most 1 user with username " + username + " in id provider " + idProvider);
    }
    return nodes.isEmpty() ? null : PrincipalNodeTranslator.userFromNode(nodes.first());
}
Also used : 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 13 with Nodes

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

the class NodeExporter method doExport.

private FindNodesByParentResult doExport(final NodePath nodePath) {
    final FindNodesByParentResult children = nodeService.findByParent(FindNodesByParentParams.create().parentPath(nodePath).build());
    final Nodes childNodes = this.nodeService.getByIds(children.getNodeIds());
    for (final Node child : childNodes) {
        try {
            exportNode(child);
        } catch (Exception e) {
            LOG.error(String.format("Failed to export node with path [%s]", child.path()), e);
            result.addError(new ExportError(e.toString()));
        }
    }
    return children;
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) ExportError(com.enonic.xp.export.ExportError) Nodes(com.enonic.xp.node.Nodes)

Example 14 with Nodes

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

the class NodeExporter method doExportChildNodes.

private void doExportChildNodes(final NodePath parentPath) {
    final Node parentNode = nodeService.getByPath(parentPath);
    final FindNodesByParentResult children = doExport(parentPath);
    final Nodes childNodes = this.nodeService.getByIds(children.getNodeIds());
    writeNodeOrderList(parentNode, childNodes);
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes)

Example 15 with Nodes

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

the class ApplyNodePermissionsCommand method applyPermissionsToChildren.

private void applyPermissionsToChildren(final Node parent) {
    final AccessControlList parentPermissions = parent.getPermissions();
    final FindNodesByParentParams findByParentParams = FindNodesByParentParams.create().parentPath(parent.path()).size(NodeSearchService.GET_ALL_SIZE_FLAG).build();
    final FindNodesByParentResult result = doFindNodesByParent(findByParentParams);
    final Nodes children = GetNodesByIdsCommand.create(this).ids(result.getNodeIds()).build().execute();
    for (Node child : children) {
        applyPermissions(parentPermissions, child);
    }
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) 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