ElasticSearchMappingStore { protected Set<MetaProperty> inspectTree(Optional<String> key, Map<String, Object> mapping) { if (mapping.get(ES_MAPPING_PROPERTIES) == null) { String t = mapping.get(ES_MAPPING_TYPE).toString(); return Collections.singleton(new MetaPropertyImpl(key.get(), false, false, Collections.singleton(this.convertType(t)))); } else { Map<String, Object> fields = (Map<String, Object>) mapping.get(ES_MAPPING_PROPERTIES); Set<MetaProperty> metaProperties = fields.entrySet() .stream() .map(field -> inspectTree(Optional.of(key.map(k -> k + ".").orElse("") + field.getKey()), (Map<String, Object>) field.getValue())) .flatMap(x -> x.stream()) .collect(Collectors.toSet()); return metaProperties; } } ElasticSearchMappingStore(ElasticSearchIndexProvider indexProvider); void updateMetaModel(KObject object,
                                MetaObject metaObject); MetaObject getMetaObject(String clusterId,
                                    String type);  }
@Test public void testInspectMappingSingleLevel() { String field = "fieldName"; Map<String, Object> tree = new LinkedHashMap<>(); Map<String, Object> attributes = new LinkedHashMap<>(); attributes.put("type", "text"); attributes.put("analyzer", "simple"); Map<String, Object> properties = new LinkedHashMap<>(); properties.put(field, attributes); tree.put("properties", properties); Set<MetaProperty> metaProps = this.store.inspectTree(Optional.empty(), tree); assertEquals(1, metaProps.size()); assertEquals(field, metaProps.iterator().next().getName()); assertEquals(String.class, metaProps.iterator().next().getTypes().iterator().next()); }
@Test public void testInspectMappingMultiLevel() { String propertiesField = "properties"; String field = "fieldName"; String secondLevelFieldName = "secondLevelfieldName"; Map<String, Object> attributes = new LinkedHashMap<>(); attributes.put("type", "text"); attributes.put("analyzer", "simple"); Map<String, Object> secondLevelField = new LinkedHashMap<>(); secondLevelField.put(secondLevelFieldName, attributes); Map<String, Object> secondLevelProperties = new LinkedHashMap<>(); secondLevelProperties.put(propertiesField, secondLevelField); Map<String, Object> properties = new LinkedHashMap<>(); properties.put(field, secondLevelProperties); Map<String, Object> tree = new LinkedHashMap<>(); tree.put(propertiesField, properties); Set<MetaProperty> metaProps = this.store.inspectTree(Optional.empty(), tree); assertEquals(1, metaProps.size()); assertEquals(field + "." + secondLevelFieldName, metaProps.iterator().next().getName()); assertEquals(String.class, metaProps.iterator().next().getTypes().iterator().next()); }