2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.xacml.rest.controller;
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.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.xacml.api.XACMLErrorConstants;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.http.MediaType;
51 import org.springframework.stereotype.Controller;
52 import org.springframework.web.bind.annotation.RequestMapping;
53 import org.springframework.web.servlet.ModelAndView;
55 import com.fasterxml.jackson.databind.DeserializationFeature;
56 import com.fasterxml.jackson.databind.JsonNode;
57 import com.fasterxml.jackson.databind.ObjectMapper;
60 public class ClosedLoopDictionaryController{
62 private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class);
64 private static CommonClassDao commonClassDao;
65 private static String vsclaction = "vsclaction";
66 private static String successMapKey = "successMapKey";
67 private static String successMessage = "success";
68 private static String operation = "operation";
69 private static String getDictionary = "getDictionary";
70 private static String dictionaryDBQuery = "dictionaryDBQuery";
71 private static String errorMsg = "error";
72 private static String vnftype = "vnftype";
73 private static String pepName = "pepName";
74 private static String varbindName = "varbindName";
75 private static String serviceName = "serviceName";
76 private static String siteName = "siteName";
77 private static String apiflag = "apiflag";
78 private static String dictionaryFields = "dictionaryFields";
79 private static String update = "update";
80 private static String duplicateResponseString = "Duplicate";
81 private static String userid = "userid";
82 private static String utf8 = "UTF-8";
83 private static String applicationJsonContentType = "application / json";
84 private static String successMsg = "Success";
87 public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
88 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
91 * This is an empty constructor
93 public ClosedLoopDictionaryController(){}
95 public UserInfo getUserInfo(String loginId){
96 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
100 @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
101 public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
103 Map<String, Object> model = new HashMap<>();
104 ObjectMapper mapper = new ObjectMapper();
105 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, vsclaction)));
106 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
107 JSONObject j = new JSONObject(msg);
108 response.getWriter().write(j.toString());
111 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
116 @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
117 public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
119 Map<String, Object> model = new HashMap<>();
120 ObjectMapper mapper = new ObjectMapper();
121 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
122 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
123 JSONObject j = new JSONObject(msg);
124 response.addHeader(successMapKey, successMessage);
125 response.addHeader(operation, getDictionary);
126 response.getWriter().write(j.toString());
129 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
130 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
131 response.addHeader(errorMsg, dictionaryDBQuery);
135 @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
136 public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
138 Map<String, Object> model = new HashMap<>();
139 ObjectMapper mapper = new ObjectMapper();
140 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, vnftype)));
141 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
142 JSONObject j = new JSONObject(msg);
143 response.addHeader(successMapKey, successMessage);
144 response.addHeader(operation, getDictionary);
145 response.getWriter().write(j.toString());
148 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
152 @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
153 public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
155 Map<String, Object> model = new HashMap<>();
156 ObjectMapper mapper = new ObjectMapper();
157 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
158 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
159 JSONObject j = new JSONObject(msg);
160 response.addHeader(successMapKey, successMessage);
161 response.addHeader(operation, getDictionary);
162 response.getWriter().write(j.toString());
165 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
166 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
167 response.addHeader(errorMsg, dictionaryDBQuery);
171 @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
172 public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
174 Map<String, Object> model = new HashMap<>();
175 ObjectMapper mapper = new ObjectMapper();
176 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, pepName)));
177 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
178 JSONObject j = new JSONObject(msg);
179 response.getWriter().write(j.toString());
182 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
186 @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
187 public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
189 Map<String, Object> model = new HashMap<>();
190 ObjectMapper mapper = new ObjectMapper();
191 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
192 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
193 JSONObject j = new JSONObject(msg);
194 response.addHeader(successMapKey, successMessage);
195 response.addHeader(operation, getDictionary);
196 response.getWriter().write(j.toString());
199 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
200 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
201 response.addHeader(errorMsg, dictionaryDBQuery);
205 @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
206 public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
208 Map<String, Object> model = new HashMap<>();
209 ObjectMapper mapper = new ObjectMapper();
210 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, varbindName)));
211 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
212 JSONObject j = new JSONObject(msg);
213 response.getWriter().write(j.toString());
216 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
220 @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
221 public void getVarbindDictionaryEntityData(HttpServletResponse response){
223 Map<String, Object> model = new HashMap<>();
224 ObjectMapper mapper = new ObjectMapper();
225 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
226 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
227 JSONObject j = new JSONObject(msg);
228 response.addHeader(successMapKey, successMessage);
229 response.addHeader(operation, getDictionary);
230 response.getWriter().write(j.toString());
233 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
234 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
235 response.addHeader(errorMsg, dictionaryDBQuery);
239 @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
240 public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
242 Map<String, Object> model = new HashMap<>();
243 ObjectMapper mapper = new ObjectMapper();
244 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, serviceName)));
245 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
246 JSONObject j = new JSONObject(msg);
247 response.getWriter().write(j.toString());
250 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
254 @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
255 public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
257 Map<String, Object> model = new HashMap<>();
258 ObjectMapper mapper = new ObjectMapper();
259 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
260 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
261 JSONObject j = new JSONObject(msg);
262 response.addHeader(successMapKey, successMessage);
263 response.addHeader(operation, getDictionary);
264 response.getWriter().write(j.toString());
267 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
268 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
269 response.addHeader(errorMsg, dictionaryDBQuery);
273 @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
274 public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
276 Map<String, Object> model = new HashMap<>();
277 ObjectMapper mapper = new ObjectMapper();
278 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, siteName)));
279 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
280 JSONObject j = new JSONObject(msg);
281 response.getWriter().write(j.toString());
284 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
288 @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
289 public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
291 Map<String, Object> model = new HashMap<>();
292 ObjectMapper mapper = new ObjectMapper();
293 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
294 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
295 JSONObject j = new JSONObject(msg);
296 response.addHeader(successMapKey, successMessage);
297 response.addHeader(operation, getDictionary);
298 response.getWriter().write(j.toString());
301 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
302 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
303 response.addHeader(errorMsg, dictionaryDBQuery);
307 @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
308 public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
310 boolean duplicateflag = false;
311 boolean isFakeUpdate = false;
312 boolean fromAPI = false;
313 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
316 ObjectMapper mapper = new ObjectMapper();
317 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
318 JsonNode root = mapper.readTree(request.getReader());
319 VSCLAction vSCLAction;
320 String userId = null;
322 vSCLAction = (VSCLAction)mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
325 //check if update operation or create, get id for data to be updated and update attributeData
326 if ((update).equals(request.getParameter(operation))) {
327 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
328 VSCLAction data = (VSCLAction) duplicateData.get(0);
329 int id = data.getId();
334 vSCLAction.setId(id);
337 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
341 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
342 userId = root.get(userid).textValue();
344 if(vSCLAction.getId() == 0){
345 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
346 if(!duplicateData.isEmpty()){
347 duplicateflag = true;
349 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
350 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
351 vSCLAction.setModifiedDate(new Date());
352 commonClassDao.save(vSCLAction);
356 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
357 commonClassDao.update(vSCLAction);
361 String responseString = "";
363 responseString = duplicateResponseString;
365 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
368 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
370 responseString = "Exists";
372 responseString = successMsg;
376 ModelAndView result = new ModelAndView();
377 result.setViewName(responseString);
380 response.setCharacterEncoding(utf8);
381 response.setContentType(applicationJsonContentType);
382 request.setCharacterEncoding(utf8);
384 PrintWriter out = response.getWriter();
385 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
386 out.write(j.toString());
391 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
392 response.setCharacterEncoding(utf8);
393 request.setCharacterEncoding(utf8);
394 PrintWriter out = response.getWriter();
395 out.write(e.getMessage());
400 @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
401 public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
403 ObjectMapper mapper = new ObjectMapper();
404 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
405 JsonNode root = mapper.readTree(request.getReader());
406 VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
407 commonClassDao.delete(vSCLAction);
408 response.setCharacterEncoding(utf8);
409 response.setContentType(applicationJsonContentType);
410 request.setCharacterEncoding(utf8);
412 PrintWriter out = response.getWriter();
414 String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
415 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
416 out.write(j.toString());
421 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
422 response.setCharacterEncoding(utf8);
423 request.setCharacterEncoding(utf8);
424 PrintWriter out = response.getWriter();
425 out.write(e.getMessage());
430 @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
431 public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
433 boolean duplicateflag = false;
434 boolean isFakeUpdate = false;
435 boolean fromAPI = false;
437 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
440 ObjectMapper mapper = new ObjectMapper();
441 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
442 JsonNode root = mapper.readTree(request.getReader());
444 String userId = null;
447 vNFType = (VNFType)mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
450 //check if update operation or create, get id for data to be updated and update attributeData
451 if ((update).equals(request.getParameter(operation))) {
452 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
453 VNFType data = (VNFType) duplicateData.get(0);
454 int id = data.getId();
461 vNFType.setUserCreatedBy(this.getUserInfo(userId));
464 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
465 userId = root.get(userid).textValue();
467 if(vNFType.getId() == 0){
468 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
469 if(!duplicateData.isEmpty()){
470 duplicateflag = true;
472 vNFType.setUserCreatedBy(this.getUserInfo(userId));
473 vNFType.setUserModifiedBy(this.getUserInfo(userId));
474 commonClassDao.save(vNFType);
478 vNFType.setUserModifiedBy(this.getUserInfo(userId));
479 vNFType.setModifiedDate(new Date());
480 commonClassDao.update(vNFType);
483 String responseString = "";
485 responseString = duplicateResponseString;
487 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
490 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
492 responseString = "Exists";
494 responseString = successMsg;
497 ModelAndView result = new ModelAndView();
498 result.setViewName(responseString);
501 response.setCharacterEncoding(utf8);
502 response.setContentType(applicationJsonContentType);
503 request.setCharacterEncoding(utf8);
505 PrintWriter out = response.getWriter();
506 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
507 out.write(j.toString());
512 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
513 response.setCharacterEncoding(utf8);
514 request.setCharacterEncoding(utf8);
515 PrintWriter out = response.getWriter();
516 out.write(e.getMessage());
521 @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
522 public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
524 ObjectMapper mapper = new ObjectMapper();
525 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
526 JsonNode root = mapper.readTree(request.getReader());
527 VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
528 commonClassDao.delete(vNFType);
529 response.setCharacterEncoding(utf8);
530 response.setContentType(applicationJsonContentType);
531 request.setCharacterEncoding(utf8);
533 PrintWriter out = response.getWriter();
535 String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
536 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
537 out.write(j.toString());
542 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
543 response.setCharacterEncoding(utf8);
544 request.setCharacterEncoding(utf8);
545 PrintWriter out = response.getWriter();
546 out.write(e.getMessage());
551 @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
552 public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
554 boolean duplicateflag = false;
555 boolean isFakeUpdate = false;
556 boolean fromAPI = false;
557 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
560 ObjectMapper mapper = new ObjectMapper();
561 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
562 JsonNode root = mapper.readTree(request.getReader());
563 PEPOptions pEPOptions;
565 String userId = null;
567 pEPOptions = (PEPOptions)mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class);
568 gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
571 //check if update operation or create, get id for data to be updated and update attributeData
572 if ((update).equals(request.getParameter(operation))) {
573 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
574 PEPOptions data = (PEPOptions) duplicateData.get(0);
575 int id = data.getId();
580 pEPOptions.setId(id);
582 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
585 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
586 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
587 userId = root.get(userid).textValue();
591 if(!gridData.getAttributes().isEmpty()){
592 for(Object attribute : gridData.getAttributes()){
593 if(attribute instanceof LinkedHashMap<?, ?>){
594 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
595 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
597 actions = actions + ":#@";
599 actions = actions + key + "=#@";
600 actions = actions + value;
605 pEPOptions.setActions(actions);
606 if(pEPOptions.getId() == 0){
607 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
608 if(!duplicateData.isEmpty()){
609 duplicateflag = true;
611 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
612 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
613 commonClassDao.save(pEPOptions);
617 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
618 pEPOptions.setModifiedDate(new Date());
619 commonClassDao.update(pEPOptions);
622 String responseString = "";
624 responseString = duplicateResponseString;
626 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
629 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
631 responseString = "Exists";
633 responseString = successMsg;
637 ModelAndView result = new ModelAndView();
638 result.setViewName(responseString);
641 response.setCharacterEncoding(utf8);
642 response.setContentType(applicationJsonContentType);
643 request.setCharacterEncoding(utf8);
645 PrintWriter out = response.getWriter();
646 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
647 out.write(j.toString());
651 }catch (Exception e){
652 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
653 response.setCharacterEncoding(utf8);
654 request.setCharacterEncoding(utf8);
655 PrintWriter out = response.getWriter();
656 out.write(e.getMessage());
661 @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
662 public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
664 ObjectMapper mapper = new ObjectMapper();
665 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
666 JsonNode root = mapper.readTree(request.getReader());
667 PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
668 commonClassDao.delete(pEPOptions);
669 response.setCharacterEncoding(utf8);
670 response.setContentType(applicationJsonContentType);
671 request.setCharacterEncoding(utf8);
673 PrintWriter out = response.getWriter();
675 String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
676 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
677 out.write(j.toString());
682 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
683 response.setCharacterEncoding(utf8);
684 request.setCharacterEncoding(utf8);
685 PrintWriter out = response.getWriter();
686 out.write(e.getMessage());
691 @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
692 public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
694 boolean duplicateflag = false;
695 boolean isFakeUpdate = false;
696 boolean fromAPI = false;
697 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
700 ObjectMapper mapper = new ObjectMapper();
701 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
702 JsonNode root = mapper.readTree(request.getReader());
703 ClosedLoopD2Services serviceData;
704 String userId = null;
706 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
709 //check if update operation or create, get id for data to be updated and update attributeData
710 if ((update).equals(request.getParameter(operation))) {
711 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
712 ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
713 int id = data.getId();
716 serviceData.setId(1);
718 serviceData.setId(id);
720 serviceData.setUserCreatedBy(this.getUserInfo(userId));
723 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
724 userId = root.get(userid).textValue();
726 if(serviceData.getId() == 0){
727 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
728 if(!duplicateData.isEmpty()){
729 duplicateflag = true;
731 serviceData.setUserCreatedBy(this.getUserInfo(userId));
732 serviceData.setUserModifiedBy(this.getUserInfo(userId));
733 commonClassDao.save(serviceData);
737 serviceData.setUserModifiedBy(this.getUserInfo(userId));
738 serviceData.setModifiedDate(new Date());
739 commonClassDao.update(serviceData);
742 String responseString = "";
744 responseString = duplicateResponseString;
746 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
749 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
751 responseString = "Exists";
753 responseString = successMsg;
756 ModelAndView result = new ModelAndView();
757 result.setViewName(responseString);
760 response.setCharacterEncoding(utf8);
761 response.setContentType(applicationJsonContentType);
762 request.setCharacterEncoding(utf8);
764 PrintWriter out = response.getWriter();
765 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
766 out.write(j.toString());
769 }catch (Exception e){
770 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
771 response.setCharacterEncoding(utf8);
772 request.setCharacterEncoding(utf8);
773 PrintWriter out = response.getWriter();
774 out.write(e.getMessage());
779 @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
780 public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
782 ObjectMapper mapper = new ObjectMapper();
783 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
784 JsonNode root = mapper.readTree(request.getReader());
785 ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
786 commonClassDao.delete(closedLoopD2Services);
787 response.setCharacterEncoding(utf8);
788 response.setContentType(applicationJsonContentType);
789 request.setCharacterEncoding(utf8);
791 PrintWriter out = response.getWriter();
793 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
794 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
795 out.write(j.toString());
800 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
801 response.setCharacterEncoding(utf8);
802 request.setCharacterEncoding(utf8);
803 PrintWriter out = response.getWriter();
804 out.write(e.getMessage());
809 @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
810 public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
812 boolean duplicateflag = false;
813 boolean isFakeUpdate = false;
814 boolean fromAPI = false;
816 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
819 ObjectMapper mapper = new ObjectMapper();
820 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
821 JsonNode root = mapper.readTree(request.getReader());
822 ClosedLoopSite siteData;
823 String userId = null;
825 siteData = (ClosedLoopSite)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
827 //check if update operation or create, get id for data to be updated and update attributeData
828 if ((update).equals(request.getParameter(operation))) {
829 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
830 ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
831 int id = data.getId();
838 siteData.setUserCreatedBy(this.getUserInfo(userId));
841 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
842 userId = root.get(userid).textValue();
844 if(siteData.getId() == 0){
845 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
846 if(!duplicateData.isEmpty()){
847 duplicateflag = true;
849 siteData.setUserCreatedBy(this.getUserInfo(userId));
850 siteData.setUserModifiedBy(this.getUserInfo(userId));
851 commonClassDao.save(siteData);
855 siteData.setUserModifiedBy(this.getUserInfo(userId));
856 siteData.setModifiedDate(new Date());
857 commonClassDao.update(siteData);
860 String responseString = "";
862 responseString = duplicateResponseString;
864 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
868 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
870 responseString = "Exists";
872 responseString = successMsg;
875 ModelAndView result = new ModelAndView();
876 result.setViewName(responseString);
879 response.setCharacterEncoding(utf8);
880 response.setContentType(applicationJsonContentType);
881 request.setCharacterEncoding(utf8);
883 PrintWriter out = response.getWriter();
884 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
885 out.write(j.toString());
888 }catch (Exception e){
889 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
890 response.setCharacterEncoding(utf8);
891 request.setCharacterEncoding(utf8);
892 PrintWriter out = response.getWriter();
893 out.write(e.getMessage());
898 @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
899 public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
901 ObjectMapper mapper = new ObjectMapper();
902 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
903 JsonNode root = mapper.readTree(request.getReader());
904 ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
905 commonClassDao.delete(closedLoopSite);
906 response.setCharacterEncoding(utf8);
907 response.setContentType(applicationJsonContentType);
908 request.setCharacterEncoding(utf8);
910 PrintWriter out = response.getWriter();
912 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
913 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
914 out.write(j.toString());
919 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
920 response.setCharacterEncoding(utf8);
921 request.setCharacterEncoding(utf8);
922 PrintWriter out = response.getWriter();
923 out.write(e.getMessage());
928 @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
929 public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
931 boolean duplicateflag = false;
932 boolean isFakeUpdate = false;
933 boolean fromAPI = false;
934 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
937 ObjectMapper mapper = new ObjectMapper();
938 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
939 JsonNode root = mapper.readTree(request.getReader());
940 VarbindDictionary varbindDictionary;
941 String userId = null;
943 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
946 //check if update operation or create, get id for data to be updated and update attributeData
947 if ((update).equals(request.getParameter(operation))) {
948 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
949 VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
950 int id = data.getId();
953 varbindDictionary.setId(1);
955 varbindDictionary.setId(id);
957 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
960 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
961 userId = root.get(userid).textValue();
963 if(varbindDictionary.getId() == 0){
964 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
965 if(!duplicateData.isEmpty()){
966 duplicateflag = true;
968 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
969 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
970 commonClassDao.save(varbindDictionary);
974 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
975 varbindDictionary.setModifiedDate(new Date());
976 commonClassDao.update(varbindDictionary);
979 String responseString = "";
981 responseString = duplicateResponseString;
983 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
987 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
989 responseString = "Exists";
991 responseString = successMsg;
994 ModelAndView result = new ModelAndView();
995 result.setViewName(responseString);
998 response.setCharacterEncoding(utf8);
999 response.setContentType(applicationJsonContentType);
1000 request.setCharacterEncoding(utf8);
1002 PrintWriter out = response.getWriter();
1003 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1004 out.write(j.toString());
1007 }catch (Exception e){
1008 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1009 response.setCharacterEncoding(utf8);
1010 request.setCharacterEncoding(utf8);
1011 PrintWriter out = response.getWriter();
1012 out.write(e.getMessage());
1017 @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1018 public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
1020 ObjectMapper mapper = new ObjectMapper();
1021 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1022 JsonNode root = mapper.readTree(request.getReader());
1023 VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
1024 commonClassDao.delete(varbindDictionary);
1025 response.setCharacterEncoding(utf8);
1026 response.setContentType(applicationJsonContentType);
1027 request.setCharacterEncoding(utf8);
1029 PrintWriter out = response.getWriter();
1031 String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
1032 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1033 out.write(j.toString());
1037 catch (Exception e){
1038 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1039 response.setCharacterEncoding(utf8);
1040 request.setCharacterEncoding(utf8);
1041 PrintWriter out = response.getWriter();
1042 out.write(e.getMessage());
1047 public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
1048 commonClassDao = commonClassDaoImpl;