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