@Test public void testDeviceAnnotation() { Map<String, String> inputMap = new HashMap<String, String>() { { put(ANNOTATION_KEY_1, ANNOTATION_VALUE_1); put(ANNOTATION_KEY_2, ANNOTATION_VALUE_2); } }; assertNotNull(cfg.annotation(inputMap)); Map<String, String> outputMap = cfg.annotation(); assertEquals(outputMap.get(ANNOTATION_KEY_1), ANNOTATION_VALUE_1); assertEquals(outputMap.get(ANNOTATION_KEY_2), ANNOTATION_VALUE_2); assertEquals(outputMap.size(), 2); }
public Map<String, String> annotation() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); String jsonAnnotation = get(ANNOTATION, null); if (jsonAnnotation == null || jsonAnnotation.isEmpty()) { return ImmutableMap.of(); } JsonNode annotationNode; try { annotationNode = MAPPER.readTree(jsonAnnotation); } catch (IOException e) { log.error("Failed to read JSON tree from: {}", jsonAnnotation); return ImmutableMap.of(); } if (annotationNode.isObject()) { ObjectNode obj = (ObjectNode) annotationNode; Iterator<Map.Entry<String, JsonNode>> it = obj.fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); final String key = entry.getKey(); final JsonNode value = entry.getValue(); if (value.isValueNode()) { if (value.isNull()) { builder.put(key, SuppressionRules.ANY_VALUE); } else { builder.put(key, value.asText()); } } else { log.warn("Encountered unexpected JSON field {} for annotation", entry); } } } else { log.error("Encountered unexpected JSONNode {} for annotation", annotationNode); return ImmutableMap.of(); } return builder.build(); }
SuppressionConfig extends Config<ApplicationId> { public Map<String, String> annotation() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); String jsonAnnotation = get(ANNOTATION, null); if (jsonAnnotation == null || jsonAnnotation.isEmpty()) { return ImmutableMap.of(); } JsonNode annotationNode; try { annotationNode = MAPPER.readTree(jsonAnnotation); } catch (IOException e) { log.error("Failed to read JSON tree from: {}", jsonAnnotation); return ImmutableMap.of(); } if (annotationNode.isObject()) { ObjectNode obj = (ObjectNode) annotationNode; Iterator<Map.Entry<String, JsonNode>> it = obj.fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); final String key = entry.getKey(); final JsonNode value = entry.getValue(); if (value.isValueNode()) { if (value.isNull()) { builder.put(key, SuppressionRules.ANY_VALUE); } else { builder.put(key, value.asText()); } } else { log.warn("Encountered unexpected JSON field {} for annotation", entry); } } } else { log.error("Encountered unexpected JSONNode {} for annotation", annotationNode); return ImmutableMap.of(); } return builder.build(); } }
SuppressionConfig extends Config<ApplicationId> { public Map<String, String> annotation() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); String jsonAnnotation = get(ANNOTATION, null); if (jsonAnnotation == null || jsonAnnotation.isEmpty()) { return ImmutableMap.of(); } JsonNode annotationNode; try { annotationNode = MAPPER.readTree(jsonAnnotation); } catch (IOException e) { log.error("Failed to read JSON tree from: {}", jsonAnnotation); return ImmutableMap.of(); } if (annotationNode.isObject()) { ObjectNode obj = (ObjectNode) annotationNode; Iterator<Map.Entry<String, JsonNode>> it = obj.fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); final String key = entry.getKey(); final JsonNode value = entry.getValue(); if (value.isValueNode()) { if (value.isNull()) { builder.put(key, SuppressionRules.ANY_VALUE); } else { builder.put(key, value.asText()); } } else { log.warn("Encountered unexpected JSON field {} for annotation", entry); } } } else { log.error("Encountered unexpected JSONNode {} for annotation", annotationNode); return ImmutableMap.of(); } return builder.build(); }  }
SuppressionConfig extends Config<ApplicationId> { public Map<String, String> annotation() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); String jsonAnnotation = get(ANNOTATION, null); if (jsonAnnotation == null || jsonAnnotation.isEmpty()) { return ImmutableMap.of(); } JsonNode annotationNode; try { annotationNode = MAPPER.readTree(jsonAnnotation); } catch (IOException e) { log.error("Failed to read JSON tree from: {}", jsonAnnotation); return ImmutableMap.of(); } if (annotationNode.isObject()) { ObjectNode obj = (ObjectNode) annotationNode; Iterator<Map.Entry<String, JsonNode>> it = obj.fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); final String key = entry.getKey(); final JsonNode value = entry.getValue(); if (value.isValueNode()) { if (value.isNull()) { builder.put(key, SuppressionRules.ANY_VALUE); } else { builder.put(key, value.asText()); } } else { log.warn("Encountered unexpected JSON field {} for annotation", entry); } } } else { log.error("Encountered unexpected JSONNode {} for annotation", annotationNode); return ImmutableMap.of(); } return builder.build(); }  Set<Device.Type> deviceTypes(); SuppressionConfig deviceTypes(Set<Device.Type> deviceTypes); Map<String, String> annotation(); SuppressionConfig annotation(Map<String, String> annotation); }
SuppressionConfig extends Config<ApplicationId> { public Map<String, String> annotation() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); String jsonAnnotation = get(ANNOTATION, null); if (jsonAnnotation == null || jsonAnnotation.isEmpty()) { return ImmutableMap.of(); } JsonNode annotationNode; try { annotationNode = MAPPER.readTree(jsonAnnotation); } catch (IOException e) { log.error("Failed to read JSON tree from: {}", jsonAnnotation); return ImmutableMap.of(); } if (annotationNode.isObject()) { ObjectNode obj = (ObjectNode) annotationNode; Iterator<Map.Entry<String, JsonNode>> it = obj.fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); final String key = entry.getKey(); final JsonNode value = entry.getValue(); if (value.isValueNode()) { if (value.isNull()) { builder.put(key, SuppressionRules.ANY_VALUE); } else { builder.put(key, value.asText()); } } else { log.warn("Encountered unexpected JSON field {} for annotation", entry); } } } else { log.error("Encountered unexpected JSONNode {} for annotation", annotationNode); return ImmutableMap.of(); } return builder.build(); }  Set<Device.Type> deviceTypes(); SuppressionConfig deviceTypes(Set<Device.Type> deviceTypes); Map<String, String> annotation(); SuppressionConfig annotation(Map<String, String> annotation);  }