Search in sources :

Example 6 with PersonInfo

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];
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) BooleanQuery(org.apache.lucene.search.BooleanQuery) PersonInfo(org.alfresco.service.cmr.security.PersonService.PersonInfo) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ArrayList(java.util.ArrayList) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) PagingRequest(org.alfresco.query.PagingRequest) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

UserTransaction (javax.transaction.UserTransaction)6 PagingRequest (org.alfresco.query.PagingRequest)6 PersonInfo (org.alfresco.service.cmr.security.PersonService.PersonInfo)6 FacesContext (javax.faces.context.FacesContext)5 ArrayList (java.util.ArrayList)3 SelectItem (javax.faces.model.SelectItem)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Pair (org.alfresco.util.Pair)3 SortableSelectItem (org.alfresco.web.ui.common.SortableSelectItem)3 IOException (java.io.IOException)2 List (java.util.List)2 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)2 ResultSet (org.alfresco.service.cmr.search.ResultSet)2 MapNode (org.alfresco.web.bean.repository.MapNode)2 Node (org.alfresco.web.bean.repository.Node)2 ReportedException (org.alfresco.web.ui.common.ReportedException)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 AbortProcessingException (javax.faces.event.AbortProcessingException)1 SearcherException (org.alfresco.repo.search.SearcherException)1 AuthorityDAO (org.alfresco.repo.security.authority.AuthorityDAO)1