* @throws SQLException
*/
public Collection<AjaxAutocompleteAnswer> findByCountryIdAutocomplete(String userIdEditing, String countryId, String term, String userIdEdited, String status) throws SQLException, NoServiceException {
String service = "ADMINUSER_PAGE";
if (hasService(userIdEditing, service)) {
User user = Dispatcher.getInstance().getUser(userIdEditing);
Connection con = null;
try {
con = DbHandler.getConnection();
Collection<CentreBean> col = UserRelation.retrieveCentreListForACountry(con, user, Integer.valueOf(1), Integer.valueOf(1), countryId, term);
BeanSorter.sort(BeanSorter.getLocale(user), col, "centrename");
Collection<AjaxAutocompleteAnswer> aaac = Collections.synchronizedList(new ArrayList<AjaxAutocompleteAnswer>());
Map<String, Map<String, GrouprelationBean>> userGroupRels = GrouprelationFinder.findAllAsMap(con);
Map<String, UsergroupBean> userGroupMap = UsergroupFinder.searchByUseUcr(Integer.valueOf(0));
// if admin user is not ucr-user, then the user might have different groupid for different centers,
// set to null now and find out groupid per center
String grpidforcentre = (userGroupMap.get(user.getGroupid()) != null ? user.getGroupid() : null);
for (CentreBean cb : col) {
if (userIdEdited != null) {
//Find all relations to centers for the user that is administrated
Collection<UsercentrerelBean> colUserCentres = UsercentrerelFinder.findByUserid(con, userIdEdited);
boolean show = true;
for (UsercentrerelBean crb : colUserCentres) {
//No status means that we are interested in all centers that the edited user is NOT related to
if (status == null && crb.getCentreid().equals(cb.getId())) {
show = false;
break;
//Status not null means that we want all centres that the user has a relation to with the specified status
} else if (status != null && crb.getCentreid().equals(cb.getId()) && Integer.valueOf(status).equals(crb.getStatus())) {
show = true;
break;
} else if (status != null) {
show = false;
}
}
if (show) {
if (grpidforcentre == null) {
grpidforcentre = UsercentrerelFinder.findGroupidByUseridCentreid(con, user.getId(), cb.getId());
}
AjaxAutocompleteAnswer aaa = new AjaxAutocompleteAnswer();
aaa.setLabel(cb.getCentrename());
aaa.setValue(cb.getId());
aaa.setExtra1(AdminUserCentreRelFormTag.getGroupSelect(LanguageHandler.getInstance(), user.getLanguageid(),
grpidforcentre, cb.getId(), null, userGroupMap, userGroupRels).toString());
aaac.add(aaa);
}
} else {
AjaxAutocompleteAnswer aaa = new AjaxAutocompleteAnswer();