Package com.osohq.oso_cloud.internal
Class AsyncQueryBuilderImpl
- java.lang.Object
-
- com.osohq.oso_cloud.internal.AsyncQueryBuilderImpl
-
- All Implemented Interfaces:
AsyncQueryBuilder,QueryComposer<AsyncQueryBuilder>
public class AsyncQueryBuilderImpl extends java.lang.Object implements AsyncQueryBuilder
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncQueryBuilderand(java.lang.String predicate, QueryArg... args)Add another condition that must be true of the query results.<T> java.util.concurrent.CompletableFuture<T>evaluate(QueryBuilderImpl.EvaluateArg<T> arg)Evaluate the query based on the structure of the providedQueryBuilderImpl.EvaluateArg.java.util.concurrent.CompletableFuture<java.lang.String>evaluateLocalFilter(java.lang.String columnName, TypedVar queryVar)Fetches a SQL fragment, which you can embed into theWHEREclause of a SQL query against your database to filter out unauthorized rows (ie.java.util.concurrent.CompletableFuture<java.lang.String>evaluateLocalSelect()Fetches a complete SQL query that can be run against your database, selecting a single row with a boolean column calledresult.java.util.concurrent.CompletableFuture<java.lang.String>evaluateLocalSelect(java.util.Map<java.lang.String,TypedVar> columnNamesToQueryVars)Fetches a complete SQL query that can be run against your database, selecting a row for each authorized combination of the query variables incolumnNamesToQueryVars(ie.AsyncQueryBuilderin(TypedVar variable, java.util.List<java.lang.String> values)Constrain a query variable to be one of a set of values.static AsyncQueryBuilderImplinit(java.util.concurrent.Executor executor, Api api, java.lang.String predicate, QueryArg... args)AsyncQueryBuilderwithContextFacts(java.util.List<Fact> facts)Add context facts to the query.
-
-
-
Method Detail
-
init
public static AsyncQueryBuilderImpl init(java.util.concurrent.Executor executor, Api api, java.lang.String predicate, QueryArg... args)
-
evaluate
public <T> java.util.concurrent.CompletableFuture<T> evaluate(QueryBuilderImpl.EvaluateArg<T> arg)
Description copied from interface:AsyncQueryBuilderEvaluate the query based on the structure of the providedQueryBuilderImpl.EvaluateArg. The shape of the return value is determined by the specificEvaluateArgused, constructed typically via theEvaluateArgsstatic factory methods.EvaluateArgs.exists(): ReturnsBooleanindicating if the query is satisfiable.EvaluateArgs.values(TypedVar): ReturnsList<String>of values for the variable.EvaluateArgs.map(TypedVar, QueryBuilderImpl.EvaluateArg): ReturnsMap<String, SubT>where keys are unique values of the key variable, and values are the results of recursively evaluating the nested value argument (SubT). This allows arbitrarily nested structures.
- Specified by:
evaluatein interfaceAsyncQueryBuilder- Type Parameters:
T- The expected result type, inferred from thearg.- Parameters:
arg- AnQueryBuilderImpl.EvaluateArgspecifying the desired structure of the results. UseEvaluateArgsfactory methods.- Returns:
- A Future of type
Trepresenting the evaluated results, matching the structure requested byarg.
-
evaluateLocalSelect
public java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalSelect(java.util.Map<java.lang.String,TypedVar> columnNamesToQueryVars)
Description copied from interface:AsyncQueryBuilderFetches a complete SQL query that can be run against your database, selecting a row for each authorized combination of the query variables incolumnNamesToQueryVars(ie. combinations of variables that satisfy the Oso query).See the Oso documentation for examples and limitations.
- Specified by:
evaluateLocalSelectin interfaceAsyncQueryBuilder- Parameters:
columnNamesToQueryVars- A mapping of the desired column names to the query variables whose values will be selected into those columns in the returned SQL query.- Returns:
- Future of SQL query containing the desired columns.
-
evaluateLocalSelect
public java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalSelect()
Description copied from interface:AsyncQueryBuilderFetches a complete SQL query that can be run against your database, selecting a single row with a boolean column calledresult.See the Oso documentation for examples and limitations.
- Specified by:
evaluateLocalSelectin interfaceAsyncQueryBuilder- Returns:
- Future of SQL query containing the
resultcolumn.
-
evaluateLocalFilter
public java.util.concurrent.CompletableFuture<java.lang.String> evaluateLocalFilter(java.lang.String columnName, TypedVar queryVar)Description copied from interface:AsyncQueryBuilderFetches a SQL fragment, which you can embed into theWHEREclause of a SQL query against your database to filter out unauthorized rows (ie. rows that don't satisfy the Oso query).See the Oso documentation for examples and limitations.
- Specified by:
evaluateLocalFilterin interfaceAsyncQueryBuilder- Parameters:
columnName- The name of the SQL column to filter.queryVar- The variable corresponding to the column to filter.- Returns:
- Future of SQL fragment, suitable for embedding in a
WHEREclause.
-
and
public AsyncQueryBuilder and(java.lang.String predicate, QueryArg... args)
Description copied from interface:QueryComposerAdd another condition that must be true of the query results. For example:// Query for all the repos on which the user can perform read action, // and require the repos to belong to a specific folder TypedVar repo = new TypedVar("Repo"); List<String> authorizedReposInFolder = oso .buildQuery("allow", new Value("User", "user123"), new Value("read"), repo) .and("has_relation", repo, new Value("folder"), new Value("Folder", "folder456")) .evaluate(repo);- Specified by:
andin interfaceQueryComposer<AsyncQueryBuilder>- Parameters:
predicate- The predicate of the conditionargs- The arguments to the condition- Returns:
- A new QueryBuilder with the added condition
-
in
public AsyncQueryBuilder in(TypedVar variable, java.util.List<java.lang.String> values)
Description copied from interface:QueryComposerConstrain a query variable to be one of a set of values. For example:TypedVar repo = new TypedVar("Repo"); TypedVar action = new TypedVar("String"); // Get all the actions a user can perform on specific repos List<String> authorizedActions = oso .buildQuery("allow", new Value("User", "user123"), action, repo) .in(repo, Arrays.asList("acme", "anvil")) .evaluate(action);- Specified by:
inin interfaceQueryComposer<AsyncQueryBuilder>- Parameters:
variable- The variable to constrainvalues- The set of allowed values for the constrained variable- Returns:
- A new QueryBuilder with the added constraint
-
withContextFacts
public AsyncQueryBuilder withContextFacts(java.util.List<Fact> facts)
Description copied from interface:QueryComposerAdd context facts to the query.- Specified by:
withContextFactsin interfaceQueryComposer<AsyncQueryBuilder>- Parameters:
facts- The context facts to add- Returns:
- A new QueryBuilder with the added context facts
-
-