@Test public void should_return_null_criterias_when_null_request() { request = null; exception.expect(IllegalArgumentException.class); exception.expectMessage("The HTTP request cannot be null"); DatatablesCriterias.getFromRequest(request); }
public static DatatablesCriterias getFromRequest(HttpServletRequest request) { Validate.notNull(request, "The HTTP request cannot be null"); int columnNumber = getColumnNumber(request); LOG.trace("Number of columns: {}", columnNumber); String paramSearch = request.getParameter(DTConstants.DT_S_SEARCH); String paramDraw = request.getParameter(DTConstants.DT_I_DRAW); String paramStart = request.getParameter(DTConstants.DT_I_START); String paramLength = request.getParameter(DTConstants.DT_I_LENGTH); Integer draw = StringUtils.isNotBlank(paramDraw) ? Integer.parseInt(paramDraw) : -1; Integer start = StringUtils.isNotBlank(paramStart) ? Integer.parseInt(paramStart) : -1; Integer length = StringUtils.isNotBlank(paramLength) ? Integer.parseInt(paramLength) : -1; List<ColumnDef> columnDefs = new ArrayList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(request.getParameter("columns[" + i + "][data]")); columnDef.setSearchable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][searchable]"))); columnDef.setSortable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][orderable]"))); columnDef.setRegex(request.getParameter("columns[" + i + "][search][regex]")); String searchTerm = request.getParameter("columns[" + i + "][search][value]"); if (StringUtils.isNotBlank(searchTerm)) { columnDef.setFiltered(true); String[] splittedSearch = searchTerm.split("~"); if ("~".equals(searchTerm)) { columnDef.setSearch(""); } else if (searchTerm.startsWith("~")) { columnDef.setSearchTo(splittedSearch[1]); } else if (searchTerm.endsWith("~")) { columnDef.setSearchFrom(splittedSearch[0]); } else if (searchTerm.contains("~")) { columnDef.setSearchFrom(splittedSearch[0]); columnDef.setSearchTo(splittedSearch[1]); } else { columnDef.setSearch(searchTerm); } } for (int j = 0; j < columnNumber; j++) { String ordered = request.getParameter("order[" + j + "][column]"); if (ordered != null && ordered.equals(String.valueOf(i))) { columnDef.setSorted(true); break; } } columnDefs.add(columnDef); } List<ColumnDef> sortedColumnDefs = new LinkedList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { String paramSortedCol = request.getParameter("order[" + i + "][column]"); if (StringUtils.isNotBlank(paramSortedCol)) { Integer sortedCol = Integer.parseInt(paramSortedCol); ColumnDef sortedColumnDef = columnDefs.get(sortedCol); String sortedColDirection = request.getParameter("order[" + i + "][dir]"); if (StringUtils.isNotBlank(sortedColDirection)) { sortedColumnDef.setSortDirection(SortDirection.valueOf(sortedColDirection.toUpperCase())); } sortedColumnDefs.add(sortedColumnDef); } } return new DatatablesCriterias(paramSearch, start, length, columnDefs, sortedColumnDefs, draw); }
DatatablesCriterias implements Serializable { public static DatatablesCriterias getFromRequest(HttpServletRequest request) { Validate.notNull(request, "The HTTP request cannot be null"); int columnNumber = getColumnNumber(request); LOG.trace("Number of columns: {}", columnNumber); String paramSearch = request.getParameter(DTConstants.DT_S_SEARCH); String paramDraw = request.getParameter(DTConstants.DT_I_DRAW); String paramStart = request.getParameter(DTConstants.DT_I_START); String paramLength = request.getParameter(DTConstants.DT_I_LENGTH); Integer draw = StringUtils.isNotBlank(paramDraw) ? Integer.parseInt(paramDraw) : -1; Integer start = StringUtils.isNotBlank(paramStart) ? Integer.parseInt(paramStart) : -1; Integer length = StringUtils.isNotBlank(paramLength) ? Integer.parseInt(paramLength) : -1; List<ColumnDef> columnDefs = new ArrayList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(request.getParameter("columns[" + i + "][data]")); columnDef.setSearchable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][searchable]"))); columnDef.setSortable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][orderable]"))); columnDef.setRegex(request.getParameter("columns[" + i + "][search][regex]")); String searchTerm = request.getParameter("columns[" + i + "][search][value]"); if (StringUtils.isNotBlank(searchTerm)) { columnDef.setFiltered(true); String[] splittedSearch = searchTerm.split("~"); if ("~".equals(searchTerm)) { columnDef.setSearch(""); } else if (searchTerm.startsWith("~")) { columnDef.setSearchTo(splittedSearch[1]); } else if (searchTerm.endsWith("~")) { columnDef.setSearchFrom(splittedSearch[0]); } else if (searchTerm.contains("~")) { columnDef.setSearchFrom(splittedSearch[0]); columnDef.setSearchTo(splittedSearch[1]); } else { columnDef.setSearch(searchTerm); } } for (int j = 0; j < columnNumber; j++) { String ordered = request.getParameter("order[" + j + "][column]"); if (ordered != null && ordered.equals(String.valueOf(i))) { columnDef.setSorted(true); break; } } columnDefs.add(columnDef); } List<ColumnDef> sortedColumnDefs = new LinkedList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { String paramSortedCol = request.getParameter("order[" + i + "][column]"); if (StringUtils.isNotBlank(paramSortedCol)) { Integer sortedCol = Integer.parseInt(paramSortedCol); ColumnDef sortedColumnDef = columnDefs.get(sortedCol); String sortedColDirection = request.getParameter("order[" + i + "][dir]"); if (StringUtils.isNotBlank(sortedColDirection)) { sortedColumnDef.setSortDirection(SortDirection.valueOf(sortedColDirection.toUpperCase())); } sortedColumnDefs.add(sortedColumnDef); } } return new DatatablesCriterias(paramSearch, start, length, columnDefs, sortedColumnDefs, draw); } }
DatatablesCriterias implements Serializable { public static DatatablesCriterias getFromRequest(HttpServletRequest request) { Validate.notNull(request, "The HTTP request cannot be null"); int columnNumber = getColumnNumber(request); LOG.trace("Number of columns: {}", columnNumber); String paramSearch = request.getParameter(DTConstants.DT_S_SEARCH); String paramDraw = request.getParameter(DTConstants.DT_I_DRAW); String paramStart = request.getParameter(DTConstants.DT_I_START); String paramLength = request.getParameter(DTConstants.DT_I_LENGTH); Integer draw = StringUtils.isNotBlank(paramDraw) ? Integer.parseInt(paramDraw) : -1; Integer start = StringUtils.isNotBlank(paramStart) ? Integer.parseInt(paramStart) : -1; Integer length = StringUtils.isNotBlank(paramLength) ? Integer.parseInt(paramLength) : -1; List<ColumnDef> columnDefs = new ArrayList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(request.getParameter("columns[" + i + "][data]")); columnDef.setSearchable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][searchable]"))); columnDef.setSortable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][orderable]"))); columnDef.setRegex(request.getParameter("columns[" + i + "][search][regex]")); String searchTerm = request.getParameter("columns[" + i + "][search][value]"); if (StringUtils.isNotBlank(searchTerm)) { columnDef.setFiltered(true); String[] splittedSearch = searchTerm.split("~"); if ("~".equals(searchTerm)) { columnDef.setSearch(""); } else if (searchTerm.startsWith("~")) { columnDef.setSearchTo(splittedSearch[1]); } else if (searchTerm.endsWith("~")) { columnDef.setSearchFrom(splittedSearch[0]); } else if (searchTerm.contains("~")) { columnDef.setSearchFrom(splittedSearch[0]); columnDef.setSearchTo(splittedSearch[1]); } else { columnDef.setSearch(searchTerm); } } for (int j = 0; j < columnNumber; j++) { String ordered = request.getParameter("order[" + j + "][column]"); if (ordered != null && ordered.equals(String.valueOf(i))) { columnDef.setSorted(true); break; } } columnDefs.add(columnDef); } List<ColumnDef> sortedColumnDefs = new LinkedList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { String paramSortedCol = request.getParameter("order[" + i + "][column]"); if (StringUtils.isNotBlank(paramSortedCol)) { Integer sortedCol = Integer.parseInt(paramSortedCol); ColumnDef sortedColumnDef = columnDefs.get(sortedCol); String sortedColDirection = request.getParameter("order[" + i + "][dir]"); if (StringUtils.isNotBlank(sortedColDirection)) { sortedColumnDef.setSortDirection(SortDirection.valueOf(sortedColDirection.toUpperCase())); } sortedColumnDefs.add(sortedColumnDef); } } return new DatatablesCriterias(paramSearch, start, length, columnDefs, sortedColumnDefs, draw); } private  DatatablesCriterias(String search, Integer displayStart, Integer displaySize, List<ColumnDef> columnDefs,
         List<ColumnDef> sortedColumnDefs, Integer draw); }
