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