Only formatting changes for checkstyle fixes
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / FirewallDictionaryController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.controller;
22
23 import com.fasterxml.jackson.databind.DeserializationFeature;
24 import com.fasterxml.jackson.databind.JsonNode;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import java.io.IOException;
27 import java.io.PrintWriter;
28 import java.net.UnknownHostException;
29 import java.util.Date;
30 import java.util.List;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33 import org.jboss.netty.handler.ipfilter.CIDR;
34 import org.json.JSONObject;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.pap.xacml.rest.adapters.GridData;
38 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
39 import org.onap.policy.rest.dao.CommonClassDao;
40 import org.onap.policy.rest.jpa.ActionList;
41 import org.onap.policy.rest.jpa.AddressGroup;
42 import org.onap.policy.rest.jpa.FWTag;
43 import org.onap.policy.rest.jpa.FWTagPicker;
44 import org.onap.policy.rest.jpa.FirewallDictionaryList;
45 import org.onap.policy.rest.jpa.GroupServiceList;
46 import org.onap.policy.rest.jpa.PortList;
47 import org.onap.policy.rest.jpa.PrefixList;
48 import org.onap.policy.rest.jpa.ProtocolList;
49 import org.onap.policy.rest.jpa.SecurityZone;
50 import org.onap.policy.rest.jpa.ServiceList;
51 import org.onap.policy.rest.jpa.TermList;
52 import org.onap.policy.rest.jpa.UserInfo;
53 import org.onap.policy.rest.jpa.Zone;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.http.MediaType;
56 import org.springframework.stereotype.Controller;
57 import org.springframework.web.bind.annotation.RequestMapping;
58 import org.springframework.web.bind.annotation.RequestMethod;
59 import org.springframework.web.servlet.ModelAndView;
60
61
62 @Controller
63 public class FirewallDictionaryController {
64
65     private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class);
66
67     private static CommonClassDao commonClassDao;
68     private static String prefixListName = "prefixListName";
69     private static String successMessage = "success";
70     private static String operation = "operation";
71     private static String errorMsg = "error";
72     private static String dictionaryFields = "dictionaryFields";
73     private static String duplicateResponseString = "Duplicate";
74     private static String utf8 = "UTF-8";
75     private static String applicationJsonContentType = "application / json";
76     private static String protocolName = "protocolName";
77     private static String groupNameStart = "Group_";
78     private static String option = "option";
79     private static String zoneName = "zoneName";
80     private static String serviceName = "serviceName";
81     private static String termName = "termName";
82     private static String userid = "userid";
83     private static String tagPickerName = "tagPickerName";
84     private static String pfListDatas = "prefixListDictionaryDatas";
85     private static String portListDatas = "portListDictionaryDatas";
86     private static String protocolListDatas = "protocolListDictionaryDatas";
87     private static String addressGroupDatas = "addressGroupDictionaryDatas";
88     private static String actionListDatas = "actionListDictionaryDatas";
89     private static String serviceGroupDatas = "serviceGroupDictionaryDatas";
90     private static String securityZoneDatas = "securityZoneDictionaryDatas";
91     private static String serviceListDatas = "serviceListDictionaryDatas";
92     private static String zoneDatas = "zoneDictionaryDatas";
93     private static String termListDictDatas = "termListDictionaryDatas";
94     private static String fwDictListDatas = "fwDictListDictionaryDatas";
95     private static String fwTagPickerDatas = "fwTagPickerDictionaryDatas";
96     private static String fwTagDatas = "fwTagDictionaryDatas";
97
98
99     @Autowired
100     public FirewallDictionaryController(CommonClassDao commonClassDao) {
101         FirewallDictionaryController.commonClassDao = commonClassDao;
102     }
103
104     public static void setCommonClassDao(CommonClassDao clDao) {
105         commonClassDao = clDao;
106     }
107
108     public FirewallDictionaryController() {
109         super();
110     }
111
112     private DictionaryUtils getDictionaryUtilsInstance() {
113         return DictionaryUtils.getDictionaryUtils();
114     }
115
116     @RequestMapping(value = {"/get_PrefixListDataByName"}, method = {RequestMethod.GET},
117             produces = MediaType.APPLICATION_JSON_VALUE)
118     public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response) {
119         DictionaryUtils utils = getDictionaryUtilsInstance();
120         utils.getDataByEntity(response, pfListDatas, prefixListName, PrefixList.class);
121     }
122
123     @RequestMapping(value = {"/get_PrefixListData"}, method = {RequestMethod.GET},
124             produces = MediaType.APPLICATION_JSON_VALUE)
125     public void getPrefixListDictionaryEntityData(HttpServletResponse response) {
126         DictionaryUtils utils = getDictionaryUtilsInstance();
127         utils.getData(response, pfListDatas, PrefixList.class);
128     }
129
130     @RequestMapping(value = {"/fw_dictionary/save_prefixList"}, method = {RequestMethod.POST})
131     public ModelAndView savePrefixListDictionary(HttpServletRequest request,
132             HttpServletResponse response) throws IOException {
133         DictionaryUtils utils = getDictionaryUtilsInstance();
134         try {
135             boolean fromAPI = utils.isRequestFromAPI(request);
136             ObjectMapper mapper = new ObjectMapper();
137             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
138             JsonNode root = mapper.readTree(request.getReader());
139             PrefixList prefixList;
140             if (fromAPI) {
141                 prefixList =
142                         mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class);
143             } else {
144                 prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(),
145                         PrefixList.class);
146             }
147
148             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
149                     prefixList.getPrefixListName(), prefixListName, PrefixList.class);
150             boolean duplicateflag = false;
151             if (!duplicateData.isEmpty()) {
152                 PrefixList data = (PrefixList) duplicateData.get(0);
153                 if (request.getParameter(operation) != null
154                         && "update".equals(request.getParameter(operation))) {
155                     prefixList.setId(data.getId());
156                 } else if ((request.getParameter(operation) != null
157                         && !"update".equals(request.getParameter(operation)))
158                         || (request.getParameter(operation) == null
159                                 && (data.getId() != prefixList.getId()))) {
160                     duplicateflag = true;
161                 }
162             }
163             String responseString = null;
164             if (!duplicateflag) {
165                 if (prefixList.getId() == 0) {
166                     commonClassDao.save(prefixList);
167                 } else {
168                     commonClassDao.update(prefixList);
169                 }
170                 responseString =
171                         mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
172             } else {
173                 responseString = duplicateResponseString;
174             }
175             if (fromAPI) {
176                 return utils.getResultForApi(responseString);
177             } else {
178                 utils.setResponseData(response, pfListDatas, responseString);
179             }
180         } catch (Exception e) {
181             utils.setErrorResponseData(response, e);
182         }
183         return null;
184     }
185
186     @RequestMapping(value = {"/fw_dictionary/remove_PrefixList"}, method = {RequestMethod.POST})
187     public void removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response)
188             throws IOException {
189         DictionaryUtils utils = getDictionaryUtilsInstance();
190         utils.removeData(request, response, pfListDatas, PrefixList.class);
191     }
192
193     @RequestMapping(value = {"/fw_dictionary/validate_prefixList"}, method = {RequestMethod.POST})
194     public void validatePrefixListDictionary(HttpServletRequest request,
195             HttpServletResponse response) throws IOException {
196         DictionaryUtils utils = getDictionaryUtilsInstance();
197         try {
198             ObjectMapper mapper = new ObjectMapper();
199             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
200             JsonNode root = mapper.readTree(request.getReader());
201             PrefixList prefixList = mapper
202                     .readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
203             String responseValidation = successMessage;
204             try {
205                 CIDR.newCIDR(prefixList.getPrefixListValue());
206             } catch (UnknownHostException e) {
207                 LOGGER.error(e);
208                 responseValidation = errorMsg;
209             }
210             response.setCharacterEncoding(utf8);
211             response.setContentType(applicationJsonContentType);
212             request.setCharacterEncoding(utf8);
213
214             PrintWriter out = response.getWriter();
215             JSONObject j = new JSONObject("{result: " + responseValidation + "}");
216             out.write(j.toString());
217         } catch (Exception e) {
218             utils.setErrorResponseData(response, e);
219         }
220     }
221
222     @RequestMapping(value = {"/get_PortListData"}, method = {RequestMethod.GET},
223             produces = MediaType.APPLICATION_JSON_VALUE)
224     public void getPortListDictionaryEntityData(HttpServletResponse response) {
225         DictionaryUtils utils = getDictionaryUtilsInstance();
226         utils.getData(response, portListDatas, PortList.class);
227     }
228
229     @RequestMapping(value = {"/fw_dictionary/save_portName"}, method = {RequestMethod.POST})
230     public ModelAndView savePortListDictionary(HttpServletRequest request,
231             HttpServletResponse response) throws IOException {
232         DictionaryUtils utils = getDictionaryUtilsInstance();
233         try {
234             boolean fromAPI = utils.isRequestFromAPI(request);
235             ObjectMapper mapper = new ObjectMapper();
236             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
237             JsonNode root = mapper.readTree(request.getReader());
238             PortList portList;
239             if (fromAPI) {
240                 portList = mapper.readValue(root.get(dictionaryFields).toString(), PortList.class);
241             } else {
242                 portList = mapper.readValue(root.get("portListDictionaryData").toString(),
243                         PortList.class);
244             }
245             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(portList.getPortName(),
246                     "portName", PortList.class);
247             boolean duplicateflag = false;
248             if (!duplicateData.isEmpty()) {
249                 PortList data = (PortList) duplicateData.get(0);
250                 if (request.getParameter(operation) != null
251                         && "update".equals(request.getParameter(operation))) {
252                     portList.setId(data.getId());
253                 } else if ((request.getParameter(operation) != null
254                         && !"update".equals(request.getParameter(operation)))
255                         || (request.getParameter(operation) == null
256                                 && (data.getId() != portList.getId()))) {
257                     duplicateflag = true;
258                 }
259             }
260             String responseString = null;
261             if (!duplicateflag) {
262                 if (portList.getId() == 0) {
263                     commonClassDao.save(portList);
264                 } else {
265                     commonClassDao.update(portList);
266                 }
267                 responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
268             } else {
269                 responseString = duplicateResponseString;
270             }
271             if (fromAPI) {
272                 return utils.getResultForApi(responseString);
273             } else {
274                 utils.setResponseData(response, portListDatas, responseString);
275             }
276         } catch (Exception e) {
277             utils.setErrorResponseData(response, e);
278         }
279         return null;
280     }
281
282     @RequestMapping(value = {"/fw_dictionary/remove_PortList"}, method = {RequestMethod.POST})
283     public void removePortListDictionary(HttpServletRequest request, HttpServletResponse response)
284             throws IOException {
285         DictionaryUtils utils = getDictionaryUtilsInstance();
286         utils.removeData(request, response, portListDatas, PortList.class);
287     }
288
289     @RequestMapping(value = {"/get_ProtocolListData"}, method = {RequestMethod.GET},
290             produces = MediaType.APPLICATION_JSON_VALUE)
291     public void getProtocolListDictionaryEntityData(HttpServletResponse response) {
292         DictionaryUtils utils = getDictionaryUtilsInstance();
293         utils.getData(response, protocolListDatas, ProtocolList.class);
294     }
295
296     @RequestMapping(value = {"/get_ProtocolListDataByName"}, method = {RequestMethod.GET},
297             produces = MediaType.APPLICATION_JSON_VALUE)
298     public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response) {
299         DictionaryUtils utils = getDictionaryUtilsInstance();
300         utils.getDataByEntity(response, protocolListDatas, protocolName, ProtocolList.class);
301     }
302
303     @RequestMapping(value = {"/fw_dictionary/save_protocolList"}, method = {RequestMethod.POST})
304     public ModelAndView saveProtocolListDictionary(HttpServletRequest request,
305             HttpServletResponse response) throws IOException {
306         DictionaryUtils utils = getDictionaryUtilsInstance();
307         try {
308             boolean fromAPI = utils.isRequestFromAPI(request);
309             ObjectMapper mapper = new ObjectMapper();
310             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
311             JsonNode root = mapper.readTree(request.getReader());
312             ProtocolList protocolList;
313             if (fromAPI) {
314                 protocolList =
315                         mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class);
316             } else {
317                 protocolList = mapper.readValue(root.get("protocolListDictionaryData").toString(),
318                         ProtocolList.class);
319             }
320             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
321                     protocolList.getProtocolName(), protocolName, ProtocolList.class);
322             boolean duplicateflag = false;
323             if (!duplicateData.isEmpty()) {
324                 ProtocolList data = (ProtocolList) duplicateData.get(0);
325                 if (request.getParameter(operation) != null
326                         && "update".equals(request.getParameter(operation))) {
327                     protocolList.setId(data.getId());
328                 } else if ((request.getParameter(operation) != null
329                         && !"update".equals(request.getParameter(operation)))
330                         || (request.getParameter(operation) == null
331                                 && (data.getId() != protocolList.getId()))) {
332                     duplicateflag = true;
333                 }
334             }
335             String responseString = null;
336             if (!duplicateflag) {
337                 if (protocolList.getId() == 0) {
338                     commonClassDao.save(protocolList);
339                 } else {
340                     commonClassDao.update(protocolList);
341                 }
342                 responseString =
343                         mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
344             } else {
345                 responseString = duplicateResponseString;
346             }
347             if (fromAPI) {
348                 return utils.getResultForApi(responseString);
349             } else {
350                 utils.setResponseData(response, protocolListDatas, responseString);
351             }
352         } catch (Exception e) {
353             utils.setErrorResponseData(response, e);
354         }
355         return null;
356     }
357
358     @RequestMapping(value = {"/fw_dictionary/remove_protocol"}, method = {RequestMethod.POST})
359     public void removeProtocolListDictionary(HttpServletRequest request,
360             HttpServletResponse response) throws IOException {
361         DictionaryUtils utils = getDictionaryUtilsInstance();
362         utils.removeData(request, response, protocolListDatas, ProtocolList.class);
363     }
364
365     @RequestMapping(value = {"/get_AddressGroupDictionaryDataByName"}, method = {RequestMethod.GET},
366             produces = MediaType.APPLICATION_JSON_VALUE)
367     public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response) {
368         DictionaryUtils utils = getDictionaryUtilsInstance();
369         utils.getDataByEntity(response, addressGroupDatas, "name", AddressGroup.class);
370     }
371
372     @RequestMapping(value = {"/get_AddressGroupData"}, method = {RequestMethod.GET},
373             produces = MediaType.APPLICATION_JSON_VALUE)
374     public void getAddressGroupDictionaryEntityData(HttpServletResponse response) {
375         DictionaryUtils utils = getDictionaryUtilsInstance();
376         utils.getData(response, addressGroupDatas, AddressGroup.class);
377     }
378
379     @RequestMapping(value = {"/fw_dictionary/save_addressGroup"}, method = {RequestMethod.POST})
380     public ModelAndView saveAddressGroupDictionary(HttpServletRequest request,
381             HttpServletResponse response) throws IOException {
382         DictionaryUtils utils = getDictionaryUtilsInstance();
383         try {
384             boolean fromAPI = utils.isRequestFromAPI(request);
385             ObjectMapper mapper = new ObjectMapper();
386             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
387             JsonNode root = mapper.readTree(request.getReader());
388             AddressGroup addressGroup;
389             GridData gridData;
390             if (fromAPI) {
391                 addressGroup =
392                         mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class);
393                 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
394             } else {
395                 addressGroup = mapper.readValue(root.get("addressGroupDictionaryData").toString(),
396                         AddressGroup.class);
397                 gridData = mapper.readValue(root.get("addressGroupDictionaryData").toString(),
398                         GridData.class);
399             }
400             if (!addressGroup.getGroupName().startsWith(groupNameStart)) {
401                 String groupName = groupNameStart + addressGroup.getGroupName();
402                 addressGroup.setGroupName(groupName);
403             }
404             addressGroup.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
405             List<Object> duplicateData = commonClassDao
406                     .checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
407             boolean duplicateflag = false;
408             if (!duplicateData.isEmpty()) {
409                 AddressGroup data = (AddressGroup) duplicateData.get(0);
410                 if (request.getParameter(operation) != null
411                         && "update".equals(request.getParameter(operation))) {
412                     addressGroup.setId(data.getId());
413                 } else if ((request.getParameter(operation) != null
414                         && !"update".equals(request.getParameter(operation)))
415                         || (request.getParameter(operation) == null
416                                 && (data.getId() != addressGroup.getId()))) {
417                     duplicateflag = true;
418                 }
419             }
420             String responseString = null;
421             if (!duplicateflag) {
422                 if (addressGroup.getId() == 0) {
423                     commonClassDao.save(addressGroup);
424                 } else {
425                     commonClassDao.update(addressGroup);
426                 }
427                 responseString =
428                         mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
429             } else {
430                 responseString = duplicateResponseString;
431             }
432             if (fromAPI) {
433                 return utils.getResultForApi(responseString);
434             } else {
435                 utils.setResponseData(response, addressGroupDatas, responseString);
436             }
437         } catch (Exception e) {
438             utils.setErrorResponseData(response, e);
439         }
440         return null;
441     }
442
443     @RequestMapping(value = {"/fw_dictionary/remove_AddressGroup"}, method = {RequestMethod.POST})
444     public void removeAddressGroupDictionary(HttpServletRequest request,
445             HttpServletResponse response) throws IOException {
446         DictionaryUtils utils = getDictionaryUtilsInstance();
447         utils.removeData(request, response, addressGroupDatas, AddressGroup.class);
448     }
449
450     @RequestMapping(value = {"/get_ActionListDictionaryDataByName"}, method = {RequestMethod.GET},
451             produces = MediaType.APPLICATION_JSON_VALUE)
452     public void getActionListDictionaryEntityDataByName(HttpServletResponse response) {
453         DictionaryUtils utils = getDictionaryUtilsInstance();
454         utils.getDataByEntity(response, actionListDatas, "actionName", ActionList.class);
455     }
456
457     @RequestMapping(value = {"/get_ActionListData"}, method = {RequestMethod.GET},
458             produces = MediaType.APPLICATION_JSON_VALUE)
459     public void getActionListDictionaryEntityData(HttpServletResponse response) {
460         DictionaryUtils utils = getDictionaryUtilsInstance();
461         utils.getData(response, actionListDatas, ActionList.class);
462     }
463
464     @RequestMapping(value = {"/fw_dictionary/save_ActionList"}, method = {RequestMethod.POST})
465     public ModelAndView saveActionListDictionary(HttpServletRequest request,
466             HttpServletResponse response) throws IOException {
467         DictionaryUtils utils = getDictionaryUtilsInstance();
468         try {
469             boolean fromAPI = utils.isRequestFromAPI(request);
470             ObjectMapper mapper = new ObjectMapper();
471             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
472             JsonNode root = mapper.readTree(request.getReader());
473             ActionList actionList;
474             if (fromAPI) {
475                 actionList =
476                         mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class);
477             } else {
478                 actionList = mapper.readValue(root.get("actionListDictionaryData").toString(),
479                         ActionList.class);
480             }
481             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
482                     actionList.getActionName(), "actionName", ActionList.class);
483             boolean duplicateflag = false;
484             if (!duplicateData.isEmpty()) {
485                 ActionList data = (ActionList) duplicateData.get(0);
486                 if (request.getParameter(operation) != null
487                         && "update".equals(request.getParameter(operation))) {
488                     actionList.setId(data.getId());
489                 } else if ((request.getParameter(operation) != null
490                         && !"update".equals(request.getParameter(operation)))
491                         || (request.getParameter(operation) == null
492                                 && (data.getId() != actionList.getId()))) {
493                     duplicateflag = true;
494                 }
495             }
496             String responseString = null;
497             if (!duplicateflag) {
498                 if (actionList.getId() == 0) {
499                     commonClassDao.save(actionList);
500                 } else {
501                     commonClassDao.update(actionList);
502                 }
503                 responseString =
504                         mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
505             } else {
506                 responseString = duplicateResponseString;
507             }
508             if (fromAPI) {
509                 return utils.getResultForApi(responseString);
510             } else {
511                 utils.setResponseData(response, actionListDatas, responseString);
512             }
513         } catch (Exception e) {
514             utils.setErrorResponseData(response, e);
515         }
516         return null;
517     }
518
519     @RequestMapping(value = {"/fw_dictionary/remove_ActionList"}, method = {RequestMethod.POST})
520     public void removeActionListDictionary(HttpServletRequest request, HttpServletResponse response)
521             throws IOException {
522         DictionaryUtils utils = getDictionaryUtilsInstance();
523         utils.removeData(request, response, actionListDatas, ActionList.class);
524     }
525
526     @RequestMapping(value = {"/get_ServiceGroupData"}, method = {RequestMethod.GET},
527             produces = MediaType.APPLICATION_JSON_VALUE)
528     public void getServiceGroupDictionaryEntityData(HttpServletResponse response) {
529         DictionaryUtils utils = getDictionaryUtilsInstance();
530         utils.getData(response, serviceGroupDatas, GroupServiceList.class);
531     }
532
533     @RequestMapping(value = {"/get_ServiceGroupDictionaryDataByName"}, method = {RequestMethod.GET},
534             produces = MediaType.APPLICATION_JSON_VALUE)
535     public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response) {
536         DictionaryUtils utils = getDictionaryUtilsInstance();
537         utils.getDataByEntity(response, serviceGroupDatas, "name", GroupServiceList.class);
538     }
539
540     @RequestMapping(value = {"/fw_dictionary/save_serviceGroup"}, method = {RequestMethod.POST})
541     public ModelAndView saveServiceGroupDictionary(HttpServletRequest request,
542             HttpServletResponse response) throws IOException {
543         DictionaryUtils utils = getDictionaryUtilsInstance();
544         try {
545             boolean fromAPI = utils.isRequestFromAPI(request);
546             ObjectMapper mapper = new ObjectMapper();
547             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
548             JsonNode root = mapper.readTree(request.getReader());
549             GroupServiceList groupServiceList;
550             GridData gridData;
551             if (fromAPI) {
552                 groupServiceList = mapper.readValue(root.get(dictionaryFields).toString(),
553                         GroupServiceList.class);
554                 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
555             } else {
556                 groupServiceList = mapper.readValue(
557                         root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class);
558                 gridData = mapper.readValue(root.get("serviceGroupDictionaryData").toString(),
559                         GridData.class);
560             }
561             if (!groupServiceList.getGroupName().startsWith(groupNameStart)) {
562                 String groupName = groupNameStart + groupServiceList.getGroupName();
563                 groupServiceList.setGroupName(groupName);
564             }
565             groupServiceList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
566             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
567                     groupServiceList.getGroupName(), "name", GroupServiceList.class);
568             boolean duplicateflag = false;
569             if (!duplicateData.isEmpty()) {
570                 GroupServiceList data = (GroupServiceList) duplicateData.get(0);
571                 if (request.getParameter(operation) != null
572                         && "update".equals(request.getParameter(operation))) {
573                     groupServiceList.setId(data.getId());
574                 } else if ((request.getParameter(operation) != null
575                         && !"update".equals(request.getParameter(operation)))
576                         || (request.getParameter(operation) == null
577                                 && (data.getId() != groupServiceList.getId()))) {
578                     duplicateflag = true;
579                 }
580             }
581             String responseString = null;
582             if (!duplicateflag) {
583                 if (groupServiceList.getId() == 0) {
584                     commonClassDao.save(groupServiceList);
585                 } else {
586                     commonClassDao.update(groupServiceList);
587                 }
588                 responseString =
589                         mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
590             } else {
591                 responseString = duplicateResponseString;
592             }
593             if (fromAPI) {
594                 return utils.getResultForApi(responseString);
595             } else {
596                 utils.setResponseData(response, serviceGroupDatas, responseString);
597             }
598         } catch (Exception e) {
599             utils.setErrorResponseData(response, e);
600         }
601         return null;
602     }
603
604     @RequestMapping(value = {"/fw_dictionary/remove_serviceGroup"}, method = {RequestMethod.POST})
605     public void removeServiceGroupDictionary(HttpServletRequest request,
606             HttpServletResponse response) throws IOException {
607         DictionaryUtils utils = getDictionaryUtilsInstance();
608         utils.removeData(request, response, serviceGroupDatas, GroupServiceList.class);
609     }
610
611     @RequestMapping(value = {"/get_SecurityZoneDataByName"}, method = {RequestMethod.GET},
612             produces = MediaType.APPLICATION_JSON_VALUE)
613     public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response) {
614         DictionaryUtils utils = getDictionaryUtilsInstance();
615         utils.getDataByEntity(response, securityZoneDatas, zoneName, SecurityZone.class);
616     }
617
618     @RequestMapping(value = {"/get_SecurityZoneData"}, method = {RequestMethod.GET},
619             produces = MediaType.APPLICATION_JSON_VALUE)
620     public void getSecurityZoneDictionaryEntityData(HttpServletResponse response) {
621         DictionaryUtils utils = getDictionaryUtilsInstance();
622         utils.getData(response, securityZoneDatas, SecurityZone.class);
623     }
624
625     @RequestMapping(value = {"/fw_dictionary/save_securityZone"}, method = {RequestMethod.POST})
626     public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request,
627             HttpServletResponse response) throws IOException {
628         DictionaryUtils utils = getDictionaryUtilsInstance();
629         try {
630             boolean fromAPI = utils.isRequestFromAPI(request);
631             ObjectMapper mapper = new ObjectMapper();
632             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
633             JsonNode root = mapper.readTree(request.getReader());
634             SecurityZone securityZone;
635             if (fromAPI) {
636                 securityZone =
637                         mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class);
638             } else {
639                 securityZone = mapper.readValue(root.get("securityZoneDictionaryData").toString(),
640                         SecurityZone.class);
641             }
642             List<Object> duplicateData = commonClassDao
643                     .checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class);
644             boolean duplicateflag = false;
645             if (!duplicateData.isEmpty()) {
646                 SecurityZone data = (SecurityZone) duplicateData.get(0);
647                 if (request.getParameter(operation) != null
648                         && "update".equals(request.getParameter(operation))) {
649                     securityZone.setId(data.getId());
650                 } else if ((request.getParameter(operation) != null
651                         && !"update".equals(request.getParameter(operation)))
652                         || (request.getParameter(operation) == null
653                                 && (data.getId() != securityZone.getId()))) {
654                     duplicateflag = true;
655                 }
656             }
657             String responseString = null;
658             if (!duplicateflag) {
659                 if (securityZone.getId() == 0) {
660                     commonClassDao.save(securityZone);
661                 } else {
662                     commonClassDao.update(securityZone);
663                 }
664                 responseString =
665                         mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
666             } else {
667                 responseString = duplicateResponseString;
668             }
669             if (fromAPI) {
670                 return utils.getResultForApi(responseString);
671             } else {
672                 utils.setResponseData(response, securityZoneDatas, responseString);
673             }
674         } catch (Exception e) {
675             utils.setErrorResponseData(response, e);
676         }
677         return null;
678     }
679
680     @RequestMapping(value = {"/fw_dictionary/remove_securityZone"}, method = {RequestMethod.POST})
681     public void removeSecurityZoneDictionary(HttpServletRequest request,
682             HttpServletResponse response) throws IOException {
683         DictionaryUtils utils = getDictionaryUtilsInstance();
684         utils.removeData(request, response, securityZoneDatas, SecurityZone.class);
685     }
686
687
688     @RequestMapping(value = {"/get_ServiceListData"}, method = {RequestMethod.GET},
689             produces = MediaType.APPLICATION_JSON_VALUE)
690     public void getServiceListDictionaryEntityData(HttpServletResponse response) {
691         DictionaryUtils utils = getDictionaryUtilsInstance();
692         utils.getData(response, serviceListDatas, ServiceList.class);
693     }
694
695     @RequestMapping(value = {"/get_ServiceListDictionaryDataByName"}, method = {RequestMethod.GET},
696             produces = MediaType.APPLICATION_JSON_VALUE)
697     public void getServiceListDictionaryEntityDataByName(HttpServletResponse response) {
698         DictionaryUtils utils = getDictionaryUtilsInstance();
699         utils.getDataByEntity(response, serviceListDatas, serviceName, ServiceList.class);
700     }
701
702     @RequestMapping(value = {"/fw_dictionary/save_serviceList"}, method = {RequestMethod.POST})
703     public ModelAndView saveServiceListDictionary(HttpServletRequest request,
704             HttpServletResponse response) throws IOException {
705         DictionaryUtils utils = getDictionaryUtilsInstance();
706         try {
707             boolean fromAPI = utils.isRequestFromAPI(request);
708             ObjectMapper mapper = new ObjectMapper();
709             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
710             JsonNode root = mapper.readTree(request.getReader());
711             ServiceList serviceList;
712             GridData serviceListGridData;
713             if (fromAPI) {
714                 serviceList =
715                         mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class);
716                 serviceListGridData =
717                         mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
718             } else {
719                 serviceList = mapper.readValue(root.get("serviceListDictionaryData").toString(),
720                         ServiceList.class);
721                 serviceListGridData = mapper.readValue(
722                         root.get("serviceListDictionaryData").toString(), GridData.class);
723             }
724             serviceList.setServiceTransProtocol(
725                     utils.appendKey(serviceListGridData.getTransportProtocols(), option, ","));
726             serviceList.setServiceAppProtocol(
727                     utils.appendKey(serviceListGridData.getAppProtocols(), option, ","));
728             serviceList.setServiceType("SERVICE");
729             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
730                     serviceList.getServiceName(), serviceName, ServiceList.class);
731             boolean duplicateflag = false;
732             if (!duplicateData.isEmpty()) {
733                 ServiceList data = (ServiceList) duplicateData.get(0);
734                 if (request.getParameter(operation) != null
735                         && "update".equals(request.getParameter(operation))) {
736                     serviceList.setId(data.getId());
737                 } else if ((request.getParameter(operation) != null
738                         && !"update".equals(request.getParameter(operation)))
739                         || (request.getParameter(operation) == null
740                                 && (data.getId() != serviceList.getId()))) {
741                     duplicateflag = true;
742                 }
743             }
744             String responseString = null;
745             if (!duplicateflag) {
746                 if (serviceList.getId() == 0) {
747                     commonClassDao.save(serviceList);
748                 } else {
749                     commonClassDao.update(serviceList);
750                 }
751                 responseString =
752                         mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
753             } else {
754                 responseString = duplicateResponseString;
755             }
756             if (fromAPI) {
757                 return utils.getResultForApi(responseString);
758             } else {
759                 utils.setResponseData(response, serviceListDatas, responseString);
760             }
761         } catch (Exception e) {
762             utils.setErrorResponseData(response, e);
763         }
764         return null;
765     }
766
767     @RequestMapping(value = {"/fw_dictionary/remove_serviceList"}, method = {RequestMethod.POST})
768     public void removeServiceListDictionary(HttpServletRequest request,
769             HttpServletResponse response) throws IOException {
770         DictionaryUtils utils = getDictionaryUtilsInstance();
771         utils.removeData(request, response, serviceListDatas, ServiceList.class);
772     }
773
774     @RequestMapping(value = {"/get_ZoneData"}, method = {RequestMethod.GET},
775             produces = MediaType.APPLICATION_JSON_VALUE)
776     public void getZoneDictionaryEntityData(HttpServletResponse response) {
777         DictionaryUtils utils = getDictionaryUtilsInstance();
778         utils.getData(response, zoneDatas, Zone.class);
779     }
780
781     @RequestMapping(value = {"/get_ZoneDictionaryDataByName"}, method = {RequestMethod.GET},
782             produces = MediaType.APPLICATION_JSON_VALUE)
783     public void getZoneDictionaryEntityDataByName(HttpServletResponse response) {
784         DictionaryUtils utils = getDictionaryUtilsInstance();
785         utils.getDataByEntity(response, zoneDatas, zoneName, Zone.class);
786     }
787
788     @RequestMapping(value = {"/fw_dictionary/save_zoneName"}, method = {RequestMethod.POST})
789     public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response)
790             throws IOException {
791         DictionaryUtils utils = getDictionaryUtilsInstance();
792         try {
793             boolean fromAPI = utils.isRequestFromAPI(request);
794             ObjectMapper mapper = new ObjectMapper();
795             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
796             JsonNode root = mapper.readTree(request.getReader());
797             Zone zone;
798             if (fromAPI) {
799                 zone = mapper.readValue(root.get(dictionaryFields).toString(), Zone.class);
800             } else {
801                 zone = mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class);
802             }
803             List<Object> duplicateData =
804                     commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class);
805             boolean duplicateflag = false;
806             if (!duplicateData.isEmpty()) {
807                 Zone data = (Zone) duplicateData.get(0);
808                 if (request.getParameter(operation) != null
809                         && "update".equals(request.getParameter(operation))) {
810                     zone.setId(data.getId());
811                 } else if ((request.getParameter(operation) != null
812                         && !"update".equals(request.getParameter(operation)))
813                         || (request.getParameter(operation) == null
814                                 && (data.getId() != zone.getId()))) {
815                     duplicateflag = true;
816                 }
817             }
818             String responseString = null;
819             if (!duplicateflag) {
820                 if (zone.getId() == 0) {
821                     commonClassDao.save(zone);
822                 } else {
823                     commonClassDao.update(zone);
824                 }
825                 responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
826             } else {
827                 responseString = duplicateResponseString;
828             }
829             if (fromAPI) {
830                 return utils.getResultForApi(responseString);
831             } else {
832                 utils.setResponseData(response, zoneDatas, responseString);
833             }
834         } catch (Exception e) {
835             utils.setErrorResponseData(response, e);
836         }
837         return null;
838     }
839
840     @RequestMapping(value = {"/fw_dictionary/remove_zone"}, method = {RequestMethod.POST})
841     public void removeZoneDictionary(HttpServletRequest request, HttpServletResponse response)
842             throws IOException {
843         DictionaryUtils utils = getDictionaryUtilsInstance();
844         utils.removeData(request, response, zoneDatas, Zone.class);
845     }
846
847     @RequestMapping(value = {"/get_TermListDataByName"}, method = {RequestMethod.GET},
848             produces = MediaType.APPLICATION_JSON_VALUE)
849     public void getTermListDictionaryEntityDataByName(HttpServletResponse response) {
850         DictionaryUtils utils = getDictionaryUtilsInstance();
851         utils.getDataByEntity(response, termListDictDatas, termName, TermList.class);
852     }
853
854     @RequestMapping(value = {"/get_TermListData"}, method = {RequestMethod.GET},
855             produces = MediaType.APPLICATION_JSON_VALUE)
856     public void getTermListDictionaryEntityData(HttpServletResponse response) {
857         DictionaryUtils utils = getDictionaryUtilsInstance();
858         utils.getData(response, termListDictDatas, TermList.class);
859     }
860
861     @RequestMapping(value = {"/fw_dictionary/save_termList"}, method = {RequestMethod.POST})
862     public ModelAndView saveTermListDictionary(HttpServletRequest request,
863             HttpServletResponse response) throws IOException {
864         DictionaryUtils utils = getDictionaryUtilsInstance();
865         try {
866             boolean fromAPI = utils.isRequestFromAPI(request);
867             ObjectMapper mapper = new ObjectMapper();
868             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
869             JsonNode root = mapper.readTree(request.getReader());
870             TermList termList;
871             TermListData termListDatas;
872             String userId = null;
873             if (fromAPI) {
874                 termList = mapper.readValue(root.get(dictionaryFields).toString(), TermList.class);
875                 termListDatas =
876                         mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class);
877                 userId = "API";
878             } else {
879                 termList = mapper.readValue(root.get("termListDictionaryData").toString(),
880                         TermList.class);
881                 termListDatas = mapper.readValue(root.get("termListDictionaryData").toString(),
882                         TermListData.class);
883                 userId = root.get(userid).textValue();
884             }
885
886             termList.setFromZones(utils.appendKey(termListDatas.getFromZoneDatas(), option, ","));
887             termList.setToZones(utils.appendKey(termListDatas.getToZoneDatas(), option, ","));
888             termList.setSrcIPList(utils.appendKey(termListDatas.getSourceListDatas(), option, ","));
889             termList.setDestIPList(
890                     utils.appendKey(termListDatas.getDestinationListDatas(), option, ","));
891             termList.setSrcPortList(
892                     utils.appendKey(termListDatas.getSourceServiceDatas(), option, ","));
893             termList.setDestPortList(
894                     utils.appendKey(termListDatas.getDestinationServiceDatas(), option, ","));
895             termList.setAction(utils.appendKey(termListDatas.getActionListDatas(), option, ","));
896
897             UserInfo userInfo = utils.getUserInfo(userId);
898             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(),
899                     termName, TermList.class);
900             boolean duplicateflag = false;
901             if (!duplicateData.isEmpty()) {
902                 TermList data = (TermList) duplicateData.get(0);
903                 if (request.getParameter(operation) != null
904                         && "update".equals(request.getParameter(operation))) {
905                     termList.setId(data.getId());
906                 } else if ((request.getParameter(operation) != null
907                         && !"update".equals(request.getParameter(operation)))
908                         || (request.getParameter(operation) == null
909                                 && (data.getId() != termList.getId()))) {
910                     duplicateflag = true;
911                 }
912             }
913             String responseString = null;
914             if (!duplicateflag) {
915                 termList.setUserModifiedBy(userInfo);
916                 if (termList.getId() == 0) {
917                     termList.setUserCreatedBy(userInfo);
918                     commonClassDao.save(termList);
919                 } else {
920                     termList.setModifiedDate(new Date());
921                     commonClassDao.update(termList);
922                 }
923                 responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
924             } else {
925                 responseString = duplicateResponseString;
926             }
927             if (fromAPI) {
928                 return utils.getResultForApi(responseString);
929             } else {
930                 utils.setResponseData(response, termListDictDatas, responseString);
931             }
932         } catch (Exception e) {
933             utils.setErrorResponseData(response, e);
934         }
935         return null;
936     }
937
938     @RequestMapping(value = {"/fw_dictionary/remove_termList"}, method = {RequestMethod.POST})
939     public void removeTermListDictionary(HttpServletRequest request, HttpServletResponse response)
940             throws IOException {
941         DictionaryUtils utils = getDictionaryUtilsInstance();
942         utils.removeData(request, response, termListDictDatas, TermList.class);
943     }
944
945     // ParentList Dictionary Data
946     @RequestMapping(value = {"/get_FWDictionaryListDataByName"}, method = {RequestMethod.GET},
947             produces = MediaType.APPLICATION_JSON_VALUE)
948     public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response) {
949         DictionaryUtils utils = getDictionaryUtilsInstance();
950         utils.getDataByEntity(response, fwDictListDatas, "parentItemName",
951                 FirewallDictionaryList.class);
952     }
953
954     @RequestMapping(value = {"/get_FWDictionaryListData"}, method = {RequestMethod.GET},
955             produces = MediaType.APPLICATION_JSON_VALUE)
956     public void getFWDictionaryListEntityData(HttpServletResponse response) {
957         DictionaryUtils utils = getDictionaryUtilsInstance();
958         utils.getData(response, fwDictListDatas, FirewallDictionaryList.class);
959     }
960
961     @RequestMapping(value = {"/fw_dictionary/save_FWDictionaryList"}, method = {RequestMethod.POST})
962     public ModelAndView saveFWDictionaryList(HttpServletRequest request,
963             HttpServletResponse response) throws IOException {
964         DictionaryUtils utils = getDictionaryUtilsInstance();
965         try {
966             boolean fromAPI = utils.isRequestFromAPI(request);
967             ObjectMapper mapper = new ObjectMapper();
968             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
969             JsonNode root = mapper.readTree(request.getReader());
970             FirewallDictionaryList fwDictList;
971             GridData gridData;
972             if (fromAPI) {
973                 fwDictList = mapper.readValue(root.get(dictionaryFields).toString(),
974                         FirewallDictionaryList.class);
975                 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
976             } else {
977                 fwDictList = mapper.readValue(root.get("fwDictListDictionaryData").toString(),
978                         FirewallDictionaryList.class);
979                 gridData = mapper.readValue(root.get("fwDictListDictionaryData").toString(),
980                         GridData.class);
981             }
982
983             fwDictList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
984             fwDictList.setAddressList(utils.appendKey(gridData.getAlAttributes(), option, ","));
985
986             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
987                     fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class);
988             boolean duplicateflag = false;
989             if (!duplicateData.isEmpty()) {
990                 FirewallDictionaryList data = (FirewallDictionaryList) duplicateData.get(0);
991                 if (request.getParameter(operation) != null
992                         && "update".equals(request.getParameter(operation))) {
993                     fwDictList.setId(data.getId());
994                 } else if ((request.getParameter(operation) != null
995                         && !"update".equals(request.getParameter(operation)))
996                         || (request.getParameter(operation) == null
997                                 && (data.getId() != fwDictList.getId()))) {
998                     duplicateflag = true;
999                 }
1000             }
1001             String responseString = null;
1002             if (!duplicateflag) {
1003                 if (fwDictList.getId() == 0) {
1004                     commonClassDao.save(fwDictList);
1005                 } else {
1006                     commonClassDao.update(fwDictList);
1007                 }
1008                 responseString = mapper
1009                         .writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1010             } else {
1011                 responseString = duplicateResponseString;
1012             }
1013             if (fromAPI) {
1014                 return utils.getResultForApi(responseString);
1015             } else {
1016                 utils.setResponseData(response, fwDictListDatas, responseString);
1017             }
1018         } catch (Exception e) {
1019             utils.setErrorResponseData(response, e);
1020         }
1021         return null;
1022     }
1023
1024     @RequestMapping(value = {"/fw_dictionary/remove_FWDictionaryList"},
1025             method = {RequestMethod.POST})
1026     public void removeFWDictionaryList(HttpServletRequest request, HttpServletResponse response)
1027             throws IOException {
1028         DictionaryUtils utils = getDictionaryUtilsInstance();
1029         utils.removeData(request, response, fwDictListDatas, FirewallDictionaryList.class);
1030     }
1031
1032
1033     @RequestMapping(value = {"/get_TagPickerNameByName"}, method = {RequestMethod.GET},
1034             produces = MediaType.APPLICATION_JSON_VALUE)
1035     public void getTagPickerNameEntityDataByName(HttpServletResponse response) {
1036         DictionaryUtils utils = getDictionaryUtilsInstance();
1037         utils.getDataByEntity(response, fwTagPickerDatas, tagPickerName, FWTagPicker.class);
1038     }
1039
1040     @RequestMapping(value = {"/get_TagPickerListData"}, method = {RequestMethod.GET},
1041             produces = MediaType.APPLICATION_JSON_VALUE)
1042     public void getTagPickerDictionaryEntityData(HttpServletResponse response) {
1043         DictionaryUtils utils = getDictionaryUtilsInstance();
1044         utils.getData(response, fwTagPickerDatas, FWTagPicker.class);
1045     }
1046
1047     @RequestMapping(value = {"/fw_dictionary/save_fwTagPicker"}, method = {RequestMethod.POST})
1048     public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request,
1049             HttpServletResponse response) throws IOException {
1050         DictionaryUtils utils = getDictionaryUtilsInstance();
1051         try {
1052             boolean fromAPI = utils.isRequestFromAPI(request);
1053             ObjectMapper mapper = new ObjectMapper();
1054             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1055             JsonNode root = mapper.readTree(request.getReader());
1056             FWTagPicker fwTagPicker;
1057             TagGridValues data;
1058             String userId = "";
1059             if (fromAPI) {
1060                 fwTagPicker =
1061                         mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class);
1062                 data = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class);
1063                 userId = "API";
1064             } else {
1065                 fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(),
1066                         FWTagPicker.class);
1067                 data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(),
1068                         TagGridValues.class);
1069                 userId = root.get(userid).textValue();
1070             }
1071             fwTagPicker.setTagValues(utils.appendKeyValue(data.getTags(), "#", ":"));
1072
1073             UserInfo userInfo = utils.getUserInfo(userId);
1074
1075             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
1076                     fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class);
1077             boolean duplicateflag = false;
1078             if (!duplicateData.isEmpty()) {
1079                 FWTagPicker data1 = (FWTagPicker) duplicateData.get(0);
1080                 if (request.getParameter(operation) != null
1081                         && "update".equals(request.getParameter(operation))) {
1082                     fwTagPicker.setId(data1.getId());
1083                 } else if ((request.getParameter(operation) != null
1084                         && !"update".equals(request.getParameter(operation)))
1085                         || (request.getParameter(operation) == null
1086                                 && (data1.getId() != fwTagPicker.getId()))) {
1087                     duplicateflag = true;
1088                 }
1089             }
1090             String responseString = null;
1091             if (!duplicateflag) {
1092                 fwTagPicker.setUserModifiedBy(userInfo);
1093                 if (fwTagPicker.getId() == 0) {
1094                     fwTagPicker.setUserCreatedBy(userInfo);
1095                     commonClassDao.save(fwTagPicker);
1096                 } else {
1097                     fwTagPicker.setModifiedDate(new Date());
1098                     commonClassDao.update(fwTagPicker);
1099                 }
1100                 responseString =
1101                         mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
1102             } else {
1103                 responseString = duplicateResponseString;
1104             }
1105             if (fromAPI) {
1106                 return utils.getResultForApi(responseString);
1107             } else {
1108                 utils.setResponseData(response, fwTagPickerDatas, responseString);
1109             }
1110         } catch (Exception e) {
1111             utils.setErrorResponseData(response, e);
1112         }
1113         return null;
1114     }
1115
1116     @RequestMapping(value = {"/fw_dictionary/remove_tagPicker"}, method = {RequestMethod.POST})
1117     public void removeFirewallTagPickerDictionary(HttpServletRequest request,
1118             HttpServletResponse response) throws IOException {
1119         DictionaryUtils utils = getDictionaryUtilsInstance();
1120         utils.removeData(request, response, fwTagPickerDatas, FWTagPicker.class);
1121     }
1122
1123     @RequestMapping(value = {"/get_TagListData"}, method = {RequestMethod.GET},
1124             produces = MediaType.APPLICATION_JSON_VALUE)
1125     public void getTagDictionaryEntityData(HttpServletResponse response) {
1126         DictionaryUtils utils = getDictionaryUtilsInstance();
1127         utils.getData(response, fwTagDatas, FWTag.class);
1128     }
1129
1130     @RequestMapping(value = {"/get_TagNameByName"}, method = {RequestMethod.GET},
1131             produces = MediaType.APPLICATION_JSON_VALUE)
1132     public void getTagNameEntityDataByName(HttpServletResponse response) {
1133         DictionaryUtils utils = getDictionaryUtilsInstance();
1134         utils.getDataByEntity(response, fwTagDatas, "fwTagName", FWTag.class);
1135     }
1136
1137
1138     @RequestMapping(value = {"/fw_dictionary/save_fwTag"}, method = {RequestMethod.POST})
1139     public ModelAndView saveFirewallTagDictionary(HttpServletRequest request,
1140             HttpServletResponse response) throws IOException {
1141         DictionaryUtils utils = getDictionaryUtilsInstance();
1142         try {
1143             boolean fromAPI = utils.isRequestFromAPI(request);
1144             ObjectMapper mapper = new ObjectMapper();
1145             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1146             JsonNode root = mapper.readTree(request.getReader());
1147             FWTag fwTag;
1148             TagGridValues tagGridValues;
1149             String userId = "";
1150             if (fromAPI) {
1151                 fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FWTag.class);
1152                 tagGridValues = mapper.readValue(root.get(dictionaryFields).toString(),
1153                         TagGridValues.class);
1154                 userId = "API";
1155             } else {
1156                 fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
1157                 tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(),
1158                         TagGridValues.class);
1159                 userId = root.get(userid).textValue();
1160             }
1161             fwTag.setTagValues(utils.appendKey(tagGridValues.getTags(), "tags", ","));
1162
1163             UserInfo userInfo = utils.getUserInfo(userId);
1164             List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(),
1165                     "fwTagName", FWTag.class);
1166             boolean duplicateflag = false;
1167             if (!duplicateData.isEmpty()) {
1168                 FWTag data = (FWTag) duplicateData.get(0);
1169                 if (request.getParameter(operation) != null
1170                         && "update".equals(request.getParameter(operation))) {
1171                     fwTag.setId(data.getId());
1172                 } else if ((request.getParameter(operation) != null
1173                         && !"update".equals(request.getParameter(operation)))
1174                         || (request.getParameter(operation) == null
1175                                 && (data.getId() != fwTag.getId()))) {
1176                     duplicateflag = true;
1177                 }
1178             }
1179             String responseString = null;
1180             if (!duplicateflag) {
1181                 fwTag.setUserModifiedBy(userInfo);
1182                 if (fwTag.getId() == 0) {
1183                     fwTag.setUserCreatedBy(userInfo);
1184                     commonClassDao.save(fwTag);
1185                 } else {
1186                     fwTag.setModifiedDate(new Date());
1187                     commonClassDao.update(fwTag);
1188                 }
1189                 responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
1190             } else {
1191                 responseString = duplicateResponseString;
1192             }
1193             if (fromAPI) {
1194                 return utils.getResultForApi(responseString);
1195             } else {
1196                 utils.setResponseData(response, fwTagDatas, responseString);
1197             }
1198         } catch (Exception e) {
1199             utils.setErrorResponseData(response, e);
1200         }
1201         return null;
1202     }
1203
1204     @RequestMapping(value = {"/fw_dictionary/remove_tagList"}, method = {RequestMethod.POST})
1205     public void removeFirewallTagDictionary(HttpServletRequest request,
1206             HttpServletResponse response) throws IOException {
1207         DictionaryUtils utils = getDictionaryUtilsInstance();
1208         utils.removeData(request, response, fwTagDatas, FWTag.class);
1209     }
1210 }
1211
1212
1213 class TagGridValues {
1214     private List<Object> tags;
1215
1216     public List<Object> getTags() {
1217         return tags;
1218     }
1219
1220     public void setTags(List<Object> tags) {
1221         this.tags = tags;
1222     }
1223 }
1224
1225
1226 class AGGridData {
1227     private List<Object> attributes;
1228
1229     public List<Object> getAttributes() {
1230         return attributes;
1231     }
1232
1233     public void setAttributes(List<Object> attributes) {
1234         this.attributes = attributes;
1235     }
1236 }
1237
1238
1239 class TermListData {
1240     private List<Object> fromZoneDatas;
1241     private List<Object> toZoneDatas;
1242     private List<Object> sourceListDatas;
1243     private List<Object> destinationListDatas;
1244     private List<Object> sourceServiceDatas;
1245     private List<Object> destinationServiceDatas;
1246     private List<Object> actionListDatas;
1247
1248     public List<Object> getFromZoneDatas() {
1249         return fromZoneDatas;
1250     }
1251
1252     public void setFromZoneDatas(List<Object> fromZoneDatas) {
1253         this.fromZoneDatas = fromZoneDatas;
1254     }
1255
1256     public List<Object> getToZoneDatas() {
1257         return toZoneDatas;
1258     }
1259
1260     public void setToZoneDatas(List<Object> toZoneDatas) {
1261         this.toZoneDatas = toZoneDatas;
1262     }
1263
1264     public List<Object> getSourceListDatas() {
1265         return sourceListDatas;
1266     }
1267
1268     public void setSourceListDatas(List<Object> sourceListDatas) {
1269         this.sourceListDatas = sourceListDatas;
1270     }
1271
1272     public List<Object> getDestinationListDatas() {
1273         return destinationListDatas;
1274     }
1275
1276     public void setDestinationListDatas(List<Object> destinationListDatas) {
1277         this.destinationListDatas = destinationListDatas;
1278     }
1279
1280     public List<Object> getSourceServiceDatas() {
1281         return sourceServiceDatas;
1282     }
1283
1284     public void setSourceServiceDatas(List<Object> sourceServiceDatas) {
1285         this.sourceServiceDatas = sourceServiceDatas;
1286     }
1287
1288     public List<Object> getDestinationServiceDatas() {
1289         return destinationServiceDatas;
1290     }
1291
1292     public void setDestinationServiceDatas(List<Object> destinationServiceDatas) {
1293         this.destinationServiceDatas = destinationServiceDatas;
1294     }
1295
1296     public List<Object> getActionListDatas() {
1297         return actionListDatas;
1298     }
1299
1300     public void setActionListDatas(List<Object> actionListDatas) {
1301         this.actionListDatas = actionListDatas;
1302     }
1303 }