Search in sources :

Example 1 with Pager

use of edu.harvard.iq.dataverse.mydata.Pager in project dataverse by IQSS.

the class UserListMaker method runUserSearch.

public UserListResult runUserSearch(String searchTerm, Integer itemsPerPage, Integer selectedPage, String sorKey) {
    // Initialize searchTerm
    if ((searchTerm == null) || (searchTerm.trim().isEmpty())) {
        searchTerm = null;
    }
    // Initialize itemsPerPage
    if ((itemsPerPage == null) || (itemsPerPage < MIN_ITEMS_PER_PAGE)) {
        itemsPerPage = ITEMS_PER_PAGE;
    }
    // Initialize selectedPage
    if ((selectedPage == null) || (selectedPage < 1)) {
        selectedPage = 1;
    }
    // Initialize sortKey
    String sortKey = null;
    Pager pager;
    // -------------------------------------------------
    // (1) What is the user count for this search?
    // -------------------------------------------------
    Long userCount = userService.getUserCount(searchTerm);
    // Are there any hits?  No; return info
    if ((userCount == null) || (userCount == 0)) {
        pager = new Pager(0, itemsPerPage, selectedPage);
        return new UserListResult(searchTerm, pager, null);
    }
    // -------------------------------------------------
    // (2) Do some calculations here regarding the selected page, offset, etc.
    // -------------------------------------------------
    OffsetPageValues offsetPageValues = getOffset(userCount, selectedPage, itemsPerPage);
    selectedPage = offsetPageValues.getPageNumber();
    int offset = offsetPageValues.getOffset();
    // -------------------------------------------------
    // (3) Retrieve the users
    // -------------------------------------------------
    List<AuthenticatedUser> userList = userService.getAuthenticatedUserList(searchTerm, sortKey, itemsPerPage, offset);
    if (userList == null) {
        pager = new Pager(0, itemsPerPage, selectedPage);
        return new UserListResult(searchTerm, pager, null);
    }
    pager = new Pager(userCount.intValue(), itemsPerPage, selectedPage);
    return new UserListResult(searchTerm, pager, userList);
}
Also used : Pager(edu.harvard.iq.dataverse.mydata.Pager) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Aggregations

AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 Pager (edu.harvard.iq.dataverse.mydata.Pager)1