public void initDataFromMDSD(JsonNode mdsdNode, JsonNode fmdBeanRoot, String language) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { LANG = language; this.mdsd = mdsdNode; JsonNode fmdBean = fmdBeanRoot.get(0); Iterator<Map.Entry<String, JsonNode>> properties = mdsdNode.get(PROPERTIES_FIELD).fields(); this.metaDataCleaned = new TreeMap<String, Object>(); if (fmdBean != null) { while (properties.hasNext()) { Map.Entry<String, JsonNode> mapDsdTmp = properties.next(); String key = mapDsdTmp.getKey(); FMDProperty objectProperty = fillObjectProperty(Lists.newArrayList(mapDsdTmp.getValue().fields()).listIterator()); Object returnedValue = getReturnedValueFromObject(objectProperty, fmdBean, key); if (returnedValue != null) { if (objectProperty.getTitleToVisualize() != null) { // 1) IF THERE IS A TYPE if (mapDsdTmp.getValue().get(TYPE_FIELD) != null) { FMDescriptor value = new FMDescriptor( key, objectProperty.getTitleToVisualize(), objectProperty.getDescription()); String order = getOrderFromEntity(mapDsdTmp.getValue()); // simple case: string type or number type if (isReadyToPut(objectProperty)) { this.metaDataCleaned.put( order, value.setValue(((TextNode) returnedValue).asText())); } else { this.metaDataCleaned.put( order, value.setValue(fillRecursive2(mapDsdTmp.getValue().fields(), returnedValue))); } } // 2) REF TYPE else if (mapDsdTmp.getValue().get(REF_FIELD) != null) { JsonNode msdRef = getMdsdObjectFromReference(mapDsdTmp.getValue().get(REF_FIELD).asText()); String order = getOrderFromEntity(mapDsdTmp.getValue()); FMDescriptor tempVal = initDtoMDSD(mapDsdTmp.getValue(), key); this.metaDataCleaned.put( order, tempVal.setValue(fillRecursive2(msdRef.fields(), returnedValue))); } } } } } }
private FMDProperty fillObjectProperty(ListIterator<Map.Entry<String, JsonNode>> fields) { FMDProperty result = new FMDProperty(); while (fields.hasNext()) { Map.Entry<String, JsonNode> tmp = fields.next(); switch (tmp.getKey()) { case TITLE_FIELD: result.setTitleToVisualize(tmp.getValue().get(LANG.toLowerCase()).asText()); break; case DESCRIPTION_FIELD: result.setDescription(tmp.getValue().get(LANG.toLowerCase()).asText()); break; case PATTERN_PROPERTIES_FIELD: result.setPatternProperties( tmp.getValue().get(FOLLOW_PATTERN_PROPERTIES).get(TYPE_FIELD).asText()); break; case ORDER_FIELD: result.setOrder(tmp.getValue().asText()); break; case TYPE_FIELD: result.setType(tmp.getValue().asText()); break; case PROPERTIES_FIELD: result.setProperties(Lists.newArrayList(tmp.getValue().fields())); break; case REF_FIELD: result.setReference(tmp.getValue().asText()); break; case REQUIRED_FIELD: result.setRequired(tmp.getValue().asText()); break; case ITEMS_FIELD: result.setItems(tmp.getValue()); break; case TITLE_FIELD_GENERIC: if (result.getTitleToVisualize() == null) { result.setTitleToVisualize(tmp.getValue().asText()); } break; } } return result; }