2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
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.io.UnsupportedEncodingException;
26 import java.net.UnknownHostException;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.LinkedHashMap;
31 import java.util.List;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
37 import org.jboss.netty.handler.ipfilter.CIDR;
38 import org.json.JSONObject;
39 import org.onap.policy.common.logging.flexlogger.FlexLogger;
40 import org.onap.policy.common.logging.flexlogger.Logger;
41 import org.onap.policy.pap.xacml.rest.adapters.GridData;
42 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
43 import org.onap.policy.rest.dao.CommonClassDao;
44 import org.onap.policy.rest.jpa.ActionList;
45 import org.onap.policy.rest.jpa.AddressGroup;
46 import org.onap.policy.rest.jpa.FWTag;
47 import org.onap.policy.rest.jpa.FWTagPicker;
48 import org.onap.policy.rest.jpa.FirewallDictionaryList;
49 import org.onap.policy.rest.jpa.GroupServiceList;
50 import org.onap.policy.rest.jpa.PrefixList;
51 import org.onap.policy.rest.jpa.PortList;
52 import org.onap.policy.rest.jpa.ProtocolList;
53 import org.onap.policy.rest.jpa.SecurityZone;
54 import org.onap.policy.rest.jpa.ServiceList;
55 import org.onap.policy.rest.jpa.TermList;
56 import org.onap.policy.rest.jpa.UserInfo;
57 import org.onap.policy.rest.jpa.Zone;
58 import org.onap.policy.xacml.api.XACMLErrorConstants;
59 import org.springframework.beans.factory.annotation.Autowired;
60 import org.springframework.http.MediaType;
61 import org.springframework.stereotype.Controller;
62 import org.springframework.web.bind.annotation.RequestMapping;
63 import org.springframework.web.servlet.ModelAndView;
65 import com.fasterxml.jackson.databind.DeserializationFeature;
66 import com.fasterxml.jackson.databind.JsonNode;
67 import com.fasterxml.jackson.databind.ObjectMapper;
71 public class FirewallDictionaryController {
73 private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class);
75 private static CommonClassDao commonClassDao;
78 public FirewallDictionaryController(CommonClassDao commonClassDao){
79 FirewallDictionaryController.commonClassDao = commonClassDao;
82 public FirewallDictionaryController(){}
84 public UserInfo getUserInfo(String loginId){
85 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
90 @RequestMapping(value={"/get_PrefixListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
91 public void getPrefixListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
93 Map<String, Object> model = new HashMap<>();
94 ObjectMapper mapper = new ObjectMapper();
95 model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PrefixList.class, "prefixListName")));
96 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
97 JSONObject j = new JSONObject(msg);
98 response.getWriter().write(j.toString());
101 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
105 @RequestMapping(value={"/get_PrefixListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
106 public void getPrefixListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
108 Map<String, Object> model = new HashMap<>();
109 ObjectMapper mapper = new ObjectMapper();
110 model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)));
111 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
112 JSONObject j = new JSONObject(msg);
113 response.addHeader("successMapKey", "success");
114 response.addHeader("operation", "getDictionary");
115 response.getWriter().write(j.toString());
118 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e);
119 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
120 response.addHeader("error", "dictionaryDBQuery");
124 @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
125 public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
127 boolean duplicateflag = false;
128 boolean isFakeUpdate = false;
129 boolean fromAPI = false;
130 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
133 ObjectMapper mapper = new ObjectMapper();
134 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
135 JsonNode root = mapper.readTree(request.getReader());
136 PrefixList prefixList;
138 prefixList = (PrefixList)mapper.readValue(root.get("dictionaryFields").toString(), PrefixList.class);
140 //check if update operation or create, get id for data to be updated and update attributeData
141 if (request.getParameter("operation").equals("update")) {
142 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class);
144 PrefixList data = (PrefixList) duplicateData.get(0);
150 prefixList.setId(id);
154 prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
156 if(prefixList.getId() == 0){
157 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class);
158 if(!duplicateData.isEmpty()){
159 duplicateflag = true;
161 commonClassDao.save(prefixList);
165 commonClassDao.update(prefixList);
168 String responseString = "";
170 responseString = "Duplicate";
172 responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
176 if (responseString!=null && !responseString.equals("Duplicate")) {
178 responseString = "Exists";
180 responseString = "Success";
183 ModelAndView result = new ModelAndView();
184 result.setViewName(responseString);
187 response.setCharacterEncoding("UTF-8");
188 response.setContentType("application / json");
189 request.setCharacterEncoding("UTF-8");
191 PrintWriter out = response.getWriter();
192 JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}");
193 out.write(j.toString());
196 }catch (Exception e){
197 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e);
198 response.setCharacterEncoding("UTF-8");
199 request.setCharacterEncoding("UTF-8");
200 PrintWriter out = response.getWriter();
201 out.write(e.getMessage());
206 @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
207 public ModelAndView removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
209 ObjectMapper mapper = new ObjectMapper();
210 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
211 JsonNode root = mapper.readTree(request.getReader());
212 PrefixList prefixList = (PrefixList)mapper.readValue(root.get("data").toString(), PrefixList.class);
213 commonClassDao.delete(prefixList);
214 response.setCharacterEncoding("UTF-8");
215 response.setContentType("application / json");
216 request.setCharacterEncoding("UTF-8");
218 PrintWriter out = response.getWriter();
219 String responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
220 JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}");
221 out.write(j.toString());
225 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
226 response.setCharacterEncoding("UTF-8");
227 request.setCharacterEncoding("UTF-8");
228 PrintWriter out = response.getWriter();
229 out.write(e.getMessage());
234 @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
235 public ModelAndView validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
237 ObjectMapper mapper = new ObjectMapper();
238 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
239 JsonNode root = mapper.readTree(request.getReader());
240 PrefixList prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
241 String responseValidation = "success";
243 CIDR.newCIDR(prefixList.getPrefixListValue());
244 }catch(UnknownHostException e){
246 responseValidation = "error";
248 response.setCharacterEncoding("UTF-8");
249 response.setContentType("application / json");
250 request.setCharacterEncoding("UTF-8");
252 PrintWriter out = response.getWriter();
253 JSONObject j = new JSONObject("{result: " + responseValidation + "}");
254 out.write(j.toString());
258 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
259 response.setCharacterEncoding("UTF-8");
260 request.setCharacterEncoding("UTF-8");
261 PrintWriter out = response.getWriter();
262 out.write(e.getMessage());
267 @RequestMapping(value={"/get_PortListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
268 public void getPortListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
270 Map<String, Object> model = new HashMap<>();
271 ObjectMapper mapper = new ObjectMapper();
272 model.put("portListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PortList.class)));
273 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
274 JSONObject j = new JSONObject(msg);
275 response.addHeader("successMapKey", "success");
276 response.addHeader("operation", "getDictionary");
277 response.getWriter().write(j.toString());
280 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
281 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
282 response.addHeader("error", "dictionaryDBQuery");
286 @RequestMapping(value={"/fw_dictionary/save_portName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
287 public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
289 boolean duplicateflag = false;
290 ObjectMapper mapper = new ObjectMapper();
291 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
292 JsonNode root = mapper.readTree(request.getReader());
293 PortList portList = (PortList)mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class);
294 if(portList.getId() == 0){
295 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class);
296 if(!duplicateData.isEmpty()){
297 duplicateflag = true;
299 commonClassDao.save(portList);
302 commonClassDao.update(portList);
304 response.setCharacterEncoding("UTF-8");
305 response.setContentType("application / json");
306 request.setCharacterEncoding("UTF-8");
308 PrintWriter out = response.getWriter();
309 String responseString = "";
311 responseString = "Duplicate";
313 responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
315 JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}");
317 out.write(j.toString());
322 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
323 response.setCharacterEncoding("UTF-8");
324 request.setCharacterEncoding("UTF-8");
325 PrintWriter out = response.getWriter();
326 out.write(e.getMessage());
331 @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
332 public ModelAndView removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
334 ObjectMapper mapper = new ObjectMapper();
335 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
336 JsonNode root = mapper.readTree(request.getReader());
337 PortList portList = (PortList)mapper.readValue(root.get("data").toString(), PortList.class);
338 commonClassDao.delete(portList);
339 response.setCharacterEncoding("UTF-8");
340 response.setContentType("application / json");
341 request.setCharacterEncoding("UTF-8");
343 PrintWriter out = response.getWriter();
344 String responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
345 JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}");
346 out.write(j.toString());
350 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
351 response.setCharacterEncoding("UTF-8");
352 request.setCharacterEncoding("UTF-8");
353 PrintWriter out = response.getWriter();
354 out.write(e.getMessage());
359 @RequestMapping(value={"/get_ProtocolListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
360 public void getProtocolListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
362 Map<String, Object> model = new HashMap<String, Object>();
363 ObjectMapper mapper = new ObjectMapper();
364 model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)));
365 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
366 JSONObject j = new JSONObject(msg);
367 response.addHeader("successMapKey", "success");
368 response.addHeader("operation", "getDictionary");
369 response.getWriter().write(j.toString());
372 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
373 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
374 response.addHeader("error", "dictionaryDBQuery");
378 @RequestMapping(value={"/get_ProtocolListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
379 public void getProtocolListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
381 Map<String, Object> model = new HashMap<String, Object>();
382 ObjectMapper mapper = new ObjectMapper();
383 model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ProtocolList.class, "protocolName")));
384 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
385 JSONObject j = new JSONObject(msg);
386 response.getWriter().write(j.toString());
389 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
393 @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
394 public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
396 boolean duplicateflag = false;
397 boolean isFakeUpdate = false;
398 boolean fromAPI = false;
399 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
402 ObjectMapper mapper = new ObjectMapper();
403 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
404 JsonNode root = mapper.readTree(request.getReader());
405 ProtocolList protocolList;
407 protocolList = (ProtocolList)mapper.readValue(root.get("dictionaryFields").toString(), ProtocolList.class);
409 //check if update operation or create, get id for data to be updated and update attributeData
410 if (request.getParameter("operation").equals("update")) {
411 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class);
413 ProtocolList data = (ProtocolList) duplicateData.get(0);
417 protocolList.setId(1);
419 protocolList.setId(id);
423 protocolList = (ProtocolList)mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class);
425 if(protocolList.getId() == 0){
426 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class);
427 if(!duplicateData.isEmpty()){
428 duplicateflag = true;
430 commonClassDao.save(protocolList);
434 commonClassDao.update(protocolList);
437 String responseString = "";
439 responseString = "Duplicate";
441 responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
445 if (responseString!=null && !responseString.equals("Duplicate")) {
447 responseString = "Exists";
449 responseString = "Success";
452 ModelAndView result = new ModelAndView();
453 result.setViewName(responseString);
456 response.setCharacterEncoding("UTF-8");
457 response.setContentType("application / json");
458 request.setCharacterEncoding("UTF-8");
460 PrintWriter out = response.getWriter();
461 JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}");
462 out.write(j.toString());
465 }catch (Exception e){
466 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
467 response.setCharacterEncoding("UTF-8");
468 request.setCharacterEncoding("UTF-8");
469 PrintWriter out = response.getWriter();
470 out.write(e.getMessage());
475 @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
476 public ModelAndView removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
478 ObjectMapper mapper = new ObjectMapper();
479 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
480 JsonNode root = mapper.readTree(request.getReader());
481 ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("data").toString(), ProtocolList.class);
482 commonClassDao.delete(protocolList);
483 response.setCharacterEncoding("UTF-8");
484 response.setContentType("application / json");
485 request.setCharacterEncoding("UTF-8");
487 PrintWriter out = response.getWriter();
489 String responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
490 JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}");
491 out.write(j.toString());
495 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
496 response.setCharacterEncoding("UTF-8");
497 request.setCharacterEncoding("UTF-8");
498 PrintWriter out = response.getWriter();
499 out.write(e.getMessage());
504 @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
505 public void getAddressGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
507 Map<String, Object> model = new HashMap<>();
508 ObjectMapper mapper = new ObjectMapper();
509 model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(AddressGroup.class, "name")));
510 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
511 JSONObject j = new JSONObject(msg);
512 response.getWriter().write(j.toString());
515 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
519 @RequestMapping(value={"/get_AddressGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
520 public void getAddressGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
522 Map<String, Object> model = new HashMap<>();
523 ObjectMapper mapper = new ObjectMapper();
524 model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)));
525 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
526 JSONObject j = new JSONObject(msg);
527 response.addHeader("successMapKey", "success");
528 response.addHeader("operation", "getDictionary");
529 response.getWriter().write(j.toString());
532 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
533 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
534 response.addHeader("error", "dictionaryDBQuery");
538 @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
539 public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
541 boolean duplicateflag = false;
542 boolean isFakeUpdate = false;
543 boolean fromAPI = false;
544 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
547 ObjectMapper mapper = new ObjectMapper();
548 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
549 JsonNode root = mapper.readTree(request.getReader());
550 AddressGroup addressGroup;
553 addressGroup = (AddressGroup)mapper.readValue(root.get("dictionaryFields").toString(), AddressGroup.class);
554 gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
556 if(!addressGroup.getGroupName().startsWith("Group_")){
557 String groupName = "Group_"+addressGroup.getGroupName();
558 addressGroup.setGroupName(groupName);
561 //check if update operation or create, get id for data to be updated and update attributeData
562 if (request.getParameter("operation").equals("update")) {
563 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
565 AddressGroup data = (AddressGroup) duplicateData.get(0);
569 addressGroup.setId(1);
571 addressGroup.setId(id);
575 addressGroup = (AddressGroup)mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class);
576 gridData = (GridData)mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class);
577 if(!addressGroup.getGroupName().startsWith("Group_")){
578 String groupName = "Group_"+addressGroup.getGroupName();
579 addressGroup.setGroupName(groupName);
582 String userValue = "";
584 if(gridData.getAttributes().size() > 0){
585 for(Object attribute : gridData.getAttributes()){
586 if(attribute instanceof LinkedHashMap<?, ?>){
587 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
589 userValue = userValue + ",";
591 userValue = userValue + key ;
596 addressGroup.setServiceList(userValue);
597 if(addressGroup.getId() == 0){
598 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
599 if(!duplicateData.isEmpty()){
600 duplicateflag = true;
602 commonClassDao.save(addressGroup);
606 commonClassDao.update(addressGroup);
609 String responseString = "";
611 responseString = "Duplicate";
613 responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
616 if (responseString!=null && !responseString.equals("Duplicate")) {
618 responseString = "Exists";
620 responseString = "Success";
623 ModelAndView result = new ModelAndView();
624 result.setViewName(responseString);
627 response.setCharacterEncoding("UTF-8");
628 response.setContentType("application / json");
629 request.setCharacterEncoding("UTF-8");
631 PrintWriter out = response.getWriter();
632 JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}");
633 out.write(j.toString());
636 }catch (Exception e){
637 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
638 response.setCharacterEncoding("UTF-8");
639 request.setCharacterEncoding("UTF-8");
640 PrintWriter out = response.getWriter();
641 out.write(e.getMessage());
646 @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
647 public ModelAndView removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
649 ObjectMapper mapper = new ObjectMapper();
650 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
651 JsonNode root = mapper.readTree(request.getReader());
652 AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("data").toString(), AddressGroup.class);
653 commonClassDao.delete(addressGroup);
654 response.setCharacterEncoding("UTF-8");
655 response.setContentType("application / json");
656 request.setCharacterEncoding("UTF-8");
658 PrintWriter out = response.getWriter();
660 String responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
661 JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}");
662 out.write(j.toString());
666 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
667 response.setCharacterEncoding("UTF-8");
668 request.setCharacterEncoding("UTF-8");
669 PrintWriter out = response.getWriter();
670 out.write(e.getMessage());
675 @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
676 public void getActionListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
678 Map<String, Object> model = new HashMap<>();
679 ObjectMapper mapper = new ObjectMapper();
680 List<Object> list = commonClassDao.getData(ActionList.class);
681 List<String> dictList = new ArrayList<>();
682 for(int i = 0; i < list.size(); i++){
683 ActionList dict = (ActionList) list.get(i);
684 dictList.add(dict.getActionName());
686 model.put("actionListDictionaryDatas", mapper.writeValueAsString(dictList));
687 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
688 JSONObject j = new JSONObject(msg);
689 response.getWriter().write(j.toString());
692 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
696 @RequestMapping(value={"/get_ActionListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
697 public void getActionListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
699 Map<String, Object> model = new HashMap<>();
700 ObjectMapper mapper = new ObjectMapper();
701 model.put("actionListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ActionList.class)));
702 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
703 JSONObject j = new JSONObject(msg);
704 response.addHeader("successMapKey", "success");
705 response.addHeader("operation", "getDictionary");
706 response.getWriter().write(j.toString());
709 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
710 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
711 response.addHeader("error", "dictionaryDBQuery");
715 @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
716 public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
718 boolean duplicateflag = false;
719 boolean isFakeUpdate = false;
720 boolean fromAPI = false;
721 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
724 ObjectMapper mapper = new ObjectMapper();
725 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
726 JsonNode root = mapper.readTree(request.getReader());
727 ActionList actionList;
729 actionList = (ActionList)mapper.readValue(root.get("dictionaryFields").toString(), ActionList.class);
731 //check if update operation or create, get id for data to be updated and update attributeData
732 if (request.getParameter("operation").equals("update")) {
733 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
735 ActionList data = (ActionList) duplicateData.get(0);
741 actionList.setId(id);
745 actionList = (ActionList)mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class);
747 if(actionList.getId() == 0){
748 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
749 if(!duplicateData.isEmpty()){
750 duplicateflag = true;
752 commonClassDao.save(actionList);
756 commonClassDao.update(actionList);
759 String responseString = "";
761 responseString = "Duplicate";
763 responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
767 if (responseString!=null && !responseString.equals("Duplicate")) {
769 responseString = "Exists";
771 responseString = "Success";
774 ModelAndView result = new ModelAndView();
775 result.setViewName(responseString);
778 response.setCharacterEncoding("UTF-8");
779 response.setContentType("application / json");
780 request.setCharacterEncoding("UTF-8");
782 PrintWriter out = response.getWriter();
783 JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}");
784 out.write(j.toString());
787 }catch (Exception e){
788 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
789 response.setCharacterEncoding("UTF-8");
790 request.setCharacterEncoding("UTF-8");
791 PrintWriter out = response.getWriter();
792 out.write(e.getMessage());
797 @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
798 public ModelAndView removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
800 ObjectMapper mapper = new ObjectMapper();
801 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
802 JsonNode root = mapper.readTree(request.getReader());
803 ActionList actionList = (ActionList)mapper.readValue(root.get("data").toString(), ActionList.class);
804 commonClassDao.delete(actionList);
805 response.setCharacterEncoding("UTF-8");
806 response.setContentType("application / json");
807 request.setCharacterEncoding("UTF-8");
809 PrintWriter out = response.getWriter();
810 String responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
811 JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}");
812 out.write(j.toString());
816 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
817 response.setCharacterEncoding("UTF-8");
818 request.setCharacterEncoding("UTF-8");
819 PrintWriter out = response.getWriter();
820 out.write(e.getMessage());
825 @RequestMapping(value={"/get_ServiceGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
826 public void getServiceGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
828 Map<String, Object> model = new HashMap<>();
829 ObjectMapper mapper = new ObjectMapper();
830 model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)));
831 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
832 JSONObject j = new JSONObject(msg);
833 response.addHeader("successMapKey", "success");
834 response.addHeader("operation", "getDictionary");
835 response.getWriter().write(j.toString());
838 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
839 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
840 response.addHeader("error", "dictionaryDBQuery");
844 @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
845 public void getServiceGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
847 Map<String, Object> model = new HashMap<>();
848 ObjectMapper mapper = new ObjectMapper();
849 model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupServiceList.class, "name")));
850 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
851 JSONObject j = new JSONObject(msg);
852 response.getWriter().write(j.toString());
855 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
859 @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
860 public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
862 boolean duplicateflag = false;
863 boolean isFakeUpdate = false;
864 boolean fromAPI = false;
865 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
868 ObjectMapper mapper = new ObjectMapper();
869 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
870 JsonNode root = mapper.readTree(request.getReader());
871 GroupServiceList groupServiceList;
874 groupServiceList = (GroupServiceList)mapper.readValue(root.get("dictionaryFields").toString(), GroupServiceList.class);
875 gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
877 if(!groupServiceList.getGroupName().startsWith("Group_")){
878 String groupName = "Group_"+groupServiceList.getGroupName();
879 groupServiceList.setGroupName(groupName);
881 //check if update operation or create, get id for data to be updated and update attributeData
882 if (request.getParameter("operation").equals("update")) {
883 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
885 GroupServiceList data = (GroupServiceList) duplicateData.get(0);
890 groupServiceList.setId(1);
892 groupServiceList.setId(id);
896 groupServiceList = (GroupServiceList)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class);
897 gridData = (GridData)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class);
899 if(!groupServiceList.getGroupName().startsWith("Group_")){
900 String groupName = "Group_"+groupServiceList.getGroupName();
901 groupServiceList.setGroupName(groupName);
903 String userValue = "";
905 if(gridData.getAttributes().size() > 0){
906 for(Object attribute : gridData.getAttributes()){
907 if(attribute instanceof LinkedHashMap<?, ?>){
908 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
910 userValue = userValue + ",";
912 userValue = userValue + key ;
917 groupServiceList.setServiceList(userValue);
918 if(groupServiceList.getId() == 0){
919 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
920 if(!duplicateData.isEmpty()){
921 duplicateflag = true;
923 commonClassDao.save(groupServiceList);
927 commonClassDao.update(groupServiceList);
930 String responseString = "";
932 responseString = "Duplicate";
934 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
938 if (responseString!=null && !responseString.equals("Duplicate")) {
940 responseString = "Exists";
942 responseString = "Success";
945 ModelAndView result = new ModelAndView();
946 result.setViewName(responseString);
949 response.setCharacterEncoding("UTF-8");
950 response.setContentType("application / json");
951 request.setCharacterEncoding("UTF-8");
953 PrintWriter out = response.getWriter();
954 JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}");
955 out.write(j.toString());
958 }catch (Exception e){
959 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
960 response.setCharacterEncoding("UTF-8");
961 request.setCharacterEncoding("UTF-8");
962 PrintWriter out = response.getWriter();
963 out.write(e.getMessage());
968 @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
969 public ModelAndView removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
971 ObjectMapper mapper = new ObjectMapper();
972 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
973 JsonNode root = mapper.readTree(request.getReader());
974 GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("data").toString(), GroupServiceList.class);
975 commonClassDao.delete(groupServiceList);
976 response.setCharacterEncoding("UTF-8");
977 response.setContentType("application / json");
978 request.setCharacterEncoding("UTF-8");
980 PrintWriter out = response.getWriter();
982 String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
983 JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}");
984 out.write(j.toString());
989 System.out.println(e);
990 response.setCharacterEncoding("UTF-8");
991 request.setCharacterEncoding("UTF-8");
992 PrintWriter out = response.getWriter();
993 out.write(e.getMessage());
998 @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
999 public void getSecurityZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1001 Map<String, Object> model = new HashMap<>();
1002 ObjectMapper mapper = new ObjectMapper();
1003 model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(SecurityZone.class, "zoneName")));
1004 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1005 JSONObject j = new JSONObject(msg);
1006 response.getWriter().write(j.toString());
1008 catch (Exception e){
1009 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1013 @RequestMapping(value={"/get_SecurityZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1014 public void getSecurityZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1016 Map<String, Object> model = new HashMap<>();
1017 ObjectMapper mapper = new ObjectMapper();
1018 model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)));
1019 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1020 JSONObject j = new JSONObject(msg);
1021 response.addHeader("successMapKey", "success");
1022 response.addHeader("operation", "getDictionary");
1023 response.getWriter().write(j.toString());
1025 catch (Exception e){
1026 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1027 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1028 response.addHeader("error", "dictionaryDBQuery");
1032 @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1033 public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1035 boolean duplicateflag = false;
1036 boolean isFakeUpdate = false;
1037 boolean fromAPI = false;
1038 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1041 ObjectMapper mapper = new ObjectMapper();
1042 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1043 JsonNode root = mapper.readTree(request.getReader());
1044 SecurityZone securityZone;
1046 securityZone = (SecurityZone)mapper.readValue(root.get("dictionaryFields").toString(), SecurityZone.class);
1048 //check if update operation or create, get id for data to be updated and update attributeData
1049 if (request.getParameter("operation").equals("update")) {
1050 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class);
1052 SecurityZone data = (SecurityZone) duplicateData.get(0);
1056 securityZone.setId(1);
1058 securityZone.setId(id);
1062 securityZone = (SecurityZone)mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class);
1064 if(securityZone.getId() == 0){
1065 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class);
1066 if(!duplicateData.isEmpty()){
1067 duplicateflag = true;
1069 commonClassDao.save(securityZone);
1073 commonClassDao.update(securityZone);
1076 String responseString = "";
1078 responseString = "Duplicate";
1080 responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
1084 if (responseString!=null && !responseString.equals("Duplicate")) {
1086 responseString = "Exists";
1088 responseString = "Success";
1091 ModelAndView result = new ModelAndView();
1092 result.setViewName(responseString);
1095 response.setCharacterEncoding("UTF-8");
1096 response.setContentType("application / json");
1097 request.setCharacterEncoding("UTF-8");
1099 PrintWriter out = response.getWriter();
1100 JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}");
1101 out.write(j.toString());
1105 }catch (Exception e){
1106 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1107 response.setCharacterEncoding("UTF-8");
1108 request.setCharacterEncoding("UTF-8");
1109 PrintWriter out = response.getWriter();
1110 out.write(e.getMessage());
1115 @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1116 public ModelAndView removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
1118 ObjectMapper mapper = new ObjectMapper();
1119 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1120 JsonNode root = mapper.readTree(request.getReader());
1121 SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("data").toString(), SecurityZone.class);
1122 commonClassDao.delete(securityZone);
1123 response.setCharacterEncoding("UTF-8");
1124 response.setContentType("application / json");
1125 request.setCharacterEncoding("UTF-8");
1127 PrintWriter out = response.getWriter();
1129 String responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
1130 JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}");
1131 out.write(j.toString());
1135 catch (Exception e){
1136 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1137 response.setCharacterEncoding("UTF-8");
1138 request.setCharacterEncoding("UTF-8");
1139 PrintWriter out = response.getWriter();
1140 out.write(e.getMessage());
1146 @RequestMapping(value={"/get_ServiceListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1147 public void getServiceListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1149 Map<String, Object> model = new HashMap<>();
1150 ObjectMapper mapper = new ObjectMapper();
1151 model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)));
1152 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1153 JSONObject j = new JSONObject(msg);
1154 response.addHeader("successMapKey", "success");
1155 response.addHeader("operation", "getDictionary");
1156 response.getWriter().write(j.toString());
1158 catch (Exception e){
1159 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1160 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1161 response.addHeader("error", "dictionaryDBQuery");
1165 @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1166 public void getServiceListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1168 Map<String, Object> model = new HashMap<>();
1169 ObjectMapper mapper = new ObjectMapper();
1170 model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ServiceList.class, "serviceName")));
1171 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1172 JSONObject j = new JSONObject(msg);
1173 response.getWriter().write(j.toString());
1175 catch (Exception e){
1176 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1180 @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1181 public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1183 boolean duplicateflag = false;
1184 boolean isFakeUpdate = false;
1185 boolean fromAPI = false;
1186 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1189 ObjectMapper mapper = new ObjectMapper();
1190 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1191 JsonNode root = mapper.readTree(request.getReader());
1192 ServiceList serviceList;
1193 GridData serviceListGridData;
1195 serviceList = (ServiceList)mapper.readValue(root.get("dictionaryFields").toString(), ServiceList.class);
1196 serviceListGridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
1198 //check if update operation or create, get id for data to be updated and update attributeData
1199 if (request.getParameter("operation").equals("update")) {
1200 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class);
1202 ServiceList data = (ServiceList) duplicateData.get(0);
1206 serviceList.setId(1);
1208 serviceList.setId(id);
1212 serviceList = (ServiceList)mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class);
1213 serviceListGridData = (GridData)mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class);
1215 String tcpValue = "";
1217 if(serviceListGridData.getTransportProtocols().size() > 0){
1218 for(Object attribute : serviceListGridData.getTransportProtocols()){
1219 if(attribute instanceof LinkedHashMap<?, ?>){
1220 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1222 tcpValue = tcpValue + ",";
1224 tcpValue = tcpValue + key ;
1229 serviceList.setServiceTransProtocol(tcpValue);
1230 String appValue = "";
1232 if(serviceListGridData.getAppProtocols().size() > 0){
1233 for(Object attribute : serviceListGridData.getAppProtocols()){
1234 if(attribute instanceof LinkedHashMap<?, ?>){
1235 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1237 appValue = appValue + ",";
1239 appValue = appValue + key ;
1244 serviceList.setServiceAppProtocol(appValue);
1245 serviceList.setServiceType("SERVICE");
1246 if(serviceList.getId() == 0){
1247 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class);
1248 if(!duplicateData.isEmpty()){
1249 duplicateflag = true;
1251 commonClassDao.save(serviceList);
1255 commonClassDao.update(serviceList);
1259 String responseString = "";
1261 responseString = "Duplicate";
1263 responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
1266 if (responseString!=null && !responseString.equals("Duplicate")) {
1268 responseString = "Exists";
1270 responseString = "Success";
1273 ModelAndView result = new ModelAndView();
1274 result.setViewName(responseString);
1277 response.setCharacterEncoding("UTF-8");
1278 response.setContentType("application / json");
1279 request.setCharacterEncoding("UTF-8");
1281 PrintWriter out = response.getWriter();
1282 JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}");
1283 out.write(j.toString());
1286 }catch (Exception e){
1287 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1288 response.setCharacterEncoding("UTF-8");
1289 request.setCharacterEncoding("UTF-8");
1290 PrintWriter out = response.getWriter();
1291 out.write(e.getMessage());
1297 @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1298 public ModelAndView removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, 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 = (ServiceList)mapper.readValue(root.get("data").toString(), ServiceList.class);
1304 commonClassDao.delete(serviceList);
1305 response.setCharacterEncoding("UTF-8");
1306 response.setContentType("application / json");
1307 request.setCharacterEncoding("UTF-8");
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());
1317 catch (Exception e){
1318 System.out.println(e);
1319 response.setCharacterEncoding("UTF-8");
1320 request.setCharacterEncoding("UTF-8");
1321 PrintWriter out = response.getWriter();
1322 out.write(e.getMessage());
1327 @RequestMapping(value={"/get_ZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1328 public void getZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1330 Map<String, Object> model = new HashMap<>();
1331 ObjectMapper mapper = new ObjectMapper();
1332 model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Zone.class)));
1333 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1334 JSONObject j = new JSONObject(msg);
1335 response.addHeader("successMapKey", "success");
1336 response.addHeader("operation", "getDictionary");
1337 response.getWriter().write(j.toString());
1339 catch (Exception e){
1340 LOGGER.error("Exception Occured"+e);
1344 @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1345 public void getZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1347 Map<String, Object> model = new HashMap<>();
1348 ObjectMapper mapper = new ObjectMapper();
1349 model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Zone.class, "zoneName")));
1350 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1351 JSONObject j = new JSONObject(msg);
1352 response.getWriter().write(j.toString());
1354 catch (Exception e){
1355 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1359 @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1360 public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1362 boolean duplicateflag = false;
1363 boolean isFakeUpdate = false;
1364 boolean fromAPI = false;
1365 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1368 ObjectMapper mapper = new ObjectMapper();
1369 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1370 JsonNode root = mapper.readTree(request.getReader());
1373 zone = (Zone)mapper.readValue(root.get("dictionaryFields").toString(), Zone.class);
1375 //check if update operation or create, get id for data to be updated and update attributeData
1376 if (request.getParameter("operation").equals("update")) {
1377 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class);
1379 Zone data = (Zone) duplicateData.get(0);
1389 zone = (Zone)mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class);
1391 if(zone.getId() == 0){
1392 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class);
1393 if(!duplicateData.isEmpty()){
1394 duplicateflag = true;
1396 commonClassDao.save(zone);
1400 commonClassDao.update(zone);
1403 String responseString = "";
1405 responseString = "Duplicate";
1407 responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
1411 if (responseString!=null && !responseString.equals("Duplicate")) {
1413 responseString = "Exists";
1415 responseString = "Success";
1418 ModelAndView result = new ModelAndView();
1419 result.setViewName(responseString);
1422 response.setCharacterEncoding("UTF-8");
1423 response.setContentType("application / json");
1424 request.setCharacterEncoding("UTF-8");
1426 PrintWriter out = response.getWriter();
1427 JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}");
1428 out.write(j.toString());
1431 }catch (Exception e){
1432 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1433 response.setCharacterEncoding("UTF-8");
1434 request.setCharacterEncoding("UTF-8");
1435 PrintWriter out = response.getWriter();
1436 out.write(e.getMessage());
1441 @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1442 public ModelAndView removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1444 ObjectMapper mapper = new ObjectMapper();
1445 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1446 JsonNode root = mapper.readTree(request.getReader());
1447 Zone zone = (Zone)mapper.readValue(root.get("data").toString(), Zone.class);
1448 commonClassDao.delete(zone);
1449 response.setCharacterEncoding("UTF-8");
1450 response.setContentType("application / json");
1451 request.setCharacterEncoding("UTF-8");
1453 PrintWriter out = response.getWriter();
1455 String responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
1456 JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}");
1457 out.write(j.toString());
1461 catch (Exception e){
1462 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1463 response.setCharacterEncoding("UTF-8");
1464 request.setCharacterEncoding("UTF-8");
1465 PrintWriter out = response.getWriter();
1466 out.write(e.getMessage());
1471 @RequestMapping(value={"/get_TermListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1472 public void getTermListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1474 Map<String, Object> model = new HashMap<String, Object>();
1475 ObjectMapper mapper = new ObjectMapper();
1476 model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(TermList.class, "termName")));
1477 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1478 JSONObject j = new JSONObject(msg);
1479 response.getWriter().write(j.toString());
1481 catch (Exception e){
1482 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1486 @RequestMapping(value={"/get_TermListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1487 public void getTermListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1489 Map<String, Object> model = new HashMap<String, Object>();
1490 ObjectMapper mapper = new ObjectMapper();
1491 model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(TermList.class)));
1492 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1493 JSONObject j = new JSONObject(msg);
1494 response.addHeader("successMapKey", "success");
1495 response.addHeader("operation", "getDictionary");
1496 response.getWriter().write(j.toString());
1498 catch (Exception e){
1499 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1500 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1501 response.addHeader("error", "dictionaryDBQuery");
1505 @RequestMapping(value={"/fw_dictionary/save_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1506 public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1508 boolean duplicateflag = false;
1509 boolean isFakeUpdate = false;
1510 boolean fromAPI = false;
1511 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1514 ObjectMapper mapper = new ObjectMapper();
1515 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1516 JsonNode root = mapper.readTree(request.getReader());
1518 TermListData termListDatas;
1519 String userId = null;
1521 termList = (TermList)mapper.readValue(root.get("dictionaryFields").toString(), TermList.class);
1522 termListDatas = (TermListData)mapper.readValue(root.get("dictionaryFields").toString(), TermListData.class);
1525 //check if update operation or create, get id for data to be updated and update attributeData
1526 if (request.getParameter("operation").equals("update")) {
1527 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class);
1529 TermList data = (TermList) duplicateData.get(0);
1537 termList.setUserCreatedBy(this.getUserInfo(userId));
1540 termList = (TermList)mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class);
1541 termListDatas = (TermListData)mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class);
1542 userId = root.get("userid").textValue();
1544 String fromZoneValue = "";
1546 if(termListDatas.getFromZoneDatas().size() > 0){
1547 for(Object fromZone : termListDatas.getFromZoneDatas()){
1548 if(fromZone instanceof LinkedHashMap<?, ?>){
1549 String key = ((LinkedHashMap<?, ?>) fromZone).get("option").toString();
1551 fromZoneValue = fromZoneValue + ",";
1553 fromZoneValue = fromZoneValue + key ;
1558 termList.setFromZones(fromZoneValue);
1560 String toZoneValue = "";
1561 int toZonecounter = 0;
1562 if(termListDatas.getToZoneDatas().size() > 0){
1563 for(Object toZone : termListDatas.getToZoneDatas()){
1564 if(toZone instanceof LinkedHashMap<?, ?>){
1565 String key = ((LinkedHashMap<?, ?>) toZone).get("option").toString();
1566 if(toZonecounter>0){
1567 toZoneValue = toZoneValue + ",";
1569 toZoneValue = toZoneValue + key ;
1574 termList.setToZones(toZoneValue);
1576 String srcListValues = "";
1577 int srcListcounter = 0;
1578 if(termListDatas.getSourceListDatas().size() > 0){
1579 for(Object srcList : termListDatas.getSourceListDatas()){
1580 if(srcList instanceof LinkedHashMap<?, ?>){
1581 String key = ((LinkedHashMap<?, ?>) srcList).get("option").toString();
1582 if(srcListcounter>0){
1583 srcListValues = srcListValues + ",";
1585 srcListValues = srcListValues + key ;
1590 termList.setSrcIPList(srcListValues);
1592 String desListValues = "";
1593 int destListcounter = 0;
1594 if(termListDatas.getDestinationListDatas().size() > 0){
1595 for(Object desList : termListDatas.getDestinationListDatas()){
1596 if(desList instanceof LinkedHashMap<?, ?>){
1597 String key = ((LinkedHashMap<?, ?>) desList).get("option").toString();
1598 if(destListcounter>0){
1599 desListValues = desListValues + ",";
1601 desListValues = desListValues + key ;
1606 termList.setDestIPList(desListValues);
1608 String srcSerValue = "";
1609 int srcSercounter = 0;
1610 if(termListDatas.getSourceServiceDatas().size() > 0){
1611 for(Object srcSrc : termListDatas.getSourceServiceDatas()){
1612 if(srcSrc instanceof LinkedHashMap<?, ?>){
1613 String key = ((LinkedHashMap<?, ?>) srcSrc).get("option").toString();
1614 if(srcSercounter>0){
1615 srcSerValue = srcSerValue + ",";
1617 srcSerValue = srcSerValue + key ;
1622 termList.setSrcPortList(srcSerValue);
1624 String desSrcValue = "";
1625 int desSrccounter = 0;
1626 if(termListDatas.getDestinationServiceDatas().size() > 0){
1627 for(Object desSrc : termListDatas.getDestinationServiceDatas()){
1628 if(desSrc instanceof LinkedHashMap<?, ?>){
1629 String key = ((LinkedHashMap<?, ?>) desSrc).get("option").toString();
1630 if(desSrccounter>0){
1631 desSrcValue = desSrcValue + ",";
1633 desSrcValue = desSrcValue + key ;
1638 termList.setDestPortList(desSrcValue);
1640 String actionValue = "";
1641 int actioncounter = 0;
1642 if(termListDatas.getActionListDatas().size() > 0){
1643 for(Object actionList : termListDatas.getActionListDatas()){
1644 if(actionList instanceof LinkedHashMap<?, ?>){
1645 String key = ((LinkedHashMap<?, ?>) actionList).get("option").toString();
1646 if(actioncounter>0){
1647 actionValue = actionValue + ",";
1649 actionValue = actionValue + key ;
1654 termList.setAction(actionValue);
1656 if(termList.getId() == 0){
1657 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class);
1658 if(!duplicateData.isEmpty()){
1659 duplicateflag = true;
1661 termList.setUserCreatedBy(this.getUserInfo(userId));
1662 termList.setUserModifiedBy(this.getUserInfo(userId));
1663 commonClassDao.save(termList);
1667 termList.setUserModifiedBy(this.getUserInfo(userId));
1668 commonClassDao.update(termList);
1671 String responseString = "";
1673 responseString = "Duplicate";
1675 responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
1679 if (responseString!=null && !responseString.equals("Duplicate")) {
1681 responseString = "Exists";
1683 responseString = "Success";
1686 ModelAndView result = new ModelAndView();
1687 result.setViewName(responseString);
1690 response.setCharacterEncoding("UTF-8");
1691 response.setContentType("application / json");
1692 request.setCharacterEncoding("UTF-8");
1694 PrintWriter out = response.getWriter();
1695 JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}");
1696 out.write(j.toString());
1699 }catch (Exception e){
1700 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1701 response.setCharacterEncoding("UTF-8");
1702 request.setCharacterEncoding("UTF-8");
1703 PrintWriter out = response.getWriter();
1704 out.write(e.getMessage());
1709 @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1710 public ModelAndView removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1712 ObjectMapper mapper = new ObjectMapper();
1713 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1714 JsonNode root = mapper.readTree(request.getReader());
1715 TermList termList = (TermList)mapper.readValue(root.get("data").toString(), TermList.class);
1716 commonClassDao.delete(termList);
1717 response.setCharacterEncoding("UTF-8");
1718 response.setContentType("application / json");
1719 request.setCharacterEncoding("UTF-8");
1721 PrintWriter out = response.getWriter();
1723 String responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
1724 JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}");
1725 out.write(j.toString());
1729 catch (Exception e){
1730 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1731 response.setCharacterEncoding("UTF-8");
1732 request.setCharacterEncoding("UTF-8");
1733 PrintWriter out = response.getWriter();
1734 out.write(e.getMessage());
1738 //ParentList Dictionary Data
1739 @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1740 public void getFWDictListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1742 Map<String, Object> model = new HashMap<>();
1743 ObjectMapper mapper = new ObjectMapper();
1744 model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FirewallDictionaryList.class, "parentItemName")));
1745 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1746 JSONObject j = new JSONObject(msg);
1747 response.getWriter().write(j.toString());
1749 catch (Exception e){
1750 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1754 @RequestMapping(value={"/get_FWDictionaryListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1755 public void getFWDictionaryListEntityData(HttpServletRequest request, HttpServletResponse response){
1757 Map<String, Object> model = new HashMap<>();
1758 ObjectMapper mapper = new ObjectMapper();
1759 model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)));
1760 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1761 JSONObject j = new JSONObject(msg);
1762 response.addHeader("successMapKey", "success");
1763 response.addHeader("operation", "getDictionary");
1764 response.getWriter().write(j.toString());
1766 catch (Exception e){
1767 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1768 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
1769 response.addHeader("error", "dictionaryDBQuery");
1773 @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1774 public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1776 boolean duplicateflag = false;
1777 ObjectMapper mapper = new ObjectMapper();
1778 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1779 JsonNode root = mapper.readTree(request.getReader());
1780 FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class);
1781 GridData gridData = (GridData)mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class);
1782 String userSLValue = "";
1784 if(gridData.getAttributes().size() > 0){
1785 for(Object attribute : gridData.getAttributes()){
1786 if(attribute instanceof LinkedHashMap<?, ?>){
1787 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1789 userSLValue = userSLValue + ",";
1791 userSLValue = userSLValue + key ;
1796 fwDictList.setServiceList(userSLValue);
1797 String userALValue = "";
1799 if(gridData.getAlAttributes().size() > 0){
1800 for(Object attribute : gridData.getAlAttributes()){
1801 if(attribute instanceof LinkedHashMap<?, ?>){
1802 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1804 userALValue = userALValue + ",";
1806 userALValue = userALValue + key ;
1811 fwDictList.setAddressList(userALValue);
1812 if(fwDictList.getId() == 0){
1813 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class);
1814 if(!duplicateData.isEmpty()){
1815 duplicateflag = true;
1817 commonClassDao.save(fwDictList);
1820 commonClassDao.update(fwDictList);
1822 response.setCharacterEncoding("UTF-8");
1823 response.setContentType("application / json");
1824 request.setCharacterEncoding("UTF-8");
1826 PrintWriter out = response.getWriter();
1827 String responseString = "";
1829 responseString = "Duplicate";
1831 responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1833 JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}");
1835 out.write(j.toString());
1839 catch (Exception e){
1840 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1841 response.setCharacterEncoding("UTF-8");
1842 request.setCharacterEncoding("UTF-8");
1843 PrintWriter out = response.getWriter();
1844 out.write(e.getMessage());
1849 @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1850 public ModelAndView removeFWDictionaryListy(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
1852 ObjectMapper mapper = new ObjectMapper();
1853 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1854 JsonNode root = mapper.readTree(request.getReader());
1855 FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("data").toString(), FirewallDictionaryList.class);
1856 commonClassDao.delete(fwDictList);
1857 response.setCharacterEncoding("UTF-8");
1858 response.setContentType("application / json");
1859 request.setCharacterEncoding("UTF-8");
1861 PrintWriter out = response.getWriter();
1863 String responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
1864 JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}");
1865 out.write(j.toString());
1869 catch (Exception e){
1870 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1871 response.setCharacterEncoding("UTF-8");
1872 request.setCharacterEncoding("UTF-8");
1873 PrintWriter out = response.getWriter();
1874 out.write(e.getMessage());
1880 @RequestMapping(value={"/get_TagPickerNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1881 public void getTagPickerNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){
1883 Map<String, Object> model = new HashMap<String, Object>();
1884 ObjectMapper mapper = new ObjectMapper();
1885 model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTagPicker.class, "tagPickerName")));
1886 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1887 JSONObject j = new JSONObject(msg);
1888 response.getWriter().write(j.toString());
1890 catch (Exception e){
1891 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1895 @RequestMapping(value={"/get_TagPickerListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1896 public void getTagPickerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
1898 Map<String, Object> model = new HashMap<String, Object>();
1899 ObjectMapper mapper = new ObjectMapper();
1900 model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)));
1901 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1902 JSONObject j = new JSONObject(msg);
1903 response.getWriter().write(j.toString());
1905 catch (Exception e){
1906 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1910 @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1911 public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
1913 boolean duplicateflag = false;
1914 boolean fromAPI = false;
1915 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
1919 ObjectMapper mapper = new ObjectMapper();
1920 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1921 JsonNode root = mapper.readTree(request.getReader());
1924 FWTagPicker fwTagPicker;
1926 String userId = null;
1928 fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
1929 data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
1932 //check if update operation or create, get id for data to be updated and update attributeData
1933 if (request.getParameter("operation").equals("update")) {
1934 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class);
1936 FWTagPicker dbdata = (FWTagPicker) duplicateData.get(0);
1937 id = dbdata.getId();
1938 fwTagPicker.setId(id);
1939 fwTagPicker.setUserCreatedBy(this.getUserInfo(userId));
1943 fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
1944 data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
1945 userId = root.get("userid").textValue();
1950 if(data.getTags().size() > 0){
1951 for(Object attribute : data.getTags()){
1952 if(attribute instanceof LinkedHashMap<?, ?>){
1953 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
1954 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
1956 header = header + "#";
1958 header = header + key + ":";
1959 header = header + value;
1964 fwTagPicker.setTagValues(header);
1965 if(fwTagPicker.getId() == 0){
1966 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class);
1967 if(!duplicateData.isEmpty()){
1968 duplicateflag = true;
1970 fwTagPicker.setUserCreatedBy(this.getUserInfo(userId));
1971 fwTagPicker.setUserModifiedBy(this.getUserInfo(userId));
1972 commonClassDao.save(fwTagPicker);
1975 fwTagPicker.setUserModifiedBy(this.getUserInfo(userId));
1976 fwTagPicker.setModifiedDate(new Date());
1977 commonClassDao.update(fwTagPicker);
1980 String responseString = "";
1982 responseString = "Duplicate";
1984 responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
1988 if (responseString!=null && !responseString.equals("Duplicate")) {
1989 responseString = "Success";
1991 ModelAndView result = new ModelAndView();
1992 result.setViewName(responseString);
1995 response.setCharacterEncoding("UTF-8");
1996 response.setContentType("application / json");
1997 request.setCharacterEncoding("UTF-8");
1999 PrintWriter out = response.getWriter();
2000 JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
2001 out.write(j.toString());
2005 catch (Exception e){
2006 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2007 response.setCharacterEncoding("UTF-8");
2008 request.setCharacterEncoding("UTF-8");
2009 PrintWriter out = response.getWriter();
2010 out.write(e.getMessage());
2015 @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2016 public ModelAndView removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
2018 ObjectMapper mapper = new ObjectMapper();
2019 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2020 JsonNode root = mapper.readTree(request.getReader());
2021 FWTagPicker fwTagPicker = (FWTagPicker)mapper.readValue(root.get("data").toString(), FWTagPicker.class);
2022 commonClassDao.delete(fwTagPicker);
2023 response.setCharacterEncoding("UTF-8");
2024 response.setContentType("application / json");
2025 request.setCharacterEncoding("UTF-8");
2027 PrintWriter out = response.getWriter();
2028 String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
2029 JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}");
2030 out.write(j.toString());
2033 catch (Exception e){
2034 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2035 response.setCharacterEncoding("UTF-8");
2036 request.setCharacterEncoding("UTF-8");
2037 PrintWriter out = response.getWriter();
2038 out.write(e.getMessage());
2044 @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
2045 public void getTagNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){
2047 Map<String, Object> model = new HashMap<>();
2048 ObjectMapper mapper = new ObjectMapper();
2049 model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName")));
2050 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
2051 JSONObject j = new JSONObject(msg);
2052 response.getWriter().write(j.toString());
2054 catch (Exception e){
2055 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2059 @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
2060 public void getTagDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
2062 Map<String, Object> model = new HashMap<>();
2063 ObjectMapper mapper = new ObjectMapper();
2064 model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTag.class)));
2065 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
2066 JSONObject j = new JSONObject(msg);
2067 response.getWriter().write(j.toString());
2069 catch (Exception e){
2070 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2074 @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2075 public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
2077 boolean duplicateflag = false;
2078 boolean fromAPI = false;
2079 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
2083 ObjectMapper mapper = new ObjectMapper();
2084 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2085 JsonNode root = mapper.readTree(request.getReader());
2089 TagGridValues tagGridValues;
2090 String userId = null;
2092 fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), FWTag.class);
2093 tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), TagGridValues.class);
2096 //check if update operation or create, get id for data to be updated and update attributeData
2097 if (request.getParameter("operation").equals("update")) {
2098 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "tagName", FWTag.class);
2100 FWTag data = (FWTag) duplicateData.get(0);
2103 fwTag.setUserCreatedBy(this.getUserInfo(userId));
2107 fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
2108 tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class);
2109 userId = root.get("userid").textValue();
2112 String userValue = "";
2114 if(tagGridValues.getTags().size() > 0){
2115 for(Object attribute : tagGridValues.getTags()){
2116 if(attribute instanceof LinkedHashMap<?, ?>){
2117 String key = ((LinkedHashMap<?, ?>) attribute).get("tags").toString();
2119 userValue = userValue + ",";
2121 userValue = userValue + key ;
2126 fwTag.setTagValues(userValue);
2127 if(fwTag.getId() == 0){
2128 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
2129 if(!duplicateData.isEmpty()){
2130 duplicateflag = true;
2132 fwTag.setUserCreatedBy(this.getUserInfo(userId));
2133 fwTag.setUserModifiedBy(this.getUserInfo(userId));
2134 commonClassDao.save(fwTag);
2137 fwTag.setUserModifiedBy(this.getUserInfo(userId));
2138 fwTag.setModifiedDate(new Date());
2139 commonClassDao.update(fwTag);
2142 String responseString = "";
2144 responseString = "Duplicate";
2146 responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
2149 if (responseString!=null && !responseString.equals("Duplicate")) {
2150 responseString = "Success";
2152 ModelAndView result = new ModelAndView();
2153 result.setViewName(responseString);
2157 response.setCharacterEncoding("UTF-8");
2158 response.setContentType("application / json");
2159 request.setCharacterEncoding("UTF-8");
2161 PrintWriter out = response.getWriter();
2162 JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
2163 out.write(j.toString());
2167 catch (Exception e){
2168 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2169 response.setCharacterEncoding("UTF-8");
2170 request.setCharacterEncoding("UTF-8");
2171 PrintWriter out = response.getWriter();
2172 out.write(e.getMessage());
2177 @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
2178 public ModelAndView removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
2180 ObjectMapper mapper = new ObjectMapper();
2181 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2182 JsonNode root = mapper.readTree(request.getReader());
2183 FWTag fwTag = (FWTag)mapper.readValue(root.get("data").toString(), FWTag.class);
2184 commonClassDao.delete(fwTag);
2185 response.setCharacterEncoding("UTF-8");
2186 response.setContentType("application / json");
2187 request.setCharacterEncoding("UTF-8");
2189 PrintWriter out = response.getWriter();
2191 String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
2192 JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}");
2193 out.write(j.toString());
2197 catch (Exception e){
2198 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
2199 response.setCharacterEncoding("UTF-8");
2200 request.setCharacterEncoding("UTF-8");
2201 PrintWriter out = response.getWriter();
2202 out.write(e.getMessage());
2208 class TagGridValues{
2209 private ArrayList<Object> tags;
2211 public ArrayList<Object> getTags() {
2215 public void setTags(ArrayList<Object> tags) {
2221 private ArrayList<Object> attributes;
2223 public ArrayList<Object> getAttributes() {
2227 public void setAttributes(ArrayList<Object> attributes) {
2228 this.attributes = attributes;
2233 private ArrayList<Object> fromZoneDatas;
2234 private ArrayList<Object> toZoneDatas;
2235 private ArrayList<Object> sourceListDatas;
2236 private ArrayList<Object> destinationListDatas;
2237 private ArrayList<Object> sourceServiceDatas;
2238 private ArrayList<Object> destinationServiceDatas;
2239 private ArrayList<Object> actionListDatas;
2240 public ArrayList<Object> getFromZoneDatas() {
2241 return fromZoneDatas;
2243 public void setFromZoneDatas(ArrayList<Object> fromZoneDatas) {
2244 this.fromZoneDatas = fromZoneDatas;
2246 public ArrayList<Object> getToZoneDatas() {
2249 public void setToZoneDatas(ArrayList<Object> toZoneDatas) {
2250 this.toZoneDatas = toZoneDatas;
2252 public ArrayList<Object> getSourceListDatas() {
2253 return sourceListDatas;
2255 public void setSourceListDatas(ArrayList<Object> sourceListDatas) {
2256 this.sourceListDatas = sourceListDatas;
2258 public ArrayList<Object> getDestinationListDatas() {
2259 return destinationListDatas;
2261 public void setDestinationListDatas(ArrayList<Object> destinationListDatas) {
2262 this.destinationListDatas = destinationListDatas;
2264 public ArrayList<Object> getSourceServiceDatas() {
2265 return sourceServiceDatas;
2267 public void setSourceServiceDatas(ArrayList<Object> sourceServiceDatas) {
2268 this.sourceServiceDatas = sourceServiceDatas;
2270 public ArrayList<Object> getDestinationServiceDatas() {
2271 return destinationServiceDatas;
2273 public void setDestinationServiceDatas(ArrayList<Object> destinationServiceDatas) {
2274 this.destinationServiceDatas = destinationServiceDatas;
2276 public ArrayList<Object> getActionListDatas() {
2277 return actionListDatas;
2279 public void setActionListDatas(ArrayList<Object> actionListDatas) {
2280 this.actionListDatas = actionListDatas;