/** * Returns SearchResultSelections that are accessible to the specified {@link ToolUser}, * optionally excluding selections that were created by the user. * * @param user the {@link ToolUser} for which SearchResultSelections should be returned. * @param excludeOwn excludes selections created by the specified {@link ToolUser} if true. * @return accessible {@link SearchResultSelection}s for the specified {@link ToolUser}. */ public static List<SearchResultSelection> findAccessibleSelections( ToolUser user, boolean excludeOwn) { if (user == null) { return null; } Query<SearchResultSelection> query = Query.from(SearchResultSelection.class); if (user.getRole() == null) { query.where("entities != missing"); } else { query.where("entities = ?", user.getRole()); } if (excludeOwn) { query.and("entities != ?", user); } else { query.or("entities = ?", user); } return query.selectAll(); }