Search in sources :

Example 1 with InvalidParameterException

use of org.motechproject.mds.web.exception.InvalidParameterException in project motech by motech.

the class ParamParser method buildQueryParams.

public static QueryParams buildQueryParams(Map<String, String> requestParams) {
    Integer page;
    Integer pageSize;
    String sortBy;
    String orderDir;
    Order order;
    try {
        page = getInteger(requestParams, PAGE, 1);
    } catch (NumberFormatException e) {
        throw new InvalidParameterException("Given page is not a number!", e);
    }
    try {
        pageSize = getInteger(requestParams, PAGE_SIZE, 20);
    } catch (NumberFormatException e) {
        throw new InvalidParameterException("Given page size is not a number!", e);
    }
    sortBy = requestParams.get(SORT_BY);
    orderDir = requestParams.get(ORDER_DIR);
    order = buildOrder(sortBy, orderDir);
    return new QueryParams(page, pageSize, order);
}
Also used : Order(org.motechproject.mds.util.Order) InvalidParameterException(org.motechproject.mds.web.exception.InvalidParameterException) QueryParams(org.motechproject.mds.query.QueryParams)

Aggregations

QueryParams (org.motechproject.mds.query.QueryParams)1 Order (org.motechproject.mds.util.Order)1 InvalidParameterException (org.motechproject.mds.web.exception.InvalidParameterException)1