+ @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;
+ }
+
+ @RequestMapping(value = {"/ms_dictionary/remove_msModel"}, method = {RequestMethod.POST})
+ public void removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ DictionaryUtils utils = getDictionaryUtilsInstance();
+ utils.removeData(request, response, microServiceModelsDictionaryDatas, MicroServiceModels.class);
+ }
+
+ private void addValuesToNewModel(HashMap<String, MsAttributeObject> classMap) {
+ // Loop through the classmap and pull out the required info for the new file.
+ String subAttribute = null;
+
+ MsAttributeObject mainClass = classMap.get(this.newModel.getModelName());
+
+ if (mainClass != null) {
+ String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[] {"[", "]", " "},
+ new String[] {"", "", ""});
+ ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));
+ dependency = getFullDependencyList(dependency);
+ for (String element : dependency) {
+ MsAttributeObject temp = classMap.get(element);
+ if (temp != null) {
+ mainClass.addAllRefAttribute(temp.getRefAttribute());
+ mainClass.addAllAttribute(temp.getAttribute());
+ }
+ }
+ subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
+ } else {
+ subAttribute = "{}";
+ this.newModel.setDependency("");
+ }
+
+ if (mainClass != null && mainClass.getDependency() == null) {
+ mainClass.setDependency("");
+ }
+ if (mainClass != null) {
+ this.newModel.setDependency(mainClass.getDependency());
+ this.newModel.setSubAttributes(subAttribute);
+ this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
+ this.newModel.setRefAttributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
+ this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+ this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+ }
+ }
+
+ private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
+ ArrayList<String> returnList = new ArrayList<>();
+ ArrayList<String> workingList = new ArrayList<>();
+ returnList.addAll(dependency);
+ for (String element : dependency) {
+ if (classMap.containsKey(element)) {
+ MsAttributeObject value = classMap.get(element);
+ String rawValue =
+ StringUtils.replaceEach(value.getDependency(), new String[] {"[", "]"}, new String[] {"", ""});
+ workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
+ for (String depend : workingList) {
+ if (!returnList.contains(depend) && !depend.isEmpty()) {
+ returnList.add(depend.trim());
+ // getFullDepedency(workingList)
+ }
+ }
+ }
+ }
+
+ return returnList;
+ }
+
+ @RequestMapping(
+ value = {"/get_MicroServiceHeaderDefaultsDataByName"},
+ method = {RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getMicroServiceHeaderDefaultsEntityDataByName(HttpServletResponse response) {
+ DictionaryUtils utils = getDictionaryUtilsInstance();
+ utils.getDataByEntity(response, microServiceHeaderDefaultDatas, "modelName", MicroserviceHeaderdeFaults.class);
+ }
+
+ @RequestMapping(
+ value = {"/get_MicroServiceHeaderDefaultsData"},
+ method = {RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getMicroServiceHeaderDefaultsEntityData(HttpServletResponse response) {
+ DictionaryUtils utils = getDictionaryUtilsInstance();
+ utils.getData(response, microServiceHeaderDefaultDatas, MicroserviceHeaderdeFaults.class);
+ }
+
+ @RequestMapping(value = {"/ms_dictionary/save_headerDefaults"}, method = {RequestMethod.POST})
+ public ModelAndView saveMicroServiceHeaderDefaultValues(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ DictionaryUtils utils = getDictionaryUtilsInstance();
+ try {
+ boolean fromAPI = utils.isRequestFromAPI(request);
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ JsonNode root = mapper.readTree(request.getReader());
+
+ MicroserviceHeaderdeFaults msHeaderdeFaults;
+ if (fromAPI) {
+ msHeaderdeFaults =
+ mapper.readValue(root.get(dictionaryFields).toString(), MicroserviceHeaderdeFaults.class);
+ } else {
+ msHeaderdeFaults = mapper.readValue(root.get("modelAttributeDictionaryData").toString(),
+ MicroserviceHeaderdeFaults.class);
+ }
+
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(msHeaderdeFaults.getModelName(),
+ "modelName", MicroserviceHeaderdeFaults.class);
+ boolean duplicateflag = false;
+ if (duplicateData != null && !duplicateData.isEmpty()) {
+ MicroserviceHeaderdeFaults data = (MicroserviceHeaderdeFaults) duplicateData.get(0);
+ if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) {
+ msHeaderdeFaults.setId(data.getId());
+ } else if ((request.getParameter(operation) != null
+ && !"update".equals(request.getParameter(operation)))
+ || (request.getParameter(operation) == null && (data.getId() != msHeaderdeFaults.getId()))) {
+ duplicateflag = true;
+ }
+ }
+
+ String responseString = null;
+ if (!duplicateflag) {
+ if (msHeaderdeFaults.getId() == 0) {
+ commonClassDao.save(msHeaderdeFaults);
+ } else {
+ commonClassDao.update(msHeaderdeFaults);
+ }
+ responseString = mapper.writeValueAsString(commonClassDao.getData(MicroserviceHeaderdeFaults.class));
+ } else {
+ responseString = duplicateResponseString;
+ }
+ if (fromAPI) {
+ return utils.getResultForApi(responseString);
+ } else {
+ utils.setResponseData(response, microServiceHeaderDefaultDatas, responseString);
+ }
+ } catch (Exception e) {
+ utils.setErrorResponseData(response, e);
+ }
+ return null;
+ }
+
+ @RequestMapping(value = {"/ms_dictionary/remove_headerDefaults"}, method = {RequestMethod.POST})
+ public void removeMicroServiceHeaderDefaults(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+ DictionaryUtils utils = getDictionaryUtilsInstance();
+ utils.removeData(request, response, microServiceHeaderDefaultDatas, MicroserviceHeaderdeFaults.class);
+ }