2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.xacml.rest.controller;
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.util.Date;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.List;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
34 import org.json.JSONObject;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.pap.xacml.rest.adapters.GridData;
38 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
39 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
40 import org.onap.policy.rest.dao.CommonClassDao;
41 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
42 import org.onap.policy.rest.jpa.ClosedLoopSite;
43 import org.onap.policy.rest.jpa.PEPOptions;
44 import org.onap.policy.rest.jpa.UserInfo;
45 import org.onap.policy.rest.jpa.VNFType;
46 import org.onap.policy.rest.jpa.VSCLAction;
47 import org.onap.policy.rest.jpa.VarbindDictionary;
48 import org.onap.policy.utils.PolicyUtils;
49 import org.onap.policy.xacml.api.XACMLErrorConstants;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.http.MediaType;
52 import org.springframework.stereotype.Controller;
53 import org.springframework.web.bind.annotation.RequestMapping;
54 import org.springframework.web.servlet.ModelAndView;
56 import com.fasterxml.jackson.databind.DeserializationFeature;
57 import com.fasterxml.jackson.databind.JsonNode;
58 import com.fasterxml.jackson.databind.ObjectMapper;
61 public class ClosedLoopDictionaryController{
63 private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class);
65 private static CommonClassDao commonClassDao;
66 private static String vsclaction = "vsclaction";
67 private static String successMapKey = "successMapKey";
68 private static String successMessage = "success";
69 private static String operation = "operation";
70 private static String getDictionary = "getDictionary";
71 private static String dictionaryDBQuery = "dictionaryDBQuery";
72 private static String errorMsg = "error";
73 private static String vnftype = "vnftype";
74 private static String pepName = "pepName";
75 private static String varbindName = "varbindName";
76 private static String serviceName = "serviceName";
77 private static String siteName = "siteName";
78 private static String apiflag = "apiflag";
79 private static String dictionaryFields = "dictionaryFields";
80 private static String update = "update";
81 private static String duplicateResponseString = "Duplicate";
82 private static String userid = "userid";
83 private static String utf8 = "UTF-8";
84 private static String applicationJsonContentType = "application / json";
85 private static String successMsg = "Success";
88 public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
89 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
92 public void setCommonClassDao(CommonClassDao commonClassDao){
93 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
96 * This is an empty constructor
98 public ClosedLoopDictionaryController(){}
100 public UserInfo getUserInfo(String loginId){
101 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
105 @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
106 public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
108 Map<String, Object> model = new HashMap<>();
109 ObjectMapper mapper = new ObjectMapper();
110 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, vsclaction)));
111 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
112 JSONObject j = new JSONObject(msg);
113 response.getWriter().write(j.toString());
116 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
121 @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
122 public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
124 Map<String, Object> model = new HashMap<>();
125 ObjectMapper mapper = new ObjectMapper();
126 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
127 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
128 JSONObject j = new JSONObject(msg);
129 response.addHeader(successMapKey, successMessage);
130 response.addHeader(operation, getDictionary);
131 response.getWriter().write(j.toString());
134 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
135 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
136 response.addHeader(errorMsg, dictionaryDBQuery);
140 @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
141 public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
143 Map<String, Object> model = new HashMap<>();
144 ObjectMapper mapper = new ObjectMapper();
145 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, vnftype)));
146 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
147 JSONObject j = new JSONObject(msg);
148 response.addHeader(successMapKey, successMessage);
149 response.addHeader(operation, getDictionary);
150 response.getWriter().write(j.toString());
153 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
157 @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
158 public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
160 Map<String, Object> model = new HashMap<>();
161 ObjectMapper mapper = new ObjectMapper();
162 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
163 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
164 JSONObject j = new JSONObject(msg);
165 response.addHeader(successMapKey, successMessage);
166 response.addHeader(operation, getDictionary);
167 response.getWriter().write(j.toString());
170 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
171 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
172 response.addHeader(errorMsg, dictionaryDBQuery);
176 @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
177 public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
179 Map<String, Object> model = new HashMap<>();
180 ObjectMapper mapper = new ObjectMapper();
181 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, pepName)));
182 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
183 JSONObject j = new JSONObject(msg);
184 response.getWriter().write(j.toString());
187 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
191 @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
192 public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
194 Map<String, Object> model = new HashMap<>();
195 ObjectMapper mapper = new ObjectMapper();
196 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
197 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
198 JSONObject j = new JSONObject(msg);
199 response.addHeader(successMapKey, successMessage);
200 response.addHeader(operation, getDictionary);
201 response.getWriter().write(j.toString());
204 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
205 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
206 response.addHeader(errorMsg, dictionaryDBQuery);
210 @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
211 public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
213 Map<String, Object> model = new HashMap<>();
214 ObjectMapper mapper = new ObjectMapper();
215 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, varbindName)));
216 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
217 JSONObject j = new JSONObject(msg);
218 response.getWriter().write(j.toString());
221 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
225 @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
226 public void getVarbindDictionaryEntityData(HttpServletResponse response){
228 Map<String, Object> model = new HashMap<>();
229 ObjectMapper mapper = new ObjectMapper();
230 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
231 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
232 JSONObject j = new JSONObject(msg);
233 response.addHeader(successMapKey, successMessage);
234 response.addHeader(operation, getDictionary);
235 response.getWriter().write(j.toString());
238 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
239 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
240 response.addHeader(errorMsg, dictionaryDBQuery);
244 @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
245 public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
247 Map<String, Object> model = new HashMap<>();
248 ObjectMapper mapper = new ObjectMapper();
249 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, serviceName)));
250 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
251 JSONObject j = new JSONObject(msg);
252 response.getWriter().write(j.toString());
255 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
259 @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
260 public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
262 Map<String, Object> model = new HashMap<>();
263 ObjectMapper mapper = new ObjectMapper();
264 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
265 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
266 JSONObject j = new JSONObject(msg);
267 response.addHeader(successMapKey, successMessage);
268 response.addHeader(operation, getDictionary);
269 response.getWriter().write(j.toString());
272 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
273 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
274 response.addHeader(errorMsg, dictionaryDBQuery);
278 @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
279 public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
281 Map<String, Object> model = new HashMap<>();
282 ObjectMapper mapper = new ObjectMapper();
283 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, siteName)));
284 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
285 JSONObject j = new JSONObject(msg);
286 response.getWriter().write(j.toString());
289 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
293 @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
294 public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
296 Map<String, Object> model = new HashMap<>();
297 ObjectMapper mapper = new ObjectMapper();
298 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
299 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
300 JSONObject j = new JSONObject(msg);
301 response.addHeader(successMapKey, successMessage);
302 response.addHeader(operation, getDictionary);
303 response.getWriter().write(j.toString());
306 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
307 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
308 response.addHeader(errorMsg, dictionaryDBQuery);
312 @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
313 public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
315 boolean duplicateflag = false;
316 boolean isFakeUpdate = false;
317 boolean fromAPI = false;
318 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
321 ObjectMapper mapper = new ObjectMapper();
322 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
323 JsonNode root = mapper.readTree(request.getReader());
324 VSCLAction vSCLAction;
325 String userId = null;
327 vSCLAction = (VSCLAction)mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
330 //check if update operation or create, get id for data to be updated and update attributeData
331 if ((update).equals(request.getParameter(operation))) {
332 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
333 VSCLAction data = (VSCLAction) duplicateData.get(0);
334 int id = data.getId();
339 vSCLAction.setId(id);
342 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
346 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
347 userId = root.get(userid).textValue();
349 if(vSCLAction.getId() == 0){
350 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
351 if(!duplicateData.isEmpty()){
352 duplicateflag = true;
354 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
355 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
356 vSCLAction.setModifiedDate(new Date());
357 commonClassDao.save(vSCLAction);
361 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
362 commonClassDao.update(vSCLAction);
366 String responseString = "";
368 responseString = duplicateResponseString;
370 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
373 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
375 responseString = "Exists";
377 responseString = successMsg;
381 ModelAndView result = new ModelAndView();
382 result.setViewName(responseString);
385 response.setCharacterEncoding(utf8);
386 response.setContentType(applicationJsonContentType);
387 request.setCharacterEncoding(utf8);
389 PrintWriter out = response.getWriter();
390 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
391 out.write(j.toString());
396 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
397 response.setCharacterEncoding(utf8);
398 request.setCharacterEncoding(utf8);
399 PrintWriter out = response.getWriter();
400 out.write(PolicyUtils.CATCH_EXCEPTION);
405 @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
406 public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
408 ObjectMapper mapper = new ObjectMapper();
409 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
410 JsonNode root = mapper.readTree(request.getReader());
411 VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
412 commonClassDao.delete(vSCLAction);
413 response.setCharacterEncoding(utf8);
414 response.setContentType(applicationJsonContentType);
415 request.setCharacterEncoding(utf8);
417 PrintWriter out = response.getWriter();
419 String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
420 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
421 out.write(j.toString());
426 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
427 response.setCharacterEncoding(utf8);
428 request.setCharacterEncoding(utf8);
429 PrintWriter out = response.getWriter();
430 out.write(PolicyUtils.CATCH_EXCEPTION);
435 @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
436 public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
438 boolean duplicateflag = false;
439 boolean isFakeUpdate = false;
440 boolean fromAPI = false;
442 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
445 ObjectMapper mapper = new ObjectMapper();
446 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
447 JsonNode root = mapper.readTree(request.getReader());
449 String userId = null;
452 vNFType = (VNFType)mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
455 //check if update operation or create, get id for data to be updated and update attributeData
456 if ((update).equals(request.getParameter(operation))) {
457 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
458 VNFType data = (VNFType) duplicateData.get(0);
459 int id = data.getId();
466 vNFType.setUserCreatedBy(this.getUserInfo(userId));
469 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
470 userId = root.get(userid).textValue();
472 if(vNFType.getId() == 0){
473 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
474 if(!duplicateData.isEmpty()){
475 duplicateflag = true;
477 vNFType.setUserCreatedBy(this.getUserInfo(userId));
478 vNFType.setUserModifiedBy(this.getUserInfo(userId));
479 commonClassDao.save(vNFType);
483 vNFType.setUserModifiedBy(this.getUserInfo(userId));
484 vNFType.setModifiedDate(new Date());
485 commonClassDao.update(vNFType);
488 String responseString = "";
490 responseString = duplicateResponseString;
492 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
495 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
497 responseString = "Exists";
499 responseString = successMsg;
502 ModelAndView result = new ModelAndView();
503 result.setViewName(responseString);
506 response.setCharacterEncoding(utf8);
507 response.setContentType(applicationJsonContentType);
508 request.setCharacterEncoding(utf8);
510 PrintWriter out = response.getWriter();
511 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
512 out.write(j.toString());
517 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
518 response.setCharacterEncoding(utf8);
519 request.setCharacterEncoding(utf8);
520 PrintWriter out = response.getWriter();
521 out.write(PolicyUtils.CATCH_EXCEPTION);
526 @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
527 public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
529 ObjectMapper mapper = new ObjectMapper();
530 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
531 JsonNode root = mapper.readTree(request.getReader());
532 VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
533 commonClassDao.delete(vNFType);
534 response.setCharacterEncoding(utf8);
535 response.setContentType(applicationJsonContentType);
536 request.setCharacterEncoding(utf8);
538 PrintWriter out = response.getWriter();
540 String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
541 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
542 out.write(j.toString());
547 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
548 response.setCharacterEncoding(utf8);
549 request.setCharacterEncoding(utf8);
550 PrintWriter out = response.getWriter();
551 out.write(PolicyUtils.CATCH_EXCEPTION);
556 @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
557 public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
559 boolean duplicateflag = false;
560 boolean isFakeUpdate = false;
561 boolean fromAPI = false;
562 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
565 ObjectMapper mapper = new ObjectMapper();
566 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
567 JsonNode root = mapper.readTree(request.getReader());
568 PEPOptions pEPOptions;
570 String userId = null;
572 pEPOptions = (PEPOptions)mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class);
573 gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
576 //check if update operation or create, get id for data to be updated and update attributeData
577 if ((update).equals(request.getParameter(operation))) {
578 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
579 PEPOptions data = (PEPOptions) duplicateData.get(0);
580 int id = data.getId();
585 pEPOptions.setId(id);
587 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
590 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
591 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
592 userId = root.get(userid).textValue();
596 if(!gridData.getAttributes().isEmpty()){
597 for(Object attribute : gridData.getAttributes()){
598 if(attribute instanceof LinkedHashMap<?, ?>){
599 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
600 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
602 actions = actions + ":#@";
604 actions = actions + key + "=#@";
605 actions = actions + value;
610 pEPOptions.setActions(actions);
611 if(pEPOptions.getId() == 0){
612 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
613 if(!duplicateData.isEmpty()){
614 duplicateflag = true;
616 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
617 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
618 commonClassDao.save(pEPOptions);
622 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
623 pEPOptions.setModifiedDate(new Date());
624 commonClassDao.update(pEPOptions);
627 String responseString = "";
629 responseString = duplicateResponseString;
631 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
634 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
636 responseString = "Exists";
638 responseString = successMsg;
642 ModelAndView result = new ModelAndView();
643 result.setViewName(responseString);
646 response.setCharacterEncoding(utf8);
647 response.setContentType(applicationJsonContentType);
648 request.setCharacterEncoding(utf8);
650 PrintWriter out = response.getWriter();
651 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
652 out.write(j.toString());
656 }catch (Exception e){
657 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
658 response.setCharacterEncoding(utf8);
659 request.setCharacterEncoding(utf8);
660 PrintWriter out = response.getWriter();
661 out.write(PolicyUtils.CATCH_EXCEPTION);
666 @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
667 public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
669 ObjectMapper mapper = new ObjectMapper();
670 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
671 JsonNode root = mapper.readTree(request.getReader());
672 PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
673 commonClassDao.delete(pEPOptions);
674 response.setCharacterEncoding(utf8);
675 response.setContentType(applicationJsonContentType);
676 request.setCharacterEncoding(utf8);
678 PrintWriter out = response.getWriter();
680 String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
681 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
682 out.write(j.toString());
687 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
688 response.setCharacterEncoding(utf8);
689 request.setCharacterEncoding(utf8);
690 PrintWriter out = response.getWriter();
691 out.write(PolicyUtils.CATCH_EXCEPTION);
696 @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
697 public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
699 boolean duplicateflag = false;
700 boolean isFakeUpdate = false;
701 boolean fromAPI = false;
702 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
705 ObjectMapper mapper = new ObjectMapper();
706 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
707 JsonNode root = mapper.readTree(request.getReader());
708 ClosedLoopD2Services serviceData;
709 String userId = null;
711 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
714 //check if update operation or create, get id for data to be updated and update attributeData
715 if ((update).equals(request.getParameter(operation))) {
716 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
717 ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
718 int id = data.getId();
721 serviceData.setId(1);
723 serviceData.setId(id);
725 serviceData.setUserCreatedBy(this.getUserInfo(userId));
728 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
729 userId = root.get(userid).textValue();
731 if(serviceData.getId() == 0){
732 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
733 if(!duplicateData.isEmpty()){
734 duplicateflag = true;
736 serviceData.setUserCreatedBy(this.getUserInfo(userId));
737 serviceData.setUserModifiedBy(this.getUserInfo(userId));
738 commonClassDao.save(serviceData);
742 serviceData.setUserModifiedBy(this.getUserInfo(userId));
743 serviceData.setModifiedDate(new Date());
744 commonClassDao.update(serviceData);
747 String responseString = "";
749 responseString = duplicateResponseString;
751 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
754 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
756 responseString = "Exists";
758 responseString = successMsg;
761 ModelAndView result = new ModelAndView();
762 result.setViewName(responseString);
765 response.setCharacterEncoding(utf8);
766 response.setContentType(applicationJsonContentType);
767 request.setCharacterEncoding(utf8);
769 PrintWriter out = response.getWriter();
770 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
771 out.write(j.toString());
774 }catch (Exception e){
775 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
776 response.setCharacterEncoding(utf8);
777 request.setCharacterEncoding(utf8);
778 PrintWriter out = response.getWriter();
779 out.write(PolicyUtils.CATCH_EXCEPTION);
784 @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
785 public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
787 ObjectMapper mapper = new ObjectMapper();
788 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
789 JsonNode root = mapper.readTree(request.getReader());
790 ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
791 commonClassDao.delete(closedLoopD2Services);
792 response.setCharacterEncoding(utf8);
793 response.setContentType(applicationJsonContentType);
794 request.setCharacterEncoding(utf8);
796 PrintWriter out = response.getWriter();
798 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
799 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
800 out.write(j.toString());
805 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
806 response.setCharacterEncoding(utf8);
807 request.setCharacterEncoding(utf8);
808 PrintWriter out = response.getWriter();
809 out.write(PolicyUtils.CATCH_EXCEPTION);
814 @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
815 public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
817 boolean duplicateflag = false;
818 boolean isFakeUpdate = false;
819 boolean fromAPI = false;
821 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
824 ObjectMapper mapper = new ObjectMapper();
825 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
826 JsonNode root = mapper.readTree(request.getReader());
827 ClosedLoopSite siteData;
828 String userId = null;
830 siteData = (ClosedLoopSite)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
832 //check if update operation or create, get id for data to be updated and update attributeData
833 if ((update).equals(request.getParameter(operation))) {
834 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
835 ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
836 int id = data.getId();
843 siteData.setUserCreatedBy(this.getUserInfo(userId));
846 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
847 userId = root.get(userid).textValue();
849 if(siteData.getId() == 0){
850 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
851 if(!duplicateData.isEmpty()){
852 duplicateflag = true;
854 siteData.setUserCreatedBy(this.getUserInfo(userId));
855 siteData.setUserModifiedBy(this.getUserInfo(userId));
856 commonClassDao.save(siteData);
860 siteData.setUserModifiedBy(this.getUserInfo(userId));
861 siteData.setModifiedDate(new Date());
862 commonClassDao.update(siteData);
865 String responseString = "";
867 responseString = duplicateResponseString;
869 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
873 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
875 responseString = "Exists";
877 responseString = successMsg;
880 ModelAndView result = new ModelAndView();
881 result.setViewName(responseString);
884 response.setCharacterEncoding(utf8);
885 response.setContentType(applicationJsonContentType);
886 request.setCharacterEncoding(utf8);
888 PrintWriter out = response.getWriter();
889 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
890 out.write(j.toString());
893 }catch (Exception e){
894 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
895 response.setCharacterEncoding(utf8);
896 request.setCharacterEncoding(utf8);
897 PrintWriter out = response.getWriter();
898 out.write(PolicyUtils.CATCH_EXCEPTION);
903 @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
904 public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
906 ObjectMapper mapper = new ObjectMapper();
907 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
908 JsonNode root = mapper.readTree(request.getReader());
909 ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
910 commonClassDao.delete(closedLoopSite);
911 response.setCharacterEncoding(utf8);
912 response.setContentType(applicationJsonContentType);
913 request.setCharacterEncoding(utf8);
915 PrintWriter out = response.getWriter();
917 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
918 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
919 out.write(j.toString());
924 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
925 response.setCharacterEncoding(utf8);
926 request.setCharacterEncoding(utf8);
927 PrintWriter out = response.getWriter();
928 out.write(PolicyUtils.CATCH_EXCEPTION);
933 @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
934 public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
936 boolean duplicateflag = false;
937 boolean isFakeUpdate = false;
938 boolean fromAPI = false;
939 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
942 ObjectMapper mapper = new ObjectMapper();
943 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
944 JsonNode root = mapper.readTree(request.getReader());
945 VarbindDictionary varbindDictionary;
946 String userId = null;
948 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
951 //check if update operation or create, get id for data to be updated and update attributeData
952 if ((update).equals(request.getParameter(operation))) {
953 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
954 VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
955 int id = data.getId();
958 varbindDictionary.setId(1);
960 varbindDictionary.setId(id);
962 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
965 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
966 userId = root.get(userid).textValue();
968 if(varbindDictionary.getId() == 0){
969 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
970 if(!duplicateData.isEmpty()){
971 duplicateflag = true;
973 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
974 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
975 commonClassDao.save(varbindDictionary);
979 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
980 varbindDictionary.setModifiedDate(new Date());
981 commonClassDao.update(varbindDictionary);
984 String responseString = "";
986 responseString = duplicateResponseString;
988 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
992 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
994 responseString = "Exists";
996 responseString = successMsg;
999 ModelAndView result = new ModelAndView();
1000 result.setViewName(responseString);
1003 response.setCharacterEncoding(utf8);
1004 response.setContentType(applicationJsonContentType);
1005 request.setCharacterEncoding(utf8);
1007 PrintWriter out = response.getWriter();
1008 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1009 out.write(j.toString());
1012 }catch (Exception e){
1013 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1014 response.setCharacterEncoding(utf8);
1015 request.setCharacterEncoding(utf8);
1016 PrintWriter out = response.getWriter();
1017 out.write(PolicyUtils.CATCH_EXCEPTION);
1022 @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1023 public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
1025 ObjectMapper mapper = new ObjectMapper();
1026 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1027 JsonNode root = mapper.readTree(request.getReader());
1028 VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
1029 commonClassDao.delete(varbindDictionary);
1030 response.setCharacterEncoding(utf8);
1031 response.setContentType(applicationJsonContentType);
1032 request.setCharacterEncoding(utf8);
1034 PrintWriter out = response.getWriter();
1036 String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
1037 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1038 out.write(j.toString());
1042 catch (Exception e){
1043 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1044 response.setCharacterEncoding(utf8);
1045 request.setCharacterEncoding(utf8);
1046 PrintWriter out = response.getWriter();
1047 out.write(PolicyUtils.CATCH_EXCEPTION);
1052 public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
1053 commonClassDao = commonClassDaoImpl;