use of org.alfresco.service.cmr.security.PersonService.PersonInfo in project acs-community-packaging by Alfresco.
the class AddUsersDialog method pickerCallback.
// ------------------------------------------------------------------------------
// Helpers
/**
* Query callback method executed by the Generic Picker component. This
* method is part of the contract to the Generic Picker, it is up to the
* backing bean to execute whatever query is appropriate and return the
* results.
*
* @param filterIndex Index of the filter drop-down selection
* @param contains Text from the contains textbox
* @return An array of SelectItem objects containing the results to display
* in the picker.
*/
public SelectItem[] pickerCallback(int filterIndex, final String contains) {
final FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
// getUserTransaction(context);
RetryingTransactionHelper txHelper = Repository.getRetryingTransactionHelper(context);
return txHelper.doInTransaction(new RetryingTransactionCallback<SelectItem[]>() {
public SelectItem[] execute() throws Exception {
SelectItem[] items = new SelectItem[0];
// Use the Person Service to retrieve user details
String term = contains.trim();
if (term.length() != 0) {
List<PersonInfo> persons = getPersonService().getPeople(Utils.generatePersonFilter(contains.trim()), true, Utils.generatePersonSort(), new PagingRequest(Utils.getPersonMaxResults(), null)).getPage();
ArrayList<SelectItem> itemList = new ArrayList<SelectItem>(persons.size());
for (PersonInfo person : persons) {
String username = person.getUserName();
if (AuthenticationUtil.getGuestUserName().equals(username) == false) {
String firstName = person.getFirstName();
String lastName = person.getLastName();
// build a sensible label for display
String name = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
SelectItem item = new SortableSelectItem(username, name + " [" + username + "]", lastName != null ? lastName : username);
itemList.add(item);
}
}
items = new SelectItem[itemList.size()];
itemList.toArray(items);
}
return items;
}
});
} catch (BooleanQuery.TooManyClauses clauses) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "too_many_users"));
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
return new SelectItem[0];
} catch (Exception err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
return new SelectItem[0];
}
}
Aggregations