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