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