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.PrintWriter;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.LinkedHashMap;
27 import java.util.List;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
33 import org.json.JSONObject;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.pap.xacml.rest.adapters.GridData;
37 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
38 import org.onap.policy.rest.dao.CommonClassDao;
39 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
40 import org.onap.policy.rest.jpa.ClosedLoopSite;
41 import org.onap.policy.rest.jpa.PEPOptions;
42 import org.onap.policy.rest.jpa.UserInfo;
43 import org.onap.policy.rest.jpa.VNFType;
44 import org.onap.policy.rest.jpa.VSCLAction;
45 import org.onap.policy.rest.jpa.VarbindDictionary;
46 import org.onap.policy.xacml.api.XACMLErrorConstants;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.http.MediaType;
49 import org.springframework.stereotype.Controller;
50 import org.springframework.web.bind.annotation.RequestMapping;
51 import org.springframework.web.servlet.ModelAndView;
53 import com.fasterxml.jackson.databind.DeserializationFeature;
54 import com.fasterxml.jackson.databind.JsonNode;
55 import com.fasterxml.jackson.databind.ObjectMapper;
58 public class ClosedLoopDictionaryController{
60 private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class);
62 private static CommonClassDao commonClassDao;
65 public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
66 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
69 public ClosedLoopDictionaryController(){}
71 public UserInfo getUserInfo(String loginId){
72 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
77 @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
78 public void getVSCLActionDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
80 Map<String, Object> model = new HashMap<>();
81 ObjectMapper mapper = new ObjectMapper();
82 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")));
83 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
84 JSONObject j = new JSONObject(msg);
85 response.getWriter().write(j.toString());
88 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
93 @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
94 public void getVSCLActionDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
96 Map<String, Object> model = new HashMap<>();
97 ObjectMapper mapper = new ObjectMapper();
98 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
99 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
100 JSONObject j = new JSONObject(msg);
101 response.addHeader("successMapKey", "success");
102 response.addHeader("operation", "getDictionary");
103 response.getWriter().write(j.toString());
106 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
107 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
108 response.addHeader("error", "dictionaryDBQuery");
112 @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
113 public void getVNFTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
115 Map<String, Object> model = new HashMap<>();
116 ObjectMapper mapper = new ObjectMapper();
117 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, "vnftype")));
118 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
119 JSONObject j = new JSONObject(msg);
120 response.addHeader("successMapKey", "success");
121 response.addHeader("operation", "getDictionary");
122 response.getWriter().write(j.toString());
125 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
129 @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
130 public void getVNFTypeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
132 Map<String, Object> model = new HashMap<>();
133 ObjectMapper mapper = new ObjectMapper();
134 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
135 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
136 JSONObject j = new JSONObject(msg);
137 response.addHeader("successMapKey", "success");
138 response.addHeader("operation", "getDictionary");
139 response.getWriter().write(j.toString());
142 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
143 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
144 response.addHeader("error", "dictionaryDBQuery");
148 @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
149 public void getPEPOptionsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
151 Map<String, Object> model = new HashMap<>();
152 ObjectMapper mapper = new ObjectMapper();
153 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")));
154 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
155 JSONObject j = new JSONObject(msg);
156 response.getWriter().write(j.toString());
159 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
163 @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
164 public void getPEPOptionsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
166 Map<String, Object> model = new HashMap<>();
167 ObjectMapper mapper = new ObjectMapper();
168 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
169 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
170 JSONObject j = new JSONObject(msg);
171 response.addHeader("successMapKey", "success");
172 response.addHeader("operation", "getDictionary");
173 response.getWriter().write(j.toString());
176 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
177 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
178 response.addHeader("error", "dictionaryDBQuery");
182 @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
183 public void getVarbindDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
185 Map<String, Object> model = new HashMap<>();
186 ObjectMapper mapper = new ObjectMapper();
187 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")));
188 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
189 JSONObject j = new JSONObject(msg);
190 response.getWriter().write(j.toString());
193 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
197 @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
198 public void getVarbindDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
200 Map<String, Object> model = new HashMap<>();
201 ObjectMapper mapper = new ObjectMapper();
202 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
203 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
204 JSONObject j = new JSONObject(msg);
205 response.addHeader("successMapKey", "success");
206 response.addHeader("operation", "getDictionary");
207 response.getWriter().write(j.toString());
210 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
211 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
212 response.addHeader("error", "dictionaryDBQuery");
216 @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
217 public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
219 Map<String, Object> model = new HashMap<>();
220 ObjectMapper mapper = new ObjectMapper();
221 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")));
222 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
223 JSONObject j = new JSONObject(msg);
224 response.getWriter().write(j.toString());
227 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
231 @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
232 public void getClosedLoopServiceDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
234 Map<String, Object> model = new HashMap<>();
235 ObjectMapper mapper = new ObjectMapper();
236 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
237 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
238 JSONObject j = new JSONObject(msg);
239 response.addHeader("successMapKey", "success");
240 response.addHeader("operation", "getDictionary");
241 response.getWriter().write(j.toString());
244 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
245 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
246 response.addHeader("error", "dictionaryDBQuery");
250 @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
251 public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
253 Map<String, Object> model = new HashMap<>();
254 ObjectMapper mapper = new ObjectMapper();
255 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")));
256 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
257 JSONObject j = new JSONObject(msg);
258 response.getWriter().write(j.toString());
261 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
265 @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
266 public void getClosedLoopSiteDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
268 Map<String, Object> model = new HashMap<>();
269 ObjectMapper mapper = new ObjectMapper();
270 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
271 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
272 JSONObject j = new JSONObject(msg);
273 response.addHeader("successMapKey", "success");
274 response.addHeader("operation", "getDictionary");
275 response.getWriter().write(j.toString());
278 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
279 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
280 response.addHeader("error", "dictionaryDBQuery");
284 @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
285 public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{
287 boolean duplicateflag = false;
288 boolean isFakeUpdate = false;
289 boolean fromAPI = false;
290 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
293 ObjectMapper mapper = new ObjectMapper();
294 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
295 JsonNode root = mapper.readTree(request.getReader());
296 VSCLAction vSCLAction;
297 String userId = null;
299 vSCLAction = (VSCLAction)mapper.readValue(root.get("dictionaryFields").toString(), VSCLAction.class);
302 //check if update operation or create, get id for data to be updated and update attributeData
303 if (request.getParameter("operation").equals("update")) {
304 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class);
306 VSCLAction data = (VSCLAction) duplicateData.get(0);
312 vSCLAction.setId(id);
315 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
319 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
320 userId = root.get("userid").textValue();
322 if(vSCLAction.getId() == 0){
323 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class);
324 if(!duplicateData.isEmpty()){
325 duplicateflag = true;
327 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
328 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
329 vSCLAction.setModifiedDate(new Date());
330 commonClassDao.save(vSCLAction);
334 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
335 commonClassDao.update(vSCLAction);
339 String responseString = "";
341 responseString = "Duplicate";
343 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
346 if (responseString!=null && !responseString.equals("Duplicate")) {
348 responseString = "Exists";
350 responseString = "Success";
354 ModelAndView result = new ModelAndView();
355 result.setViewName(responseString);
358 response.setCharacterEncoding("UTF-8");
359 response.setContentType("application / json");
360 request.setCharacterEncoding("UTF-8");
362 PrintWriter out = response.getWriter();
363 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
364 out.write(j.toString());
369 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
370 response.setCharacterEncoding("UTF-8");
371 request.setCharacterEncoding("UTF-8");
372 PrintWriter out = response.getWriter();
373 out.write(e.getMessage());
378 @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
379 public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
381 ObjectMapper mapper = new ObjectMapper();
382 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
383 JsonNode root = mapper.readTree(request.getReader());
384 VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
385 commonClassDao.delete(vSCLAction);
386 response.setCharacterEncoding("UTF-8");
387 response.setContentType("application / json");
388 request.setCharacterEncoding("UTF-8");
390 PrintWriter out = response.getWriter();
392 String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
393 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
394 out.write(j.toString());
399 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
400 response.setCharacterEncoding("UTF-8");
401 request.setCharacterEncoding("UTF-8");
402 PrintWriter out = response.getWriter();
403 out.write(e.getMessage());
408 @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
409 public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{
411 boolean duplicateflag = false;
412 boolean isFakeUpdate = false;
413 boolean fromAPI = false;
415 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
418 ObjectMapper mapper = new ObjectMapper();
419 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
420 JsonNode root = mapper.readTree(request.getReader());
422 String userId = null;
425 vNFType = (VNFType)mapper.readValue(root.get("dictionaryFields").toString(), VNFType.class);
428 //check if update operation or create, get id for data to be updated and update attributeData
429 if (request.getParameter("operation").equals("update")) {
430 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class);
432 VNFType data = (VNFType) duplicateData.get(0);
440 vNFType.setUserCreatedBy(this.getUserInfo(userId));
443 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
444 userId = root.get("userid").textValue();
446 if(vNFType.getId() == 0){
447 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class);
448 if(!duplicateData.isEmpty()){
449 duplicateflag = true;
451 vNFType.setUserCreatedBy(this.getUserInfo(userId));
452 vNFType.setUserModifiedBy(this.getUserInfo(userId));
453 commonClassDao.save(vNFType);
457 vNFType.setUserModifiedBy(this.getUserInfo(userId));
458 vNFType.setModifiedDate(new Date());
459 commonClassDao.update(vNFType);
462 String responseString = "";
464 responseString = "Duplicate";
466 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
469 if (responseString!=null && !responseString.equals("Duplicate")) {
471 responseString = "Exists";
473 responseString = "Success";
476 ModelAndView result = new ModelAndView();
477 result.setViewName(responseString);
480 response.setCharacterEncoding("UTF-8");
481 response.setContentType("application / json");
482 request.setCharacterEncoding("UTF-8");
484 PrintWriter out = response.getWriter();
485 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
486 out.write(j.toString());
491 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
492 response.setCharacterEncoding("UTF-8");
493 request.setCharacterEncoding("UTF-8");
494 PrintWriter out = response.getWriter();
495 out.write(e.getMessage());
500 @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
501 public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception {
503 ObjectMapper mapper = new ObjectMapper();
504 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
505 JsonNode root = mapper.readTree(request.getReader());
506 VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
507 commonClassDao.delete(vNFType);
508 response.setCharacterEncoding("UTF-8");
509 response.setContentType("application / json");
510 request.setCharacterEncoding("UTF-8");
512 PrintWriter out = response.getWriter();
514 String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
515 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
516 out.write(j.toString());
521 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
522 response.setCharacterEncoding("UTF-8");
523 request.setCharacterEncoding("UTF-8");
524 PrintWriter out = response.getWriter();
525 out.write(e.getMessage());
530 @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
531 public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{
533 boolean duplicateflag = false;
534 boolean isFakeUpdate = false;
535 boolean fromAPI = false;
536 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
539 ObjectMapper mapper = new ObjectMapper();
540 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
541 JsonNode root = mapper.readTree(request.getReader());
542 PEPOptions pEPOptions;
544 String userId = null;
546 pEPOptions = (PEPOptions)mapper.readValue(root.get("dictionaryFields").toString(), PEPOptions.class);
547 gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
550 //check if update operation or create, get id for data to be updated and update attributeData
551 if (request.getParameter("operation").equals("update")) {
552 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class);
554 PEPOptions data = (PEPOptions) duplicateData.get(0);
560 pEPOptions.setId(id);
562 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
565 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
566 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
567 userId = root.get("userid").textValue();
571 if(gridData.getAttributes().size() > 0){
572 for(Object attribute : gridData.getAttributes()){
573 if(attribute instanceof LinkedHashMap<?, ?>){
574 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
575 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
577 actions = actions + ":#@";
579 actions = actions + key + "=#@";
580 actions = actions + value;
585 pEPOptions.setActions(actions);
586 if(pEPOptions.getId() == 0){
587 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class);
588 if(!duplicateData.isEmpty()){
589 duplicateflag = true;
591 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
592 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
593 commonClassDao.save(pEPOptions);
597 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
598 pEPOptions.setModifiedDate(new Date());
599 commonClassDao.update(pEPOptions);
602 String responseString = "";
604 responseString = "Duplicate";
606 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
609 if (responseString!=null && !responseString.equals("Duplicate")) {
611 responseString = "Exists";
613 responseString = "Success";
617 ModelAndView result = new ModelAndView();
618 result.setViewName(responseString);
621 response.setCharacterEncoding("UTF-8");
622 response.setContentType("application / json");
623 request.setCharacterEncoding("UTF-8");
625 PrintWriter out = response.getWriter();
626 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
627 out.write(j.toString());
631 }catch (Exception e){
632 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
633 response.setCharacterEncoding("UTF-8");
634 request.setCharacterEncoding("UTF-8");
635 PrintWriter out = response.getWriter();
636 out.write(e.getMessage());
641 @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
642 public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception {
644 ObjectMapper mapper = new ObjectMapper();
645 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
646 JsonNode root = mapper.readTree(request.getReader());
647 PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
648 commonClassDao.delete(pEPOptions);
649 response.setCharacterEncoding("UTF-8");
650 response.setContentType("application / json");
651 request.setCharacterEncoding("UTF-8");
653 PrintWriter out = response.getWriter();
655 String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
656 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
657 out.write(j.toString());
662 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
663 response.setCharacterEncoding("UTF-8");
664 request.setCharacterEncoding("UTF-8");
665 PrintWriter out = response.getWriter();
666 out.write(e.getMessage());
671 @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
672 public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{
674 boolean duplicateflag = false;
675 boolean isFakeUpdate = false;
676 boolean fromAPI = false;
677 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
680 ObjectMapper mapper = new ObjectMapper();
681 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
682 JsonNode root = mapper.readTree(request.getReader());
683 ClosedLoopD2Services serviceData;
684 String userId = null;
686 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopD2Services.class);
689 //check if update operation or create, get id for data to be updated and update attributeData
690 if (request.getParameter("operation").equals("update")) {
691 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class);
693 ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
697 serviceData.setId(1);
699 serviceData.setId(id);
701 serviceData.setUserCreatedBy(this.getUserInfo(userId));
704 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
705 userId = root.get("userid").textValue();
707 if(serviceData.getId() == 0){
708 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class);
709 if(!duplicateData.isEmpty()){
710 duplicateflag = true;
712 serviceData.setUserCreatedBy(this.getUserInfo(userId));
713 serviceData.setUserModifiedBy(this.getUserInfo(userId));
714 commonClassDao.save(serviceData);
718 serviceData.setUserModifiedBy(this.getUserInfo(userId));
719 serviceData.setModifiedDate(new Date());
720 commonClassDao.update(serviceData);
723 String responseString = "";
725 responseString = "Duplicate";
727 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
730 if (responseString!=null && !responseString.equals("Duplicate")) {
732 responseString = "Exists";
734 responseString = "Success";
737 ModelAndView result = new ModelAndView();
738 result.setViewName(responseString);
741 response.setCharacterEncoding("UTF-8");
742 response.setContentType("application / json");
743 request.setCharacterEncoding("UTF-8");
745 PrintWriter out = response.getWriter();
746 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
747 out.write(j.toString());
750 }catch (Exception e){
751 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
752 response.setCharacterEncoding("UTF-8");
753 request.setCharacterEncoding("UTF-8");
754 PrintWriter out = response.getWriter();
755 out.write(e.getMessage());
760 @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
761 public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception {
763 ObjectMapper mapper = new ObjectMapper();
764 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
765 JsonNode root = mapper.readTree(request.getReader());
766 ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
767 commonClassDao.delete(closedLoopD2Services);
768 response.setCharacterEncoding("UTF-8");
769 response.setContentType("application / json");
770 request.setCharacterEncoding("UTF-8");
772 PrintWriter out = response.getWriter();
774 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
775 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
776 out.write(j.toString());
781 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
782 response.setCharacterEncoding("UTF-8");
783 request.setCharacterEncoding("UTF-8");
784 PrintWriter out = response.getWriter();
785 out.write(e.getMessage());
790 @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
791 public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{
793 boolean duplicateflag = false;
794 boolean isFakeUpdate = false;
795 boolean fromAPI = false;
797 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
800 ObjectMapper mapper = new ObjectMapper();
801 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
802 JsonNode root = mapper.readTree(request.getReader());
803 ClosedLoopSite siteData;
804 String userId = null;
806 siteData = (ClosedLoopSite)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopSite.class);
808 //check if update operation or create, get id for data to be updated and update attributeData
809 if (request.getParameter("operation").equals("update")) {
810 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class);
812 ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
820 siteData.setUserCreatedBy(this.getUserInfo(userId));
823 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
824 userId = root.get("userid").textValue();
826 if(siteData.getId() == 0){
827 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class);
828 if(!duplicateData.isEmpty()){
829 duplicateflag = true;
831 siteData.setUserCreatedBy(this.getUserInfo(userId));
832 siteData.setUserModifiedBy(this.getUserInfo(userId));
833 commonClassDao.save(siteData);
837 siteData.setUserModifiedBy(this.getUserInfo(userId));
838 siteData.setModifiedDate(new Date());
839 commonClassDao.update(siteData);
842 String responseString = "";
844 responseString = "Duplicate";
846 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
850 if (responseString!=null && !responseString.equals("Duplicate")) {
852 responseString = "Exists";
854 responseString = "Success";
857 ModelAndView result = new ModelAndView();
858 result.setViewName(responseString);
861 response.setCharacterEncoding("UTF-8");
862 response.setContentType("application / json");
863 request.setCharacterEncoding("UTF-8");
865 PrintWriter out = response.getWriter();
866 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
867 out.write(j.toString());
870 }catch (Exception e){
871 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
872 response.setCharacterEncoding("UTF-8");
873 request.setCharacterEncoding("UTF-8");
874 PrintWriter out = response.getWriter();
875 out.write(e.getMessage());
880 @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
881 public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception {
883 ObjectMapper mapper = new ObjectMapper();
884 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
885 JsonNode root = mapper.readTree(request.getReader());
886 ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
887 commonClassDao.delete(closedLoopSite);
888 response.setCharacterEncoding("UTF-8");
889 response.setContentType("application / json");
890 request.setCharacterEncoding("UTF-8");
892 PrintWriter out = response.getWriter();
894 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
895 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
896 out.write(j.toString());
901 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
902 response.setCharacterEncoding("UTF-8");
903 request.setCharacterEncoding("UTF-8");
904 PrintWriter out = response.getWriter();
905 out.write(e.getMessage());
910 @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
911 public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{
913 boolean duplicateflag = false;
914 boolean isFakeUpdate = false;
915 boolean fromAPI = false;
916 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
919 ObjectMapper mapper = new ObjectMapper();
920 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
921 JsonNode root = mapper.readTree(request.getReader());
922 VarbindDictionary varbindDictionary;
923 String userId = null;
925 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("dictionaryFields").toString(), VarbindDictionary.class);
928 //check if update operation or create, get id for data to be updated and update attributeData
929 if (request.getParameter("operation").equals("update")) {
930 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class);
932 VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
936 varbindDictionary.setId(1);
938 varbindDictionary.setId(id);
940 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
943 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
944 userId = root.get("userid").textValue();
946 if(varbindDictionary.getId() == 0){
947 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class);
948 if(!duplicateData.isEmpty()){
949 duplicateflag = true;
951 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
952 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
953 commonClassDao.save(varbindDictionary);
957 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
958 varbindDictionary.setModifiedDate(new Date());
959 commonClassDao.update(varbindDictionary);
962 String responseString = "";
964 responseString = "Duplicate";
966 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
970 if (responseString!=null && !responseString.equals("Duplicate")) {
972 responseString = "Exists";
974 responseString = "Success";
977 ModelAndView result = new ModelAndView();
978 result.setViewName(responseString);
981 response.setCharacterEncoding("UTF-8");
982 response.setContentType("application / json");
983 request.setCharacterEncoding("UTF-8");
985 PrintWriter out = response.getWriter();
986 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
987 out.write(j.toString());
990 }catch (Exception e){
991 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
992 response.setCharacterEncoding("UTF-8");
993 request.setCharacterEncoding("UTF-8");
994 PrintWriter out = response.getWriter();
995 out.write(e.getMessage());
1000 @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1001 public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception {
1003 ObjectMapper mapper = new ObjectMapper();
1004 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1005 JsonNode root = mapper.readTree(request.getReader());
1006 VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
1007 commonClassDao.delete(varbindDictionary);
1008 response.setCharacterEncoding("UTF-8");
1009 response.setContentType("application / json");
1010 request.setCharacterEncoding("UTF-8");
1012 PrintWriter out = response.getWriter();
1014 String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
1015 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1016 out.write(j.toString());
1020 catch (Exception e){
1021 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1022 response.setCharacterEncoding("UTF-8");
1023 request.setCharacterEncoding("UTF-8");
1024 PrintWriter out = response.getWriter();
1025 out.write(e.getMessage());