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