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