@Test public void testLoadNameSpace() throws IOException { String json = "[" + "{\n" + " \"nameSpace\": [\"v6.0\", \"v6.1\"],\n" + " \"resources\":[\n" + " {\n" + " \"path\":\"/reportCards\",\n" + " \"doc\":\"some doc.\"\n" + " }]}," + "{\n" + " \"nameSpace\": [\"v7.0\"],\n" + " \"resources\":[\n" + " {\n" + " \"path\":\"/schools\",\n" + " \"dateSearchDisallowed\":\"true\",\n" + " \"doc\":\"some school doc.\"\n" + " }]}]"; ByteArrayInputStream inputStream = new ByteArrayInputStream(json.getBytes()); ApiNameSpace[] nameSpaces = resourceEndPoint.loadNameSpace(inputStream); assertEquals("Should match", 2, nameSpaces.length); ApiNameSpace nameSpace = nameSpaces[0]; assertEquals("Should match", 2, nameSpace.getNameSpace().length); assertEquals("Should match", "v6.0", nameSpace.getNameSpace()[0]); assertEquals("Should match", "v6.1", nameSpace.getNameSpace()[1]); assertEquals("Should match", 1, nameSpace.getResources().size()); assertEquals("Should match", "/reportCards", nameSpace.getResources().get(0).getPath()); assertEquals("Should match", "some doc.", nameSpace.getResources().get(0).getDoc()); nameSpace = nameSpaces[1]; assertEquals("Should match", 1, nameSpace.getNameSpace().length); assertEquals("Should match", "v7.0", nameSpace.getNameSpace()[0]); assertEquals("Should match", 1, nameSpace.getResources().size()); assertEquals("Should match", "/schools", nameSpace.getResources().get(0).getPath()); assertEquals("Should match", "some school doc.", nameSpace.getResources().get(0).getDoc()); assertEquals("Should have one entry", 1, resourceEndPoint.getDateRangeDisallowedEndPoints().size()); assertTrue("Should match", resourceEndPoint.getDateRangeDisallowedEndPoints().contains("v7.0/schools")); }
protected ApiNameSpace[] loadNameSpace(InputStream fileStream) throws IOException { ObjectMapper mapper = new ObjectMapper(); ApiNameSpace[] apiNameSpaces = mapper.readValue(fileStream, ApiNameSpace[].class); for (ApiNameSpace apiNameSpace : apiNameSpaces) { String[] nameSpaces = apiNameSpace.getNameSpace(); for (String nameSpace : nameSpaces) { nameSpaceMappings.putAll(buildNameSpaceMappings(nameSpace, nameSpaceMappings)); List<ResourceEndPointTemplate> resources = apiNameSpace.getResources(); for (ResourceEndPointTemplate resource : resources) { if (!resource.isQueryable()) { queryingDisallowedEndPoints.add(resource.getPath().substring(1)); } if (resource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath()); } if (resource.isBlockGetRequest()) { blockGetRequestEndPoints.add(nameSpace + resource.getPath()); } if (resource.getSubResources() != null) { for (ResourceEndPointTemplate subResource : resource.getSubResources()) { if (subResource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath() + subResource.getPath()); } } } resourceEndPoints.putAll(buildEndPoints(nameSpace, "", resource)); } } } return apiNameSpaces; }
ResourceEndPoint { protected ApiNameSpace[] loadNameSpace(InputStream fileStream) throws IOException { ObjectMapper mapper = new ObjectMapper(); ApiNameSpace[] apiNameSpaces = mapper.readValue(fileStream, ApiNameSpace[].class); for (ApiNameSpace apiNameSpace : apiNameSpaces) { String[] nameSpaces = apiNameSpace.getNameSpace(); for (String nameSpace : nameSpaces) { nameSpaceMappings.putAll(buildNameSpaceMappings(nameSpace, nameSpaceMappings)); List<ResourceEndPointTemplate> resources = apiNameSpace.getResources(); for (ResourceEndPointTemplate resource : resources) { if (!resource.isQueryable()) { queryingDisallowedEndPoints.add(resource.getPath().substring(1)); } if (resource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath()); } if (resource.isBlockGetRequest()) { blockGetRequestEndPoints.add(nameSpace + resource.getPath()); } if (resource.getSubResources() != null) { for (ResourceEndPointTemplate subResource : resource.getSubResources()) { if (subResource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath() + subResource.getPath()); } } } resourceEndPoints.putAll(buildEndPoints(nameSpace, "", resource)); } } } return apiNameSpaces; } }
ResourceEndPoint { protected ApiNameSpace[] loadNameSpace(InputStream fileStream) throws IOException { ObjectMapper mapper = new ObjectMapper(); ApiNameSpace[] apiNameSpaces = mapper.readValue(fileStream, ApiNameSpace[].class); for (ApiNameSpace apiNameSpace : apiNameSpaces) { String[] nameSpaces = apiNameSpace.getNameSpace(); for (String nameSpace : nameSpaces) { nameSpaceMappings.putAll(buildNameSpaceMappings(nameSpace, nameSpaceMappings)); List<ResourceEndPointTemplate> resources = apiNameSpace.getResources(); for (ResourceEndPointTemplate resource : resources) { if (!resource.isQueryable()) { queryingDisallowedEndPoints.add(resource.getPath().substring(1)); } if (resource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath()); } if (resource.isBlockGetRequest()) { blockGetRequestEndPoints.add(nameSpace + resource.getPath()); } if (resource.getSubResources() != null) { for (ResourceEndPointTemplate subResource : resource.getSubResources()) { if (subResource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath() + subResource.getPath()); } } } resourceEndPoints.putAll(buildEndPoints(nameSpace, "", resource)); } } } return apiNameSpaces; }  }
ResourceEndPoint { protected ApiNameSpace[] loadNameSpace(InputStream fileStream) throws IOException { ObjectMapper mapper = new ObjectMapper(); ApiNameSpace[] apiNameSpaces = mapper.readValue(fileStream, ApiNameSpace[].class); for (ApiNameSpace apiNameSpace : apiNameSpaces) { String[] nameSpaces = apiNameSpace.getNameSpace(); for (String nameSpace : nameSpaces) { nameSpaceMappings.putAll(buildNameSpaceMappings(nameSpace, nameSpaceMappings)); List<ResourceEndPointTemplate> resources = apiNameSpace.getResources(); for (ResourceEndPointTemplate resource : resources) { if (!resource.isQueryable()) { queryingDisallowedEndPoints.add(resource.getPath().substring(1)); } if (resource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath()); } if (resource.isBlockGetRequest()) { blockGetRequestEndPoints.add(nameSpace + resource.getPath()); } if (resource.getSubResources() != null) { for (ResourceEndPointTemplate subResource : resource.getSubResources()) { if (subResource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath() + subResource.getPath()); } } } resourceEndPoints.putAll(buildEndPoints(nameSpace, "", resource)); } } } return apiNameSpaces; }  @PostConstruct void load(); List<String> getQueryingDisallowedEndPoints(); Set<String> getDateRangeDisallowedEndPoints(); Set<String> getBlockGetRequestEndPoints(); Map<String, String> getResources(); Map<String, SortedSet<String>> getNameSpaceMappings(); void setNameSpaceMappings(Map<String, SortedSet<String>> nameSpaceMappings); }
ResourceEndPoint { protected ApiNameSpace[] loadNameSpace(InputStream fileStream) throws IOException { ObjectMapper mapper = new ObjectMapper(); ApiNameSpace[] apiNameSpaces = mapper.readValue(fileStream, ApiNameSpace[].class); for (ApiNameSpace apiNameSpace : apiNameSpaces) { String[] nameSpaces = apiNameSpace.getNameSpace(); for (String nameSpace : nameSpaces) { nameSpaceMappings.putAll(buildNameSpaceMappings(nameSpace, nameSpaceMappings)); List<ResourceEndPointTemplate> resources = apiNameSpace.getResources(); for (ResourceEndPointTemplate resource : resources) { if (!resource.isQueryable()) { queryingDisallowedEndPoints.add(resource.getPath().substring(1)); } if (resource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath()); } if (resource.isBlockGetRequest()) { blockGetRequestEndPoints.add(nameSpace + resource.getPath()); } if (resource.getSubResources() != null) { for (ResourceEndPointTemplate subResource : resource.getSubResources()) { if (subResource.isDateSearchDisallowed()) { dateRangeDisallowedEndPoints.add(nameSpace + resource.getPath() + subResource.getPath()); } } } resourceEndPoints.putAll(buildEndPoints(nameSpace, "", resource)); } } } return apiNameSpaces; }  @PostConstruct void load(); List<String> getQueryingDisallowedEndPoints(); Set<String> getDateRangeDisallowedEndPoints(); Set<String> getBlockGetRequestEndPoints(); Map<String, String> getResources(); Map<String, SortedSet<String>> getNameSpaceMappings(); void setNameSpaceMappings(Map<String, SortedSet<String>> nameSpaceMappings);  }