@Override public Set<String> fetchIds() { try { String json = jsondb.getAsString(getCollectionPath(), new GetOptions().depth(1)); if (json != null) { Map<String,Boolean> map = Json.reader().forType(new TypeReference<Map<String,Boolean>>() {}).readValue(json); return map.keySet() .stream().map(path -> path.substring(path.indexOf(':') + 1)).collect(Collectors.toSet()); } else { return Collections.<String>emptySet(); } } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException|IOException e) { throw SyndesisServerException.launderThrowable(e); } }
options.depth(1);
options.depth(1);
/** * If Integrations get deleted we should also delete their metrics * * @param activeIntegrationIds * @throws IOException * @throws JsonMappingException */ @Override public void curate(Set<String> activeIntegrationIds) throws IOException, JsonMappingException { //1. Loop over all RawMetrics String json = jsonDB.getAsString(path(), new GetOptions().depth(1)); if (json != null) { Map<String,Boolean> metricsMap = Json.reader().forType(TYPE_REFERENCE).readValue(json); Set<String> rawIntegrationIds = metricsMap.keySet(); for (String rawIntId : rawIntegrationIds) { if (! activeIntegrationIds.contains(rawIntId)) { jsonDB.delete(path(rawIntId)); } } } }
@Test public void testGetDepth2() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL", "more-props", map( "city", "Tampa", "state", "FL" ) ) ))); String json = jsondb.getAsString("/test", new GetOptions().depth(2)); assertThat(json).isEqualTo("{\"name\":\"Hiram Chirino\",\"props\":{\"city\":\"Tampa\",\"state\":\"FL\",\"props\":true}}"); }
@Test public void testGetDepth2() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL", "more-props", map( "city", "Tampa", "state", "FL" ) ) ))); String json = jsondb.getAsString("/test", new GetOptions().depth(2)); assertThat(json).isEqualTo("{\"name\":\"Hiram Chirino\",\"props\":{\"city\":\"Tampa\",\"state\":\"FL\",\"props\":true}}"); }
@Test public void testGetDepth1() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL" ) ))); String json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"name\":\"Hiram Chirino\",\"props\":true}"); jsondb.delete("/test"); jsondb.set("/test/a1/b1/c1", "1"); jsondb.set("/test/a1/b2/c1", "2"); jsondb.set("/test/a2/b3/c1", "3"); jsondb.set("/test/a3/b4/c1", "4"); jsondb.set("/test/a4/b5/c1", "5"); json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"a1\":true,\"a2\":true,\"a3\":true,\"a4\":true}"); }
@Test public void testGetDepth1() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL" ) ))); String json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"name\":\"Hiram Chirino\",\"props\":true}"); jsondb.delete("/test"); jsondb.set("/test/a1/b1/c1", "1"); jsondb.set("/test/a1/b2/c1", "2"); jsondb.set("/test/a2/b3/c1", "3"); jsondb.set("/test/a3/b4/c1", "4"); jsondb.set("/test/a4/b5/c1", "5"); json = jsondb.getAsString("/test", new GetOptions().depth(1)); assertThat(json).isEqualTo("{\"a1\":true,\"a2\":true,\"a3\":true,\"a4\":true}"); }