@Test(expected = HTTP400Exception.class) public void testBuildCheckParams() throws HTTP400Exception { String param1 = "_querySpec"; String value1 = "whatever"; String param2 = "sourceSystem.code"; String value2 = "CRS"; String param3 = "_fields"; String value3 = "Aves"; MultivaluedHashMap<String, String> parameterMap = new MultivaluedHashMap<>(); parameterMap.put(param1, new ArrayList<>(Arrays.asList(value1))); parameterMap.put(param2, new ArrayList<>(Arrays.asList(value2))); parameterMap.put(param3, new ArrayList<>(Arrays.asList(value3))); UriInfo uriInfo = mock(UriInfo.class); when(uriInfo.getQueryParameters()).thenReturn(parameterMap); new HttpQuerySpecBuilder(uriInfo).build(); }
public QuerySpec build() { logger.info("Extracting QuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromSearchSpecParam(values); } QuerySpec qs = new QuerySpec(); ComparisonOperator operator = getComparisonOperator(); for (String param : params.keySet()) { values = params.get(param); if (values.size() != 1) { String msg = String.format(ERR_DUPLICATE_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } String value = values.iterator().next(); logger.info("Processing parameter {}: \"{}\"", param, value); switch (param) { case "querySpec": throw new HTTP400Exception(uriInfo, ERR_NO_UNDERSCORE); case PARAM_IGNORE_CASE: break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; default: if (param.charAt(0) == '_') { String msg = String.format(ERR_ILLEGAL_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } if (value.equals("@NULL@")) { qs.addCondition(new QueryCondition(param, EQUALS, null)); } else if (value.equals("@NOT_NULL@")) { qs.addCondition(new QueryCondition(param, NOT_EQUALS, null)); } else { qs.addCondition(new QueryCondition(param, operator, value)); } break; } } return qs; }
HttpQuerySpecBuilder { public QuerySpec build() { logger.info("Extracting QuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromSearchSpecParam(values); } QuerySpec qs = new QuerySpec(); ComparisonOperator operator = getComparisonOperator(); for (String param : params.keySet()) { values = params.get(param); if (values.size() != 1) { String msg = String.format(ERR_DUPLICATE_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } String value = values.iterator().next(); logger.info("Processing parameter {}: \"{}\"", param, value); switch (param) { case "querySpec": throw new HTTP400Exception(uriInfo, ERR_NO_UNDERSCORE); case PARAM_IGNORE_CASE: break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; default: if (param.charAt(0) == '_') { String msg = String.format(ERR_ILLEGAL_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } if (value.equals("@NULL@")) { qs.addCondition(new QueryCondition(param, EQUALS, null)); } else if (value.equals("@NOT_NULL@")) { qs.addCondition(new QueryCondition(param, NOT_EQUALS, null)); } else { qs.addCondition(new QueryCondition(param, operator, value)); } break; } } return qs; } }
HttpQuerySpecBuilder { public QuerySpec build() { logger.info("Extracting QuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromSearchSpecParam(values); } QuerySpec qs = new QuerySpec(); ComparisonOperator operator = getComparisonOperator(); for (String param : params.keySet()) { values = params.get(param); if (values.size() != 1) { String msg = String.format(ERR_DUPLICATE_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } String value = values.iterator().next(); logger.info("Processing parameter {}: \"{}\"", param, value); switch (param) { case "querySpec": throw new HTTP400Exception(uriInfo, ERR_NO_UNDERSCORE); case PARAM_IGNORE_CASE: break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; default: if (param.charAt(0) == '_') { String msg = String.format(ERR_ILLEGAL_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } if (value.equals("@NULL@")) { qs.addCondition(new QueryCondition(param, EQUALS, null)); } else if (value.equals("@NOT_NULL@")) { qs.addCondition(new QueryCondition(param, NOT_EQUALS, null)); } else { qs.addCondition(new QueryCondition(param, operator, value)); } break; } } return qs; } HttpQuerySpecBuilder(UriInfo uriInfo);  HttpQuerySpecBuilder(MultivaluedMap<String, String> formData, UriInfo uriInfo); }
HttpQuerySpecBuilder { public QuerySpec build() { logger.info("Extracting QuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromSearchSpecParam(values); } QuerySpec qs = new QuerySpec(); ComparisonOperator operator = getComparisonOperator(); for (String param : params.keySet()) { values = params.get(param); if (values.size() != 1) { String msg = String.format(ERR_DUPLICATE_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } String value = values.iterator().next(); logger.info("Processing parameter {}: \"{}\"", param, value); switch (param) { case "querySpec": throw new HTTP400Exception(uriInfo, ERR_NO_UNDERSCORE); case PARAM_IGNORE_CASE: break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; default: if (param.charAt(0) == '_') { String msg = String.format(ERR_ILLEGAL_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } if (value.equals("@NULL@")) { qs.addCondition(new QueryCondition(param, EQUALS, null)); } else if (value.equals("@NOT_NULL@")) { qs.addCondition(new QueryCondition(param, NOT_EQUALS, null)); } else { qs.addCondition(new QueryCondition(param, operator, value)); } break; } } return qs; } HttpQuerySpecBuilder(UriInfo uriInfo);  HttpQuerySpecBuilder(MultivaluedMap<String, String> formData, UriInfo uriInfo); QuerySpec build(); }
HttpQuerySpecBuilder { public QuerySpec build() { logger.info("Extracting QuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromSearchSpecParam(values); } QuerySpec qs = new QuerySpec(); ComparisonOperator operator = getComparisonOperator(); for (String param : params.keySet()) { values = params.get(param); if (values.size() != 1) { String msg = String.format(ERR_DUPLICATE_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } String value = values.iterator().next(); logger.info("Processing parameter {}: \"{}\"", param, value); switch (param) { case "querySpec": throw new HTTP400Exception(uriInfo, ERR_NO_UNDERSCORE); case PARAM_IGNORE_CASE: break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; default: if (param.charAt(0) == '_') { String msg = String.format(ERR_ILLEGAL_PARAM, param); throw new HTTP400Exception(uriInfo, msg); } if (value.equals("@NULL@")) { qs.addCondition(new QueryCondition(param, EQUALS, null)); } else if (value.equals("@NOT_NULL@")) { qs.addCondition(new QueryCondition(param, NOT_EQUALS, null)); } else { qs.addCondition(new QueryCondition(param, operator, value)); } break; } } return qs; } HttpQuerySpecBuilder(UriInfo uriInfo);  HttpQuerySpecBuilder(MultivaluedMap<String, String> formData, UriInfo uriInfo); QuerySpec build(); static final String PARAM_QUERY_SPEC; static final String PARAM_FIELDS; static final String PARAM_FROM; static final String PARAM_SIZE; static final String PARAM_OPERATOR; static final String PARAM_SORT_FIELDS; static final String PARAM_IGNORE_CASE; }