2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.pap.xacml.rest.controller;
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.net.UnknownHostException;
26 import java.util.Date;
27 import java.util.HashMap;
28 import java.util.LinkedHashMap;
29 import java.util.List;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
35 import org.jboss.netty.handler.ipfilter.CIDR;
36 import org.json.JSONObject;
37 import org.onap.policy.common.logging.flexlogger.FlexLogger;
38 import org.onap.policy.common.logging.flexlogger.Logger;
39 import org.onap.policy.pap.xacml.rest.adapters.GridData;
40 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
41 import org.onap.policy.rest.dao.CommonClassDao;
42 import org.onap.policy.rest.jpa.ActionList;
43 import org.onap.policy.rest.jpa.AddressGroup;
44 import org.onap.policy.rest.jpa.FWTag;
45 import org.onap.policy.rest.jpa.FWTagPicker;
46 import org.onap.policy.rest.jpa.FirewallDictionaryList;
47 import org.onap.policy.rest.jpa.GroupServiceList;
48 import org.onap.policy.rest.jpa.PortList;
49 import org.onap.policy.rest.jpa.PrefixList;
50 import org.onap.policy.rest.jpa.ProtocolList;
51 import org.onap.policy.rest.jpa.SecurityZone;
52 import org.onap.policy.rest.jpa.ServiceList;
53 import org.onap.policy.rest.jpa.TermList;
54 import org.onap.policy.rest.jpa.UserInfo;
55 import org.onap.policy.rest.jpa.Zone;
56 import org.onap.policy.utils.PolicyUtils;
57 import org.onap.policy.xacml.api.XACMLErrorConstants;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.http.MediaType;
60 import org.springframework.stereotype.Controller;
61 import org.springframework.web.bind.annotation.RequestMapping;
62 import org.springframework.web.servlet.ModelAndView;
64 import com.fasterxml.jackson.databind.DeserializationFeature;
65 import com.fasterxml.jackson.databind.JsonNode;
66 import com.fasterxml.jackson.databind.ObjectMapper;
70 public class FirewallDictionaryController {
72 private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class);
74 private static CommonClassDao commonClassDao;
75 private static String prefixListName = "prefixListName";
76 private static String successMapKey = "successMapKey";
77 private static String successMessage = "success";
78 private static String operation = "operation";
79 private static String getDictionary = "getDictionary";
80 private static String errorMsg = "error";
81 private static String dictionaryDBQuery = "dictionaryDBQuery";
82 private static String apiflag = "apiflag";
83 private static String dictionaryFields ="dictionaryFields";
84 private static String update = "update";
85 private static String duplicateResponseString = "Duplicate";
86 private static String successMsg = "Success";
87 private static String utf8 = "UTF-8";
88 private static String applicationJsonContentType = "application / json";
89 private static String existsResponseString = "Exists";
90 private static String protocolName = "protocolName";
91 private static String groupNameStart = "Group_";
92 private static String option = "option";
93 private static String zoneName = "zoneName";
94 private static String serviceName = "serviceName";
95 private static String termName = "termName";
96 private static String userid = "userid";
97 private static String tagPickerName = "tagPickerName";
98 private static String fwTagDictionaryDatas = "fwTagDictionaryDatas";
102 public FirewallDictionaryController(CommonClassDao commonClassDao){
103 FirewallDictionaryController.commonClassDao = commonClassDao;
106 public static void setCommonClassDao(CommonClassDao clDao){
107 commonClassDao = clDao;
110 public FirewallDictionaryController(){
112 * This is an empty constructor
116 public UserInfo getUserInfo(String loginId){
117 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
121 @RequestMapping(value={"/get_PrefixListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
122 public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response){
124 Map<String, Object> model = new HashMap<>();
125 ObjectMapper mapper = new ObjectMapper();
126 model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PrefixList.class, prefixListName)));
127 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
128 JSONObject j = new JSONObject(msg);
129 response.getWriter().write(j.toString());
132 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
136 @RequestMapping(value={"/get_PrefixListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
137 public void getPrefixListDictionaryEntityData(HttpServletResponse response){
139 Map<String, Object> model = new HashMap<>();
140 ObjectMapper mapper = new ObjectMapper();
141 model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)));
142 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
143 JSONObject j = new JSONObject(msg);
144 response.addHeader(successMapKey, successMessage);
145 response.addHeader(operation, getDictionary);
146 response.getWriter().write(j.toString());
149 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e);
150 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
151 response.addHeader(errorMsg, dictionaryDBQuery);
155 @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
156 public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
158 boolean duplicateflag = false;
159 boolean isFakeUpdate = false;
160 boolean fromAPI = false;
161 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
164 ObjectMapper mapper = new ObjectMapper();
165 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
166 JsonNode root = mapper.readTree(request.getReader());
167 PrefixList prefixList;
169 prefixList = mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class);
171 //check if update operation or create, get id for data to be updated and update attributeData
172 if (update.equals(request.getParameter(operation))) {
173 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class);
174 PrefixList data = (PrefixList) duplicateData.get(0);
175 int id = data.getId();
180 prefixList.setId(id);
184 prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
186 if(prefixList.getId() == 0){
187 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class);
188 if(!duplicateData.isEmpty()){
189 duplicateflag = true;
191 commonClassDao.save(prefixList);
195 commonClassDao.update(prefixList);
198 String responseString = "";
200 responseString = duplicateResponseString;
202 responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
206 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
208 responseString = existsResponseString;
210 responseString = successMsg;
213 ModelAndView result = new ModelAndView();
214 result.setViewName(responseString);
217 response.setCharacterEncoding(utf8);
218 response.setContentType(applicationJsonContentType);
219 request.setCharacterEncoding(utf8);
221 PrintWriter out = response.getWriter();
222 JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}");
223 out.write(j.toString());
226 }catch (Exception e){
227 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e);
228 response.setCharacterEncoding(utf8);
229 request.setCharacterEncoding(utf8);
230 PrintWriter out = response.getWriter();
231 out.write(PolicyUtils.CATCH_EXCEPTION);
236 @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
237 public void removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
239 ObjectMapper mapper = new ObjectMapper();
240 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
241 JsonNode root = mapper.readTree(request.getReader());
242 PrefixList prefixList = mapper.readValue(root.get("data").toString(), PrefixList.class);
243 commonClassDao.delete(prefixList);
244 response.setCharacterEncoding(utf8);
245 response.setContentType(applicationJsonContentType);
246 request.setCharacterEncoding(utf8);
248 PrintWriter out = response.getWriter();
249 String responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
250 JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}");
251 out.write(j.toString());
254 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
255 response.setCharacterEncoding(utf8);
256 request.setCharacterEncoding(utf8);
257 PrintWriter out = response.getWriter();
258 out.write(PolicyUtils.CATCH_EXCEPTION);
262 @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
263 public void validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
265 ObjectMapper mapper = new ObjectMapper();
266 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
267 JsonNode root = mapper.readTree(request.getReader());
268 PrefixList prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
269 String responseValidation = successMessage;
271 CIDR.newCIDR(prefixList.getPrefixListValue());
272 }catch(UnknownHostException e){
274 responseValidation = errorMsg;
276 response.setCharacterEncoding(utf8);
277 response.setContentType(applicationJsonContentType);
278 request.setCharacterEncoding(utf8);
280 PrintWriter out = response.getWriter();
281 JSONObject j = new JSONObject("{result: " + responseValidation + "}");
282 out.write(j.toString());
285 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
286 response.setCharacterEncoding(utf8);
287 request.setCharacterEncoding(utf8);
288 PrintWriter out = response.getWriter();
289 out.write(PolicyUtils.CATCH_EXCEPTION);
293 @RequestMapping(value={"/get_PortListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
294 public void getPortListDictionaryEntityData(HttpServletResponse response){
296 Map<String, Object> model = new HashMap<>();
297 ObjectMapper mapper = new ObjectMapper();
298 model.put("portListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PortList.class)));
299 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
300 JSONObject j = new JSONObject(msg);
301 response.addHeader(successMapKey, successMessage);
302 response.addHeader(operation, getDictionary);
303 response.getWriter().write(j.toString());
306 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
307 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
308 response.addHeader(errorMsg, dictionaryDBQuery);
312 @RequestMapping(value={"/fw_dictionary/save_portName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
313 public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
315 boolean duplicateflag = false;
316 ObjectMapper mapper = new ObjectMapper();
317 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
318 JsonNode root = mapper.readTree(request.getReader());
319 PortList portList = mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class);
320 if(portList.getId() == 0){
321 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class);
322 if(!duplicateData.isEmpty()){
323 duplicateflag = true;
325 commonClassDao.save(portList);
328 commonClassDao.update(portList);
330 response.setCharacterEncoding(utf8);
331 response.setContentType(applicationJsonContentType);
332 request.setCharacterEncoding(utf8);
334 PrintWriter out = response.getWriter();
335 String responseString = "";
337 responseString = duplicateResponseString;
339 responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
341 JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}");
343 out.write(j.toString());
348 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
349 response.setCharacterEncoding(utf8);
350 request.setCharacterEncoding(utf8);
351 PrintWriter out = response.getWriter();
352 out.write(PolicyUtils.CATCH_EXCEPTION);
357 @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
358 public void removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
360 ObjectMapper mapper = new ObjectMapper();
361 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
362 JsonNode root = mapper.readTree(request.getReader());
363 PortList portList = mapper.readValue(root.get("data").toString(), PortList.class);
364 commonClassDao.delete(portList);
365 response.setCharacterEncoding(utf8);
366 response.setContentType(applicationJsonContentType);
367 request.setCharacterEncoding(utf8);
369 PrintWriter out = response.getWriter();
370 String responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
371 JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}");
372 out.write(j.toString());
375 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
376 response.setCharacterEncoding(utf8);
377 request.setCharacterEncoding(utf8);
378 PrintWriter out = response.getWriter();
379 out.write(PolicyUtils.CATCH_EXCEPTION);
383 @RequestMapping(value={"/get_ProtocolListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
384 public void getProtocolListDictionaryEntityData(HttpServletResponse response){
386 Map<String, Object> model = new HashMap<>();
387 ObjectMapper mapper = new ObjectMapper();
388 model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)));
389 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
390 JSONObject j = new JSONObject(msg);
391 response.addHeader(successMapKey, successMessage);
392 response.addHeader(operation, getDictionary);
393 response.getWriter().write(j.toString());
396 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
397 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
398 response.addHeader(errorMsg, dictionaryDBQuery);
402 @RequestMapping(value={"/get_ProtocolListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
403 public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response){
405 Map<String, Object> model = new HashMap<>();
406 ObjectMapper mapper = new ObjectMapper();
407 model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ProtocolList.class, protocolName)));
408 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
409 JSONObject j = new JSONObject(msg);
410 response.getWriter().write(j.toString());
413 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
417 @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
418 public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
420 boolean duplicateflag = false;
421 boolean isFakeUpdate = false;
422 boolean fromAPI = false;
423 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
426 ObjectMapper mapper = new ObjectMapper();
427 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
428 JsonNode root = mapper.readTree(request.getReader());
429 ProtocolList protocolList;
431 protocolList = mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class);
433 //check if update operation or create, get id for data to be updated and update attributeData
434 if ((update).equals(request.getParameter(operation))) {
435 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class);
436 ProtocolList data = (ProtocolList) duplicateData.get(0);
437 int id = data.getId();
440 protocolList.setId(1);
442 protocolList.setId(id);
446 protocolList = mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class);
448 if(protocolList.getId() == 0){
449 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class);
450 if(!duplicateData.isEmpty()){
451 duplicateflag = true;
453 commonClassDao.save(protocolList);
457 commonClassDao.update(protocolList);
460 String responseString = "";
462 responseString = duplicateResponseString;
464 responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
468 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
470 responseString = existsResponseString;
472 responseString = successMsg;
475 ModelAndView result = new ModelAndView();
476 result.setViewName(responseString);
479 response.setCharacterEncoding(utf8);
480 response.setContentType(applicationJsonContentType);
481 request.setCharacterEncoding(utf8);
483 PrintWriter out = response.getWriter();
484 JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}");
485 out.write(j.toString());
488 }catch (Exception e){
489 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
490 response.setCharacterEncoding(utf8);
491 request.setCharacterEncoding(utf8);
492 PrintWriter out = response.getWriter();
493 out.write(PolicyUtils.CATCH_EXCEPTION);
498 @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
499 public void removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
501 ObjectMapper mapper = new ObjectMapper();
502 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
503 JsonNode root = mapper.readTree(request.getReader());
504 ProtocolList protocolList = mapper.readValue(root.get("data").toString(), ProtocolList.class);
505 commonClassDao.delete(protocolList);
506 response.setCharacterEncoding(utf8);
507 response.setContentType(applicationJsonContentType);
508 request.setCharacterEncoding(utf8);
510 PrintWriter out = response.getWriter();
512 String responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
513 JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}");
514 out.write(j.toString());
517 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
518 response.setCharacterEncoding(utf8);
519 request.setCharacterEncoding(utf8);
520 PrintWriter out = response.getWriter();
521 out.write(PolicyUtils.CATCH_EXCEPTION);
525 @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
526 public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response){
528 Map<String, Object> model = new HashMap<>();
529 ObjectMapper mapper = new ObjectMapper();
530 model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(AddressGroup.class, "name")));
531 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
532 JSONObject j = new JSONObject(msg);
533 response.getWriter().write(j.toString());
536 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
540 @RequestMapping(value={"/get_AddressGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
541 public void getAddressGroupDictionaryEntityData(HttpServletResponse response){
543 Map<String, Object> model = new HashMap<>();
544 ObjectMapper mapper = new ObjectMapper();
545 model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)));
546 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
547 JSONObject j = new JSONObject(msg);
548 response.addHeader(successMapKey, successMessage);
549 response.addHeader(operation, getDictionary);
550 response.getWriter().write(j.toString());
553 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
554 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
555 response.addHeader(errorMsg, dictionaryDBQuery);
559 @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
560 public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
562 boolean duplicateflag = false;
563 boolean isFakeUpdate = false;
564 boolean fromAPI = false;
565 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
568 ObjectMapper mapper = new ObjectMapper();
569 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
570 JsonNode root = mapper.readTree(request.getReader());
571 AddressGroup addressGroup;
574 addressGroup = mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class);
575 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
577 if(!addressGroup.getGroupName().startsWith(groupNameStart)){
578 String groupName = groupNameStart+addressGroup.getGroupName();
579 addressGroup.setGroupName(groupName);
582 //check if update operation or create, get id for data to be updated and update attributeData
583 if ((update).equals(request.getParameter(operation))) {
584 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
585 AddressGroup data = (AddressGroup) duplicateData.get(0);
586 int id = data.getId();
589 addressGroup.setId(1);
591 addressGroup.setId(id);
595 addressGroup = mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class);
596 gridData = mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class);
597 if(!addressGroup.getGroupName().startsWith(groupNameStart)){
598 String groupName = groupNameStart+addressGroup.getGroupName();
599 addressGroup.setGroupName(groupName);
602 StringBuilder userValue = new StringBuilder();
604 if(!gridData.getAttributes().isEmpty()){
605 for(Object attribute : gridData.getAttributes()){
606 if(attribute instanceof LinkedHashMap<?, ?>){
607 String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString();
609 userValue.append(",");
611 userValue.append(key) ;
616 addressGroup.setServiceList(userValue.toString());
617 if(addressGroup.getId() == 0){
618 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
619 if(!duplicateData.isEmpty()){
620 duplicateflag = true;
622 commonClassDao.save(addressGroup);
626 commonClassDao.update(addressGroup);
629 String responseString = "";
631 responseString = duplicateResponseString;
633 responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
636 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
638 responseString = existsResponseString;
640 responseString = successMsg;
643 ModelAndView result = new ModelAndView();
644 result.setViewName(responseString);
647 response.setCharacterEncoding(utf8);
648 response.setContentType(applicationJsonContentType);
649 request.setCharacterEncoding(utf8);
651 PrintWriter out = response.getWriter();
652 JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}");
653 out.write(j.toString());
656 }catch (Exception e){
657 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
658 response.setCharacterEncoding(utf8);
659 request.setCharacterEncoding(utf8);
660 PrintWriter out = response.getWriter();
661 out.write(PolicyUtils.CATCH_EXCEPTION);
666 @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
667 public void removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
669 ObjectMapper mapper = new ObjectMapper();
670 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
671 JsonNode root = mapper.readTree(request.getReader());
672 AddressGroup addressGroup = mapper.readValue(root.get("data").toString(), AddressGroup.class);
673 commonClassDao.delete(addressGroup);
674 response.setCharacterEncoding(utf8);
675 response.setContentType(applicationJsonContentType);
676 request.setCharacterEncoding(utf8);
678 PrintWriter out = response.getWriter();
680 String responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
681 JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}");
682 out.write(j.toString());
685 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
686 response.setCharacterEncoding(utf8);
687 request.setCharacterEncoding(utf8);
688 PrintWriter out = response.getWriter();
689 out.write(PolicyUtils.CATCH_EXCEPTION);
693 @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
694 public void getActionListDictionaryEntityDataByName(HttpServletResponse response){
696 Map<String, Object> model = new HashMap<>();
697 ObjectMapper mapper = new ObjectMapper();
698 List<String> list = commonClassDao.getDataByColumn(ActionList.class, "actionName");
699 model.put("actionListDictionaryDatas", mapper.writeValueAsString(list));
700 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
701 JSONObject j = new JSONObject(msg);
702 response.getWriter().write(j.toString());
705 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
709 @RequestMapping(value={"/get_ActionListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
710 public void getActionListDictionaryEntityData(HttpServletResponse response){
712 Map<String, Object> model = new HashMap<>();
713 ObjectMapper mapper = new ObjectMapper();
714 model.put("actionListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ActionList.class)));
715 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
716 JSONObject j = new JSONObject(msg);
717 response.addHeader(successMapKey, successMessage);
718 response.addHeader(operation, getDictionary);
719 response.getWriter().write(j.toString());
722 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
723 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
724 response.addHeader(errorMsg, dictionaryDBQuery);
728 @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
729 public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
731 boolean duplicateflag = false;
732 boolean isFakeUpdate = false;
733 boolean fromAPI = false;
734 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
737 ObjectMapper mapper = new ObjectMapper();
738 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
739 JsonNode root = mapper.readTree(request.getReader());
740 ActionList actionList;
742 actionList = mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class);
744 //check if update operation or create, get id for data to be updated and update attributeData
745 if ((update).equals(request.getParameter(operation))) {
746 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
747 ActionList data = (ActionList) duplicateData.get(0);
748 int id = data.getId();
753 actionList.setId(id);
757 actionList = mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class);
759 if(actionList.getId() == 0){
760 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
761 if(!duplicateData.isEmpty()){
762 duplicateflag = true;
764 commonClassDao.save(actionList);
768 commonClassDao.update(actionList);
771 String responseString = "";
773 responseString = duplicateResponseString;
775 responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
779 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
781 responseString = existsResponseString;
783 responseString = successMsg;
786 ModelAndView result = new ModelAndView();
787 result.setViewName(responseString);
790 response.setCharacterEncoding(utf8);
791 response.setContentType(applicationJsonContentType);
792 request.setCharacterEncoding(utf8);
794 PrintWriter out = response.getWriter();
795 JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}");
796 out.write(j.toString());
799 }catch (Exception e){
800 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
801 response.setCharacterEncoding(utf8);
802 request.setCharacterEncoding(utf8);
803 PrintWriter out = response.getWriter();
804 out.write(PolicyUtils.CATCH_EXCEPTION);
809 @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
810 public void removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
812 ObjectMapper mapper = new ObjectMapper();
813 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
814 JsonNode root = mapper.readTree(request.getReader());
815 ActionList actionList = mapper.readValue(root.get("data").toString(), ActionList.class);
816 commonClassDao.delete(actionList);
817 response.setCharacterEncoding(utf8);
818 response.setContentType(applicationJsonContentType);
819 request.setCharacterEncoding(utf8);
821 PrintWriter out = response.getWriter();
822 String responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
823 JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}");
824 out.write(j.toString());
827 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
828 response.setCharacterEncoding(utf8);
829 request.setCharacterEncoding(utf8);
830 PrintWriter out = response.getWriter();
831 out.write(PolicyUtils.CATCH_EXCEPTION);
835 @RequestMapping(value={"/get_ServiceGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
836 public void getServiceGroupDictionaryEntityData(HttpServletResponse response){
838 Map<String, Object> model = new HashMap<>();
839 ObjectMapper mapper = new ObjectMapper();
840 model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)));
841 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
842 JSONObject j = new JSONObject(msg);
843 response.addHeader(successMapKey, successMessage);
844 response.addHeader(operation, getDictionary);
845 response.getWriter().write(j.toString());
848 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
849 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
850 response.addHeader(errorMsg, dictionaryDBQuery);
854 @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
855 public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response){
857 Map<String, Object> model = new HashMap<>();
858 ObjectMapper mapper = new ObjectMapper();
859 model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupServiceList.class, "name")));
860 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
861 JSONObject j = new JSONObject(msg);
862 response.getWriter().write(j.toString());
865 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
869 @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
870 public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
872 boolean duplicateflag = false;
873 boolean isFakeUpdate = false;
874 boolean fromAPI = false;
875 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
878 ObjectMapper mapper = new ObjectMapper();
879 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
880 JsonNode root = mapper.readTree(request.getReader());
881 GroupServiceList groupServiceList;
884 groupServiceList = mapper.readValue(root.get(dictionaryFields).toString(), GroupServiceList.class);
885 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
887 if(!groupServiceList.getGroupName().startsWith(groupNameStart)){
888 String groupName = groupNameStart+groupServiceList.getGroupName();
889 groupServiceList.setGroupName(groupName);
891 //check if update operation or create, get id for data to be updated and update attributeData
892 if ((update).equals(request.getParameter(operation))) {
893 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
894 GroupServiceList data = (GroupServiceList) duplicateData.get(0);
895 int id = data.getId();
899 groupServiceList.setId(1);
901 groupServiceList.setId(id);
905 groupServiceList = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class);
906 gridData = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class);
908 if(!groupServiceList.getGroupName().startsWith(groupNameStart)){
909 String groupName = groupNameStart+groupServiceList.getGroupName();
910 groupServiceList.setGroupName(groupName);
912 StringBuilder userValue = new StringBuilder();
914 if(!gridData.getAttributes().isEmpty()){
915 for(Object attribute : gridData.getAttributes()){
916 if(attribute instanceof LinkedHashMap<?, ?>){
917 String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString();
919 userValue.append(",");
921 userValue.append(key);
926 groupServiceList.setServiceList(userValue.toString());
927 if(groupServiceList.getId() == 0){
928 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
929 if(!duplicateData.isEmpty()){
930 duplicateflag = true;
932 commonClassDao.save(groupServiceList);
936 commonClassDao.update(groupServiceList);
939 String responseString = "";
941 responseString = duplicateResponseString;
943 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
947 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
949 responseString = existsResponseString;
951 responseString = successMsg;
954 ModelAndView result = new ModelAndView();
955 result.setViewName(responseString);
958 response.setCharacterEncoding(utf8);
959 response.setContentType(applicationJsonContentType);
960 request.setCharacterEncoding(utf8);
962 PrintWriter out = response.getWriter();
963 JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}");
964 out.write(j.toString());
967 }catch (Exception e){
968 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
969 response.setCharacterEncoding(utf8);
970 request.setCharacterEncoding(utf8);
971 PrintWriter out = response.getWriter();
972 out.write(PolicyUtils.CATCH_EXCEPTION);
977 @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
978 public void removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
980 ObjectMapper mapper = new ObjectMapper();
981 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
982 JsonNode root = mapper.readTree(request.getReader());
983 GroupServiceList groupServiceList = mapper.readValue(root.get("data").toString(), GroupServiceList.class);
984 commonClassDao.delete(groupServiceList);
985 response.setCharacterEncoding(utf8);
986 response.setContentType(applicationJsonContentType);
987 request.setCharacterEncoding(utf8);
989 PrintWriter out = response.getWriter();
991 String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
992 JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}");
993 out.write(j.toString());
997 response.setCharacterEncoding(utf8);
998 request.setCharacterEncoding(utf8);
999 PrintWriter out = response.getWriter();
1000 out.write(PolicyUtils.CATCH_EXCEPTION);
1004 @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1005 public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response){
1007 Map<String, Object> model = new HashMap<>();
1008 ObjectMapper mapper = new ObjectMapper();
1009 model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(SecurityZone.class, zoneName)));
1010 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1011 JSONObject j = new JSONObject(msg);
1012 response.getWriter().write(j.toString());
1014 catch (Exception e){
1015 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1019 @RequestMapping(value={"/get_SecurityZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1020 public void getSecurityZoneDictionaryEntityData(HttpServletResponse response){
1022 Map<String, Object> model = new HashMap<>();
1023 ObjectMapper mapper = new ObjectMapper();
1024 model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)));
1025 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1026 JSONObject j = new JSONObject(msg);
1027 response.addHeader(successMapKey, successMessage);
1028 response.addHeader(operation, getDictionary);
1029 response.getWriter().write(j.toString());
1031 catch (Exception e){
1032 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1033 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1034 response.addHeader(errorMsg, dictionaryDBQuery);
1038 @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1039 public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1041 boolean duplicateflag = false;
1042 boolean isFakeUpdate = false;
1043 boolean fromAPI = false;
1044 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
1047 ObjectMapper mapper = new ObjectMapper();
1048 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1049 JsonNode root = mapper.readTree(request.getReader());
1050 SecurityZone securityZone;
1052 securityZone = mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class);
1054 //check if update operation or create, get id for data to be updated and update attributeData
1055 if ((update).equals(request.getParameter(operation))) {
1056 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class);
1057 SecurityZone data = (SecurityZone) duplicateData.get(0);
1058 int id = data.getId();
1061 securityZone.setId(1);
1063 securityZone.setId(id);
1067 securityZone = mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class);
1069 if(securityZone.getId() == 0){
1070 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class);
1071 if(!duplicateData.isEmpty()){
1072 duplicateflag = true;
1074 commonClassDao.save(securityZone);
1078 commonClassDao.update(securityZone);
1081 String responseString = "";
1083 responseString = duplicateResponseString;
1085 responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
1089 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
1091 responseString = existsResponseString;
1093 responseString = successMsg;
1096 ModelAndView result = new ModelAndView();
1097 result.setViewName(responseString);
1100 response.setCharacterEncoding(utf8);
1101 response.setContentType(applicationJsonContentType);
1102 request.setCharacterEncoding(utf8);
1104 PrintWriter out = response.getWriter();
1105 JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}");
1106 out.write(j.toString());
1110 }catch (Exception e){
1111 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1112 response.setCharacterEncoding(utf8);
1113 request.setCharacterEncoding(utf8);
1114 PrintWriter out = response.getWriter();
1115 out.write(PolicyUtils.CATCH_EXCEPTION);
1120 @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1121 public void removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
1123 ObjectMapper mapper = new ObjectMapper();
1124 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1125 JsonNode root = mapper.readTree(request.getReader());
1126 SecurityZone securityZone = mapper.readValue(root.get("data").toString(), SecurityZone.class);
1127 commonClassDao.delete(securityZone);
1128 response.setCharacterEncoding(utf8);
1129 response.setContentType(applicationJsonContentType);
1130 request.setCharacterEncoding(utf8);
1132 PrintWriter out = response.getWriter();
1134 String responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
1135 JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}");
1136 out.write(j.toString());
1138 catch (Exception e){
1139 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1140 response.setCharacterEncoding(utf8);
1141 request.setCharacterEncoding(utf8);
1142 PrintWriter out = response.getWriter();
1143 out.write(PolicyUtils.CATCH_EXCEPTION);
1148 @RequestMapping(value={"/get_ServiceListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1149 public void getServiceListDictionaryEntityData(HttpServletResponse response){
1151 Map<String, Object> model = new HashMap<>();
1152 ObjectMapper mapper = new ObjectMapper();
1153 model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)));
1154 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1155 JSONObject j = new JSONObject(msg);
1156 response.addHeader(successMapKey, successMessage);
1157 response.addHeader(operation, getDictionary);
1158 response.getWriter().write(j.toString());
1160 catch (Exception e){
1161 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1162 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1163 response.addHeader(errorMsg, dictionaryDBQuery);
1167 @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1168 public void getServiceListDictionaryEntityDataByName(HttpServletResponse response){
1170 Map<String, Object> model = new HashMap<>();
1171 ObjectMapper mapper = new ObjectMapper();
1172 model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ServiceList.class, serviceName)));
1173 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1174 JSONObject j = new JSONObject(msg);
1175 response.getWriter().write(j.toString());
1177 catch (Exception e){
1178 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1182 @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1183 public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1185 boolean duplicateflag = false;
1186 boolean isFakeUpdate = false;
1187 boolean fromAPI = false;
1188 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
1191 ObjectMapper mapper = new ObjectMapper();
1192 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1193 JsonNode root = mapper.readTree(request.getReader());
1194 ServiceList serviceList;
1195 GridData serviceListGridData;
1197 serviceList = mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class);
1198 serviceListGridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
1200 //check if update operation or create, get id for data to be updated and update attributeData
1201 if ((update).equals(request.getParameter(operation))) {
1202 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class);
1203 ServiceList data = (ServiceList) duplicateData.get(0);
1204 int id = data.getId();
1207 serviceList.setId(1);
1209 serviceList.setId(id);
1213 serviceList = mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class);
1214 serviceListGridData = mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class);
1216 StringBuilder tcpValue = new StringBuilder();
1218 if(!serviceListGridData.getTransportProtocols().isEmpty()){
1219 for(Object attribute : serviceListGridData.getTransportProtocols()){
1220 if(attribute instanceof LinkedHashMap<?, ?>){
1221 String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString();
1223 tcpValue.append(",");
1225 tcpValue.append(key);
1230 serviceList.setServiceTransProtocol(tcpValue.toString());
1231 StringBuilder appValue = new StringBuilder();
1233 if(!serviceListGridData.getAppProtocols().isEmpty()){
1234 for(Object attribute : serviceListGridData.getAppProtocols()){
1235 if(attribute instanceof LinkedHashMap<?, ?>){
1236 String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString();
1238 appValue.append(",");
1240 appValue.append(key);
1245 serviceList.setServiceAppProtocol(appValue.toString());
1246 serviceList.setServiceType("SERVICE");
1247 if(serviceList.getId() == 0){
1248 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class);
1249 if(!duplicateData.isEmpty()){
1250 duplicateflag = true;
1252 commonClassDao.save(serviceList);
1256 commonClassDao.update(serviceList);
1260 String responseString = "";
1262 responseString = duplicateResponseString;
1264 responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
1267 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
1269 responseString = existsResponseString;
1271 responseString = successMsg;
1274 ModelAndView result = new ModelAndView();
1275 result.setViewName(responseString);
1278 response.setCharacterEncoding(utf8);
1279 response.setContentType(applicationJsonContentType);
1280 request.setCharacterEncoding(utf8);
1282 PrintWriter out = response.getWriter();
1283 JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}");
1284 out.write(j.toString());
1287 }catch (Exception e){
1288 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1289 response.setCharacterEncoding(utf8);
1290 request.setCharacterEncoding(utf8);
1291 PrintWriter out = response.getWriter();
1292 out.write(PolicyUtils.CATCH_EXCEPTION);
1297 @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1298 public void removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
1300 ObjectMapper mapper = new ObjectMapper();
1301 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1302 JsonNode root = mapper.readTree(request.getReader());
1303 ServiceList serviceList = mapper.readValue(root.get("data").toString(), ServiceList.class);
1304 commonClassDao.delete(serviceList);
1305 response.setCharacterEncoding(utf8);
1306 response.setContentType(applicationJsonContentType);
1307 request.setCharacterEncoding(utf8);
1309 PrintWriter out = response.getWriter();
1311 String responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
1312 JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}");
1313 out.write(j.toString());
1315 catch (Exception e){
1317 response.setCharacterEncoding(utf8);
1318 request.setCharacterEncoding(utf8);
1319 PrintWriter out = response.getWriter();
1320 out.write(PolicyUtils.CATCH_EXCEPTION);
1324 @RequestMapping(value={"/get_ZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1325 public void getZoneDictionaryEntityData(HttpServletResponse response){
1327 Map<String, Object> model = new HashMap<>();
1328 ObjectMapper mapper = new ObjectMapper();
1329 model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Zone.class)));
1330 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1331 JSONObject j = new JSONObject(msg);
1332 response.addHeader(successMapKey, successMessage);
1333 response.addHeader(operation, getDictionary);
1334 response.getWriter().write(j.toString());
1336 catch (Exception e){
1337 LOGGER.error("Exception Occured"+e);
1341 @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1342 public void getZoneDictionaryEntityDataByName(HttpServletResponse response){
1344 Map<String, Object> model = new HashMap<>();
1345 ObjectMapper mapper = new ObjectMapper();
1346 model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Zone.class, zoneName)));
1347 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1348 JSONObject j = new JSONObject(msg);
1349 response.getWriter().write(j.toString());
1351 catch (Exception e){
1352 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1356 @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1357 public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1359 boolean duplicateflag = false;
1360 boolean isFakeUpdate = false;
1361 boolean fromAPI = false;
1362 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
1365 ObjectMapper mapper = new ObjectMapper();
1366 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1367 JsonNode root = mapper.readTree(request.getReader());
1370 zone = mapper.readValue(root.get(dictionaryFields).toString(), Zone.class);
1372 //check if update operation or create, get id for data to be updated and update attributeData
1373 if ((update).equals(request.getParameter(operation))) {
1374 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class);
1375 Zone data = (Zone) duplicateData.get(0);
1376 int id = data.getId();
1385 zone = mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class);
1387 if(zone.getId() == 0){
1388 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class);
1389 if(!duplicateData.isEmpty()){
1390 duplicateflag = true;
1392 commonClassDao.save(zone);
1396 commonClassDao.update(zone);
1399 String responseString = "";
1401 responseString = duplicateResponseString;
1403 responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
1407 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
1409 responseString = existsResponseString;
1411 responseString = successMsg;
1414 ModelAndView result = new ModelAndView();
1415 result.setViewName(responseString);
1418 response.setCharacterEncoding(utf8);
1419 response.setContentType(applicationJsonContentType);
1420 request.setCharacterEncoding(utf8);
1422 PrintWriter out = response.getWriter();
1423 JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}");
1424 out.write(j.toString());
1427 }catch (Exception e){
1428 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1429 response.setCharacterEncoding(utf8);
1430 request.setCharacterEncoding(utf8);
1431 PrintWriter out = response.getWriter();
1432 out.write(PolicyUtils.CATCH_EXCEPTION);
1437 @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1438 public void removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1440 ObjectMapper mapper = new ObjectMapper();
1441 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1442 JsonNode root = mapper.readTree(request.getReader());
1443 Zone zone = mapper.readValue(root.get("data").toString(), Zone.class);
1444 commonClassDao.delete(zone);
1445 response.setCharacterEncoding(utf8);
1446 response.setContentType(applicationJsonContentType);
1447 request.setCharacterEncoding(utf8);
1449 PrintWriter out = response.getWriter();
1451 String responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
1452 JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}");
1453 out.write(j.toString());
1455 catch (Exception e){
1456 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1457 response.setCharacterEncoding(utf8);
1458 request.setCharacterEncoding(utf8);
1459 PrintWriter out = response.getWriter();
1460 out.write(PolicyUtils.CATCH_EXCEPTION);
1464 @RequestMapping(value={"/get_TermListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1465 public void getTermListDictionaryEntityDataByName(HttpServletResponse response){
1467 Map<String, Object> model = new HashMap<>();
1468 ObjectMapper mapper = new ObjectMapper();
1469 model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(TermList.class, termName)));
1470 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1471 JSONObject j = new JSONObject(msg);
1472 response.getWriter().write(j.toString());
1474 catch (Exception e){
1475 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1479 @RequestMapping(value={"/get_TermListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1480 public void getTermListDictionaryEntityData(HttpServletResponse response){
1482 Map<String, Object> model = new HashMap<>();
1483 ObjectMapper mapper = new ObjectMapper();
1484 model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(TermList.class)));
1485 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1486 JSONObject j = new JSONObject(msg);
1487 response.addHeader(successMapKey, successMessage);
1488 response.addHeader(operation, getDictionary);
1489 response.getWriter().write(j.toString());
1491 catch (Exception e){
1492 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1493 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1494 response.addHeader(errorMsg, dictionaryDBQuery);
1498 @RequestMapping(value={"/fw_dictionary/save_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1499 public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1501 boolean duplicateflag = false;
1502 boolean isFakeUpdate = false;
1503 boolean fromAPI = false;
1504 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
1507 ObjectMapper mapper = new ObjectMapper();
1508 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1509 JsonNode root = mapper.readTree(request.getReader());
1511 TermListData termListDatas;
1512 String userId = null;
1514 termList = mapper.readValue(root.get(dictionaryFields).toString(), TermList.class);
1515 termListDatas = mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class);
1518 //check if update operation or create, get id for data to be updated and update attributeData
1519 if ((update).equals(request.getParameter(operation))) {
1520 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class);
1521 TermList data = (TermList) duplicateData.get(0);
1522 int id = data.getId();
1529 termList.setUserCreatedBy(this.getUserInfo(userId));
1532 termList = mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class);
1533 termListDatas = mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class);
1534 userId = root.get(userid).textValue();
1536 StringBuilder fromZoneValue = new StringBuilder();
1538 if(!termListDatas.getFromZoneDatas().isEmpty()){
1539 for(Object fromZone : termListDatas.getFromZoneDatas()){
1540 if(fromZone instanceof LinkedHashMap<?, ?>){
1541 String key = ((LinkedHashMap<?, ?>) fromZone).get(option).toString();
1543 fromZoneValue.append(",");
1545 fromZoneValue.append(key);
1550 termList.setFromZones(fromZoneValue.toString());
1552 StringBuilder toZoneValue = new StringBuilder();
1553 int toZonecounter = 0;
1554 if(!termListDatas.getToZoneDatas().isEmpty()){
1555 for(Object toZone : termListDatas.getToZoneDatas()){
1556 if(toZone instanceof LinkedHashMap<?, ?>){
1557 String key = ((LinkedHashMap<?, ?>) toZone).get(option).toString();
1558 if(toZonecounter>0){
1559 toZoneValue.append(",");
1561 toZoneValue.append(key);
1566 termList.setToZones(toZoneValue.toString());
1568 StringBuilder srcListValues = new StringBuilder();
1569 int srcListcounter = 0;
1570 if(!termListDatas.getSourceListDatas().isEmpty()){
1571 for(Object srcList : termListDatas.getSourceListDatas()){
1572 if(srcList instanceof LinkedHashMap<?, ?>){
1573 String key = ((LinkedHashMap<?, ?>) srcList).get(option).toString();
1574 if(srcListcounter>0){
1575 srcListValues.append(",");
1577 srcListValues.append(key);
1582 termList.setSrcIPList(srcListValues.toString());
1584 StringBuilder desListValues = new StringBuilder();
1585 int destListcounter = 0;
1586 if(!termListDatas.getDestinationListDatas().isEmpty()){
1587 for(Object desList : termListDatas.getDestinationListDatas()){
1588 if(desList instanceof LinkedHashMap<?, ?>){
1589 String key = ((LinkedHashMap<?, ?>) desList).get(option).toString();
1590 if(destListcounter>0){
1591 desListValues.append(",");
1593 desListValues.append(key);
1598 termList.setDestIPList(desListValues.toString());
1600 StringBuilder srcSerValue = new StringBuilder();
1601 int srcSercounter = 0;
1602 if(!termListDatas.getSourceServiceDatas().isEmpty()){
1603 for(Object srcSrc : termListDatas.getSourceServiceDatas()){
1604 if(srcSrc instanceof LinkedHashMap<?, ?>){
1605 String key = ((LinkedHashMap<?, ?>) srcSrc).get(option).toString();
1606 if(srcSercounter>0){
1607 srcSerValue.append(",");
1609 srcSerValue.append(key);
1614 termList.setSrcPortList(srcSerValue.toString());
1616 StringBuilder desSrcValue = new StringBuilder();
1617 int desSrccounter = 0;
1618 if(!termListDatas.getDestinationServiceDatas().isEmpty()){
1619 for(Object desSrc : termListDatas.getDestinationServiceDatas()){
1620 if(desSrc instanceof LinkedHashMap<?, ?>){
1621 String key = ((LinkedHashMap<?, ?>) desSrc).get(option).toString();
1622 if(desSrccounter>0){
1623 desSrcValue.append(",");
1625 desSrcValue.append(key);
1630 termList.setDestPortList(desSrcValue.toString());
1632 StringBuilder actionValue = new StringBuilder();
1633 int actioncounter = 0;
1634 if(!termListDatas.getActionListDatas().isEmpty()){
1635 for(Object actionList : termListDatas.getActionListDatas()){
1636 if(actionList instanceof LinkedHashMap<?, ?>){
1637 String key = ((LinkedHashMap<?, ?>) actionList).get(option).toString();
1638 if(actioncounter>0){
1639 actionValue.append(",");
1641 actionValue.append(key);
1646 termList.setAction(actionValue.toString());
1648 if(termList.getId() == 0){
1649 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class);
1650 if(!duplicateData.isEmpty()){
1651 duplicateflag = true;
1653 termList.setUserCreatedBy(this.getUserInfo(userId));
1654 termList.setUserModifiedBy(this.getUserInfo(userId));
1655 termList.setCreatedDate(new Date());
1656 commonClassDao.save(termList);
1660 termList.setUserModifiedBy(this.getUserInfo(userId));
1661 termList.setModifiedDate(new Date());
1662 commonClassDao.update(termList);
1665 String responseString = "";
1667 responseString = duplicateResponseString;
1669 responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
1673 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
1675 responseString = existsResponseString;
1677 responseString = successMsg;
1680 ModelAndView result = new ModelAndView();
1681 result.setViewName(responseString);
1684 response.setCharacterEncoding(utf8);
1685 response.setContentType(applicationJsonContentType);
1686 request.setCharacterEncoding(utf8);
1688 PrintWriter out = response.getWriter();
1689 JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}");
1690 out.write(j.toString());
1693 }catch (Exception e){
1694 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1695 response.setCharacterEncoding(utf8);
1696 request.setCharacterEncoding(utf8);
1697 PrintWriter out = response.getWriter();
1698 out.write(PolicyUtils.CATCH_EXCEPTION);
1703 @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1704 public void removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1706 ObjectMapper mapper = new ObjectMapper();
1707 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1708 JsonNode root = mapper.readTree(request.getReader());
1709 TermList termList = mapper.readValue(root.get("data").toString(), TermList.class);
1710 commonClassDao.delete(termList);
1711 response.setCharacterEncoding(utf8);
1712 response.setContentType(applicationJsonContentType);
1713 request.setCharacterEncoding(utf8);
1715 PrintWriter out = response.getWriter();
1717 String responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
1718 JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}");
1719 out.write(j.toString());
1721 catch (Exception e){
1722 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1723 response.setCharacterEncoding(utf8);
1724 request.setCharacterEncoding(utf8);
1725 PrintWriter out = response.getWriter();
1726 out.write(PolicyUtils.CATCH_EXCEPTION);
1729 //ParentList Dictionary Data
1730 @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1731 public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response){
1733 Map<String, Object> model = new HashMap<>();
1734 ObjectMapper mapper = new ObjectMapper();
1735 model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FirewallDictionaryList.class, "parentItemName")));
1736 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1737 JSONObject j = new JSONObject(msg);
1738 response.getWriter().write(j.toString());
1740 catch (Exception e){
1741 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1745 @RequestMapping(value={"/get_FWDictionaryListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1746 public void getFWDictionaryListEntityData(HttpServletResponse response){
1748 Map<String, Object> model = new HashMap<>();
1749 ObjectMapper mapper = new ObjectMapper();
1750 model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)));
1751 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1752 JSONObject j = new JSONObject(msg);
1753 response.addHeader(successMapKey, successMessage);
1754 response.addHeader(operation, getDictionary);
1755 response.getWriter().write(j.toString());
1757 catch (Exception e){
1758 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1759 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1760 response.addHeader(errorMsg, dictionaryDBQuery);
1764 @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1765 public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException{
1767 boolean duplicateflag = false;
1768 ObjectMapper mapper = new ObjectMapper();
1769 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1770 JsonNode root = mapper.readTree(request.getReader());
1771 FirewallDictionaryList fwDictList = mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class);
1772 GridData gridData = mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class);
1773 StringBuilder userSLValue = new StringBuilder();
1775 if(!gridData.getAttributes().isEmpty()){
1776 for(Object attribute : gridData.getAttributes()){
1777 if(attribute instanceof LinkedHashMap<?, ?>){
1778 String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString();
1780 userSLValue.append(",");
1782 userSLValue.append(key);
1787 fwDictList.setServiceList(userSLValue.toString());
1788 StringBuilder userALValue = new StringBuilder();
1790 if(!gridData.getAlAttributes().isEmpty()){
1791 for(Object attribute : gridData.getAlAttributes()){
1792 if(attribute instanceof LinkedHashMap<?, ?>){
1793 String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString();
1795 userALValue.append(",");
1797 userALValue.append(key);
1802 fwDictList.setAddressList(userALValue.toString());
1803 if(fwDictList.getId() == 0){
1804 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class);
1805 if(!duplicateData.isEmpty()){
1806 duplicateflag = true;
1808 commonClassDao.save(fwDictList);
1811 commonClassDao.update(fwDictList);
1813 response.setCharacterEncoding(utf8);
1814 response.setContentType(applicationJsonContentType);
1815 request.setCharacterEncoding(utf8);
1817 PrintWriter out = response.getWriter();
1818 String responseString = "";
1820 responseString = duplicateResponseString;
1822 responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1824 JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}");
1825 out.write(j.toString());
1828 catch (Exception e){
1829 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1830 response.setCharacterEncoding(utf8);
1831 request.setCharacterEncoding(utf8);
1832 PrintWriter out = response.getWriter();
1833 out.write(PolicyUtils.CATCH_EXCEPTION);
1838 @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1839 public void removeFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException {
1841 ObjectMapper mapper = new ObjectMapper();
1842 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1843 JsonNode root = mapper.readTree(request.getReader());
1844 FirewallDictionaryList fwDictList = mapper.readValue(root.get("data").toString(), FirewallDictionaryList.class);
1845 commonClassDao.delete(fwDictList);
1846 response.setCharacterEncoding(utf8);
1847 response.setContentType(applicationJsonContentType);
1848 request.setCharacterEncoding(utf8);
1850 PrintWriter out = response.getWriter();
1852 String responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1853 JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}");
1854 out.write(j.toString());
1856 catch (Exception e){
1857 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1858 response.setCharacterEncoding(utf8);
1859 request.setCharacterEncoding(utf8);
1860 PrintWriter out = response.getWriter();
1861 out.write(PolicyUtils.CATCH_EXCEPTION);
1866 @RequestMapping(value={"/get_TagPickerNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1867 public void getTagPickerNameEntityDataByName(HttpServletResponse response){
1869 Map<String, Object> model = new HashMap<>();
1870 ObjectMapper mapper = new ObjectMapper();
1871 model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTagPicker.class, tagPickerName)));
1872 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1873 JSONObject j = new JSONObject(msg);
1874 response.getWriter().write(j.toString());
1876 catch (Exception e){
1877 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1881 @RequestMapping(value={"/get_TagPickerListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1882 public void getTagPickerDictionaryEntityData(HttpServletResponse response){
1884 Map<String, Object> model = new HashMap<>();
1885 ObjectMapper mapper = new ObjectMapper();
1886 model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)));
1887 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1888 JSONObject j = new JSONObject(msg);
1889 response.addHeader(successMapKey, successMessage);
1890 response.addHeader(operation, getDictionary);
1891 response.getWriter().write(j.toString());
1893 catch (Exception e){
1894 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1898 @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1899 public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
1901 boolean duplicateflag = false;
1902 boolean fromAPI = false;
1903 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase (request.getParameter(apiflag))) {
1906 ObjectMapper mapper = new ObjectMapper();
1907 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1908 JsonNode root = mapper.readTree(request.getReader());
1909 FWTagPicker fwTagPicker;
1913 fwTagPicker = mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class);
1915 //check if update operation or create, get id for data to be updated and update attributeData
1916 if ((update).equals(request.getParameter(operation))) {
1917 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class);
1919 FWTagPicker dbdata = (FWTagPicker) duplicateData.get(0);
1920 id = dbdata.getId();
1921 fwTagPicker.setId(id);
1922 fwTagPicker.setUserCreatedBy(this.getUserInfo(userId));
1926 fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
1927 data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
1928 userId = root.get(userid).textValue();
1930 StringBuilder header = new StringBuilder();
1932 if(!data.getTags().isEmpty()){
1933 for(Object attribute : data.getTags()){
1934 if(attribute instanceof LinkedHashMap<?, ?>){
1935 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1936 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
1940 header.append(key+":"+value);
1945 fwTagPicker.setTagValues(header.toString());
1948 if(fwTagPicker.getId() == 0){
1949 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class);
1950 if(!duplicateData.isEmpty()){
1951 duplicateflag = true;
1953 fwTagPicker.setUserCreatedBy(this.getUserInfo(userId));
1954 fwTagPicker.setUserModifiedBy(this.getUserInfo(userId));
1955 commonClassDao.save(fwTagPicker);
1958 fwTagPicker.setUserModifiedBy(this.getUserInfo(userId));
1959 fwTagPicker.setModifiedDate(new Date());
1960 commonClassDao.update(fwTagPicker);
1962 String responseString = "";
1964 responseString = duplicateResponseString;
1966 responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
1970 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
1971 responseString = successMsg;
1973 ModelAndView result = new ModelAndView();
1974 result.setViewName(responseString);
1977 response.setCharacterEncoding(utf8);
1978 response.setContentType(applicationJsonContentType);
1979 request.setCharacterEncoding(utf8);
1981 PrintWriter out = response.getWriter();
1982 JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
1983 out.write(j.toString());
1987 catch (Exception e){
1988 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1989 response.setCharacterEncoding(utf8);
1990 request.setCharacterEncoding(utf8);
1991 PrintWriter out = response.getWriter();
1992 out.write(PolicyUtils.CATCH_EXCEPTION);
1997 @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1998 public void removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
2000 ObjectMapper mapper = new ObjectMapper();
2001 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2002 JsonNode root = mapper.readTree(request.getReader());
2003 FWTagPicker fwTagPicker = mapper.readValue(root.get("data").toString(), FWTagPicker.class);
2004 commonClassDao.delete(fwTagPicker);
2005 response.setCharacterEncoding(utf8);
2006 response.setContentType(applicationJsonContentType);
2007 request.setCharacterEncoding(utf8);
2009 PrintWriter out = response.getWriter();
2010 String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
2011 JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
2012 out.write(j.toString());
2014 catch (Exception e){
2015 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2016 response.setCharacterEncoding(utf8);
2017 request.setCharacterEncoding(utf8);
2018 PrintWriter out = response.getWriter();
2019 out.write(PolicyUtils.CATCH_EXCEPTION);
2023 @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
2024 public void getTagDictionaryEntityData(HttpServletResponse response){
2026 Map<String, Object> model = new HashMap<>();
2027 ObjectMapper mapper = new ObjectMapper();
2028 model.put(fwTagDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(FWTag.class)));
2029 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
2030 JSONObject j = new JSONObject(msg);
2031 response.addHeader(successMapKey, successMessage);
2032 response.addHeader(operation, getDictionary);
2033 response.getWriter().write(j.toString());
2035 catch (Exception e){
2036 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2040 @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
2041 public void getTagNameEntityDataByName(HttpServletResponse response){
2043 Map<String, Object> model = new HashMap<>();
2044 ObjectMapper mapper = new ObjectMapper();
2045 model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName")));
2046 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
2047 JSONObject j = new JSONObject(msg);
2048 response.getWriter().write(j.toString());
2050 catch (Exception e){
2051 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2056 @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2057 public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
2059 boolean duplicateflag = false;
2060 boolean fromAPI = false;
2061 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
2064 ObjectMapper mapper = new ObjectMapper();
2065 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2066 JsonNode root = mapper.readTree(request.getReader());
2071 fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FWTag.class);
2073 //check if update operation or create, get id for data to be updated and update attributeData
2074 if (update.equals(request.getParameter(operation))) {
2075 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
2077 FWTag data = (FWTag) duplicateData.get(0);
2080 fwTag.setUserCreatedBy(this.getUserInfo(userId));
2083 TagGridValues tagGridValues;
2084 fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
2085 tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class);
2086 userId = root.get(userid).textValue();
2088 StringBuilder userValue = new StringBuilder();
2090 if(!tagGridValues.getTags().isEmpty()){
2091 for(Object attribute : tagGridValues.getTags()){
2092 if(attribute instanceof LinkedHashMap<?, ?>){
2093 String key = ((LinkedHashMap<?, ?>) attribute).get("tags").toString();
2095 userValue.append(",");
2097 userValue.append(key);
2102 fwTag.setTagValues(userValue.toString());
2105 if(fwTag.getId() == 0){
2106 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
2107 if(!duplicateData.isEmpty()){
2108 duplicateflag = true;
2110 fwTag.setUserCreatedBy(this.getUserInfo(userId));
2111 fwTag.setUserModifiedBy(this.getUserInfo(userId));
2112 commonClassDao.save(fwTag);
2115 fwTag.setUserModifiedBy(this.getUserInfo(userId));
2116 commonClassDao.update(fwTag);
2118 String responseString = "";
2120 responseString = "Duplicate";
2122 responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
2126 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
2127 responseString = successMsg;
2129 ModelAndView result = new ModelAndView();
2130 result.setViewName(responseString);
2133 response.setCharacterEncoding(utf8);
2134 response.setContentType(applicationJsonContentType);
2135 request.setCharacterEncoding(utf8);
2137 PrintWriter out = response.getWriter();
2138 JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
2139 out.write(j.toString());
2143 catch (Exception e){
2144 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2145 response.setCharacterEncoding(utf8);
2146 request.setCharacterEncoding(utf8);
2147 PrintWriter out = response.getWriter();
2148 out.write(PolicyUtils.CATCH_EXCEPTION);
2153 @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2154 public void removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
2156 ObjectMapper mapper = new ObjectMapper();
2157 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2158 JsonNode root = mapper.readTree(request.getReader());
2159 FWTag fwTag = mapper.readValue(root.get("data").toString(), FWTag.class);
2160 commonClassDao.delete(fwTag);
2161 response.setCharacterEncoding(utf8);
2162 response.setContentType(applicationJsonContentType);
2163 request.setCharacterEncoding(utf8);
2165 PrintWriter out = response.getWriter();
2167 String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
2168 JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
2169 out.write(j.toString());
2171 catch (Exception e){
2172 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2173 response.setCharacterEncoding(utf8);
2174 request.setCharacterEncoding(utf8);
2175 PrintWriter out = response.getWriter();
2176 out.write(PolicyUtils.CATCH_EXCEPTION);
2181 class TagGridValues{
2182 private List<Object> tags;
2184 public List<Object> getTags() {
2188 public void setTags(List<Object> tags) {
2194 private List<Object> attributes;
2196 public List<Object> getAttributes() {
2200 public void setAttributes(List<Object> attributes) {
2201 this.attributes = attributes;
2206 private List<Object> fromZoneDatas;
2207 private List<Object> toZoneDatas;
2208 private List<Object> sourceListDatas;
2209 private List<Object> destinationListDatas;
2210 private List<Object> sourceServiceDatas;
2211 private List<Object> destinationServiceDatas;
2212 private List<Object> actionListDatas;
2213 public List<Object> getFromZoneDatas() {
2214 return fromZoneDatas;
2216 public void setFromZoneDatas(List<Object> fromZoneDatas) {
2217 this.fromZoneDatas = fromZoneDatas;
2219 public List<Object> getToZoneDatas() {
2222 public void setToZoneDatas(List<Object> toZoneDatas) {
2223 this.toZoneDatas = toZoneDatas;
2225 public List<Object> getSourceListDatas() {
2226 return sourceListDatas;
2228 public void setSourceListDatas(List<Object> sourceListDatas) {
2229 this.sourceListDatas = sourceListDatas;
2231 public List<Object> getDestinationListDatas() {
2232 return destinationListDatas;
2234 public void setDestinationListDatas(List<Object> destinationListDatas) {
2235 this.destinationListDatas = destinationListDatas;
2237 public List<Object> getSourceServiceDatas() {
2238 return sourceServiceDatas;
2240 public void setSourceServiceDatas(List<Object> sourceServiceDatas) {
2241 this.sourceServiceDatas = sourceServiceDatas;
2243 public List<Object> getDestinationServiceDatas() {
2244 return destinationServiceDatas;
2246 public void setDestinationServiceDatas(List<Object> destinationServiceDatas) {
2247 this.destinationServiceDatas = destinationServiceDatas;
2249 public List<Object> getActionListDatas() {
2250 return actionListDatas;
2252 public void setActionListDatas(List<Object> actionListDatas) {
2253 this.actionListDatas = actionListDatas;