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