}
// create query object now from string
String query = sb.toString();
DB db = DBFactory.getInstance();
DBQuery dbq = db.createQuery(query);
// add user attributes
if (login != null)
dbq.setString("login", login);
// add user properties attributes
if (userproperties != null && !userproperties.isEmpty()) {
for (String key : userproperties.keySet()) {
String value = userproperties.get(key);
value = makeFuzzyQueryString(value);
dbq.setString(key + "_value", value.toLowerCase());
}
}
// add named security group names
if (hasGroups) {
for (int i = 0; i < groups.length; i++) {
SecurityGroupImpl group = (SecurityGroupImpl) groups[i]; // need to work with impls
dbq.setEntity("group_" + i, group);
}
}
// add policies
if (hasPermissionOnResources) {
for (int i = 0; i < permissionOnResources.length; i++) {
PermissionOnResourceable permissionOnResource = permissionOnResources[i];
dbq.setString("permission_" + i, permissionOnResource.getPermission());
Long id = permissionOnResource.getOlatResourceable().getResourceableId();
dbq.setLong("resourceId_" + i, (id == null ? 0 : id.longValue()));
dbq.setString("resourceName_" + i, permissionOnResource.getOlatResourceable().getResourceableTypeName());
}
}
// add authentication providers
if (hasAuthProviders) {
for (int i = 0; i < authProviders.length; i++) {
String authProvider = authProviders[i];
if (authProvider != null) {
dbq.setString("authProvider_" + i, authProvider);
}
// ignore null auth provider, already set to null in query
}
}
// add date restrictions
if (createdAfter != null) {
dbq.setDate("createdAfter", createdAfter);
}
if (createdBefore != null) {
dbq.setDate("createdBefore", createdBefore);
}
if (status != null) {
dbq.setInteger("status", status);
}
// execute query
return dbq.list();
}