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.openecomp.policy.pap.xacml.rest.controller;
23 import java.io.PrintWriter;
24 import java.util.HashMap;
25 import java.util.LinkedHashMap;
26 import java.util.List;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
32 import org.json.JSONObject;
33 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
34 import org.openecomp.policy.common.logging.flexlogger.Logger;
35 import org.openecomp.policy.pap.xacml.rest.adapters.GridData;
36 import org.openecomp.policy.pap.xacml.rest.util.JsonMessage;
37 import org.openecomp.policy.rest.dao.CommonClassDao;
38 import org.openecomp.policy.rest.jpa.ClosedLoopD2Services;
39 import org.openecomp.policy.rest.jpa.ClosedLoopSite;
40 import org.openecomp.policy.rest.jpa.PEPOptions;
41 import org.openecomp.policy.rest.jpa.UserInfo;
42 import org.openecomp.policy.rest.jpa.VNFType;
43 import org.openecomp.policy.rest.jpa.VSCLAction;
44 import org.openecomp.policy.rest.jpa.VarbindDictionary;
45 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.http.MediaType;
48 import org.springframework.stereotype.Controller;
49 import org.springframework.web.bind.annotation.RequestMapping;
50 import org.springframework.web.servlet.ModelAndView;
52 import com.fasterxml.jackson.databind.DeserializationFeature;
53 import com.fasterxml.jackson.databind.JsonNode;
54 import com.fasterxml.jackson.databind.ObjectMapper;
57 public class ClosedLoopDictionaryController{
59 private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class);
61 private static CommonClassDao commonClassDao;
64 public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
65 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
68 public ClosedLoopDictionaryController(){}
70 public UserInfo getUserInfo(String loginId){
71 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
76 @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
77 public void getVSCLActionDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
79 Map<String, Object> model = new HashMap<>();
80 ObjectMapper mapper = new ObjectMapper();
81 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")));
82 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
83 JSONObject j = new JSONObject(msg);
84 response.getWriter().write(j.toString());
87 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
92 @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
93 public void getVSCLActionDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
95 Map<String, Object> model = new HashMap<>();
96 ObjectMapper mapper = new ObjectMapper();
97 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
98 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
99 JSONObject j = new JSONObject(msg);
100 response.addHeader("successMapKey", "success");
101 response.addHeader("operation", "getDictionary");
102 response.getWriter().write(j.toString());
105 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
106 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
107 response.addHeader("error", "dictionaryDBQuery");
111 @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
112 public void getVNFTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
114 Map<String, Object> model = new HashMap<>();
115 ObjectMapper mapper = new ObjectMapper();
116 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, "vnftype")));
117 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
118 JSONObject j = new JSONObject(msg);
119 response.addHeader("successMapKey", "success");
120 response.addHeader("operation", "getDictionary");
121 response.getWriter().write(j.toString());
124 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
128 @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
129 public void getVNFTypeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
131 Map<String, Object> model = new HashMap<>();
132 ObjectMapper mapper = new ObjectMapper();
133 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
134 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
135 JSONObject j = new JSONObject(msg);
136 response.addHeader("successMapKey", "success");
137 response.addHeader("operation", "getDictionary");
138 response.getWriter().write(j.toString());
141 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
142 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
143 response.addHeader("error", "dictionaryDBQuery");
147 @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
148 public void getPEPOptionsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
150 Map<String, Object> model = new HashMap<>();
151 ObjectMapper mapper = new ObjectMapper();
152 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")));
153 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
154 JSONObject j = new JSONObject(msg);
155 response.getWriter().write(j.toString());
158 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
162 @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
163 public void getPEPOptionsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
165 Map<String, Object> model = new HashMap<>();
166 ObjectMapper mapper = new ObjectMapper();
167 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
168 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
169 JSONObject j = new JSONObject(msg);
170 response.addHeader("successMapKey", "success");
171 response.addHeader("operation", "getDictionary");
172 response.getWriter().write(j.toString());
175 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
176 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
177 response.addHeader("error", "dictionaryDBQuery");
181 @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
182 public void getVarbindDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
184 Map<String, Object> model = new HashMap<>();
185 ObjectMapper mapper = new ObjectMapper();
186 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")));
187 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
188 JSONObject j = new JSONObject(msg);
189 response.getWriter().write(j.toString());
192 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
196 @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
197 public void getVarbindDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
199 Map<String, Object> model = new HashMap<>();
200 ObjectMapper mapper = new ObjectMapper();
201 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
202 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
203 JSONObject j = new JSONObject(msg);
204 response.addHeader("successMapKey", "success");
205 response.addHeader("operation", "getDictionary");
206 response.getWriter().write(j.toString());
209 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
210 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
211 response.addHeader("error", "dictionaryDBQuery");
215 @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
216 public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
218 Map<String, Object> model = new HashMap<>();
219 ObjectMapper mapper = new ObjectMapper();
220 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")));
221 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
222 JSONObject j = new JSONObject(msg);
223 response.getWriter().write(j.toString());
226 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
230 @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
231 public void getClosedLoopServiceDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
233 Map<String, Object> model = new HashMap<>();
234 ObjectMapper mapper = new ObjectMapper();
235 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
236 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
237 JSONObject j = new JSONObject(msg);
238 response.addHeader("successMapKey", "success");
239 response.addHeader("operation", "getDictionary");
240 response.getWriter().write(j.toString());
243 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
244 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
245 response.addHeader("error", "dictionaryDBQuery");
249 @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
250 public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
252 Map<String, Object> model = new HashMap<>();
253 ObjectMapper mapper = new ObjectMapper();
254 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")));
255 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
256 JSONObject j = new JSONObject(msg);
257 response.getWriter().write(j.toString());
260 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
264 @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
265 public void getClosedLoopSiteDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
267 Map<String, Object> model = new HashMap<>();
268 ObjectMapper mapper = new ObjectMapper();
269 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
270 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
271 JSONObject j = new JSONObject(msg);
272 response.addHeader("successMapKey", "success");
273 response.addHeader("operation", "getDictionary");
274 response.getWriter().write(j.toString());
277 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
278 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
279 response.addHeader("error", "dictionaryDBQuery");
283 @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
284 public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{
286 boolean duplicateflag = false;
287 boolean isFakeUpdate = false;
288 boolean fromAPI = false;
289 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
292 ObjectMapper mapper = new ObjectMapper();
293 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
294 JsonNode root = mapper.readTree(request.getReader());
295 VSCLAction vSCLAction;
296 String userId = null;
298 vSCLAction = (VSCLAction)mapper.readValue(root.get("dictionaryFields").toString(), VSCLAction.class);
301 //check if update operation or create, get id for data to be updated and update attributeData
302 if (request.getParameter("operation").equals("update")) {
303 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class);
305 VSCLAction data = (VSCLAction) duplicateData.get(0);
311 vSCLAction.setId(id);
314 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
318 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
319 userId = root.get("userid").textValue();
321 if(vSCLAction.getId() == 0){
322 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class);
323 if(!duplicateData.isEmpty()){
324 duplicateflag = true;
326 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
327 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
328 commonClassDao.save(vSCLAction);
332 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
333 commonClassDao.update(vSCLAction);
337 String responseString = "";
339 responseString = "Duplicate";
341 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
344 if (responseString!=null && !responseString.equals("Duplicate")) {
346 responseString = "Exists";
348 responseString = "Success";
352 ModelAndView result = new ModelAndView();
353 result.setViewName(responseString);
356 response.setCharacterEncoding("UTF-8");
357 response.setContentType("application / json");
358 request.setCharacterEncoding("UTF-8");
360 PrintWriter out = response.getWriter();
361 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
362 out.write(j.toString());
367 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
368 response.setCharacterEncoding("UTF-8");
369 request.setCharacterEncoding("UTF-8");
370 PrintWriter out = response.getWriter();
371 out.write(e.getMessage());
376 @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
377 public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
379 ObjectMapper mapper = new ObjectMapper();
380 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
381 JsonNode root = mapper.readTree(request.getReader());
382 VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
383 commonClassDao.delete(vSCLAction);
384 response.setCharacterEncoding("UTF-8");
385 response.setContentType("application / json");
386 request.setCharacterEncoding("UTF-8");
388 PrintWriter out = response.getWriter();
390 String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
391 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
392 out.write(j.toString());
397 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
398 response.setCharacterEncoding("UTF-8");
399 request.setCharacterEncoding("UTF-8");
400 PrintWriter out = response.getWriter();
401 out.write(e.getMessage());
406 @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
407 public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{
409 boolean duplicateflag = false;
410 boolean isFakeUpdate = false;
411 boolean fromAPI = false;
413 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
416 ObjectMapper mapper = new ObjectMapper();
417 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
418 JsonNode root = mapper.readTree(request.getReader());
420 String userId = null;
423 vNFType = (VNFType)mapper.readValue(root.get("dictionaryFields").toString(), VNFType.class);
426 //check if update operation or create, get id for data to be updated and update attributeData
427 if (request.getParameter("operation").equals("update")) {
428 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class);
430 VNFType data = (VNFType) duplicateData.get(0);
438 vNFType.setUserCreatedBy(this.getUserInfo(userId));
441 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
442 userId = root.get("userid").textValue();
444 if(vNFType.getId() == 0){
445 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class);
446 if(!duplicateData.isEmpty()){
447 duplicateflag = true;
449 vNFType.setUserCreatedBy(this.getUserInfo(userId));
450 vNFType.setUserModifiedBy(this.getUserInfo(userId));
451 commonClassDao.save(vNFType);
455 vNFType.setUserModifiedBy(this.getUserInfo(userId));
456 commonClassDao.update(vNFType);
459 String responseString = "";
461 responseString = "Duplicate";
463 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
466 if (responseString!=null && !responseString.equals("Duplicate")) {
468 responseString = "Exists";
470 responseString = "Success";
473 ModelAndView result = new ModelAndView();
474 result.setViewName(responseString);
477 response.setCharacterEncoding("UTF-8");
478 response.setContentType("application / json");
479 request.setCharacterEncoding("UTF-8");
481 PrintWriter out = response.getWriter();
482 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
483 out.write(j.toString());
488 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
489 response.setCharacterEncoding("UTF-8");
490 request.setCharacterEncoding("UTF-8");
491 PrintWriter out = response.getWriter();
492 out.write(e.getMessage());
497 @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
498 public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception {
500 ObjectMapper mapper = new ObjectMapper();
501 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
502 JsonNode root = mapper.readTree(request.getReader());
503 VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
504 commonClassDao.delete(vNFType);
505 response.setCharacterEncoding("UTF-8");
506 response.setContentType("application / json");
507 request.setCharacterEncoding("UTF-8");
509 PrintWriter out = response.getWriter();
511 String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
512 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
513 out.write(j.toString());
518 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
519 response.setCharacterEncoding("UTF-8");
520 request.setCharacterEncoding("UTF-8");
521 PrintWriter out = response.getWriter();
522 out.write(e.getMessage());
527 @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
528 public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{
530 boolean duplicateflag = false;
531 boolean isFakeUpdate = false;
532 boolean fromAPI = false;
533 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
536 ObjectMapper mapper = new ObjectMapper();
537 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
538 JsonNode root = mapper.readTree(request.getReader());
539 PEPOptions pEPOptions;
541 String userId = null;
543 pEPOptions = (PEPOptions)mapper.readValue(root.get("dictionaryFields").toString(), PEPOptions.class);
544 gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
547 //check if update operation or create, get id for data to be updated and update attributeData
548 if (request.getParameter("operation").equals("update")) {
549 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class);
551 PEPOptions data = (PEPOptions) duplicateData.get(0);
557 pEPOptions.setId(id);
559 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
562 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
563 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
564 userId = root.get("userid").textValue();
568 if(gridData.getAttributes().size() > 0){
569 for(Object attribute : gridData.getAttributes()){
570 if(attribute instanceof LinkedHashMap<?, ?>){
571 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
572 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
574 actions = actions + ":#@";
576 actions = actions + key + "=#@";
577 actions = actions + value;
582 pEPOptions.setActions(actions);
583 if(pEPOptions.getId() == 0){
584 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class);
585 if(!duplicateData.isEmpty()){
586 duplicateflag = true;
588 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
589 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
590 commonClassDao.save(pEPOptions);
594 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
595 commonClassDao.update(pEPOptions);
598 String responseString = "";
600 responseString = "Duplicate";
602 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
605 if (responseString!=null && !responseString.equals("Duplicate")) {
607 responseString = "Exists";
609 responseString = "Success";
613 ModelAndView result = new ModelAndView();
614 result.setViewName(responseString);
617 response.setCharacterEncoding("UTF-8");
618 response.setContentType("application / json");
619 request.setCharacterEncoding("UTF-8");
621 PrintWriter out = response.getWriter();
622 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
623 out.write(j.toString());
627 }catch (Exception e){
628 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
629 response.setCharacterEncoding("UTF-8");
630 request.setCharacterEncoding("UTF-8");
631 PrintWriter out = response.getWriter();
632 out.write(e.getMessage());
637 @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
638 public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception {
640 ObjectMapper mapper = new ObjectMapper();
641 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
642 JsonNode root = mapper.readTree(request.getReader());
643 PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
644 commonClassDao.delete(pEPOptions);
645 response.setCharacterEncoding("UTF-8");
646 response.setContentType("application / json");
647 request.setCharacterEncoding("UTF-8");
649 PrintWriter out = response.getWriter();
651 String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
652 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
653 out.write(j.toString());
658 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
659 response.setCharacterEncoding("UTF-8");
660 request.setCharacterEncoding("UTF-8");
661 PrintWriter out = response.getWriter();
662 out.write(e.getMessage());
667 @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
668 public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{
670 boolean duplicateflag = false;
671 boolean isFakeUpdate = false;
672 boolean fromAPI = false;
673 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
676 ObjectMapper mapper = new ObjectMapper();
677 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
678 JsonNode root = mapper.readTree(request.getReader());
679 ClosedLoopD2Services serviceData;
680 String userId = null;
682 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopD2Services.class);
685 //check if update operation or create, get id for data to be updated and update attributeData
686 if (request.getParameter("operation").equals("update")) {
687 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class);
689 ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
693 serviceData.setId(1);
695 serviceData.setId(id);
697 serviceData.setUserCreatedBy(this.getUserInfo(userId));
700 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
701 userId = root.get("userid").textValue();
703 if(serviceData.getId() == 0){
704 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class);
705 if(!duplicateData.isEmpty()){
706 duplicateflag = true;
708 serviceData.setUserCreatedBy(this.getUserInfo(userId));
709 serviceData.setUserModifiedBy(this.getUserInfo(userId));
710 commonClassDao.save(serviceData);
714 serviceData.setUserModifiedBy(this.getUserInfo(userId));
715 commonClassDao.update(serviceData);
718 String responseString = "";
720 responseString = "Duplicate";
722 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
725 if (responseString!=null && !responseString.equals("Duplicate")) {
727 responseString = "Exists";
729 responseString = "Success";
732 ModelAndView result = new ModelAndView();
733 result.setViewName(responseString);
736 response.setCharacterEncoding("UTF-8");
737 response.setContentType("application / json");
738 request.setCharacterEncoding("UTF-8");
740 PrintWriter out = response.getWriter();
741 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
742 out.write(j.toString());
745 }catch (Exception e){
746 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
747 response.setCharacterEncoding("UTF-8");
748 request.setCharacterEncoding("UTF-8");
749 PrintWriter out = response.getWriter();
750 out.write(e.getMessage());
755 @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
756 public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception {
758 ObjectMapper mapper = new ObjectMapper();
759 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
760 JsonNode root = mapper.readTree(request.getReader());
761 ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
762 commonClassDao.delete(closedLoopD2Services);
763 response.setCharacterEncoding("UTF-8");
764 response.setContentType("application / json");
765 request.setCharacterEncoding("UTF-8");
767 PrintWriter out = response.getWriter();
769 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
770 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
771 out.write(j.toString());
776 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
777 response.setCharacterEncoding("UTF-8");
778 request.setCharacterEncoding("UTF-8");
779 PrintWriter out = response.getWriter();
780 out.write(e.getMessage());
785 @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
786 public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{
788 boolean duplicateflag = false;
789 boolean isFakeUpdate = false;
790 boolean fromAPI = false;
792 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
795 ObjectMapper mapper = new ObjectMapper();
796 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
797 JsonNode root = mapper.readTree(request.getReader());
798 ClosedLoopSite siteData;
799 String userId = null;
801 siteData = (ClosedLoopSite)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopSite.class);
803 //check if update operation or create, get id for data to be updated and update attributeData
804 if (request.getParameter("operation").equals("update")) {
805 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class);
807 ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
815 siteData.setUserCreatedBy(this.getUserInfo(userId));
818 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
819 userId = root.get("userid").textValue();
821 if(siteData.getId() == 0){
822 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class);
823 if(!duplicateData.isEmpty()){
824 duplicateflag = true;
826 siteData.setUserCreatedBy(this.getUserInfo(userId));
827 siteData.setUserModifiedBy(this.getUserInfo(userId));
828 commonClassDao.save(siteData);
832 siteData.setUserModifiedBy(this.getUserInfo(userId));
833 commonClassDao.update(siteData);
836 String responseString = "";
838 responseString = "Duplicate";
840 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
844 if (responseString!=null && !responseString.equals("Duplicate")) {
846 responseString = "Exists";
848 responseString = "Success";
851 ModelAndView result = new ModelAndView();
852 result.setViewName(responseString);
855 response.setCharacterEncoding("UTF-8");
856 response.setContentType("application / json");
857 request.setCharacterEncoding("UTF-8");
859 PrintWriter out = response.getWriter();
860 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
861 out.write(j.toString());
864 }catch (Exception e){
865 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
866 response.setCharacterEncoding("UTF-8");
867 request.setCharacterEncoding("UTF-8");
868 PrintWriter out = response.getWriter();
869 out.write(e.getMessage());
874 @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
875 public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception {
877 ObjectMapper mapper = new ObjectMapper();
878 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
879 JsonNode root = mapper.readTree(request.getReader());
880 ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
881 commonClassDao.delete(closedLoopSite);
882 response.setCharacterEncoding("UTF-8");
883 response.setContentType("application / json");
884 request.setCharacterEncoding("UTF-8");
886 PrintWriter out = response.getWriter();
888 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
889 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
890 out.write(j.toString());
895 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
896 response.setCharacterEncoding("UTF-8");
897 request.setCharacterEncoding("UTF-8");
898 PrintWriter out = response.getWriter();
899 out.write(e.getMessage());
904 @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
905 public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{
907 boolean duplicateflag = false;
908 boolean isFakeUpdate = false;
909 boolean fromAPI = false;
910 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
913 ObjectMapper mapper = new ObjectMapper();
914 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
915 JsonNode root = mapper.readTree(request.getReader());
916 VarbindDictionary varbindDictionary;
917 String userId = null;
919 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("dictionaryFields").toString(), VarbindDictionary.class);
922 //check if update operation or create, get id for data to be updated and update attributeData
923 if (request.getParameter("operation").equals("update")) {
924 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class);
926 VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
930 varbindDictionary.setId(1);
932 varbindDictionary.setId(id);
934 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
937 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
938 userId = root.get("userid").textValue();
940 if(varbindDictionary.getId() == 0){
941 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class);
942 if(!duplicateData.isEmpty()){
943 duplicateflag = true;
945 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
946 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
947 commonClassDao.save(varbindDictionary);
951 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
952 commonClassDao.update(varbindDictionary);
955 String responseString = "";
957 responseString = "Duplicate";
959 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
963 if (responseString!=null && !responseString.equals("Duplicate")) {
965 responseString = "Exists";
967 responseString = "Success";
970 ModelAndView result = new ModelAndView();
971 result.setViewName(responseString);
974 response.setCharacterEncoding("UTF-8");
975 response.setContentType("application / json");
976 request.setCharacterEncoding("UTF-8");
978 PrintWriter out = response.getWriter();
979 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
980 out.write(j.toString());
983 }catch (Exception e){
984 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
985 response.setCharacterEncoding("UTF-8");
986 request.setCharacterEncoding("UTF-8");
987 PrintWriter out = response.getWriter();
988 out.write(e.getMessage());
993 @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
994 public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception {
996 ObjectMapper mapper = new ObjectMapper();
997 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
998 JsonNode root = mapper.readTree(request.getReader());
999 VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
1000 commonClassDao.delete(varbindDictionary);
1001 response.setCharacterEncoding("UTF-8");
1002 response.setContentType("application / json");
1003 request.setCharacterEncoding("UTF-8");
1005 PrintWriter out = response.getWriter();
1007 String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
1008 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1009 out.write(j.toString());
1013 catch (Exception e){
1014 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1015 response.setCharacterEncoding("UTF-8");
1016 request.setCharacterEncoding("UTF-8");
1017 PrintWriter out = response.getWriter();
1018 out.write(e.getMessage());