DatatablesCriterias implements Serializable { public static DatatablesCriterias getFromRequest(HttpServletRequest request) { Validate.notNull(request, "The HTTP request cannot be null"); int columnNumber = getColumnNumber(request); LOG.trace("Number of columns: {}", columnNumber); String paramSearch = request.getParameter(DTConstants.DT_S_SEARCH); String paramDraw = request.getParameter(DTConstants.DT_I_DRAW); String paramStart = request.getParameter(DTConstants.DT_I_START); String paramLength = request.getParameter(DTConstants.DT_I_LENGTH); Integer draw = StringUtils.isNotBlank(paramDraw) ? Integer.parseInt(paramDraw) : -1; Integer start = StringUtils.isNotBlank(paramStart) ? Integer.parseInt(paramStart) : -1; Integer length = StringUtils.isNotBlank(paramLength) ? Integer.parseInt(paramLength) : -1; List<ColumnDef> columnDefs = new ArrayList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(request.getParameter("columns[" + i + "][data]")); columnDef.setSearchable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][searchable]"))); columnDef.setSortable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][orderable]"))); columnDef.setRegex(request.getParameter("columns[" + i + "][search][regex]")); String searchTerm = request.getParameter("columns[" + i + "][search][value]"); if (StringUtils.isNotBlank(searchTerm)) { columnDef.setFiltered(true); String[] splittedSearch = searchTerm.split("~"); if ("~".equals(searchTerm)) { columnDef.setSearch(""); } else if (searchTerm.startsWith("~")) { columnDef.setSearchTo(splittedSearch[1]); } else if (searchTerm.endsWith("~")) { columnDef.setSearchFrom(splittedSearch[0]); } else if (searchTerm.contains("~")) { columnDef.setSearchFrom(splittedSearch[0]); columnDef.setSearchTo(splittedSearch[1]); } else { columnDef.setSearch(searchTerm); } } for (int j = 0; j < columnNumber; j++) { String ordered = request.getParameter("order[" + j + "][column]"); if (ordered != null && ordered.equals(String.valueOf(i))) { columnDef.setSorted(true); break; } } columnDefs.add(columnDef); } List<ColumnDef> sortedColumnDefs = new LinkedList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { String paramSortedCol = request.getParameter("order[" + i + "][column]"); if (StringUtils.isNotBlank(paramSortedCol)) { Integer sortedCol = Integer.parseInt(paramSortedCol); ColumnDef sortedColumnDef = columnDefs.get(sortedCol); String sortedColDirection = request.getParameter("order[" + i + "][dir]"); if (StringUtils.isNotBlank(sortedColDirection)) { sortedColumnDef.setSortDirection(SortDirection.valueOf(sortedColDirection.toUpperCase())); } sortedColumnDefs.add(sortedColumnDef); } } return new DatatablesCriterias(paramSearch, start, length, columnDefs, sortedColumnDefs, draw); } private  DatatablesCriterias(String search, Integer displayStart, Integer displaySize, List<ColumnDef> columnDefs,
         List<ColumnDef> sortedColumnDefs, Integer draw); Integer getStart(); Integer getLength(); String getSearch(); Integer getDraw(); List<ColumnDef> getColumnDefs(); List<ColumnDef> getSortingColumnDefs(); List<ColumnDef> getSortedColumnDefs(); Boolean hasOneFilterableColumn(); Boolean hasOneSearchableColumn(); Boolean hasOneFilteredColumn(); Boolean hasOneSortedColumn(); static DatatablesCriterias getFromRequest(HttpServletRequest request); @Override String toString(); }
