Search in sources :

Example 1 with SortableSelectItem

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;
}
Also used : SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem)

Example 2 with SortableSelectItem

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;
}
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) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) PagingRequest(org.alfresco.query.PagingRequest) IOException(java.io.IOException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) SelectItem(javax.faces.model.SelectItem) Pair(org.alfresco.util.Pair)

Example 3 with SortableSelectItem

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;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) PersonInfo(org.alfresco.service.cmr.security.PersonService.PersonInfo) 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) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 4 with SortableSelectItem

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];
    }
}
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

SelectItem (javax.faces.model.SelectItem)4 SortableSelectItem (org.alfresco.web.ui.common.SortableSelectItem)4 ArrayList (java.util.ArrayList)3 FacesContext (javax.faces.context.FacesContext)3 UserTransaction (javax.transaction.UserTransaction)3 PagingRequest (org.alfresco.query.PagingRequest)3 PersonInfo (org.alfresco.service.cmr.security.PersonService.PersonInfo)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 IOException (java.io.IOException)1 List (java.util.List)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 Pair (org.alfresco.util.Pair)1