public List<User> getRoleUsersByRole(Organization org, Role role) {
StringBuilder hql = new StringBuilder("from User u where u.disabled = 'F' and u.removed = 'F' and u.orgUser <> 'T'");
if(org != null) {
if(org.getChildren()!= null) {
hql.append(" and (u.organization=:org or :corg in elements(u.organization.children))");
}else {
hql.append(" and u.organization=:org");
}
}
if(role!=null) {
hql.append(" and :role in elements(u.roles)");
}
Query q = HibernateUtil.createQuery(hql.toString());
if(org != null) {
if(org.getChildren()!= null) {
if(org.getParent() != null) {
q.setEntity("org", org).setEntity("corg", org.getParent());
}else{
q.setEntity("org", org).setEntity("corg", org);
}
}else {
q.setEntity("org", org);
}
}
if(role!=null) {
q.setEntity("role", role);
}
return list(q);
// return find("from User where disabled=? and removed=? and organization=? and ? in elements(roles) and ? in elements(roles)", false, false, org,role1,role2);
}
StringBuilder hql = new StringBuilder("from User u where u.disabled = 'F' and u.removed = 'F' and u.orgUser <> 'T'");
if(org != null) {
if(org.getChildren()!= null) {
hql.append(" and (u.organization=:org or :corg in elements(u.organization.children))");
}else {
hql.append(" and u.organization=:org");
}
}
if(role!=null) {
hql.append(" and :role in elements(u.roles)");
}
Query q = HibernateUtil.createQuery(hql.toString());
if(org != null) {
if(org.getChildren()!= null) {
if(org.getParent() != null) {
q.setEntity("org", org).setEntity("corg", org.getParent());
}else{
q.setEntity("org", org).setEntity("corg", org);
}
}else {
q.setEntity("org", org);
}
}
if(role!=null) {
q.setEntity("role", role);
}
return list(q);
// return find("from User where disabled=? and removed=? and organization=? and ? in elements(roles) and ? in elements(roles)", false, false, org,role1,role2);
}