DatatablesCriterias implements Serializable { public static DatatablesCriterias getFromRequest(HttpServletRequest request) { Validate.notNull(request, "The HTTP request cannot be null"); int columnNumber = getColumnNumber(request); LOG.trace("Number of columns: {}", columnNumber); String paramSearch = request.getParameter(DTConstants.DT_S_SEARCH); String paramDraw = request.getParameter(DTConstants.DT_I_DRAW); String paramStart = request.getParameter(DTConstants.DT_I_START); String paramLength = request.getParameter(DTConstants.DT_I_LENGTH); Integer draw = StringUtils.isNotBlank(paramDraw) ? Integer.parseInt(paramDraw) : -1; Integer start = StringUtils.isNotBlank(paramStart) ? Integer.parseInt(paramStart) : -1; Integer length = StringUtils.isNotBlank(paramLength) ? Integer.parseInt(paramLength) : -1; List<ColumnDef> columnDefs = new ArrayList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(request.getParameter("columns[" + i + "][data]")); columnDef.setSearchable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][searchable]"))); columnDef.setSortable(Boolean.parseBoolean(request.getParameter("columns[" + i + "][orderable]"))); columnDef.setRegex(request.getParameter("columns[" + i + "][search][regex]")); String searchTerm = request.getParameter("columns[" + i + "][search][value]"); if (StringUtils.isNotBlank(searchTerm)) { columnDef.setFiltered(true); String[] splittedSearch = searchTerm.split("~"); if ("~".equals(searchTerm)) { columnDef.setSearch(""); } else if (searchTerm.startsWith("~")) { columnDef.setSearchTo(splittedSearch[1]); } else if (searchTerm.endsWith("~")) { columnDef.setSearchFrom(splittedSearch[0]); } else if (searchTerm.contains("~")) { columnDef.setSearchFrom(splittedSearch[0]); columnDef.setSearchTo(splittedSearch[1]); } else { columnDef.setSearch(searchTerm); } } for (int j = 0; j < columnNumber; j++) { String ordered = request.getParameter("order[" + j + "][column]"); if (ordered != null && ordered.equals(String.valueOf(i))) { columnDef.setSorted(true); break; } } columnDefs.add(columnDef); } List<ColumnDef> sortedColumnDefs = new LinkedList<ColumnDef>(); for (int i = 0; i < columnNumber; i++) { String paramSortedCol = request.getParameter("order[" + i + "][column]"); if (StringUtils.isNotBlank(paramSortedCol)) { Integer sortedCol = Integer.parseInt(paramSortedCol); ColumnDef sortedColumnDef = columnDefs.get(sortedCol); String sortedColDirection = request.getParameter("order[" + i + "][dir]"); if (StringUtils.isNotBlank(sortedColDirection)) { sortedColumnDef.setSortDirection(SortDirection.valueOf(sortedColDirection.toUpperCase())); } sortedColumnDefs.add(sortedColumnDef); } } return new DatatablesCriterias(paramSearch, start, length, columnDefs, sortedColumnDefs, draw); } private  DatatablesCriterias(String search, Integer displayStart, Integer displaySize, List<ColumnDef> columnDefs,
         List<ColumnDef> sortedColumnDefs, Integer draw); Integer getStart(); Integer getLength(); String getSearch(); Integer getDraw(); List<ColumnDef> getColumnDefs(); List<ColumnDef> getSortingColumnDefs(); List<ColumnDef> getSortedColumnDefs(); Boolean hasOneFilterableColumn(); Boolean hasOneSearchableColumn(); Boolean hasOneFilteredColumn(); Boolean hasOneSortedColumn(); static DatatablesCriterias getFromRequest(HttpServletRequest request); @Override String toString();  }