use of org.alfresco.web.ui.common.SortableSelectItem in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method addGroupItems.
private List<SelectItem> addGroupItems(String search, int maxResults) {
Set<String> groups = getGroups(search);
List<SelectItem> results = new ArrayList<SelectItem>(groups.size());
int count = 0;
String groupDisplayName;
for (String group : groups) {
// get display name, if not present strip prefix from group id
groupDisplayName = getAuthorityService().getAuthorityDisplayName(group);
if (groupDisplayName == null || groupDisplayName.length() == 0) {
groupDisplayName = group.substring(PermissionService.GROUP_PREFIX.length());
}
results.add(new SortableSelectItem(group, groupDisplayName, groupDisplayName));
if (++count == maxResults)
break;
}
return results;
}
use of org.alfresco.web.ui.common.SortableSelectItem in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method pickerCallback.
/**
* 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, String contains) {
FacesContext context = FacesContext.getCurrentInstance();
// quick exit if not enough characters entered for a search
String search = contains.trim();
int searchMin = Application.getClientConfig(context).getPickerSearchMinimum();
if (search.length() < searchMin) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, MSG_SEARCH_MINIMUM), searchMin));
return new SelectItem[0];
}
SelectItem[] items;
this.maxUsersReturned = false;
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
int maxResults = Application.getClientConfig(context).getInviteUsersMaxResults();
if (maxResults <= 0) {
maxResults = Utils.getPersonMaxResults();
}
List<SelectItem> results;
if (filterIndex == 0) {
// Use lucene search to retrieve user details
List<Pair<QName, String>> filter = null;
if (search == null || search.length() == 0) {
// if there is no search term, search for all people
} else {
filter = Utils.generatePersonFilter(search);
}
if (logger.isDebugEnabled()) {
logger.debug("Maximum invite users results size: " + maxResults);
logger.debug("Using query filter to find users: " + filter);
}
List<PersonInfo> persons = getPersonService().getPeople(filter, true, Utils.generatePersonSort(), new PagingRequest(maxResults, null)).getPage();
results = new ArrayList<SelectItem>(persons.size());
for (int index = 0; index < persons.size(); index++) {
PersonInfo person = persons.get(index);
String firstName = person.getFirstName();
String lastName = person.getLastName();
String username = person.getUserName();
if (username != null) {
String name = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
SelectItem item = new SortableSelectItem(username, name + " [" + username + "]", lastName != null ? lastName : username);
results.add(item);
}
}
} else {
results = addGroupItems(search, maxResults);
}
items = new SelectItem[results.size()];
results.toArray(items);
Arrays.sort(items);
// set the maximum users returned flag if appropriate
if (results.size() == maxResults) {
this.maxUsersReturned = true;
}
// commit the transaction
tx.commit();
} catch (BooleanQuery.TooManyClauses clauses) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), "too_many_users"));
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
items = new SelectItem[0];
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
items = new SelectItem[0];
}
return items;
}
use of org.alfresco.web.ui.common.SortableSelectItem in project acs-community-packaging by Alfresco.
the class BaseReassignDialog method pickerCallback.
/**
* 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, String contains) {
FacesContext context = FacesContext.getCurrentInstance();
// quick exit if not enough characters entered for a search
String search = contains.trim();
int searchMin = Application.getClientConfig(context).getPickerSearchMinimum();
if (search.length() < searchMin) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, MSG_SEARCH_MINIMUM), searchMin));
return new SelectItem[0];
}
SelectItem[] items;
UserTransaction tx = null;
ResultSet resultSet = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
int maxResults = Application.getClientConfig(context).getInviteUsersMaxResults();
if (maxResults <= 0) {
maxResults = Utils.getPersonMaxResults();
}
List<PersonInfo> persons = getPersonService().getPeople(Utils.generatePersonFilter(contains.trim()), true, Utils.generatePersonSort(), new PagingRequest(maxResults, 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();
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);
Arrays.sort(items);
// commit the transaction
tx.commit();
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
items = new SelectItem[0];
} finally {
if (resultSet != null) {
resultSet.close();
}
}
return items;
}
use of org.alfresco.web.ui.common.SortableSelectItem 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