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