Interface QueryComposer<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      T and​(java.lang.String predicate, QueryArg... args)
      Add another condition that must be true of the query results.
      T in​(TypedVar variable, java.util.List<java.lang.String> values)
      Constrain a query variable to be one of a set of values.
      T withContextFacts​(java.util.List<Fact> facts)
      Add context facts to the query.
    • Method Detail

      • and

        T and​(java.lang.String predicate,
              QueryArg... args)
        Add 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);
         
        Parameters:
        predicate - The predicate of the condition
        args - The arguments to the condition
        Returns:
        A new QueryBuilder with the added condition
      • in

        T in​(TypedVar variable,
             java.util.List<java.lang.String> values)
        Constrain 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);
         
        Parameters:
        variable - The variable to constrain
        values - The set of allowed values for the constrained variable
        Returns:
        A new QueryBuilder with the added constraint
        Throws:
        java.lang.IllegalArgumentException - if the variable is not used in the query or values have already been set
      • withContextFacts

        T withContextFacts​(java.util.List<Fact> facts)
        Add context facts to the query.
        Parameters:
        facts - The context facts to add
        Returns:
        A new QueryBuilder with the added context facts