@Test public void testSaveMicroServiceModelsDictionary() { logger.info("testSaveMicroServiceModelsDictionary: Entering"); MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { when(request.getReader()).thenReturn(br); controller.saveMicroServiceModelsDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testSaveMicroServiceModelsDictionary: exit"); }
@RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { this.newModel = new MicroServiceModels(); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); MicroServiceModels microServiceModels = new MicroServiceModels(); String userId = null; String dataOrderInfo = null; if (root.has("dataOrderInfo")) { dataOrderInfo = root.get("dataOrderInfo").toString(); } 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()); } } classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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(); MsAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); this.newModel.setSubAttributes(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.setRefAttributes(refAttributesAfterFirstEquals); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel .setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); } else { if (fromAPI) { microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class); userId = "API"; } 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(classMapData)) { classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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.setAttributes(this.newModel.getAttributes()); microServiceModels.setRefAttributes(this.newModel.getRefAttributes()); microServiceModels.setDependency(this.newModel.getDependency()); microServiceModels.setModelName(this.newModel.getModelName()); microServiceModels.setSubAttributes(this.newModel.getSubAttributes()); microServiceModels.setVersion(this.newModel.getVersion()); microServiceModels.setEnumValues(this.newModel.getEnumValues()); microServiceModels.setAnnotation(this.newModel.getAnnotation()); if (dataOrderInfo != null) { microServiceModels.setDataOrderInfo(dataOrderInfo); } String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); boolean duplicateflag = false; if (duplicateData != null && !duplicateData.isEmpty()) { MicroServiceModels data = (MicroServiceModels) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { microServiceModels.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))) { duplicateflag = true; } } UserInfo userInfo = utils.getUserInfo(userId); String responseString = null; if (!duplicateflag) { microServiceModels.setUserCreatedBy(userInfo); if (microServiceModels.getId() == 0) { commonClassDao.save(microServiceModels); } else { commonClassDao.update(microServiceModels); } responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; }
MicroServiceDictionaryController { @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { this.newModel = new MicroServiceModels(); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); MicroServiceModels microServiceModels = new MicroServiceModels(); String userId = null; String dataOrderInfo = null; if (root.has("dataOrderInfo")) { dataOrderInfo = root.get("dataOrderInfo").toString(); } 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()); } } classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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(); MsAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); this.newModel.setSubAttributes(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.setRefAttributes(refAttributesAfterFirstEquals); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel .setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); } else { if (fromAPI) { microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class); userId = "API"; } 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(classMapData)) { classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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.setAttributes(this.newModel.getAttributes()); microServiceModels.setRefAttributes(this.newModel.getRefAttributes()); microServiceModels.setDependency(this.newModel.getDependency()); microServiceModels.setModelName(this.newModel.getModelName()); microServiceModels.setSubAttributes(this.newModel.getSubAttributes()); microServiceModels.setVersion(this.newModel.getVersion()); microServiceModels.setEnumValues(this.newModel.getEnumValues()); microServiceModels.setAnnotation(this.newModel.getAnnotation()); if (dataOrderInfo != null) { microServiceModels.setDataOrderInfo(dataOrderInfo); } String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); boolean duplicateflag = false; if (duplicateData != null && !duplicateData.isEmpty()) { MicroServiceModels data = (MicroServiceModels) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { microServiceModels.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))) { duplicateflag = true; } } UserInfo userInfo = utils.getUserInfo(userId); String responseString = null; if (!duplicateflag) { microServiceModels.setUserCreatedBy(userInfo); if (microServiceModels.getId() == 0) { commonClassDao.save(microServiceModels); } else { commonClassDao.update(microServiceModels); } responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } }
MicroServiceDictionaryController { @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { this.newModel = new MicroServiceModels(); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); MicroServiceModels microServiceModels = new MicroServiceModels(); String userId = null; String dataOrderInfo = null; if (root.has("dataOrderInfo")) { dataOrderInfo = root.get("dataOrderInfo").toString(); } 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()); } } classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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(); MsAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); this.newModel.setSubAttributes(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.setRefAttributes(refAttributesAfterFirstEquals); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel .setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); } else { if (fromAPI) { microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class); userId = "API"; } 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(classMapData)) { classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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.setAttributes(this.newModel.getAttributes()); microServiceModels.setRefAttributes(this.newModel.getRefAttributes()); microServiceModels.setDependency(this.newModel.getDependency()); microServiceModels.setModelName(this.newModel.getModelName()); microServiceModels.setSubAttributes(this.newModel.getSubAttributes()); microServiceModels.setVersion(this.newModel.getVersion()); microServiceModels.setEnumValues(this.newModel.getEnumValues()); microServiceModels.setAnnotation(this.newModel.getAnnotation()); if (dataOrderInfo != null) { microServiceModels.setDataOrderInfo(dataOrderInfo); } String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); boolean duplicateflag = false; if (duplicateData != null && !duplicateData.isEmpty()) { MicroServiceModels data = (MicroServiceModels) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { microServiceModels.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))) { duplicateflag = true; } } UserInfo userInfo = utils.getUserInfo(userId); String responseString = null; if (!duplicateflag) { microServiceModels.setUserCreatedBy(userInfo); if (microServiceModels.getId() == 0) { commonClassDao.save(microServiceModels); } else { commonClassDao.update(microServiceModels); } responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } MicroServiceDictionaryController(); @Autowired  MicroServiceDictionaryController(CommonClassDao commonClassDao); }
MicroServiceDictionaryController { @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { this.newModel = new MicroServiceModels(); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); MicroServiceModels microServiceModels = new MicroServiceModels(); String userId = null; String dataOrderInfo = null; if (root.has("dataOrderInfo")) { dataOrderInfo = root.get("dataOrderInfo").toString(); } 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()); } } classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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(); MsAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); this.newModel.setSubAttributes(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.setRefAttributes(refAttributesAfterFirstEquals); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel .setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); } else { if (fromAPI) { microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class); userId = "API"; } 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(classMapData)) { classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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.setAttributes(this.newModel.getAttributes()); microServiceModels.setRefAttributes(this.newModel.getRefAttributes()); microServiceModels.setDependency(this.newModel.getDependency()); microServiceModels.setModelName(this.newModel.getModelName()); microServiceModels.setSubAttributes(this.newModel.getSubAttributes()); microServiceModels.setVersion(this.newModel.getVersion()); microServiceModels.setEnumValues(this.newModel.getEnumValues()); microServiceModels.setAnnotation(this.newModel.getAnnotation()); if (dataOrderInfo != null) { microServiceModels.setDataOrderInfo(dataOrderInfo); } String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); boolean duplicateflag = false; if (duplicateData != null && !duplicateData.isEmpty()) { MicroServiceModels data = (MicroServiceModels) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { microServiceModels.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))) { duplicateflag = true; } } UserInfo userInfo = utils.getUserInfo(userId); String responseString = null; if (!duplicateflag) { microServiceModels.setUserCreatedBy(userInfo); if (microServiceModels.getId() == 0) { commonClassDao.save(microServiceModels); } else { commonClassDao.update(microServiceModels); } responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } MicroServiceDictionaryController(); @Autowired  MicroServiceDictionaryController(CommonClassDao commonClassDao); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_DCAEUUIDDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_DCAEUUIDData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEUUIDDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_dcaeUUID"}, method = {RequestMethod.POST}) ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_dcaeuuid"}, method = {RequestMethod.POST}) void removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceConfigNameDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceConfigNameData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceDictData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceDictNameDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_DictionaryData"}, method = {RequestMethod.POST}) ModelAndView saveDictionaryData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msDictionaryData"}, method = {RequestMethod.POST}) void removeMicroServiceDictionaryData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_configName"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msConfigName"}, method = {RequestMethod.POST}) void removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceLocationDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceLocationData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_location"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msLocation"}, method = {RequestMethod.POST}) void removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceAttributeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceAttributeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_modelAttribute"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_modelAttribute"}, method = {RequestMethod.POST}) void removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByVersion"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request,
            HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataServiceVersion"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByClass"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryClassEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msModel"}, method = {RequestMethod.POST}) void removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceHeaderDefaultsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceHeaderDefaultsEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceHeaderDefaultsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceHeaderDefaultsEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_headerDefaults"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceHeaderDefaultValues(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_headerDefaults"}, method = {RequestMethod.POST}) void removeMicroServiceHeaderDefaults(HttpServletRequest request, HttpServletResponse response); }
MicroServiceDictionaryController { @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { this.newModel = new MicroServiceModels(); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); MicroServiceModels microServiceModels = new MicroServiceModels(); String userId = null; String dataOrderInfo = null; if (root.has("dataOrderInfo")) { dataOrderInfo = root.get("dataOrderInfo").toString(); } 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()); } } classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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(); MsAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); this.newModel.setSubAttributes(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.setRefAttributes(refAttributesAfterFirstEquals); this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", "")); this.newModel .setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", "")); } else { if (fromAPI) { microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class); userId = "API"; } 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(classMapData)) { classMap = new LinkedHashMap<>(); JsonNode data = root.get(classMapData); 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.setAttributes(this.newModel.getAttributes()); microServiceModels.setRefAttributes(this.newModel.getRefAttributes()); microServiceModels.setDependency(this.newModel.getDependency()); microServiceModels.setModelName(this.newModel.getModelName()); microServiceModels.setSubAttributes(this.newModel.getSubAttributes()); microServiceModels.setVersion(this.newModel.getVersion()); microServiceModels.setEnumValues(this.newModel.getEnumValues()); microServiceModels.setAnnotation(this.newModel.getAnnotation()); if (dataOrderInfo != null) { microServiceModels.setDataOrderInfo(dataOrderInfo); } String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); boolean duplicateflag = false; if (duplicateData != null && !duplicateData.isEmpty()) { MicroServiceModels data = (MicroServiceModels) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { microServiceModels.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))) { duplicateflag = true; } } UserInfo userInfo = utils.getUserInfo(userId); String responseString = null; if (!duplicateflag) { microServiceModels.setUserCreatedBy(userInfo); if (microServiceModels.getId() == 0) { commonClassDao.save(microServiceModels); } else { commonClassDao.update(microServiceModels); } responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } MicroServiceDictionaryController(); @Autowired  MicroServiceDictionaryController(CommonClassDao commonClassDao); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_DCAEUUIDDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_DCAEUUIDData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEUUIDDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_dcaeUUID"}, method = {RequestMethod.POST}) ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_dcaeuuid"}, method = {RequestMethod.POST}) void removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceConfigNameDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceConfigNameData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceDictData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceDictNameDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_DictionaryData"}, method = {RequestMethod.POST}) ModelAndView saveDictionaryData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msDictionaryData"}, method = {RequestMethod.POST}) void removeMicroServiceDictionaryData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_configName"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msConfigName"}, method = {RequestMethod.POST}) void removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceLocationDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceLocationData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_location"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msLocation"}, method = {RequestMethod.POST}) void removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceAttributeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceAttributeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_modelAttribute"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_modelAttribute"}, method = {RequestMethod.POST}) void removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByVersion"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request,
            HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataServiceVersion"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByClass"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryClassEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msModel"}, method = {RequestMethod.POST}) void removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceHeaderDefaultsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceHeaderDefaultsEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceHeaderDefaultsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceHeaderDefaultsEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_headerDefaults"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceHeaderDefaultValues(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_headerDefaults"}, method = {RequestMethod.POST}) void removeMicroServiceHeaderDefaults(HttpServletRequest request, HttpServletResponse response);  }