- MicroServiceModels microServiceModels = new MicroServiceModels();
- String userId = null;
- if (fromAPI) {
- microServiceModels = (MicroServiceModels)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceModels.class);
- userId = "API";
-
- //check if update operation or create, get id for data to be updated and update attributeData
- if (request.getParameter(OPERATION).equals("update")) {
- String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
- List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
- int id = 0;
- for (int i=0; i< duplicateData.size(); i++){
- MicroServiceModels data = (MicroServiceModels) duplicateData.get(0);
- id = data.getId();
- }
- microServiceModels.setId(id);
- microServiceModels.setUserCreatedBy(this.getUserInfo(userId));
-
- }
- } else {
- //microServiceModels = (MicroServiceModels)mapper.readValue(root.get("microServiceModelsDictionaryData").toString(), MicroServiceModels.class);
- if (root.has("microServiceModelsDictionaryData")){
- if (root.get("microServiceModelsDictionaryData").has("description")){
- microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", ""));
- }
- if (root.get("microServiceModelsDictionaryData").has("modelName")){
- microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""));
- this.newModel.setModelName(microServiceModels.getModelName());
- }
- if (root.get("microServiceModelsDictionaryData").has("version")){
- microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", ""));
- this.newModel.setVersion(microServiceModels.getVersion());
- }
- }
- if(root.has("classMap")){
- classMap = new HashMap<String, MSAttributeObject>();
- JsonNode data = root.get("classMap");
- ObjectMapper mapper1 = new ObjectMapper();
- String data1 = data.toString().substring(1, data.toString().length()-1);
- data1 = data1.replace("\\", "");
- JSONObject jsonObject = new JSONObject(data1);
- Set<String> keys = jsonObject.keySet();
- for(String key : keys){
- String value = jsonObject.get(key).toString();
- MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
- classMap.put(key, msAttributeObject);
- }
- }
- userId = root.get("userid").textValue();
- addValuesToNewModel(classMap);
- }
+ MicroServiceModels microServiceModels = new MicroServiceModels();
+ String userId = null;
+
+ if(root.has("modelType")){
+ JsonNode dataType = root.get("modelType");
+ String modelType= dataType.toString();
+ if(modelType.contains("yml")){
+ if (root.has("microServiceModelsDictionaryData")){
+ if (root.get("microServiceModelsDictionaryData").has("description")){
+ microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", ""));
+ }
+ if (root.get("microServiceModelsDictionaryData").has("modelName")){
+ microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""));
+ this.newModel.setModelName(microServiceModels.getModelName());
+ }
+ if (root.get("microServiceModelsDictionaryData").has("version")){
+ microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", ""));
+ this.newModel.setVersion(microServiceModels.getVersion());
+ }
+ }
+
+ MSAttributeObject mainClass = null;
+ classMap = new HashMap<String, MSAttributeObject>();
+ JsonNode data = root.get("classMap");
+ ObjectMapper mapper1 = new ObjectMapper();
+ String data1 = data.toString().substring(1, data.toString().length()-1);
+ data1 = data1.replace("\\", "");
+ data1=data1.replace("\"{","{");
+ data1=data1.replace("}\"","}");
+ JSONObject jsonObject = new JSONObject(data1);
+ Set<String> keys = jsonObject.keySet();
+ for(String key : keys){
+ String value = jsonObject.get(key).toString();
+ MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
+ classMap.put(key, msAttributeObject);
+ }
+
+ userId = root.get("userid").textValue();
+ mainClass = classMap.get(this.newModel.getModelName());
+ this.newModel.setDependency("[]");
+ String value = new Gson().toJson(mainClass.getSubClass());
+ this.newModel.setSub_attributes(value);
+ String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
+ int equalsIndexForAttributes= attributes.indexOf("=");
+ String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1);
+ this.newModel.setAttributes(atttributesAfterFirstEquals);
+ String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
+ int equalsIndex= refAttributes.indexOf("=");
+ String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1);
+ this.newModel.setRef_attributes(refAttributesAfterFirstEquals);
+ this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+ this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+
+ }else{
+ if (fromAPI) {
+ microServiceModels = (MicroServiceModels)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceModels.class);
+ userId = "API";
+
+ //check if update operation or create, get id for data to be updated and update attributeData
+ if (request.getParameter(OPERATION).equals("update")) {
+ String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
+ int id = 0;
+ for (int i=0; i< duplicateData.size(); i++){
+ MicroServiceModels data = (MicroServiceModels) duplicateData.get(0);
+ id = data.getId();
+ }
+ microServiceModels.setId(id);
+ microServiceModels.setUserCreatedBy(this.getUserInfo(userId));
+
+ }
+ } else {
+ if (root.has("microServiceModelsDictionaryData")){
+ if (root.get("microServiceModelsDictionaryData").has("description")){
+ microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", ""));
+ }
+ if (root.get("microServiceModelsDictionaryData").has("modelName")){
+ microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""));
+ this.newModel.setModelName(microServiceModels.getModelName());
+ }
+ if (root.get("microServiceModelsDictionaryData").has("version")){
+ microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", ""));
+ this.newModel.setVersion(microServiceModels.getVersion());
+ }
+ }
+ if(root.has("classMap")){
+ classMap = new HashMap<String, MSAttributeObject>();
+ JsonNode data = root.get("classMap");
+ ObjectMapper mapper1 = new ObjectMapper();
+ String data1 = data.toString().substring(1, data.toString().length()-1);
+ data1 = data1.replace("\\", "");
+ JSONObject jsonObject = new JSONObject(data1);
+ Set<String> keys = jsonObject.keySet();
+ for(String key : keys){
+ String value = jsonObject.get(key).toString();
+ MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
+ classMap.put(key, msAttributeObject);
+ }
+ }
+ userId = root.get("userid").textValue();
+ addValuesToNewModel(classMap);
+ }
+ }
+
+ }