+
+ @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView removeFirewallTagPickerDictionary(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());
+ FWTagPicker fwTagPicker = (FWTagPicker)mapper.readValue(root.get("data").toString(), FWTagPicker.class);
+ commonClassDao.delete(fwTagPicker);
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+
+ PrintWriter out = response.getWriter();
+ String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
+ JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
+ out.write(j.toString());
+ return null;
+ }
+ catch (Exception e){
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
+ response.setCharacterEncoding("UTF-8");
+ request.setCharacterEncoding("UTF-8");
+ PrintWriter out = response.getWriter();
+ out.write(e.getMessage());
+ }
+ return null;
+ }
+
+
+ @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+ public void getTagNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){
+ try{
+ Map<String, Object> model = new HashMap<String, Object>();
+ ObjectMapper mapper = new ObjectMapper();
+ model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName")));
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
+ JSONObject j = new JSONObject(msg);
+ response.getWriter().write(j.toString());
+ }
+ catch (Exception e){
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
+ }
+ }
+
+ @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+ public void getTagDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ try{
+ Map<String, Object> model = new HashMap<String, Object>();
+ ObjectMapper mapper = new ObjectMapper();
+ model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTag.class)));
+ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
+ JSONObject j = new JSONObject(msg);
+ response.getWriter().write(j.toString());
+ }
+ catch (Exception e){
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
+ }
+ }
+
+ @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView saveFirewallTagDictionary(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());
+
+
+ FWTag fwTag;
+ TagGridValues tagGridValues;
+ String userId = null;
+ if (fromAPI) {
+ fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), FWTag.class);
+ tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), TagGridValues.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")) {
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "tagName", FWTag.class);
+ int id = 0;
+ FWTag data = (FWTag) duplicateData.get(0);
+ id = data.getId();
+ fwTag.setId(id);
+ fwTag.setUserCreatedBy(this.getUserInfo(userId));
+
+ }
+ } else {
+ fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
+ tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class);
+ userId = root.get("userid").textValue();
+ }
+
+ String userValue = "";
+ int counter = 0;
+ if(tagGridValues.getTags().size() > 0){
+ for(Object attribute : tagGridValues.getTags()){
+ if(attribute instanceof LinkedHashMap<?, ?>){
+ String key = ((LinkedHashMap<?, ?>) attribute).get("tags").toString();
+ if(counter>0){
+ userValue = userValue + ",";
+ }
+ userValue = userValue + key ;
+ counter ++;
+ }
+ }
+ }
+ fwTag.setTagValues(userValue);
+ if(fwTag.getId() == 0){
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
+ if(!duplicateData.isEmpty()){
+ duplicateflag = true;
+ }else{
+ fwTag.setUserCreatedBy(this.getUserInfo(userId));
+ fwTag.setUserModifiedBy(this.getUserInfo(userId));
+ commonClassDao.save(fwTag);
+ }
+ }else{
+ fwTag.setUserModifiedBy(this.getUserInfo(userId));
+ commonClassDao.update(fwTag);
+ }
+
+ String responseString = "";
+ if(duplicateflag){
+ responseString = "Duplicate";
+ }else{
+ responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.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("{fwTagDictionaryDatas: " + responseString + "}");
+ out.write(j.toString());
+ return null;
+ }
+ }
+ catch (Exception e){
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
+ response.setCharacterEncoding("UTF-8");
+ request.setCharacterEncoding("UTF-8");
+ PrintWriter out = response.getWriter();
+ out.write(e.getMessage());
+ }
+ return null;
+ }
+
+ @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
+ public ModelAndView removeFirewallTagDictionary(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());
+ FWTag fwTag = (FWTag)mapper.readValue(root.get("data").toString(), FWTag.class);
+ commonClassDao.delete(fwTag);
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("application / json");
+ request.setCharacterEncoding("UTF-8");
+
+ PrintWriter out = response.getWriter();
+
+ String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
+ JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
+ out.write(j.toString());
+
+ return null;
+ }
+ catch (Exception e){
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
+ response.setCharacterEncoding("UTF-8");
+ request.setCharacterEncoding("UTF-8");
+ PrintWriter out = response.getWriter();
+ out.write(e.getMessage());
+ }
+ return null;
+ }
+}
+
+class TagGridValues{
+ private ArrayList<Object> tags;
+
+ public ArrayList<Object> getTags() {
+ return tags;
+ }
+
+ public void setTags(ArrayList<Object> tags) {
+ this.tags = tags;
+ }