@Test public void testGetFields() throws Exception { String fields = "prop,category/prop1,category2/category3/prop2[1,2,3],prop3[4,5,6],category4[7,8,9],sub-resource/*[10,11,12],finalProp"; UriInfo uriInfo = createMock(UriInfo.class); @SuppressWarnings("unchecked") MultivaluedMap<String, String> mapQueryParams = createMock(MultivaluedMap.class); expect(uriInfo.getQueryParameters()).andReturn(mapQueryParams); expect(mapQueryParams.getFirst("fields")).andReturn(fields); replay(uriInfo, mapQueryParams); Request request = getTestRequest(null, null, uriInfo, null, null, null, null); Map<String, TemporalInfo> mapFields = request.getFields(); assertEquals(7, mapFields.size()); String prop = "prop"; assertTrue(mapFields.containsKey(prop)); assertNull(mapFields.get(prop)); String prop1 = PropertyHelper.getPropertyId("category", "prop1"); assertTrue(mapFields.containsKey(prop1)); assertNull(mapFields.get(prop1)); String prop2 = PropertyHelper.getPropertyId("category2/category3", "prop2"); assertTrue(mapFields.containsKey(prop2)); assertEquals(new TemporalInfoImpl(1, 2, 3), mapFields.get(prop2)); String prop3 = "prop3"; assertTrue(mapFields.containsKey(prop3)); assertEquals(new TemporalInfoImpl(4, 5, 6), mapFields.get(prop3)); String category4 = "category4"; assertTrue(mapFields.containsKey(category4)); assertEquals(new TemporalInfoImpl(7, 8, 9), mapFields.get(category4)); String subResource = PropertyHelper.getPropertyId("sub-resource", "*"); assertTrue(mapFields.containsKey(subResource)); assertEquals(new TemporalInfoImpl(10, 11, 12), mapFields.get(subResource)); String finalProp = "finalProp"; assertTrue(mapFields.containsKey(finalProp)); assertNull(mapFields.get(finalProp)); verify(uriInfo, mapQueryParams); }
@Override public Map<String, TemporalInfo> getFields() { Map<String, TemporalInfo> mapProperties; String partialResponseFields = m_uriInfo.getQueryParameters().getFirst(QueryLexer.QUERY_FIELDS); if (partialResponseFields == null) { mapProperties = Collections.emptyMap(); } else { Set<String> setMatches = new HashSet<String>(); Pattern re = Pattern.compile("[^,\\[]*?\\[[^\\]]*?\\]|[^,]+"); Matcher m = re.matcher(partialResponseFields); while (m.find()){ for (int groupIdx = 0; groupIdx < m.groupCount() + 1; groupIdx++) { setMatches.add(m.group(groupIdx)); } } mapProperties = new HashMap<String, TemporalInfo>(setMatches.size()); for (String field : setMatches) { TemporalInfo temporalInfo = null; if (field.contains("[")) { String[] temporalData = field.substring(field.indexOf('[') + 1, field.indexOf(']')).split(","); field = field.substring(0, field.indexOf('[')); long start = Long.parseLong(temporalData[0].trim()); long end = -1; long step = -1; if (temporalData.length >= 2) { end = Long.parseLong(temporalData[1].trim()); if (temporalData.length == 3) { step = Long.parseLong(temporalData[2].trim()); } } temporalInfo = new TemporalInfoImpl(start, end, step); } mapProperties.put(field, temporalInfo); } } return mapProperties; }
BaseRequest implements Request { @Override public Map<String, TemporalInfo> getFields() { Map<String, TemporalInfo> mapProperties; String partialResponseFields = m_uriInfo.getQueryParameters().getFirst(QueryLexer.QUERY_FIELDS); if (partialResponseFields == null) { mapProperties = Collections.emptyMap(); } else { Set<String> setMatches = new HashSet<String>(); Pattern re = Pattern.compile("[^,\\[]*?\\[[^\\]]*?\\]|[^,]+"); Matcher m = re.matcher(partialResponseFields); while (m.find()){ for (int groupIdx = 0; groupIdx < m.groupCount() + 1; groupIdx++) { setMatches.add(m.group(groupIdx)); } } mapProperties = new HashMap<String, TemporalInfo>(setMatches.size()); for (String field : setMatches) { TemporalInfo temporalInfo = null; if (field.contains("[")) { String[] temporalData = field.substring(field.indexOf('[') + 1, field.indexOf(']')).split(","); field = field.substring(0, field.indexOf('[')); long start = Long.parseLong(temporalData[0].trim()); long end = -1; long step = -1; if (temporalData.length >= 2) { end = Long.parseLong(temporalData[1].trim()); if (temporalData.length == 3) { step = Long.parseLong(temporalData[2].trim()); } } temporalInfo = new TemporalInfoImpl(start, end, step); } mapProperties.put(field, temporalInfo); } } return mapProperties; } }
BaseRequest implements Request { @Override public Map<String, TemporalInfo> getFields() { Map<String, TemporalInfo> mapProperties; String partialResponseFields = m_uriInfo.getQueryParameters().getFirst(QueryLexer.QUERY_FIELDS); if (partialResponseFields == null) { mapProperties = Collections.emptyMap(); } else { Set<String> setMatches = new HashSet<String>(); Pattern re = Pattern.compile("[^,\\[]*?\\[[^\\]]*?\\]|[^,]+"); Matcher m = re.matcher(partialResponseFields); while (m.find()){ for (int groupIdx = 0; groupIdx < m.groupCount() + 1; groupIdx++) { setMatches.add(m.group(groupIdx)); } } mapProperties = new HashMap<String, TemporalInfo>(setMatches.size()); for (String field : setMatches) { TemporalInfo temporalInfo = null; if (field.contains("[")) { String[] temporalData = field.substring(field.indexOf('[') + 1, field.indexOf(']')).split(","); field = field.substring(0, field.indexOf('[')); long start = Long.parseLong(temporalData[0].trim()); long end = -1; long step = -1; if (temporalData.length >= 2) { end = Long.parseLong(temporalData[1].trim()); if (temporalData.length == 3) { step = Long.parseLong(temporalData[2].trim()); } } temporalInfo = new TemporalInfoImpl(start, end, step); } mapProperties.put(field, temporalInfo); } } return mapProperties; } BaseRequest(HttpHeaders headers, RequestBody body, UriInfo uriInfo, ResourceInstance resource); }
BaseRequest implements Request { @Override public Map<String, TemporalInfo> getFields() { Map<String, TemporalInfo> mapProperties; String partialResponseFields = m_uriInfo.getQueryParameters().getFirst(QueryLexer.QUERY_FIELDS); if (partialResponseFields == null) { mapProperties = Collections.emptyMap(); } else { Set<String> setMatches = new HashSet<String>(); Pattern re = Pattern.compile("[^,\\[]*?\\[[^\\]]*?\\]|[^,]+"); Matcher m = re.matcher(partialResponseFields); while (m.find()){ for (int groupIdx = 0; groupIdx < m.groupCount() + 1; groupIdx++) { setMatches.add(m.group(groupIdx)); } } mapProperties = new HashMap<String, TemporalInfo>(setMatches.size()); for (String field : setMatches) { TemporalInfo temporalInfo = null; if (field.contains("[")) { String[] temporalData = field.substring(field.indexOf('[') + 1, field.indexOf(']')).split(","); field = field.substring(0, field.indexOf('[')); long start = Long.parseLong(temporalData[0].trim()); long end = -1; long step = -1; if (temporalData.length >= 2) { end = Long.parseLong(temporalData[1].trim()); if (temporalData.length == 3) { step = Long.parseLong(temporalData[2].trim()); } } temporalInfo = new TemporalInfoImpl(start, end, step); } mapProperties.put(field, temporalInfo); } } return mapProperties; } BaseRequest(HttpHeaders headers, RequestBody body, UriInfo uriInfo, ResourceInstance resource); @Override Result process(); @Override ResourceInstance getResource(); @Override String getURI(); @Override int getAPIVersion(); @Override Predicate getQueryPredicate(); @Override Map<String, TemporalInfo> getFields(); @Override Renderer getRenderer(); @Override Map<String, List<String>> getHttpHeaders(); @Override PageRequest getPageRequest(); @Override RequestBody getBody(); @Override SortRequest getSortRequest(); @Override String getRemoteAddress(); }
BaseRequest implements Request { @Override public Map<String, TemporalInfo> getFields() { Map<String, TemporalInfo> mapProperties; String partialResponseFields = m_uriInfo.getQueryParameters().getFirst(QueryLexer.QUERY_FIELDS); if (partialResponseFields == null) { mapProperties = Collections.emptyMap(); } else { Set<String> setMatches = new HashSet<String>(); Pattern re = Pattern.compile("[^,\\[]*?\\[[^\\]]*?\\]|[^,]+"); Matcher m = re.matcher(partialResponseFields); while (m.find()){ for (int groupIdx = 0; groupIdx < m.groupCount() + 1; groupIdx++) { setMatches.add(m.group(groupIdx)); } } mapProperties = new HashMap<String, TemporalInfo>(setMatches.size()); for (String field : setMatches) { TemporalInfo temporalInfo = null; if (field.contains("[")) { String[] temporalData = field.substring(field.indexOf('[') + 1, field.indexOf(']')).split(","); field = field.substring(0, field.indexOf('[')); long start = Long.parseLong(temporalData[0].trim()); long end = -1; long step = -1; if (temporalData.length >= 2) { end = Long.parseLong(temporalData[1].trim()); if (temporalData.length == 3) { step = Long.parseLong(temporalData[2].trim()); } } temporalInfo = new TemporalInfoImpl(start, end, step); } mapProperties.put(field, temporalInfo); } } return mapProperties; } BaseRequest(HttpHeaders headers, RequestBody body, UriInfo uriInfo, ResourceInstance resource); @Override Result process(); @Override ResourceInstance getResource(); @Override String getURI(); @Override int getAPIVersion(); @Override Predicate getQueryPredicate(); @Override Map<String, TemporalInfo> getFields(); @Override Renderer getRenderer(); @Override Map<String, List<String>> getHttpHeaders(); @Override PageRequest getPageRequest(); @Override RequestBody getBody(); @Override SortRequest getSortRequest(); @Override String getRemoteAddress(); static final int DEFAULT_PAGE_SIZE; static final String PAGE_SIZE_PROPERTY_KEY; static final String ASC_ORDER_PROPERTY_KEY; }