@Test public void shouldBuildQueryParams() { Map<String, String> requestParams = new HashMap<>(); requestParams.put("page", "14"); requestParams.put("pageSize", "120"); requestParams.put("sort", "someColumn"); requestParams.put("order", "desc"); QueryParams queryParams = ParamParser.buildQueryParams(requestParams); assertEquals(Integer.valueOf(14), queryParams.getPage()); assertEquals(Integer.valueOf(120), queryParams.getPageSize()); assertNotNull(queryParams.getOrderList()); assertEquals(1, queryParams.getOrderList().size()); assertEquals("someColumn", queryParams.getOrderList().get(0).getField()); assertEquals(Order.Direction.DESC, queryParams.getOrderList().get(0).getDirection()); requestParams.remove("sort"); requestParams.remove("order"); queryParams = ParamParser.buildQueryParams(requestParams); assertTrue(queryParams.getOrderList().isEmpty()); requestParams.put("sort", "anotherColumn"); queryParams = ParamParser.buildQueryParams(requestParams); assertNotNull(queryParams.getOrderList()); assertEquals(1, queryParams.getOrderList().size()); assertEquals("anotherColumn", queryParams.getOrderList().get(0).getField()); assertEquals(Order.Direction.ASC, queryParams.getOrderList().get(0).getDirection()); }
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); }
ParamParser { 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); } }
ParamParser { 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); } private  ParamParser(); }
ParamParser { 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); } private  ParamParser(); static QueryParams buildQueryParams(Map<String, String> requestParams); static String getLookupName(Map<String, String> requestParams); static Long getId(Map<String, String> requestParams); static Boolean getIncludeBlob(Map<String, String> requestParams); }
ParamParser { 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); } private  ParamParser(); static QueryParams buildQueryParams(Map<String, String> requestParams); static String getLookupName(Map<String, String> requestParams); static Long getId(Map<String, String> requestParams); static Boolean getIncludeBlob(Map<String, String> requestParams); static final String PAGE; static final String PAGE_SIZE; static final String SORT_BY; static final String ORDER_DIR; static final String LOOKUP_NAME; static final String ID; static final String INCLUDE_BLOB; }