+ @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+ public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ try{
+ Map<String, Object> model = new HashMap<>();
+ ObjectMapper mapper = new ObjectMapper();
+ model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceAttribute.class, "name")));
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
+ JSONObject j = new JSONObject(msg);
+ response.getWriter().write(j.toString());
+ }
+ catch (Exception e){
+ LOGGER.error(e.getMessage());
+ }
+ }
+
+ @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+ public void getMicroServiceAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ try{
+ Map<String, Object> model = new HashMap<>();
+ ObjectMapper mapper = new ObjectMapper();
+ model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)));
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
+ JSONObject j = new JSONObject(msg);
+ response.addHeader(SUCCESSKEY, SUCCESS);
+ response.addHeader(OPERATION, GETDICTIONARY);
+ response.getWriter().write(j.toString());
+
+ }
+ catch (Exception e){
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ response.addHeader(ERROR, DICTIONARYDBQUERY);
+ LOGGER.error(e.getMessage());
+ }
+ }
+
+ @RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
+ try {
+ boolean duplicateflag = false;
+ boolean fromAPI = false;
+ if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
+ fromAPI = true;
+ }
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ JsonNode root = mapper.readTree(request.getReader());
+
+ MicroServiceAttribute microServiceAttribute;
+ if (fromAPI) {
+ microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceAttribute.class);
+
+ //check if update operation or create, get id for data to be updated and update attributeData
+ if (request.getParameter(OPERATION).equals("update")) {
+ MicroServiceAttribute initialAttribute = (MicroServiceAttribute)mapper.readValue(root.get("initialFields").toString(), MicroServiceAttribute.class);
+
+ String checkValue = initialAttribute.getName() + ":" + initialAttribute.getValue() + ":" + initialAttribute.getModelName();
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
+ int id=0;
+ for (int i= 0; i<duplicateData.size(); i++){
+ MicroServiceAttribute data = (MicroServiceAttribute) duplicateData.get(0);
+ id = data.getId();
+ }
+ microServiceAttribute.setId(id);
+ }
+ } else {
+ microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("modelAttributeDictionaryData").toString(), MicroServiceAttribute.class);
+ }
+
+ if(microServiceAttribute.getId() == 0){
+ String checkValue = microServiceAttribute.getName() + ":" + microServiceAttribute.getValue() + ":" + microServiceAttribute.getModelName();
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
+ if(!duplicateData.isEmpty()){
+ duplicateflag = true;
+ }else{
+ commonClassDao.save(microServiceAttribute);
+ }
+ }else{
+ commonClassDao.update(microServiceAttribute);
+ }
+
+ String responseString = "";
+ if(duplicateflag){
+ responseString = "Duplicate";
+ }else{
+ responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class));
+ }
+
+ if (fromAPI) {
+ if (responseString!=null && !responseString.equals("Duplicate")) {
+ responseString = "Success";
+ }
+ ModelAndView result = new ModelAndView();
+ result.setViewName(responseString);
+ return result;
+ } else {
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+
+ PrintWriter out = response.getWriter();
+ JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
+ out.write(j.toString());
+ return null;
+ }
+ }
+ catch (Exception e){
+ response.setCharacterEncoding("UTF-8");
+ request.setCharacterEncoding("UTF-8");
+ PrintWriter out = response.getWriter();
+ out.write(e.getMessage());
+ }
+ return null;
+ }
+
+ @RequestMapping(value={"/ms_dictionary/remove_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ try{
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ JsonNode root = mapper.readTree(request.getReader());
+ MicroServiceAttribute microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("data").toString(), MicroServiceAttribute.class);
+ commonClassDao.delete(microServiceAttribute);
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+
+ PrintWriter out = response.getWriter();
+
+ String responseString = mapper.writeValueAsString(MicroServiceDictionaryController.commonClassDao.getData(MicroServiceAttribute.class));
+ JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
+ out.write(j.toString());
+
+ return null;
+ }
+ catch (Exception e){
+ LOGGER.error(e.getMessage());
+ response.setCharacterEncoding("UTF-8");
+ request.setCharacterEncoding("UTF-8");
+ PrintWriter out = response.getWriter();
+ out.write(e.getMessage());
+ }
+ return null;
+ }
+
+