@Test public void testBuildGetComparisonOperator() { String param1 = "sourceSystem.code"; String value1 = "BRAHMS"; String param2 = "collectionType"; String value2 = "Botany"; String param3 = "license"; String value3 = "CC0"; String param4 = "_fields"; String value4 = "unitID,recordBasis,gatheringEvent.country"; 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))); parameterMap.put(param4, new ArrayList<>(Arrays.asList(value4))); String param5 = "_ignoreCase", value5 = "true"; parameterMap.put(param5, new ArrayList<>(Arrays.asList(value5))); UriInfo uriInfo = mock(UriInfo.class); when(uriInfo.getQueryParameters()).thenReturn(parameterMap); GroupByScientificNameQuerySpec qs = new HttpGroupByScientificNameQuerySpecBuilder(uriInfo) .build(); Boolean operatorTest = false; for (QueryCondition cond : qs.getConditions()) { if (cond.getOperator() == EQUALS_IC) { operatorTest = true; } else { operatorTest = false; break; } } assertTrue("Test of parameter: _ignoreCase=true", operatorTest); value5 = ""; parameterMap.get(param5).set(0, value5); uriInfo = mock(UriInfo.class); when(uriInfo.getQueryParameters()).thenReturn(parameterMap); qs = new HttpGroupByScientificNameQuerySpecBuilder(uriInfo).build(); operatorTest = false; for (QueryCondition cond : qs.getConditions()) { if (cond.getOperator() == EQUALS) { operatorTest = true; } else { operatorTest = false; break; } } assertTrue("Test of parameter: _ignoreCase=\"\"", operatorTest); }
public GroupByScientificNameQuerySpec build() { logger.info("Extracting NameGroupQuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromQuerySpecParam(values); } GroupByScientificNameQuerySpec qs = new GroupByScientificNameQuerySpec(); 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_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; case PARAM_GROUP_SORT: qs.setGroupSort(GroupSort.parse(value)); break; case PARAM_GROUP_FILTER: if (value.length() != 0) { String[] filters = value.split(","); Filter filter = new Filter(); if (filters.length == 1) { filter.acceptRegexp(filters[0]); } else { filter.acceptValues(filters); } qs.setGroupFilter(filter); } break; case PARAM_SPECIMENS_FROM: qs.setSpecimensFrom(getIntParam(param, value)); break; case PARAM_SPECIMENS_SIZE: qs.setSpecimensSize(getIntParam(param, value)); break; case PARAM_SPECIMENS_SORT_FIELDS: qs.setSpecimensSortFields(getSortFields(value)); break; case PARAM_SPECIMENS_NO_TAXA: qs.setNoTaxa(ConfigObject.isTrueValue(value, true)); 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; }
HttpGroupByScientificNameQuerySpecBuilder { public GroupByScientificNameQuerySpec build() { logger.info("Extracting NameGroupQuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromQuerySpecParam(values); } GroupByScientificNameQuerySpec qs = new GroupByScientificNameQuerySpec(); 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_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; case PARAM_GROUP_SORT: qs.setGroupSort(GroupSort.parse(value)); break; case PARAM_GROUP_FILTER: if (value.length() != 0) { String[] filters = value.split(","); Filter filter = new Filter(); if (filters.length == 1) { filter.acceptRegexp(filters[0]); } else { filter.acceptValues(filters); } qs.setGroupFilter(filter); } break; case PARAM_SPECIMENS_FROM: qs.setSpecimensFrom(getIntParam(param, value)); break; case PARAM_SPECIMENS_SIZE: qs.setSpecimensSize(getIntParam(param, value)); break; case PARAM_SPECIMENS_SORT_FIELDS: qs.setSpecimensSortFields(getSortFields(value)); break; case PARAM_SPECIMENS_NO_TAXA: qs.setNoTaxa(ConfigObject.isTrueValue(value, true)); 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; } }
HttpGroupByScientificNameQuerySpecBuilder { public GroupByScientificNameQuerySpec build() { logger.info("Extracting NameGroupQuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromQuerySpecParam(values); } GroupByScientificNameQuerySpec qs = new GroupByScientificNameQuerySpec(); 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_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; case PARAM_GROUP_SORT: qs.setGroupSort(GroupSort.parse(value)); break; case PARAM_GROUP_FILTER: if (value.length() != 0) { String[] filters = value.split(","); Filter filter = new Filter(); if (filters.length == 1) { filter.acceptRegexp(filters[0]); } else { filter.acceptValues(filters); } qs.setGroupFilter(filter); } break; case PARAM_SPECIMENS_FROM: qs.setSpecimensFrom(getIntParam(param, value)); break; case PARAM_SPECIMENS_SIZE: qs.setSpecimensSize(getIntParam(param, value)); break; case PARAM_SPECIMENS_SORT_FIELDS: qs.setSpecimensSortFields(getSortFields(value)); break; case PARAM_SPECIMENS_NO_TAXA: qs.setNoTaxa(ConfigObject.isTrueValue(value, true)); 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; } HttpGroupByScientificNameQuerySpecBuilder(UriInfo uriInfo);  HttpGroupByScientificNameQuerySpecBuilder(MultivaluedMap<String, String> formData,
			UriInfo uriInfo); }
HttpGroupByScientificNameQuerySpecBuilder { public GroupByScientificNameQuerySpec build() { logger.info("Extracting NameGroupQuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromQuerySpecParam(values); } GroupByScientificNameQuerySpec qs = new GroupByScientificNameQuerySpec(); 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_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; case PARAM_GROUP_SORT: qs.setGroupSort(GroupSort.parse(value)); break; case PARAM_GROUP_FILTER: if (value.length() != 0) { String[] filters = value.split(","); Filter filter = new Filter(); if (filters.length == 1) { filter.acceptRegexp(filters[0]); } else { filter.acceptValues(filters); } qs.setGroupFilter(filter); } break; case PARAM_SPECIMENS_FROM: qs.setSpecimensFrom(getIntParam(param, value)); break; case PARAM_SPECIMENS_SIZE: qs.setSpecimensSize(getIntParam(param, value)); break; case PARAM_SPECIMENS_SORT_FIELDS: qs.setSpecimensSortFields(getSortFields(value)); break; case PARAM_SPECIMENS_NO_TAXA: qs.setNoTaxa(ConfigObject.isTrueValue(value, true)); 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; } HttpGroupByScientificNameQuerySpecBuilder(UriInfo uriInfo);  HttpGroupByScientificNameQuerySpecBuilder(MultivaluedMap<String, String> formData,
			UriInfo uriInfo); GroupByScientificNameQuerySpec build(); }
HttpGroupByScientificNameQuerySpecBuilder { public GroupByScientificNameQuerySpec build() { logger.info("Extracting NameGroupQuerySpec object from request"); checkParams(uriInfo); List<String> values = params.get(PARAM_QUERY_SPEC); if (values != null) { return buildFromQuerySpecParam(values); } GroupByScientificNameQuerySpec qs = new GroupByScientificNameQuerySpec(); 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_OPERATOR: qs.setLogicalOperator(getLogicalOperator(value)); break; case PARAM_FROM: qs.setFrom(getIntParam(param, value)); break; case PARAM_SIZE: qs.setSize(getIntParam(param, value)); break; case PARAM_SORT_FIELDS: qs.setSortFields(getSortFields(value)); break; case PARAM_FIELDS: qs.setFields(getFields(value)); break; case PARAM_GROUP_SORT: qs.setGroupSort(GroupSort.parse(value)); break; case PARAM_GROUP_FILTER: if (value.length() != 0) { String[] filters = value.split(","); Filter filter = new Filter(); if (filters.length == 1) { filter.acceptRegexp(filters[0]); } else { filter.acceptValues(filters); } qs.setGroupFilter(filter); } break; case PARAM_SPECIMENS_FROM: qs.setSpecimensFrom(getIntParam(param, value)); break; case PARAM_SPECIMENS_SIZE: qs.setSpecimensSize(getIntParam(param, value)); break; case PARAM_SPECIMENS_SORT_FIELDS: qs.setSpecimensSortFields(getSortFields(value)); break; case PARAM_SPECIMENS_NO_TAXA: qs.setNoTaxa(ConfigObject.isTrueValue(value, true)); 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; } HttpGroupByScientificNameQuerySpecBuilder(UriInfo uriInfo);  HttpGroupByScientificNameQuerySpecBuilder(MultivaluedMap<String, String> formData,
			UriInfo uriInfo); GroupByScientificNameQuerySpec 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; static final String PARAM_GROUP_SORT; static final String PARAM_GROUP_FILTER; static final String PARAM_SPECIMENS_FROM; static final String PARAM_SPECIMENS_SIZE; static final String PARAM_SPECIMENS_SORT_FIELDS; static final String PARAM_SPECIMENS_NO_TAXA; }