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