Sonar fix forONAP-PAP-REST critical sonar issues
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / FirewallDictionaryController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.controller;
22
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.io.UnsupportedEncodingException;
26 import java.net.UnknownHostException;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.LinkedHashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36
37 import org.jboss.netty.handler.ipfilter.CIDR;
38 import org.json.JSONObject;
39 import org.onap.policy.common.logging.flexlogger.FlexLogger;
40 import org.onap.policy.common.logging.flexlogger.Logger;
41 import org.onap.policy.pap.xacml.rest.adapters.GridData;
42 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
43 import org.onap.policy.rest.dao.CommonClassDao;
44 import org.onap.policy.rest.jpa.ActionList;
45 import org.onap.policy.rest.jpa.AddressGroup;
46 import org.onap.policy.rest.jpa.FWTag;
47 import org.onap.policy.rest.jpa.FWTagPicker;
48 import org.onap.policy.rest.jpa.FirewallDictionaryList;
49 import org.onap.policy.rest.jpa.GroupServiceList;
50 import org.onap.policy.rest.jpa.PrefixList;
51 import org.onap.policy.rest.jpa.PortList;
52 import org.onap.policy.rest.jpa.ProtocolList;
53 import org.onap.policy.rest.jpa.SecurityZone;
54 import org.onap.policy.rest.jpa.ServiceList;
55 import org.onap.policy.rest.jpa.TermList;
56 import org.onap.policy.rest.jpa.UserInfo;
57 import org.onap.policy.rest.jpa.Zone;
58 import org.onap.policy.xacml.api.XACMLErrorConstants;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.http.MediaType;
61 import org.springframework.stereotype.Controller;
62 import org.springframework.web.bind.annotation.RequestMapping;
63 import org.springframework.web.servlet.ModelAndView;
64
65 import com.fasterxml.jackson.databind.DeserializationFeature;
66 import com.fasterxml.jackson.databind.JsonNode;
67 import com.fasterxml.jackson.databind.ObjectMapper;
68
69
70 @Controller
71 public class FirewallDictionaryController {
72
73         private static final Logger LOGGER  = FlexLogger.getLogger(FirewallDictionaryController.class);
74
75         private static CommonClassDao commonClassDao;
76         
77         @Autowired
78         public FirewallDictionaryController(CommonClassDao commonClassDao){
79                 FirewallDictionaryController.commonClassDao = commonClassDao;
80         }
81         
82         public FirewallDictionaryController(){} 
83
84         public UserInfo getUserInfo(String loginId){
85                 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
86                 return name;    
87         }
88
89
90         @RequestMapping(value={"/get_PrefixListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
91         public void getPrefixListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
92                 try{
93                         Map<String, Object> model = new HashMap<>();
94                         ObjectMapper mapper = new ObjectMapper();
95                         model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PrefixList.class, "prefixListName")));
96                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
97                         JSONObject j = new JSONObject(msg);
98                         response.getWriter().write(j.toString());
99                 }
100                 catch (Exception e){
101                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
102                 }
103         }
104
105         @RequestMapping(value={"/get_PrefixListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
106         public void getPrefixListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
107                 try{
108                         Map<String, Object> model = new HashMap<>();
109                         ObjectMapper mapper = new ObjectMapper();
110                         model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)));
111                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
112                         JSONObject j = new JSONObject(msg);
113                         response.addHeader("successMapKey", "success"); 
114                         response.addHeader("operation", "getDictionary");
115                         response.getWriter().write(j.toString());
116                 }
117                 catch (Exception e){
118                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e);
119                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
120                         response.addHeader("error", "dictionaryDBQuery");
121                 }
122         }
123
124         @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
125         public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
126                 try {
127                         boolean duplicateflag = false;
128                         boolean isFakeUpdate = false;
129                         boolean fromAPI = false;
130                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
131                                 fromAPI = true;
132                         }
133                         ObjectMapper mapper = new ObjectMapper();
134                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
135                         JsonNode root = mapper.readTree(request.getReader());
136                         PrefixList prefixList;
137                         if (fromAPI) {
138                                 prefixList = (PrefixList)mapper.readValue(root.get("dictionaryFields").toString(), PrefixList.class);
139
140                                 //check if update operation or create, get id for data to be updated and update attributeData
141                                 if (request.getParameter("operation").equals("update")) {
142                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class);
143                                         int id = 0;
144                                         PrefixList data = (PrefixList) duplicateData.get(0);
145                                         id = data.getId();
146                                         if(id==0){
147                                                 isFakeUpdate=true;
148                                                 prefixList.setId(1);
149                                         } else {
150                                                 prefixList.setId(id);
151                                         }
152                                 }
153                         } else {
154                                 prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
155                         }
156                         if(prefixList.getId() == 0){
157                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class);
158                                 if(!duplicateData.isEmpty()){
159                                         duplicateflag = true;
160                                 }else{
161                                         commonClassDao.save(prefixList);
162                                 }               
163                         }else{
164                                 if(!isFakeUpdate) {
165                                         commonClassDao.update(prefixList); 
166                                 }
167                         } 
168                         String responseString = "";
169                         if(duplicateflag){
170                                 responseString = "Duplicate";
171                         }else{
172                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
173                         }
174
175                         if (fromAPI) {
176                                 if (responseString!=null && !responseString.equals("Duplicate")) {
177                                         if(isFakeUpdate){
178                                                 responseString = "Exists";
179                                         } else {
180                                                 responseString = "Success";
181                                         }
182                                 }
183                                 ModelAndView result = new ModelAndView();
184                                 result.setViewName(responseString);
185                                 return result;
186                         } else {
187                                 response.setCharacterEncoding("UTF-8");
188                                 response.setContentType("application / json");
189                                 request.setCharacterEncoding("UTF-8");
190
191                                 PrintWriter out = response.getWriter();
192                                 JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}");
193                                 out.write(j.toString());
194                                 return null;
195                         }
196                 }catch (Exception e){
197                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e);
198                         response.setCharacterEncoding("UTF-8");
199                         request.setCharacterEncoding("UTF-8");
200                         PrintWriter out = response.getWriter();
201                         out.write(e.getMessage());
202                 }
203                 return null;
204         }
205
206         @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
207         public ModelAndView removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
208                 try{
209                         ObjectMapper mapper = new ObjectMapper();
210                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
211                         JsonNode root = mapper.readTree(request.getReader());
212                         PrefixList prefixList = (PrefixList)mapper.readValue(root.get("data").toString(), PrefixList.class);
213                         commonClassDao.delete(prefixList);
214                         response.setCharacterEncoding("UTF-8");
215                         response.setContentType("application / json");
216                         request.setCharacterEncoding("UTF-8");
217
218                         PrintWriter out = response.getWriter();
219                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
220                         JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}");
221                         out.write(j.toString());
222                         return null;
223                 }
224                 catch (Exception e){
225                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
226                         response.setCharacterEncoding("UTF-8");
227                         request.setCharacterEncoding("UTF-8");
228                         PrintWriter out = response.getWriter();
229                         out.write(e.getMessage());
230                 }
231                 return null;
232         }
233
234         @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
235         public ModelAndView validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
236                 try {
237                         ObjectMapper mapper = new ObjectMapper();
238                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
239                         JsonNode root = mapper.readTree(request.getReader());
240                         PrefixList prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
241                         String responseValidation = "success";
242                         try{
243                                 CIDR.newCIDR(prefixList.getPrefixListValue());
244                         }catch(UnknownHostException e){
245                                 LOGGER.error(e);
246                                 responseValidation = "error";
247                         }               
248                         response.setCharacterEncoding("UTF-8");
249                         response.setContentType("application / json");
250                         request.setCharacterEncoding("UTF-8");
251
252                         PrintWriter out = response.getWriter();
253                         JSONObject j = new JSONObject("{result: " + responseValidation + "}");
254                         out.write(j.toString());
255                         return null;
256                 }
257                 catch (Exception e){
258                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
259                         response.setCharacterEncoding("UTF-8");
260                         request.setCharacterEncoding("UTF-8");
261                         PrintWriter out = response.getWriter();
262                         out.write(e.getMessage());
263                 }
264                 return null;
265         }
266
267         @RequestMapping(value={"/get_PortListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
268         public void getPortListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
269                 try{
270                         Map<String, Object> model = new HashMap<>();
271                         ObjectMapper mapper = new ObjectMapper();
272                         model.put("portListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PortList.class)));
273                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
274                         JSONObject j = new JSONObject(msg);
275                         response.addHeader("successMapKey", "success"); 
276                         response.addHeader("operation", "getDictionary");
277                         response.getWriter().write(j.toString());
278                 }
279                 catch (Exception e){
280                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
281                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
282                         response.addHeader("error", "dictionaryDBQuery");
283                 }
284         }
285
286         @RequestMapping(value={"/fw_dictionary/save_portName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
287         public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
288                 try {
289                         boolean duplicateflag = false;
290                         ObjectMapper mapper = new ObjectMapper();
291                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
292                         JsonNode root = mapper.readTree(request.getReader());
293                         PortList portList = (PortList)mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class);
294                         if(portList.getId() == 0){
295                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class);
296                                 if(!duplicateData.isEmpty()){
297                                         duplicateflag = true;
298                                 }else{
299                                         commonClassDao.save(portList);
300                                 }
301                         }else{
302                                 commonClassDao.update(portList); 
303                         } 
304                         response.setCharacterEncoding("UTF-8");
305                         response.setContentType("application / json");
306                         request.setCharacterEncoding("UTF-8");
307
308                         PrintWriter out = response.getWriter();
309                         String responseString = "";
310                         if(duplicateflag){
311                                 responseString = "Duplicate";
312                         }else{
313                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
314                         }
315                         JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}");
316
317                         out.write(j.toString());
318
319                         return null;
320                 }
321                 catch (Exception e){
322                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
323                         response.setCharacterEncoding("UTF-8");
324                         request.setCharacterEncoding("UTF-8");
325                         PrintWriter out = response.getWriter();
326                         out.write(e.getMessage());
327                 }
328                 return null;
329         }
330
331         @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
332         public ModelAndView removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
333                 try{
334                         ObjectMapper mapper = new ObjectMapper();
335                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
336                         JsonNode root = mapper.readTree(request.getReader());
337                         PortList portList = (PortList)mapper.readValue(root.get("data").toString(), PortList.class);
338                         commonClassDao.delete(portList);
339                         response.setCharacterEncoding("UTF-8");
340                         response.setContentType("application / json");
341                         request.setCharacterEncoding("UTF-8");
342
343                         PrintWriter out = response.getWriter();
344                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
345                         JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}");
346                         out.write(j.toString());
347                         return null;
348                 }
349                 catch (Exception e){
350                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
351                         response.setCharacterEncoding("UTF-8");
352                         request.setCharacterEncoding("UTF-8");
353                         PrintWriter out = response.getWriter();
354                         out.write(e.getMessage());
355                 }
356                 return null;
357         }
358
359         @RequestMapping(value={"/get_ProtocolListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
360         public void getProtocolListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
361                 try{
362                         Map<String, Object> model = new HashMap<String, Object>();
363                         ObjectMapper mapper = new ObjectMapper();
364                         model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)));
365                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
366                         JSONObject j = new JSONObject(msg);
367                         response.addHeader("successMapKey", "success"); 
368                         response.addHeader("operation", "getDictionary");
369                         response.getWriter().write(j.toString());
370                 }
371                 catch (Exception e){
372                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
373                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
374                         response.addHeader("error", "dictionaryDBQuery");
375                 }
376         }
377
378         @RequestMapping(value={"/get_ProtocolListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
379         public void getProtocolListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
380                 try{
381                         Map<String, Object> model = new HashMap<String, Object>();
382                         ObjectMapper mapper = new ObjectMapper();
383                         model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ProtocolList.class, "protocolName")));
384                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
385                         JSONObject j = new JSONObject(msg);
386                         response.getWriter().write(j.toString());
387                 }
388                 catch (Exception e){
389                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
390                 }
391         }
392
393         @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
394         public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
395                 try {
396                         boolean duplicateflag = false;
397                         boolean isFakeUpdate = false;
398                         boolean fromAPI = false;
399                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
400                                 fromAPI = true;
401                         }
402                         ObjectMapper mapper = new ObjectMapper();
403                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
404                         JsonNode root = mapper.readTree(request.getReader());
405                         ProtocolList protocolList;
406                         if (fromAPI) {
407                                 protocolList = (ProtocolList)mapper.readValue(root.get("dictionaryFields").toString(), ProtocolList.class);
408
409                                 //check if update operation or create, get id for data to be updated and update attributeData
410                                 if (request.getParameter("operation").equals("update")) {
411                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class);
412                                         int id = 0;
413                                         ProtocolList data = (ProtocolList) duplicateData.get(0);
414                                         id = data.getId();
415                                         if(id==0){
416                                                 isFakeUpdate=true;
417                                                 protocolList.setId(1);
418                                         } else {
419                                                 protocolList.setId(id);
420                                         }
421                                 }
422                         } else {
423                                 protocolList = (ProtocolList)mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class);
424                         }
425                         if(protocolList.getId() == 0){
426                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class);
427                                 if(!duplicateData.isEmpty()){
428                                         duplicateflag = true;
429                                 }else{
430                                         commonClassDao.save(protocolList);
431                                 }
432                         }else{
433                                 if(!isFakeUpdate){
434                                         commonClassDao.update(protocolList);
435                                 }
436                         } 
437                         String responseString = "";
438                         if(duplicateflag){
439                                 responseString = "Duplicate";
440                         }else{
441                                 responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
442                         }
443
444                         if (fromAPI) {
445                                 if (responseString!=null && !responseString.equals("Duplicate")) {
446                                         if(isFakeUpdate){
447                                                 responseString = "Exists";
448                                         } else {
449                                                 responseString = "Success";
450                                         }
451                                 }
452                                 ModelAndView result = new ModelAndView();
453                                 result.setViewName(responseString);
454                                 return result;
455                         } else {
456                                 response.setCharacterEncoding("UTF-8");
457                                 response.setContentType("application / json");
458                                 request.setCharacterEncoding("UTF-8");
459
460                                 PrintWriter out = response.getWriter();
461                                 JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}");
462                                 out.write(j.toString());
463                                 return null;
464                         }
465                 }catch (Exception e){
466                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
467                         response.setCharacterEncoding("UTF-8");
468                         request.setCharacterEncoding("UTF-8");
469                         PrintWriter out = response.getWriter();
470                         out.write(e.getMessage());
471                 }
472                 return null;
473         }
474
475         @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
476         public ModelAndView removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
477                 try{
478                         ObjectMapper mapper = new ObjectMapper();
479                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
480                         JsonNode root = mapper.readTree(request.getReader());
481                         ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("data").toString(), ProtocolList.class);
482                         commonClassDao.delete(protocolList);
483                         response.setCharacterEncoding("UTF-8");
484                         response.setContentType("application / json");
485                         request.setCharacterEncoding("UTF-8");
486
487                         PrintWriter out = response.getWriter();
488
489                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
490                         JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}");
491                         out.write(j.toString());
492                         return null;
493                 }
494                 catch (Exception e){
495                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
496                         response.setCharacterEncoding("UTF-8");
497                         request.setCharacterEncoding("UTF-8");
498                         PrintWriter out = response.getWriter();
499                         out.write(e.getMessage());
500                 }
501                 return null;
502         }
503
504         @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
505         public void getAddressGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
506                 try{
507                         Map<String, Object> model = new HashMap<>();
508                         ObjectMapper mapper = new ObjectMapper();
509                         model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(AddressGroup.class, "name")));
510                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
511                         JSONObject j = new JSONObject(msg);
512                         response.getWriter().write(j.toString());
513                 }
514                 catch (Exception e){
515                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
516                 }
517         }
518
519         @RequestMapping(value={"/get_AddressGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
520         public void getAddressGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
521                 try{
522                         Map<String, Object> model = new HashMap<>();
523                         ObjectMapper mapper = new ObjectMapper();
524                         model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)));
525                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
526                         JSONObject j = new JSONObject(msg);
527                         response.addHeader("successMapKey", "success"); 
528                         response.addHeader("operation", "getDictionary");
529                         response.getWriter().write(j.toString());
530                 }
531                 catch (Exception e){
532                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
533                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
534                         response.addHeader("error", "dictionaryDBQuery");
535                 }
536         }
537
538         @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
539         public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
540                 try {
541                         boolean duplicateflag = false;
542                         boolean isFakeUpdate = false;
543                         boolean fromAPI = false;
544                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
545                                 fromAPI = true;
546                         }
547                         ObjectMapper mapper = new ObjectMapper();
548                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
549                         JsonNode root = mapper.readTree(request.getReader());
550                         AddressGroup addressGroup;
551                         GridData gridData;
552                         if (fromAPI) {
553                                 addressGroup = (AddressGroup)mapper.readValue(root.get("dictionaryFields").toString(), AddressGroup.class);
554                                 gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
555
556                                 if(!addressGroup.getGroupName().startsWith("Group_")){
557                                         String groupName = "Group_"+addressGroup.getGroupName();
558                                         addressGroup.setGroupName(groupName);
559                                 }
560
561                                 //check if update operation or create, get id for data to be updated and update attributeData
562                                 if (request.getParameter("operation").equals("update")) {
563                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
564                                         int id = 0;
565                                         AddressGroup data = (AddressGroup) duplicateData.get(0);
566                                         id = data.getId();
567                                         if(id==0){
568                                                 isFakeUpdate=true;
569                                                 addressGroup.setId(1);
570                                         } else {
571                                                 addressGroup.setId(id);
572                                         }            
573                                 }
574                         } else {
575                                 addressGroup = (AddressGroup)mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class);
576                                 gridData = (GridData)mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class);
577                                 if(!addressGroup.getGroupName().startsWith("Group_")){
578                                         String groupName = "Group_"+addressGroup.getGroupName();
579                                         addressGroup.setGroupName(groupName);
580                                 }
581                         }
582                         String userValue = "";
583                         int counter = 0;
584                         if(gridData.getAttributes().size() > 0){
585                                 for(Object attribute : gridData.getAttributes()){
586                                         if(attribute instanceof LinkedHashMap<?, ?>){
587                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
588                                                 if(counter>0){
589                                                         userValue = userValue + ",";
590                                                 }
591                                                 userValue = userValue + key ;
592                                                 counter ++;
593                                         }
594                                 }
595                         }
596                         addressGroup.setServiceList(userValue);
597                         if(addressGroup.getId() == 0){
598                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
599                                 if(!duplicateData.isEmpty()){
600                                         duplicateflag = true;
601                                 }else{
602                                         commonClassDao.save(addressGroup);
603                                 }
604                         }else{
605                                 if (!isFakeUpdate) {
606                                         commonClassDao.update(addressGroup); 
607                                 }
608                         } 
609                         String responseString = "";
610                         if(duplicateflag){
611                                 responseString = "Duplicate";
612                         }else{
613                                 responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
614                         }
615                         if (fromAPI) {
616                                 if (responseString!=null && !responseString.equals("Duplicate")) {
617                                         if(isFakeUpdate){
618                                                 responseString = "Exists";
619                                         } else {
620                                                 responseString = "Success";
621                                         }
622                                 }
623                                 ModelAndView result = new ModelAndView();
624                                 result.setViewName(responseString);
625                                 return result;
626                         } else {
627                                 response.setCharacterEncoding("UTF-8");
628                                 response.setContentType("application / json");
629                                 request.setCharacterEncoding("UTF-8");
630
631                                 PrintWriter out = response.getWriter();
632                                 JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}");
633                                 out.write(j.toString());
634                                 return null;
635                         }
636                 }catch (Exception e){
637                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
638                         response.setCharacterEncoding("UTF-8");
639                         request.setCharacterEncoding("UTF-8");
640                         PrintWriter out = response.getWriter();
641                         out.write(e.getMessage());
642                 }
643                 return null;
644         }
645
646         @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
647         public ModelAndView removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
648                 try{
649                         ObjectMapper mapper = new ObjectMapper();
650                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
651                         JsonNode root = mapper.readTree(request.getReader());
652                         AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("data").toString(), AddressGroup.class);
653                         commonClassDao.delete(addressGroup);
654                         response.setCharacterEncoding("UTF-8");
655                         response.setContentType("application / json");
656                         request.setCharacterEncoding("UTF-8");
657
658                         PrintWriter out = response.getWriter();
659
660                         String responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
661                         JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}");
662                         out.write(j.toString());
663                         return null;
664                 }
665                 catch (Exception e){
666                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
667                         response.setCharacterEncoding("UTF-8");
668                         request.setCharacterEncoding("UTF-8");
669                         PrintWriter out = response.getWriter();
670                         out.write(e.getMessage());
671                 }
672                 return null;
673         }
674
675         @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
676         public void getActionListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
677                 try{
678                         Map<String, Object> model = new HashMap<>();
679                         ObjectMapper mapper = new ObjectMapper();
680                         List<Object> list = commonClassDao.getData(ActionList.class);
681                         List<String> dictList = new ArrayList<>();
682                         for(int i = 0; i < list.size(); i++){
683                                 ActionList dict = (ActionList) list.get(i);
684                                 dictList.add(dict.getActionName());
685                         }
686                         model.put("actionListDictionaryDatas", mapper.writeValueAsString(dictList));
687                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
688                         JSONObject j = new JSONObject(msg);
689                         response.getWriter().write(j.toString());
690                 }
691                 catch (Exception e){
692                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
693                 }
694         }
695
696         @RequestMapping(value={"/get_ActionListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
697         public void getActionListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
698                 try{
699                         Map<String, Object> model = new HashMap<>();
700                         ObjectMapper mapper = new ObjectMapper();
701                         model.put("actionListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ActionList.class)));
702                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
703                         JSONObject j = new JSONObject(msg);
704                         response.addHeader("successMapKey", "success"); 
705                         response.addHeader("operation", "getDictionary");
706                         response.getWriter().write(j.toString());
707                 }
708                 catch (Exception e){
709                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
710                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
711                         response.addHeader("error", "dictionaryDBQuery");
712                 }
713         }
714
715         @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
716         public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
717                 try {
718                         boolean duplicateflag = false;
719                         boolean isFakeUpdate = false;
720                         boolean fromAPI = false;
721                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
722                                 fromAPI = true;
723                         }
724                         ObjectMapper mapper = new ObjectMapper();
725                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
726                         JsonNode root = mapper.readTree(request.getReader());
727                         ActionList actionList;
728                         if (fromAPI) {
729                                 actionList = (ActionList)mapper.readValue(root.get("dictionaryFields").toString(), ActionList.class);
730
731                                 //check if update operation or create, get id for data to be updated and update attributeData
732                                 if (request.getParameter("operation").equals("update")) {
733                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
734                                         int id = 0;
735                                         ActionList data = (ActionList) duplicateData.get(0);
736                                         id = data.getId();
737                                         if(id==0){
738                                                 isFakeUpdate=true;
739                                                 actionList.setId(1);
740                                         } else {
741                                                 actionList.setId(id);
742                                         }  
743                                 }
744                         } else {
745                                 actionList = (ActionList)mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class);
746                         }
747                         if(actionList.getId() == 0){
748                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
749                                 if(!duplicateData.isEmpty()){
750                                         duplicateflag = true;
751                                 }else{
752                                         commonClassDao.save(actionList);
753                                 }
754                         }else{
755                                 if(!isFakeUpdate) {
756                                         commonClassDao.update(actionList);
757                                 }
758                         } 
759                         String responseString = "";
760                         if(duplicateflag){
761                                 responseString = "Duplicate";
762                         }else{
763                                 responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
764                         }
765
766                         if (fromAPI) {
767                                 if (responseString!=null && !responseString.equals("Duplicate")) {
768                                         if(isFakeUpdate){
769                                                 responseString = "Exists";
770                                         } else {
771                                                 responseString = "Success";
772                                         }
773                                 }
774                                 ModelAndView result = new ModelAndView();
775                                 result.setViewName(responseString);
776                                 return result;
777                         } else {
778                                 response.setCharacterEncoding("UTF-8");
779                                 response.setContentType("application / json");
780                                 request.setCharacterEncoding("UTF-8");
781
782                                 PrintWriter out = response.getWriter();
783                                 JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}");
784                                 out.write(j.toString());
785                                 return null;
786                         }
787                 }catch (Exception e){
788                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
789                         response.setCharacterEncoding("UTF-8");
790                         request.setCharacterEncoding("UTF-8");
791                         PrintWriter out = response.getWriter();
792                         out.write(e.getMessage());
793                 }
794                 return null;
795         }
796
797         @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
798         public ModelAndView removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
799                 try{
800                         ObjectMapper mapper = new ObjectMapper();
801                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
802                         JsonNode root = mapper.readTree(request.getReader());
803                         ActionList actionList = (ActionList)mapper.readValue(root.get("data").toString(), ActionList.class);
804                         commonClassDao.delete(actionList);
805                         response.setCharacterEncoding("UTF-8");
806                         response.setContentType("application / json");
807                         request.setCharacterEncoding("UTF-8");
808
809                         PrintWriter out = response.getWriter();
810                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
811                         JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}");
812                         out.write(j.toString());
813                         return null;
814                 }
815                 catch (Exception e){
816                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
817                         response.setCharacterEncoding("UTF-8");
818                         request.setCharacterEncoding("UTF-8");
819                         PrintWriter out = response.getWriter();
820                         out.write(e.getMessage());
821                 }
822                 return null;
823         }
824
825         @RequestMapping(value={"/get_ServiceGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
826         public void getServiceGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
827                 try{
828                         Map<String, Object> model = new HashMap<>();
829                         ObjectMapper mapper = new ObjectMapper();
830                         model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)));
831                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
832                         JSONObject j = new JSONObject(msg);
833                         response.addHeader("successMapKey", "success"); 
834                         response.addHeader("operation", "getDictionary");
835                         response.getWriter().write(j.toString());
836                 }
837                 catch (Exception e){
838                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
839                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
840                         response.addHeader("error", "dictionaryDBQuery");
841                 }
842         }
843
844         @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
845         public void getServiceGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
846                 try{
847                         Map<String, Object> model = new HashMap<>();
848                         ObjectMapper mapper = new ObjectMapper();
849                         model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupServiceList.class, "name")));
850                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
851                         JSONObject j = new JSONObject(msg);
852                         response.getWriter().write(j.toString());
853                 }
854                 catch (Exception e){
855                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
856                 }
857         }
858
859         @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
860         public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
861                 try {
862                         boolean duplicateflag = false;
863                         boolean isFakeUpdate = false;
864                         boolean fromAPI = false;
865                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
866                                 fromAPI = true;
867                         }
868                         ObjectMapper mapper = new ObjectMapper();
869                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
870                         JsonNode root = mapper.readTree(request.getReader());
871                         GroupServiceList groupServiceList;
872                         GridData gridData;
873                         if (fromAPI) {
874                                 groupServiceList = (GroupServiceList)mapper.readValue(root.get("dictionaryFields").toString(), GroupServiceList.class);
875                                 gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
876
877                                 if(!groupServiceList.getGroupName().startsWith("Group_")){
878                                         String groupName = "Group_"+groupServiceList.getGroupName();
879                                         groupServiceList.setGroupName(groupName);
880                                 }
881                                 //check if update operation or create, get id for data to be updated and update attributeData
882                                 if (request.getParameter("operation").equals("update")) {
883                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
884                                         int id = 0;
885                                         GroupServiceList data = (GroupServiceList) duplicateData.get(0);
886                                         id = data.getId();
887
888                                         if(id==0){
889                                                 isFakeUpdate=true;
890                                                 groupServiceList.setId(1);
891                                         } else {
892                                                 groupServiceList.setId(id);
893                                         }   
894                                 }
895                         } else {
896                                 groupServiceList = (GroupServiceList)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class);
897                                 gridData = (GridData)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class);
898                         }
899                         if(!groupServiceList.getGroupName().startsWith("Group_")){
900                                 String groupName = "Group_"+groupServiceList.getGroupName();
901                                 groupServiceList.setGroupName(groupName);
902                         }
903                         String userValue = "";
904                         int counter = 0;
905                         if(gridData.getAttributes().size() > 0){
906                                 for(Object attribute : gridData.getAttributes()){
907                                         if(attribute instanceof LinkedHashMap<?, ?>){
908                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
909                                                 if(counter>0){
910                                                         userValue = userValue + ",";
911                                                 }
912                                                 userValue = userValue + key ;
913                                                 counter ++;
914                                         }
915                                 }
916                         }
917                         groupServiceList.setServiceList(userValue);
918                         if(groupServiceList.getId() == 0){
919                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
920                                 if(!duplicateData.isEmpty()){
921                                         duplicateflag = true;
922                                 }else{
923                                         commonClassDao.save(groupServiceList);
924                                 }
925                         }else{
926                                 if(!isFakeUpdate) {
927                                         commonClassDao.update(groupServiceList); 
928                                 }
929                         } 
930                         String responseString = "";
931                         if(duplicateflag){
932                                 responseString = "Duplicate";
933                         }else{
934                                 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
935                         }
936
937                         if (fromAPI) {
938                                 if (responseString!=null && !responseString.equals("Duplicate")) {
939                                         if(isFakeUpdate){
940                                                 responseString = "Exists";
941                                         } else {
942                                                 responseString = "Success";
943                                         }
944                                 }
945                                 ModelAndView result = new ModelAndView();
946                                 result.setViewName(responseString);
947                                 return result;
948                         } else {
949                                 response.setCharacterEncoding("UTF-8");
950                                 response.setContentType("application / json");
951                                 request.setCharacterEncoding("UTF-8");
952
953                                 PrintWriter out = response.getWriter();
954                                 JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}");
955                                 out.write(j.toString());
956                                 return null;
957                         }
958                 }catch (Exception e){
959                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
960                         response.setCharacterEncoding("UTF-8");
961                         request.setCharacterEncoding("UTF-8");
962                         PrintWriter out = response.getWriter();
963                         out.write(e.getMessage());
964                 }
965                 return null;
966         }
967
968         @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
969         public ModelAndView removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
970                 try{
971                         ObjectMapper mapper = new ObjectMapper();
972                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
973                         JsonNode root = mapper.readTree(request.getReader());
974                         GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("data").toString(), GroupServiceList.class);
975                         commonClassDao.delete(groupServiceList);
976                         response.setCharacterEncoding("UTF-8");
977                         response.setContentType("application / json");
978                         request.setCharacterEncoding("UTF-8");
979
980                         PrintWriter out = response.getWriter();
981
982                         String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
983                         JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}");
984                         out.write(j.toString());
985
986                         return null;
987                 }
988                 catch (Exception e){
989                         System.out.println(e);
990                         response.setCharacterEncoding("UTF-8");
991                         request.setCharacterEncoding("UTF-8");
992                         PrintWriter out = response.getWriter();
993                         out.write(e.getMessage());
994                 }
995                 return null;
996         }
997
998         @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
999         public void getSecurityZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1000                 try{
1001                         Map<String, Object> model = new HashMap<>();
1002                         ObjectMapper mapper = new ObjectMapper();
1003                         model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(SecurityZone.class, "zoneName")));
1004                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1005                         JSONObject j = new JSONObject(msg);
1006                         response.getWriter().write(j.toString());
1007                 }
1008                 catch (Exception e){
1009                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1010                 }
1011         }
1012
1013         @RequestMapping(value={"/get_SecurityZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1014         public void getSecurityZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1015                 try{
1016                         Map<String, Object> model = new HashMap<>();
1017                         ObjectMapper mapper = new ObjectMapper();
1018                         model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)));
1019                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1020                         JSONObject j = new JSONObject(msg);
1021                         response.addHeader("successMapKey", "success"); 
1022                         response.addHeader("operation", "getDictionary");
1023                         response.getWriter().write(j.toString());
1024                 }
1025                 catch (Exception e){
1026                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1027                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
1028                         response.addHeader("error", "dictionaryDBQuery");
1029                 }
1030         }
1031
1032         @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1033         public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1034                 try {
1035                         boolean duplicateflag = false;
1036                         boolean isFakeUpdate = false;
1037                         boolean fromAPI = false;
1038                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1039                                 fromAPI = true;
1040                         }
1041                         ObjectMapper mapper = new ObjectMapper();
1042                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1043                         JsonNode root = mapper.readTree(request.getReader());
1044                         SecurityZone securityZone;
1045                         if (fromAPI) {
1046                                 securityZone = (SecurityZone)mapper.readValue(root.get("dictionaryFields").toString(), SecurityZone.class);
1047
1048                                 //check if update operation or create, get id for data to be updated and update attributeData
1049                                 if (request.getParameter("operation").equals("update")) {
1050                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class);
1051                                         int id = 0;
1052                                         SecurityZone data = (SecurityZone) duplicateData.get(0);
1053                                         id = data.getId();
1054                                         if(id==0){
1055                                                 isFakeUpdate=true;
1056                                                 securityZone.setId(1);
1057                                         } else {
1058                                                 securityZone.setId(id);
1059                                         }               
1060                                 }
1061                         } else {
1062                                 securityZone = (SecurityZone)mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class);
1063                         }
1064                         if(securityZone.getId() == 0){
1065                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class);
1066                                 if(!duplicateData.isEmpty()){
1067                                         duplicateflag = true;
1068                                 }else{
1069                                         commonClassDao.save(securityZone);
1070                                 }                       
1071                         }else{
1072                                 if(!isFakeUpdate) {
1073                                         commonClassDao.update(securityZone); 
1074                                 }
1075                         } 
1076                         String responseString = "";
1077                         if(duplicateflag){
1078                                 responseString = "Duplicate";
1079                         }else{
1080                                 responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
1081                         }
1082
1083                         if (fromAPI) {
1084                                 if (responseString!=null && !responseString.equals("Duplicate")) {
1085                                         if(isFakeUpdate){
1086                                                 responseString = "Exists";
1087                                         } else {
1088                                                 responseString = "Success";
1089                                         }   
1090                                 }
1091                                 ModelAndView result = new ModelAndView();
1092                                 result.setViewName(responseString);
1093                                 return result;
1094                         } else {
1095                                 response.setCharacterEncoding("UTF-8");
1096                                 response.setContentType("application / json");
1097                                 request.setCharacterEncoding("UTF-8");
1098
1099                                 PrintWriter out = response.getWriter();
1100                                 JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}");
1101                                 out.write(j.toString());
1102                                 return null;
1103                         }
1104
1105                 }catch (Exception e){
1106                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1107                         response.setCharacterEncoding("UTF-8");
1108                         request.setCharacterEncoding("UTF-8");
1109                         PrintWriter out = response.getWriter();
1110                         out.write(e.getMessage());
1111                 }
1112                 return null;
1113         }
1114
1115         @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1116         public ModelAndView removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
1117                 try{
1118                         ObjectMapper mapper = new ObjectMapper();
1119                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1120                         JsonNode root = mapper.readTree(request.getReader());
1121                         SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("data").toString(), SecurityZone.class);
1122                         commonClassDao.delete(securityZone);
1123                         response.setCharacterEncoding("UTF-8");
1124                         response.setContentType("application / json");
1125                         request.setCharacterEncoding("UTF-8");
1126
1127                         PrintWriter out = response.getWriter();
1128
1129                         String responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
1130                         JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}");
1131                         out.write(j.toString());
1132
1133                         return null;
1134                 }
1135                 catch (Exception e){
1136                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1137                         response.setCharacterEncoding("UTF-8");
1138                         request.setCharacterEncoding("UTF-8");
1139                         PrintWriter out = response.getWriter();
1140                         out.write(e.getMessage());
1141                 }
1142                 return null;
1143         }
1144
1145
1146         @RequestMapping(value={"/get_ServiceListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1147         public void getServiceListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1148                 try{
1149                         Map<String, Object> model = new HashMap<>();
1150                         ObjectMapper mapper = new ObjectMapper();
1151                         model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)));
1152                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1153                         JSONObject j = new JSONObject(msg);
1154                         response.addHeader("successMapKey", "success"); 
1155                         response.addHeader("operation", "getDictionary");
1156                         response.getWriter().write(j.toString());
1157                 }
1158                 catch (Exception e){
1159                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1160                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
1161                         response.addHeader("error", "dictionaryDBQuery");
1162                 }
1163         }
1164
1165         @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1166         public void getServiceListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1167                 try{
1168                         Map<String, Object> model = new HashMap<>();
1169                         ObjectMapper mapper = new ObjectMapper();
1170                         model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ServiceList.class, "serviceName")));
1171                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1172                         JSONObject j = new JSONObject(msg);
1173                         response.getWriter().write(j.toString());
1174                 }
1175                 catch (Exception e){
1176                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1177                 }
1178         }
1179
1180         @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1181         public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1182                 try {
1183                         boolean duplicateflag = false;
1184                         boolean isFakeUpdate = false;
1185                         boolean fromAPI = false;
1186                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1187                                 fromAPI = true;
1188                         }
1189                         ObjectMapper mapper = new ObjectMapper();
1190                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1191                         JsonNode root = mapper.readTree(request.getReader());
1192                         ServiceList serviceList;
1193                         GridData serviceListGridData;
1194                         if (fromAPI) {
1195                                 serviceList = (ServiceList)mapper.readValue(root.get("dictionaryFields").toString(), ServiceList.class);
1196                                 serviceListGridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
1197
1198                                 //check if update operation or create, get id for data to be updated and update attributeData
1199                                 if (request.getParameter("operation").equals("update")) {
1200                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class);
1201                                         int id = 0;
1202                                         ServiceList data = (ServiceList) duplicateData.get(0);
1203                                         id = data.getId();
1204                                         if(id==0){
1205                                                 isFakeUpdate=true;
1206                                                 serviceList.setId(1);
1207                                         } else {
1208                                                 serviceList.setId(id);
1209                                         }
1210                                 }
1211                         }else{
1212                                 serviceList = (ServiceList)mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class);
1213                                 serviceListGridData = (GridData)mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class);
1214                         }
1215                         String tcpValue = "";
1216                         int counter = 0;
1217                         if(serviceListGridData.getTransportProtocols().size() > 0){
1218                                 for(Object attribute : serviceListGridData.getTransportProtocols()){
1219                                         if(attribute instanceof LinkedHashMap<?, ?>){
1220                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1221                                                 if(counter>0){
1222                                                         tcpValue = tcpValue + ",";
1223                                                 }
1224                                                 tcpValue = tcpValue + key ;
1225                                                 counter ++;
1226                                         }
1227                                 }
1228                         }
1229                         serviceList.setServiceTransProtocol(tcpValue);
1230                         String appValue = "";
1231                         int counter1 = 0;
1232                         if(serviceListGridData.getAppProtocols().size() > 0){
1233                                 for(Object attribute : serviceListGridData.getAppProtocols()){
1234                                         if(attribute instanceof LinkedHashMap<?, ?>){
1235                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1236                                                 if(counter1>0){
1237                                                         appValue = appValue + ",";
1238                                                 }
1239                                                 appValue = appValue + key ;
1240                                                 counter1 ++;
1241                                         }
1242                                 }
1243                         }
1244                         serviceList.setServiceAppProtocol(appValue);
1245                         serviceList.setServiceType("SERVICE");
1246                         if(serviceList.getId() == 0){
1247                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class);
1248                                 if(!duplicateData.isEmpty()){
1249                                         duplicateflag = true;
1250                                 }else{
1251                                         commonClassDao.save(serviceList);
1252                                 }
1253                         }else{
1254                                 if(!isFakeUpdate) {
1255                                         commonClassDao.update(serviceList); 
1256                                 }
1257                         } 
1258
1259                         String responseString = "";
1260                         if(duplicateflag){
1261                                 responseString = "Duplicate";
1262                         }else{
1263                                 responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
1264                         } 
1265                         if (fromAPI) {
1266                                 if (responseString!=null && !responseString.equals("Duplicate")) {
1267                                         if(isFakeUpdate){
1268                                                 responseString = "Exists";
1269                                         } else {
1270                                                 responseString = "Success";
1271                                         }
1272                                 }
1273                                 ModelAndView result = new ModelAndView();
1274                                 result.setViewName(responseString);
1275                                 return result;
1276                         } else {
1277                                 response.setCharacterEncoding("UTF-8");
1278                                 response.setContentType("application / json");
1279                                 request.setCharacterEncoding("UTF-8");
1280
1281                                 PrintWriter out = response.getWriter();
1282                                 JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}");
1283                                 out.write(j.toString());
1284                                 return null;
1285                         }
1286                 }catch (Exception e){
1287                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1288                         response.setCharacterEncoding("UTF-8");
1289                         request.setCharacterEncoding("UTF-8");
1290                         PrintWriter out = response.getWriter();
1291                         out.write(e.getMessage());
1292                 }
1293
1294                 return null;
1295         }
1296
1297         @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1298         public ModelAndView removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
1299                 try{
1300                         ObjectMapper mapper = new ObjectMapper();
1301                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1302                         JsonNode root = mapper.readTree(request.getReader());
1303                         ServiceList serviceList = (ServiceList)mapper.readValue(root.get("data").toString(), ServiceList.class);
1304                         commonClassDao.delete(serviceList);
1305                         response.setCharacterEncoding("UTF-8");
1306                         response.setContentType("application / json");
1307                         request.setCharacterEncoding("UTF-8");
1308
1309                         PrintWriter out = response.getWriter();
1310
1311                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
1312                         JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}");
1313                         out.write(j.toString());
1314
1315                         return null;
1316                 }
1317                 catch (Exception e){
1318                         System.out.println(e);
1319                         response.setCharacterEncoding("UTF-8");
1320                         request.setCharacterEncoding("UTF-8");
1321                         PrintWriter out = response.getWriter();
1322                         out.write(e.getMessage());
1323                 }
1324                 return null;
1325         }
1326
1327         @RequestMapping(value={"/get_ZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1328         public void getZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1329                 try{
1330                         Map<String, Object> model = new HashMap<>();
1331                         ObjectMapper mapper = new ObjectMapper();
1332                         model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Zone.class)));
1333                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1334                         JSONObject j = new JSONObject(msg);
1335                         response.addHeader("successMapKey", "success"); 
1336                         response.addHeader("operation", "getDictionary");
1337                         response.getWriter().write(j.toString());
1338                 }
1339                 catch (Exception e){
1340                         LOGGER.error("Exception Occured"+e);
1341                 }
1342         }
1343
1344         @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1345         public void getZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1346                 try{
1347                         Map<String, Object> model = new HashMap<>();
1348                         ObjectMapper mapper = new ObjectMapper();
1349                         model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Zone.class, "zoneName")));
1350                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1351                         JSONObject j = new JSONObject(msg);
1352                         response.getWriter().write(j.toString());
1353                 }
1354                 catch (Exception e){
1355                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1356                 }
1357         }
1358
1359         @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1360         public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1361                 try {
1362                         boolean duplicateflag = false;
1363                         boolean isFakeUpdate = false;
1364                         boolean fromAPI = false;
1365                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1366                                 fromAPI = true;
1367                         }
1368                         ObjectMapper mapper = new ObjectMapper();
1369                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1370                         JsonNode root = mapper.readTree(request.getReader());
1371                         Zone zone;
1372                         if (fromAPI) {
1373                                 zone = (Zone)mapper.readValue(root.get("dictionaryFields").toString(), Zone.class);
1374
1375                                 //check if update operation or create, get id for data to be updated and update attributeData
1376                                 if (request.getParameter("operation").equals("update")) {
1377                                         List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class);
1378                                         int id = 0;
1379                                         Zone data = (Zone) duplicateData.get(0);
1380                                         id = data.getId();
1381                                         if(id==0){
1382                                                 isFakeUpdate=true;
1383                                                 zone.setId(1);
1384                                         } else {
1385                                                 zone.setId(id);
1386                                         }
1387                                 }
1388                         } else {
1389                                 zone = (Zone)mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class);
1390                         }
1391                         if(zone.getId() == 0){
1392                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class);
1393                                 if(!duplicateData.isEmpty()){
1394                                         duplicateflag = true;
1395                                 }else{
1396                                         commonClassDao.save(zone);
1397                                 }       
1398                         }else{
1399                                 if(!isFakeUpdate) {
1400                                         commonClassDao.update(zone); 
1401                                 }
1402                         } 
1403                         String responseString = "";
1404                         if(duplicateflag){
1405                                 responseString = "Duplicate";
1406                         }else{
1407                                 responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
1408                         }
1409
1410                         if (fromAPI) {
1411                                 if (responseString!=null && !responseString.equals("Duplicate")) {
1412                                         if(isFakeUpdate){
1413                                                 responseString = "Exists";
1414                                         } else {
1415                                                 responseString = "Success";
1416                                         }
1417                                 }
1418                                 ModelAndView result = new ModelAndView();
1419                                 result.setViewName(responseString);
1420                                 return result;
1421                         } else {
1422                                 response.setCharacterEncoding("UTF-8");
1423                                 response.setContentType("application / json");
1424                                 request.setCharacterEncoding("UTF-8");
1425
1426                                 PrintWriter out = response.getWriter();
1427                                 JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}");
1428                                 out.write(j.toString());
1429                                 return null;
1430                         }
1431                 }catch (Exception e){
1432                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1433                         response.setCharacterEncoding("UTF-8");
1434                         request.setCharacterEncoding("UTF-8");
1435                         PrintWriter out = response.getWriter();
1436                         out.write(e.getMessage());
1437                 }
1438                 return null;
1439         }
1440
1441         @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1442         public ModelAndView removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1443                 try{
1444                         ObjectMapper mapper = new ObjectMapper();
1445                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1446                         JsonNode root = mapper.readTree(request.getReader());
1447                         Zone zone = (Zone)mapper.readValue(root.get("data").toString(), Zone.class);
1448                         commonClassDao.delete(zone);
1449                         response.setCharacterEncoding("UTF-8");
1450                         response.setContentType("application / json");
1451                         request.setCharacterEncoding("UTF-8");
1452
1453                         PrintWriter out = response.getWriter();
1454
1455                         String responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
1456                         JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}");
1457                         out.write(j.toString());
1458
1459                         return null;
1460                 }
1461                 catch (Exception e){
1462                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1463                         response.setCharacterEncoding("UTF-8");
1464                         request.setCharacterEncoding("UTF-8");
1465                         PrintWriter out = response.getWriter();
1466                         out.write(e.getMessage());
1467                 }
1468                 return null;
1469         }
1470
1471         @RequestMapping(value={"/get_TermListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1472         public void getTermListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1473                 try{
1474                         Map<String, Object> model = new HashMap<String, Object>();
1475                         ObjectMapper mapper = new ObjectMapper();
1476                         model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(TermList.class, "termName")));
1477                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1478                         JSONObject j = new JSONObject(msg);
1479                         response.getWriter().write(j.toString());
1480                 }
1481                 catch (Exception e){
1482                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1483                 }
1484         }
1485
1486         @RequestMapping(value={"/get_TermListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1487         public void getTermListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1488                 try{
1489                         Map<String, Object> model = new HashMap<String, Object>();
1490                         ObjectMapper mapper = new ObjectMapper();
1491                         model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(TermList.class)));
1492                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1493                         JSONObject j = new JSONObject(msg);
1494                         response.addHeader("successMapKey", "success"); 
1495                         response.addHeader("operation", "getDictionary");
1496                         response.getWriter().write(j.toString());
1497                 }
1498                 catch (Exception e){
1499                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1500                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
1501                         response.addHeader("error", "dictionaryDBQuery");
1502                 }
1503         }
1504
1505         @RequestMapping(value={"/fw_dictionary/save_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1506         public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1507                 try {
1508                         boolean duplicateflag = false;
1509                         boolean isFakeUpdate = false;
1510                         boolean fromAPI = false;
1511                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1512                                 fromAPI = true;
1513                         }
1514                         ObjectMapper mapper = new ObjectMapper();
1515                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1516                         JsonNode root = mapper.readTree(request.getReader());
1517                         TermList termList;
1518                         TermListData termListDatas;
1519                         String userId = null;
1520                         if (fromAPI) {
1521                                 termList = (TermList)mapper.readValue(root.get("dictionaryFields").toString(), TermList.class);
1522                                 termListDatas = (TermListData)mapper.readValue(root.get("dictionaryFields").toString(), TermListData.class);
1523                                 userId = "API";
1524
1525                                 //check if update operation or create, get id for data to be updated and update attributeData
1526                                 if (request.getParameter("operation").equals("update")) {
1527                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class);
1528                                         int id = 0;
1529                                         TermList data = (TermList) duplicateData.get(0);
1530                                         id = data.getId();
1531                                         if(id==0){
1532                                                 isFakeUpdate=true;
1533                                                 termList.setId(1);
1534                                         } else {
1535                                                 termList.setId(id);
1536                                         }                 
1537                                         termList.setUserCreatedBy(this.getUserInfo(userId));
1538                                 }
1539                         } else {
1540                                 termList = (TermList)mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class);
1541                                 termListDatas = (TermListData)mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class);
1542                                 userId = root.get("userid").textValue();
1543                         }
1544                         String fromZoneValue = "";
1545                         int counter = 0;
1546                         if(termListDatas.getFromZoneDatas().size() > 0){
1547                                 for(Object fromZone : termListDatas.getFromZoneDatas()){
1548                                         if(fromZone instanceof LinkedHashMap<?, ?>){
1549                                                 String key = ((LinkedHashMap<?, ?>) fromZone).get("option").toString();
1550                                                 if(counter>0){
1551                                                         fromZoneValue = fromZoneValue + ",";
1552                                                 }
1553                                                 fromZoneValue = fromZoneValue + key ;
1554                                                 counter ++;
1555                                         }
1556                                 }
1557                         }
1558                         termList.setFromZones(fromZoneValue);
1559
1560                         String toZoneValue = "";
1561                         int toZonecounter = 0;
1562                         if(termListDatas.getToZoneDatas().size() > 0){
1563                                 for(Object toZone : termListDatas.getToZoneDatas()){
1564                                         if(toZone instanceof LinkedHashMap<?, ?>){
1565                                                 String key = ((LinkedHashMap<?, ?>) toZone).get("option").toString();
1566                                                 if(toZonecounter>0){
1567                                                         toZoneValue = toZoneValue + ",";
1568                                                 }
1569                                                 toZoneValue = toZoneValue + key ;
1570                                                 toZonecounter ++;
1571                                         }
1572                                 }
1573                         }
1574                         termList.setToZones(toZoneValue);
1575
1576                         String srcListValues = "";
1577                         int srcListcounter = 0;
1578                         if(termListDatas.getSourceListDatas().size() > 0){
1579                                 for(Object srcList : termListDatas.getSourceListDatas()){
1580                                         if(srcList instanceof LinkedHashMap<?, ?>){
1581                                                 String key = ((LinkedHashMap<?, ?>) srcList).get("option").toString();
1582                                                 if(srcListcounter>0){
1583                                                         srcListValues = srcListValues + ",";
1584                                                 }
1585                                                 srcListValues = srcListValues + key ;
1586                                                 srcListcounter ++;
1587                                         }
1588                                 }
1589                         }
1590                         termList.setSrcIPList(srcListValues);
1591
1592                         String desListValues = "";
1593                         int destListcounter = 0;
1594                         if(termListDatas.getDestinationListDatas().size() > 0){
1595                                 for(Object desList : termListDatas.getDestinationListDatas()){
1596                                         if(desList instanceof LinkedHashMap<?, ?>){
1597                                                 String key = ((LinkedHashMap<?, ?>) desList).get("option").toString();
1598                                                 if(destListcounter>0){
1599                                                         desListValues = desListValues + ",";
1600                                                 }
1601                                                 desListValues = desListValues + key ;
1602                                                 destListcounter ++;
1603                                         }
1604                                 }
1605                         }
1606                         termList.setDestIPList(desListValues);
1607
1608                         String srcSerValue = "";
1609                         int srcSercounter = 0;
1610                         if(termListDatas.getSourceServiceDatas().size() > 0){
1611                                 for(Object srcSrc : termListDatas.getSourceServiceDatas()){
1612                                         if(srcSrc instanceof LinkedHashMap<?, ?>){
1613                                                 String key = ((LinkedHashMap<?, ?>) srcSrc).get("option").toString();
1614                                                 if(srcSercounter>0){
1615                                                         srcSerValue = srcSerValue + ",";
1616                                                 }
1617                                                 srcSerValue = srcSerValue + key ;
1618                                                 srcSercounter ++;
1619                                         }
1620                                 }
1621                         }
1622                         termList.setSrcPortList(srcSerValue);
1623
1624                         String desSrcValue = "";
1625                         int desSrccounter = 0;
1626                         if(termListDatas.getDestinationServiceDatas().size() > 0){
1627                                 for(Object desSrc : termListDatas.getDestinationServiceDatas()){
1628                                         if(desSrc instanceof LinkedHashMap<?, ?>){
1629                                                 String key = ((LinkedHashMap<?, ?>) desSrc).get("option").toString();
1630                                                 if(desSrccounter>0){
1631                                                         desSrcValue = desSrcValue + ",";
1632                                                 }
1633                                                 desSrcValue = desSrcValue + key ;
1634                                                 desSrccounter ++;
1635                                         }
1636                                 }
1637                         }
1638                         termList.setDestPortList(desSrcValue);
1639
1640                         String actionValue = "";
1641                         int actioncounter = 0;
1642                         if(termListDatas.getActionListDatas().size() > 0){
1643                                 for(Object actionList : termListDatas.getActionListDatas()){
1644                                         if(actionList instanceof LinkedHashMap<?, ?>){
1645                                                 String key = ((LinkedHashMap<?, ?>) actionList).get("option").toString();
1646                                                 if(actioncounter>0){
1647                                                         actionValue = actionValue + ",";
1648                                                 }
1649                                                 actionValue = actionValue + key ;
1650                                                 actioncounter ++;
1651                                         }
1652                                 }
1653                         }
1654                         termList.setAction(actionValue);
1655
1656                         if(termList.getId() == 0){
1657                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class);
1658                                 if(!duplicateData.isEmpty()){
1659                                         duplicateflag = true;
1660                                 }else{
1661                                         termList.setUserCreatedBy(this.getUserInfo(userId));
1662                                         termList.setUserModifiedBy(this.getUserInfo(userId));
1663                                         commonClassDao.save(termList);
1664                                 }
1665                         }else{
1666                                 if(!isFakeUpdate) {
1667                                         termList.setUserModifiedBy(this.getUserInfo(userId));
1668                                         commonClassDao.update(termList); 
1669                                 }
1670                         } 
1671                         String responseString = "";
1672                         if(duplicateflag){
1673                                 responseString = "Duplicate";
1674                         }else{
1675                                 responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
1676                         }
1677
1678                         if (fromAPI) {
1679                                 if (responseString!=null && !responseString.equals("Duplicate")) {
1680                                         if(isFakeUpdate){
1681                                                 responseString = "Exists";
1682                                         } else {
1683                                                 responseString = "Success";
1684                                         }
1685                                 }
1686                                 ModelAndView result = new ModelAndView();
1687                                 result.setViewName(responseString);
1688                                 return result;
1689                         } else {
1690                                 response.setCharacterEncoding("UTF-8");
1691                                 response.setContentType("application / json");
1692                                 request.setCharacterEncoding("UTF-8");
1693
1694                                 PrintWriter out = response.getWriter();
1695                                 JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}");
1696                                 out.write(j.toString());
1697                                 return null;
1698                         }
1699                 }catch (Exception e){
1700                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1701                         response.setCharacterEncoding("UTF-8");
1702                         request.setCharacterEncoding("UTF-8");
1703                         PrintWriter out = response.getWriter();
1704                         out.write(e.getMessage());
1705                 }
1706                 return null;
1707         }
1708
1709         @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1710         public ModelAndView removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1711                 try{
1712                         ObjectMapper mapper = new ObjectMapper();
1713                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1714                         JsonNode root = mapper.readTree(request.getReader());
1715                         TermList termList = (TermList)mapper.readValue(root.get("data").toString(), TermList.class);
1716                         commonClassDao.delete(termList);
1717                         response.setCharacterEncoding("UTF-8");
1718                         response.setContentType("application / json");
1719                         request.setCharacterEncoding("UTF-8");
1720
1721                         PrintWriter out = response.getWriter();
1722
1723                         String responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
1724                         JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}");
1725                         out.write(j.toString());
1726
1727                         return null;
1728                 }
1729                 catch (Exception e){
1730                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1731                         response.setCharacterEncoding("UTF-8");
1732                         request.setCharacterEncoding("UTF-8");
1733                         PrintWriter out = response.getWriter();
1734                         out.write(e.getMessage());
1735                 }
1736                 return null;
1737         }
1738         //ParentList Dictionary Data
1739         @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1740         public void getFWDictListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1741                 try{
1742                         Map<String, Object> model = new HashMap<>();
1743                         ObjectMapper mapper = new ObjectMapper();
1744                         model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FirewallDictionaryList.class, "parentItemName")));
1745                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1746                         JSONObject j = new JSONObject(msg);
1747                         response.getWriter().write(j.toString());
1748                 }
1749                 catch (Exception e){
1750                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1751                 }
1752         }
1753
1754         @RequestMapping(value={"/get_FWDictionaryListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1755         public void getFWDictionaryListEntityData(HttpServletRequest request, HttpServletResponse response){
1756                 try{
1757                         Map<String, Object> model = new HashMap<>();
1758                         ObjectMapper mapper = new ObjectMapper();
1759                         model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)));
1760                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1761                         JSONObject j = new JSONObject(msg);
1762                         response.addHeader("successMapKey", "success"); 
1763                         response.addHeader("operation", "getDictionary");
1764                         response.getWriter().write(j.toString());
1765                 }
1766                 catch (Exception e){
1767                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1768                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
1769                         response.addHeader("error", "dictionaryDBQuery");
1770                 }
1771         }
1772
1773         @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1774         public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1775                 try {
1776                         boolean duplicateflag = false;
1777                         ObjectMapper mapper = new ObjectMapper();
1778                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1779                         JsonNode root = mapper.readTree(request.getReader());
1780                         FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class);
1781                         GridData gridData = (GridData)mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class);
1782                         String userSLValue = "";
1783                         int slcounter = 0;
1784                         if(gridData.getAttributes().size() > 0){
1785                                 for(Object attribute : gridData.getAttributes()){
1786                                         if(attribute instanceof LinkedHashMap<?, ?>){
1787                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1788                                                 if(slcounter>0){
1789                                                         userSLValue = userSLValue + ",";
1790                                                 }
1791                                                 userSLValue = userSLValue + key ;
1792                                                 slcounter ++;
1793                                         }
1794                                 }
1795                         }
1796                         fwDictList.setServiceList(userSLValue);
1797                         String userALValue = "";
1798                         int alcounter = 0;
1799                         if(gridData.getAlAttributes().size() > 0){
1800                                 for(Object attribute : gridData.getAlAttributes()){
1801                                         if(attribute instanceof LinkedHashMap<?, ?>){
1802                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1803                                                 if(alcounter>0){
1804                                                         userALValue = userALValue + ",";
1805                                                 }
1806                                                 userALValue = userALValue + key ;
1807                                                 alcounter ++;
1808                                         }
1809                                 }
1810                         }
1811                         fwDictList.setAddressList(userALValue);
1812                         if(fwDictList.getId() == 0){
1813                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class);
1814                                 if(!duplicateData.isEmpty()){
1815                                         duplicateflag = true;
1816                                 }else{
1817                                         commonClassDao.save(fwDictList);
1818                                 }
1819                         }else{
1820                                 commonClassDao.update(fwDictList); 
1821                         } 
1822                         response.setCharacterEncoding("UTF-8");
1823                         response.setContentType("application / json");
1824                         request.setCharacterEncoding("UTF-8");
1825
1826                         PrintWriter out = response.getWriter();
1827                         String responseString = "";
1828                         if(duplicateflag){
1829                                 responseString = "Duplicate";
1830                         }else{
1831                                 responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1832                         }
1833                         JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}");
1834
1835                         out.write(j.toString());
1836
1837                         return null;
1838                 }
1839                 catch (Exception e){
1840                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1841                         response.setCharacterEncoding("UTF-8");
1842                         request.setCharacterEncoding("UTF-8");
1843                         PrintWriter out = response.getWriter();
1844                         out.write(e.getMessage());
1845                 }
1846                 return null;
1847         }
1848
1849         @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1850         public ModelAndView removeFWDictionaryListy(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
1851                 try{
1852                         ObjectMapper mapper = new ObjectMapper();
1853                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1854                         JsonNode root = mapper.readTree(request.getReader());
1855                         FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("data").toString(), FirewallDictionaryList.class);
1856                         commonClassDao.delete(fwDictList);
1857                         response.setCharacterEncoding("UTF-8");
1858                         response.setContentType("application / json");
1859                         request.setCharacterEncoding("UTF-8");
1860
1861                         PrintWriter out = response.getWriter();
1862
1863                         String responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1864                         JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}");
1865                         out.write(j.toString());
1866
1867                         return null;
1868                 }
1869                 catch (Exception e){
1870                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1871                         response.setCharacterEncoding("UTF-8");
1872                         request.setCharacterEncoding("UTF-8");
1873                         PrintWriter out = response.getWriter();
1874                         out.write(e.getMessage());
1875                 }
1876                 return null;
1877         }
1878
1879
1880         @RequestMapping(value={"/get_TagPickerNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1881         public void getTagPickerNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1882                 try{
1883                         Map<String, Object> model = new HashMap<String, Object>();
1884                         ObjectMapper mapper = new ObjectMapper();
1885                         model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTagPicker.class, "tagPickerName")));
1886                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1887                         JSONObject j = new JSONObject(msg);
1888                         response.getWriter().write(j.toString());
1889                 }
1890                 catch (Exception e){
1891                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1892                 }
1893         }
1894
1895         @RequestMapping(value={"/get_TagPickerListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1896         public void getTagPickerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1897                 try{
1898                         Map<String, Object> model = new HashMap<String, Object>();
1899                         ObjectMapper mapper = new ObjectMapper();
1900                         model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)));
1901                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1902                         JSONObject j = new JSONObject(msg);
1903                         response.getWriter().write(j.toString());
1904                 }
1905                 catch (Exception e){
1906                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1907                 }
1908         }
1909
1910         @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1911         public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1912                 try {
1913                         boolean duplicateflag = false;
1914                         boolean fromAPI = false;
1915                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1916                                 fromAPI = true;
1917                         }
1918
1919                         ObjectMapper mapper = new ObjectMapper();
1920                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1921                         JsonNode root = mapper.readTree(request.getReader());
1922
1923
1924                         FWTagPicker fwTagPicker;
1925                         TagGridValues data;
1926                         String userId = null;
1927                         if (fromAPI) {
1928                                 fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
1929                                 data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
1930                                 userId = "API";
1931
1932                                 //check if update operation or create, get id for data to be updated and update attributeData
1933                                 if (request.getParameter("operation").equals("update")) {
1934                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class);
1935                                         int id = 0;
1936                                         FWTagPicker dbdata = (FWTagPicker) duplicateData.get(0);
1937                                         id = dbdata.getId();
1938                                         fwTagPicker.setId(id);
1939                                         fwTagPicker.setUserCreatedBy(this.getUserInfo(userId));
1940                                 }
1941                         } else {
1942
1943                                 fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
1944                                 data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
1945                                 userId = root.get("userid").textValue();
1946                         }
1947
1948                         String header = "";
1949                         int counter = 0;
1950                         if(data.getTags().size() > 0){
1951                                 for(Object attribute : data.getTags()){
1952                                         if(attribute instanceof LinkedHashMap<?, ?>){
1953                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1954                                                 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
1955                                                 if(counter>0){
1956                                                         header = header + "#";
1957                                                 }
1958                                                 header = header + key + ":";
1959                                                 header = header + value;
1960                                                 counter ++;
1961                                         }
1962                                 }
1963                         }
1964                         fwTagPicker.setTagValues(header);
1965                         if(fwTagPicker.getId() == 0){
1966                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class);
1967                                 if(!duplicateData.isEmpty()){
1968                                         duplicateflag = true;
1969                                 }else{
1970                                         fwTagPicker.setUserCreatedBy(this.getUserInfo(userId));
1971                                         fwTagPicker.setUserModifiedBy(this.getUserInfo(userId));
1972                                         commonClassDao.save(fwTagPicker);
1973                                 }
1974                         }else{
1975                                 fwTagPicker.setUserModifiedBy(this.getUserInfo(userId));
1976                                 fwTagPicker.setModifiedDate(new Date());
1977                                 commonClassDao.update(fwTagPicker); 
1978                         } 
1979
1980                         String responseString = "";
1981                         if(duplicateflag){
1982                                 responseString = "Duplicate";
1983                         }else{
1984                                 responseString =  mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
1985                         }
1986
1987                         if (fromAPI) {
1988                                 if (responseString!=null && !responseString.equals("Duplicate")) {
1989                                         responseString = "Success";
1990                                 }
1991                                 ModelAndView result = new ModelAndView();
1992                                 result.setViewName(responseString);
1993                                 return result;
1994                         } else {
1995                                 response.setCharacterEncoding("UTF-8");
1996                                 response.setContentType("application / json");
1997                                 request.setCharacterEncoding("UTF-8");
1998
1999                                 PrintWriter out = response.getWriter();
2000                                 JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
2001                                 out.write(j.toString());
2002                                 return null;
2003                         }
2004                 }
2005                 catch (Exception e){
2006                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2007                         response.setCharacterEncoding("UTF-8");
2008                         request.setCharacterEncoding("UTF-8");
2009                         PrintWriter out = response.getWriter();
2010                         out.write(e.getMessage());
2011                 }
2012                 return null;
2013         }
2014
2015         @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2016         public ModelAndView removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
2017                 try{
2018                         ObjectMapper mapper = new ObjectMapper();
2019                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2020                         JsonNode root = mapper.readTree(request.getReader());
2021                         FWTagPicker fwTagPicker = (FWTagPicker)mapper.readValue(root.get("data").toString(), FWTagPicker.class);
2022                         commonClassDao.delete(fwTagPicker);
2023                         response.setCharacterEncoding("UTF-8");
2024                         response.setContentType("application / json");
2025                         request.setCharacterEncoding("UTF-8");
2026
2027                         PrintWriter out = response.getWriter();
2028                         String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
2029                         JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
2030                         out.write(j.toString());
2031                         return null;
2032                 }
2033                 catch (Exception e){
2034                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2035                         response.setCharacterEncoding("UTF-8");
2036                         request.setCharacterEncoding("UTF-8");
2037                         PrintWriter out = response.getWriter();
2038                         out.write(e.getMessage());
2039                 }
2040                 return null;
2041         }
2042
2043
2044         @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
2045         public void getTagNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){
2046                 try{
2047                         Map<String, Object> model = new HashMap<>();
2048                         ObjectMapper mapper = new ObjectMapper();
2049                         model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName")));
2050                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
2051                         JSONObject j = new JSONObject(msg);
2052                         response.getWriter().write(j.toString());
2053                 }
2054                 catch (Exception e){
2055                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2056                 }
2057         }
2058
2059         @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
2060         public void getTagDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
2061                 try{
2062                         Map<String, Object> model = new HashMap<>();
2063                         ObjectMapper mapper = new ObjectMapper();
2064                         model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTag.class)));
2065                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
2066                         JSONObject j = new JSONObject(msg);
2067                         response.getWriter().write(j.toString());
2068                 }
2069                 catch (Exception e){
2070                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2071                 }
2072         }
2073
2074         @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2075         public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
2076                 try {
2077                         boolean duplicateflag = false;
2078                         boolean fromAPI = false;
2079                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
2080                                 fromAPI = true;
2081                         }
2082
2083                         ObjectMapper mapper = new ObjectMapper();
2084                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2085                         JsonNode root = mapper.readTree(request.getReader());
2086
2087
2088                         FWTag fwTag;
2089                         TagGridValues tagGridValues;
2090                         String userId = null;
2091                         if (fromAPI) {
2092                                 fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), FWTag.class);
2093                                 tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), TagGridValues.class);
2094                                 userId = "API";
2095
2096                                 //check if update operation or create, get id for data to be updated and update attributeData
2097                                 if (request.getParameter("operation").equals("update")) {
2098                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "tagName", FWTag.class);
2099                                         int id = 0;
2100                                         FWTag data = (FWTag) duplicateData.get(0);
2101                                         id = data.getId();
2102                                         fwTag.setId(id);
2103                                         fwTag.setUserCreatedBy(this.getUserInfo(userId));
2104
2105                                 }
2106                         } else {
2107                                 fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
2108                                 tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class);
2109                                 userId = root.get("userid").textValue();
2110                         }
2111
2112                         String userValue = "";
2113                         int counter = 0;
2114                         if(tagGridValues.getTags().size() > 0){
2115                                 for(Object attribute : tagGridValues.getTags()){
2116                                         if(attribute instanceof LinkedHashMap<?, ?>){
2117                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("tags").toString();
2118                                                 if(counter>0){
2119                                                         userValue = userValue + ",";
2120                                                 }
2121                                                 userValue = userValue + key ;
2122                                                 counter ++;
2123                                         }
2124                                 }
2125                         }
2126                         fwTag.setTagValues(userValue);
2127                         if(fwTag.getId() == 0){
2128                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
2129                                 if(!duplicateData.isEmpty()){
2130                                         duplicateflag = true;
2131                                 }else{
2132                                         fwTag.setUserCreatedBy(this.getUserInfo(userId));
2133                                         fwTag.setUserModifiedBy(this.getUserInfo(userId));
2134                                         commonClassDao.save(fwTag);
2135                                 }   
2136                         }else{
2137                                 fwTag.setUserModifiedBy(this.getUserInfo(userId));
2138                                 fwTag.setModifiedDate(new Date());
2139                                 commonClassDao.update(fwTag); 
2140                         } 
2141
2142                         String responseString = "";
2143                         if(duplicateflag){
2144                                 responseString = "Duplicate";
2145                         }else{
2146                                 responseString =  mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
2147                         }
2148                         if (fromAPI) {
2149                                 if (responseString!=null && !responseString.equals("Duplicate")) {
2150                                         responseString = "Success";
2151                                 }
2152                                 ModelAndView result = new ModelAndView();
2153                                 result.setViewName(responseString);
2154                                 return result;
2155                         } else {
2156
2157                                 response.setCharacterEncoding("UTF-8");
2158                                 response.setContentType("application / json");
2159                                 request.setCharacterEncoding("UTF-8");
2160
2161                                 PrintWriter out = response.getWriter();
2162                                 JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
2163                                 out.write(j.toString());
2164                                 return null;
2165                         }
2166                 }
2167                 catch (Exception e){
2168                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2169                         response.setCharacterEncoding("UTF-8");
2170                         request.setCharacterEncoding("UTF-8");
2171                         PrintWriter out = response.getWriter();
2172                         out.write(e.getMessage());
2173                 }
2174                 return null;
2175         }
2176
2177         @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2178         public ModelAndView removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
2179                 try{
2180                         ObjectMapper mapper = new ObjectMapper();
2181                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2182                         JsonNode root = mapper.readTree(request.getReader());
2183                         FWTag fwTag = (FWTag)mapper.readValue(root.get("data").toString(), FWTag.class);
2184                         commonClassDao.delete(fwTag);
2185                         response.setCharacterEncoding("UTF-8");
2186                         response.setContentType("application / json");
2187                         request.setCharacterEncoding("UTF-8");
2188
2189                         PrintWriter out = response.getWriter();
2190
2191                         String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
2192                         JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
2193                         out.write(j.toString());
2194
2195                         return null;
2196                 }
2197                 catch (Exception e){
2198                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2199                         response.setCharacterEncoding("UTF-8");
2200                         request.setCharacterEncoding("UTF-8");
2201                         PrintWriter out = response.getWriter();
2202                         out.write(e.getMessage());
2203                 }
2204                 return null;
2205         }
2206 }
2207
2208 class TagGridValues{
2209         private ArrayList<Object> tags;
2210
2211         public ArrayList<Object> getTags() {
2212                 return tags;
2213         }
2214
2215         public void setTags(ArrayList<Object> tags) {
2216                 this.tags = tags;
2217         }
2218 }
2219
2220 class AGGridData{
2221         private ArrayList<Object> attributes;
2222
2223         public ArrayList<Object> getAttributes() {
2224                 return attributes;
2225         }
2226
2227         public void setAttributes(ArrayList<Object> attributes) {
2228                 this.attributes = attributes;
2229         }
2230 }
2231
2232 class TermListData{
2233         private ArrayList<Object> fromZoneDatas;
2234         private ArrayList<Object> toZoneDatas;
2235         private ArrayList<Object> sourceListDatas;
2236         private ArrayList<Object> destinationListDatas;
2237         private ArrayList<Object> sourceServiceDatas;
2238         private ArrayList<Object> destinationServiceDatas;
2239         private ArrayList<Object> actionListDatas;
2240         public ArrayList<Object> getFromZoneDatas() {
2241                 return fromZoneDatas;
2242         }
2243         public void setFromZoneDatas(ArrayList<Object> fromZoneDatas) {
2244                 this.fromZoneDatas = fromZoneDatas;
2245         }
2246         public ArrayList<Object> getToZoneDatas() {
2247                 return toZoneDatas;
2248         }
2249         public void setToZoneDatas(ArrayList<Object> toZoneDatas) {
2250                 this.toZoneDatas = toZoneDatas;
2251         }
2252         public ArrayList<Object> getSourceListDatas() {
2253                 return sourceListDatas;
2254         }
2255         public void setSourceListDatas(ArrayList<Object> sourceListDatas) {
2256                 this.sourceListDatas = sourceListDatas;
2257         }
2258         public ArrayList<Object> getDestinationListDatas() {
2259                 return destinationListDatas;
2260         }
2261         public void setDestinationListDatas(ArrayList<Object> destinationListDatas) {
2262                 this.destinationListDatas = destinationListDatas;
2263         }
2264         public ArrayList<Object> getSourceServiceDatas() {
2265                 return sourceServiceDatas;
2266         }
2267         public void setSourceServiceDatas(ArrayList<Object> sourceServiceDatas) {
2268                 this.sourceServiceDatas = sourceServiceDatas;
2269         }
2270         public ArrayList<Object> getDestinationServiceDatas() {
2271                 return destinationServiceDatas;
2272         }
2273         public void setDestinationServiceDatas(ArrayList<Object> destinationServiceDatas) {
2274                 this.destinationServiceDatas = destinationServiceDatas;
2275         }
2276         public ArrayList<Object> getActionListDatas() {
2277                 return actionListDatas;
2278         }
2279         public void setActionListDatas(ArrayList<Object> actionListDatas) {
2280                 this.actionListDatas = actionListDatas;
2281         }
2282 }