/** * Domain function to search users based on criteria that are assembled into a filter VO. */ public AppUserShortWithNameVoCollection searchUsers(AppUserShortVo filterVo) throws DomainInterfaceException { if (filterVo == null) throw new DomainInterfaceException("Can not search on null user surname"); if (filterVo.getUserRealName() == null || filterVo.getUserRealName().length() == 0) throw new DomainInterfaceException("Can not search on null or zero lenght surname"); String[] names = filterVo.getUserRealName().split(" "); DomainFactory factory = getDomainFactory(); StringBuffer hql = new StringBuffer(); String query = " from AppUser au "; ArrayList<String> markers = new ArrayList<String>(); ArrayList<Object> values = new ArrayList<Object>(); // Build search criteria Forename OR Surname { if (markers.size() > 0) hql.append(" AND ("); else hql.append(" ("); for (int i = 0; i < names.length; i++) { hql.append("au.mos.name.upperSurname like :SURNAME" + i); markers.add("SURNAME" + i); values.add("%" + names[i].toUpperCase() + "%"); hql.append(" OR "); hql.append("au.mos.name.upperForename like :FORENAME" + i); markers.add("FORENAME" + i); values.add("%" + names[i].toUpperCase() + "%"); if (i != names.length - 1) hql.append(" OR "); } hql.append(")"); } if (markers.size() > 0) query += " where "; query += hql.toString(); try { List<DomainObject> results = factory.find(query, markers, values); // We need to create a AppUserVoCollection because we need the name (if we create AppUserShortVoCollection we do not get the name) return AppUserShortWithNameVoAssembler.createAppUserShortWithNameVoCollectionFromAppUser(results); } catch (RuntimeException e) { e.printStackTrace(); return null; } }