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.util.JsonMessage;
39 import org.onap.policy.rest.dao.CommonClassDao;
40 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
41 import org.onap.policy.rest.jpa.ClosedLoopSite;
42 import org.onap.policy.rest.jpa.PEPOptions;
43 import org.onap.policy.rest.jpa.UserInfo;
44 import org.onap.policy.rest.jpa.VNFType;
45 import org.onap.policy.rest.jpa.VSCLAction;
46 import org.onap.policy.rest.jpa.VarbindDictionary;
47 import org.onap.policy.xacml.api.XACMLErrorConstants;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.http.MediaType;
50 import org.springframework.stereotype.Controller;
51 import org.springframework.web.bind.annotation.RequestMapping;
52 import org.springframework.web.servlet.ModelAndView;
54 import com.fasterxml.jackson.databind.DeserializationFeature;
55 import com.fasterxml.jackson.databind.JsonNode;
56 import com.fasterxml.jackson.databind.ObjectMapper;
59 public class ClosedLoopDictionaryController{
61 private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class);
63 private static CommonClassDao commonClassDao;
64 private static String vsclaction = "vsclaction";
65 private static String successMapKey = "successMapKey";
66 private static String successMessage = "success";
67 private static String operation = "operation";
68 private static String getDictionary = "getDictionary";
69 private static String dictionaryDBQuery = "dictionaryDBQuery";
70 private static String errorMsg = "error";
71 private static String vnftype = "vnftype";
72 private static String pepName = "pepName";
73 private static String varbindName = "varbindName";
74 private static String serviceName = "serviceName";
75 private static String siteName = "siteName";
76 private static String apiflag = "apiflag";
77 private static String dictionaryFields = "dictionaryFields";
78 private static String update = "update";
79 private static String duplicateResponseString = "Duplicate";
80 private static String userid = "userid";
81 private static String utf8 = "UTF-8";
82 private static String applicationJsonContentType = "application / json";
83 private static String successMsg = "Success";
86 public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
87 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
90 * This is an empty constructor
92 public ClosedLoopDictionaryController(){}
94 public UserInfo getUserInfo(String loginId){
95 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
99 @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
100 public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
102 Map<String, Object> model = new HashMap<>();
103 ObjectMapper mapper = new ObjectMapper();
104 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, vsclaction)));
105 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
106 JSONObject j = new JSONObject(msg);
107 response.getWriter().write(j.toString());
110 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
115 @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
116 public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
118 Map<String, Object> model = new HashMap<>();
119 ObjectMapper mapper = new ObjectMapper();
120 model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
121 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
122 JSONObject j = new JSONObject(msg);
123 response.addHeader(successMapKey, successMessage);
124 response.addHeader(operation, getDictionary);
125 response.getWriter().write(j.toString());
128 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
129 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
130 response.addHeader(errorMsg, dictionaryDBQuery);
134 @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
135 public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
137 Map<String, Object> model = new HashMap<>();
138 ObjectMapper mapper = new ObjectMapper();
139 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, vnftype)));
140 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
141 JSONObject j = new JSONObject(msg);
142 response.addHeader(successMapKey, successMessage);
143 response.addHeader(operation, getDictionary);
144 response.getWriter().write(j.toString());
147 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
151 @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
152 public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
154 Map<String, Object> model = new HashMap<>();
155 ObjectMapper mapper = new ObjectMapper();
156 model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
157 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
158 JSONObject j = new JSONObject(msg);
159 response.addHeader(successMapKey, successMessage);
160 response.addHeader(operation, getDictionary);
161 response.getWriter().write(j.toString());
164 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
165 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
166 response.addHeader(errorMsg, dictionaryDBQuery);
170 @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
171 public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
173 Map<String, Object> model = new HashMap<>();
174 ObjectMapper mapper = new ObjectMapper();
175 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, pepName)));
176 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
177 JSONObject j = new JSONObject(msg);
178 response.getWriter().write(j.toString());
181 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
185 @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
186 public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
188 Map<String, Object> model = new HashMap<>();
189 ObjectMapper mapper = new ObjectMapper();
190 model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
191 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
192 JSONObject j = new JSONObject(msg);
193 response.addHeader(successMapKey, successMessage);
194 response.addHeader(operation, getDictionary);
195 response.getWriter().write(j.toString());
198 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
199 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
200 response.addHeader(errorMsg, dictionaryDBQuery);
204 @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
205 public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
207 Map<String, Object> model = new HashMap<>();
208 ObjectMapper mapper = new ObjectMapper();
209 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, varbindName)));
210 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
211 JSONObject j = new JSONObject(msg);
212 response.getWriter().write(j.toString());
215 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
219 @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
220 public void getVarbindDictionaryEntityData(HttpServletResponse response){
222 Map<String, Object> model = new HashMap<>();
223 ObjectMapper mapper = new ObjectMapper();
224 model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
225 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
226 JSONObject j = new JSONObject(msg);
227 response.addHeader(successMapKey, successMessage);
228 response.addHeader(operation, getDictionary);
229 response.getWriter().write(j.toString());
232 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
233 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
234 response.addHeader(errorMsg, dictionaryDBQuery);
238 @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
239 public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
241 Map<String, Object> model = new HashMap<>();
242 ObjectMapper mapper = new ObjectMapper();
243 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, serviceName)));
244 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
245 JSONObject j = new JSONObject(msg);
246 response.getWriter().write(j.toString());
249 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
253 @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
254 public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
256 Map<String, Object> model = new HashMap<>();
257 ObjectMapper mapper = new ObjectMapper();
258 model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
259 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
260 JSONObject j = new JSONObject(msg);
261 response.addHeader(successMapKey, successMessage);
262 response.addHeader(operation, getDictionary);
263 response.getWriter().write(j.toString());
266 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
267 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
268 response.addHeader(errorMsg, dictionaryDBQuery);
272 @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
273 public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
275 Map<String, Object> model = new HashMap<>();
276 ObjectMapper mapper = new ObjectMapper();
277 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, siteName)));
278 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
279 JSONObject j = new JSONObject(msg);
280 response.getWriter().write(j.toString());
283 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
287 @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
288 public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
290 Map<String, Object> model = new HashMap<>();
291 ObjectMapper mapper = new ObjectMapper();
292 model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
293 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
294 JSONObject j = new JSONObject(msg);
295 response.addHeader(successMapKey, successMessage);
296 response.addHeader(operation, getDictionary);
297 response.getWriter().write(j.toString());
300 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
301 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
302 response.addHeader(errorMsg, dictionaryDBQuery);
306 @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
307 public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
309 boolean duplicateflag = false;
310 boolean isFakeUpdate = false;
311 boolean fromAPI = false;
312 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
315 ObjectMapper mapper = new ObjectMapper();
316 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
317 JsonNode root = mapper.readTree(request.getReader());
318 VSCLAction vSCLAction;
319 String userId = null;
321 vSCLAction = (VSCLAction)mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
324 //check if update operation or create, get id for data to be updated and update attributeData
325 if ((update).equals(request.getParameter(operation))) {
326 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
327 VSCLAction data = (VSCLAction) duplicateData.get(0);
328 int id = data.getId();
333 vSCLAction.setId(id);
336 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
340 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
341 userId = root.get(userid).textValue();
343 if(vSCLAction.getId() == 0){
344 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
345 if(!duplicateData.isEmpty()){
346 duplicateflag = true;
348 vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
349 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
350 vSCLAction.setModifiedDate(new Date());
351 commonClassDao.save(vSCLAction);
355 vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
356 commonClassDao.update(vSCLAction);
360 String responseString = "";
362 responseString = duplicateResponseString;
364 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
367 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
369 responseString = "Exists";
371 responseString = successMsg;
375 ModelAndView result = new ModelAndView();
376 result.setViewName(responseString);
379 response.setCharacterEncoding(utf8);
380 response.setContentType(applicationJsonContentType);
381 request.setCharacterEncoding(utf8);
383 PrintWriter out = response.getWriter();
384 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
385 out.write(j.toString());
390 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
391 response.setCharacterEncoding(utf8);
392 request.setCharacterEncoding(utf8);
393 PrintWriter out = response.getWriter();
394 out.write(e.getMessage());
399 @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
400 public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
402 ObjectMapper mapper = new ObjectMapper();
403 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
404 JsonNode root = mapper.readTree(request.getReader());
405 VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
406 commonClassDao.delete(vSCLAction);
407 response.setCharacterEncoding(utf8);
408 response.setContentType(applicationJsonContentType);
409 request.setCharacterEncoding(utf8);
411 PrintWriter out = response.getWriter();
413 String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
414 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
415 out.write(j.toString());
420 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
421 response.setCharacterEncoding(utf8);
422 request.setCharacterEncoding(utf8);
423 PrintWriter out = response.getWriter();
424 out.write(e.getMessage());
429 @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
430 public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
432 boolean duplicateflag = false;
433 boolean isFakeUpdate = false;
434 boolean fromAPI = false;
436 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
439 ObjectMapper mapper = new ObjectMapper();
440 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
441 JsonNode root = mapper.readTree(request.getReader());
443 String userId = null;
446 vNFType = (VNFType)mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
449 //check if update operation or create, get id for data to be updated and update attributeData
450 if ((update).equals(request.getParameter(operation))) {
451 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
452 VNFType data = (VNFType) duplicateData.get(0);
453 int id = data.getId();
460 vNFType.setUserCreatedBy(this.getUserInfo(userId));
463 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
464 userId = root.get(userid).textValue();
466 if(vNFType.getId() == 0){
467 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
468 if(!duplicateData.isEmpty()){
469 duplicateflag = true;
471 vNFType.setUserCreatedBy(this.getUserInfo(userId));
472 vNFType.setUserModifiedBy(this.getUserInfo(userId));
473 commonClassDao.save(vNFType);
477 vNFType.setUserModifiedBy(this.getUserInfo(userId));
478 vNFType.setModifiedDate(new Date());
479 commonClassDao.update(vNFType);
482 String responseString = "";
484 responseString = duplicateResponseString;
486 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
489 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
491 responseString = "Exists";
493 responseString = successMsg;
496 ModelAndView result = new ModelAndView();
497 result.setViewName(responseString);
500 response.setCharacterEncoding(utf8);
501 response.setContentType(applicationJsonContentType);
502 request.setCharacterEncoding(utf8);
504 PrintWriter out = response.getWriter();
505 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
506 out.write(j.toString());
511 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
512 response.setCharacterEncoding(utf8);
513 request.setCharacterEncoding(utf8);
514 PrintWriter out = response.getWriter();
515 out.write(e.getMessage());
520 @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
521 public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
523 ObjectMapper mapper = new ObjectMapper();
524 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
525 JsonNode root = mapper.readTree(request.getReader());
526 VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
527 commonClassDao.delete(vNFType);
528 response.setCharacterEncoding(utf8);
529 response.setContentType(applicationJsonContentType);
530 request.setCharacterEncoding(utf8);
532 PrintWriter out = response.getWriter();
534 String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
535 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
536 out.write(j.toString());
541 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
542 response.setCharacterEncoding(utf8);
543 request.setCharacterEncoding(utf8);
544 PrintWriter out = response.getWriter();
545 out.write(e.getMessage());
550 @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
551 public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
553 boolean duplicateflag = false;
554 boolean isFakeUpdate = false;
555 boolean fromAPI = false;
556 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
559 ObjectMapper mapper = new ObjectMapper();
560 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
561 JsonNode root = mapper.readTree(request.getReader());
562 PEPOptions pEPOptions;
564 String userId = null;
566 pEPOptions = (PEPOptions)mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class);
567 gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
570 //check if update operation or create, get id for data to be updated and update attributeData
571 if ((update).equals(request.getParameter(operation))) {
572 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
573 PEPOptions data = (PEPOptions) duplicateData.get(0);
574 int id = data.getId();
579 pEPOptions.setId(id);
581 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
584 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
585 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
586 userId = root.get(userid).textValue();
590 if(!gridData.getAttributes().isEmpty()){
591 for(Object attribute : gridData.getAttributes()){
592 if(attribute instanceof LinkedHashMap<?, ?>){
593 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
594 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
596 actions = actions + ":#@";
598 actions = actions + key + "=#@";
599 actions = actions + value;
604 pEPOptions.setActions(actions);
605 if(pEPOptions.getId() == 0){
606 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
607 if(!duplicateData.isEmpty()){
608 duplicateflag = true;
610 pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
611 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
612 commonClassDao.save(pEPOptions);
616 pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
617 pEPOptions.setModifiedDate(new Date());
618 commonClassDao.update(pEPOptions);
621 String responseString = "";
623 responseString = duplicateResponseString;
625 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
628 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
630 responseString = "Exists";
632 responseString = successMsg;
636 ModelAndView result = new ModelAndView();
637 result.setViewName(responseString);
640 response.setCharacterEncoding(utf8);
641 response.setContentType(applicationJsonContentType);
642 request.setCharacterEncoding(utf8);
644 PrintWriter out = response.getWriter();
645 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
646 out.write(j.toString());
650 }catch (Exception e){
651 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
652 response.setCharacterEncoding(utf8);
653 request.setCharacterEncoding(utf8);
654 PrintWriter out = response.getWriter();
655 out.write(e.getMessage());
660 @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
661 public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
663 ObjectMapper mapper = new ObjectMapper();
664 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
665 JsonNode root = mapper.readTree(request.getReader());
666 PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
667 commonClassDao.delete(pEPOptions);
668 response.setCharacterEncoding(utf8);
669 response.setContentType(applicationJsonContentType);
670 request.setCharacterEncoding(utf8);
672 PrintWriter out = response.getWriter();
674 String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
675 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
676 out.write(j.toString());
681 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
682 response.setCharacterEncoding(utf8);
683 request.setCharacterEncoding(utf8);
684 PrintWriter out = response.getWriter();
685 out.write(e.getMessage());
690 @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
691 public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
693 boolean duplicateflag = false;
694 boolean isFakeUpdate = false;
695 boolean fromAPI = false;
696 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
699 ObjectMapper mapper = new ObjectMapper();
700 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
701 JsonNode root = mapper.readTree(request.getReader());
702 ClosedLoopD2Services serviceData;
703 String userId = null;
705 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
708 //check if update operation or create, get id for data to be updated and update attributeData
709 if ((update).equals(request.getParameter(operation))) {
710 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
711 ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
712 int id = data.getId();
715 serviceData.setId(1);
717 serviceData.setId(id);
719 serviceData.setUserCreatedBy(this.getUserInfo(userId));
722 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
723 userId = root.get(userid).textValue();
725 if(serviceData.getId() == 0){
726 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
727 if(!duplicateData.isEmpty()){
728 duplicateflag = true;
730 serviceData.setUserCreatedBy(this.getUserInfo(userId));
731 serviceData.setUserModifiedBy(this.getUserInfo(userId));
732 commonClassDao.save(serviceData);
736 serviceData.setUserModifiedBy(this.getUserInfo(userId));
737 serviceData.setModifiedDate(new Date());
738 commonClassDao.update(serviceData);
741 String responseString = "";
743 responseString = duplicateResponseString;
745 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
748 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
750 responseString = "Exists";
752 responseString = successMsg;
755 ModelAndView result = new ModelAndView();
756 result.setViewName(responseString);
759 response.setCharacterEncoding(utf8);
760 response.setContentType(applicationJsonContentType);
761 request.setCharacterEncoding(utf8);
763 PrintWriter out = response.getWriter();
764 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
765 out.write(j.toString());
768 }catch (Exception e){
769 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
770 response.setCharacterEncoding(utf8);
771 request.setCharacterEncoding(utf8);
772 PrintWriter out = response.getWriter();
773 out.write(e.getMessage());
778 @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
779 public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
781 ObjectMapper mapper = new ObjectMapper();
782 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
783 JsonNode root = mapper.readTree(request.getReader());
784 ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
785 commonClassDao.delete(closedLoopD2Services);
786 response.setCharacterEncoding(utf8);
787 response.setContentType(applicationJsonContentType);
788 request.setCharacterEncoding(utf8);
790 PrintWriter out = response.getWriter();
792 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
793 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
794 out.write(j.toString());
799 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
800 response.setCharacterEncoding(utf8);
801 request.setCharacterEncoding(utf8);
802 PrintWriter out = response.getWriter();
803 out.write(e.getMessage());
808 @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
809 public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
811 boolean duplicateflag = false;
812 boolean isFakeUpdate = false;
813 boolean fromAPI = false;
815 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
818 ObjectMapper mapper = new ObjectMapper();
819 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
820 JsonNode root = mapper.readTree(request.getReader());
821 ClosedLoopSite siteData;
822 String userId = null;
824 siteData = (ClosedLoopSite)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
826 //check if update operation or create, get id for data to be updated and update attributeData
827 if ((update).equals(request.getParameter(operation))) {
828 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
829 ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
830 int id = data.getId();
837 siteData.setUserCreatedBy(this.getUserInfo(userId));
840 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
841 userId = root.get(userid).textValue();
843 if(siteData.getId() == 0){
844 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
845 if(!duplicateData.isEmpty()){
846 duplicateflag = true;
848 siteData.setUserCreatedBy(this.getUserInfo(userId));
849 siteData.setUserModifiedBy(this.getUserInfo(userId));
850 commonClassDao.save(siteData);
854 siteData.setUserModifiedBy(this.getUserInfo(userId));
855 siteData.setModifiedDate(new Date());
856 commonClassDao.update(siteData);
859 String responseString = "";
861 responseString = duplicateResponseString;
863 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
867 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
869 responseString = "Exists";
871 responseString = successMsg;
874 ModelAndView result = new ModelAndView();
875 result.setViewName(responseString);
878 response.setCharacterEncoding(utf8);
879 response.setContentType(applicationJsonContentType);
880 request.setCharacterEncoding(utf8);
882 PrintWriter out = response.getWriter();
883 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
884 out.write(j.toString());
887 }catch (Exception e){
888 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
889 response.setCharacterEncoding(utf8);
890 request.setCharacterEncoding(utf8);
891 PrintWriter out = response.getWriter();
892 out.write(e.getMessage());
897 @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
898 public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
900 ObjectMapper mapper = new ObjectMapper();
901 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
902 JsonNode root = mapper.readTree(request.getReader());
903 ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
904 commonClassDao.delete(closedLoopSite);
905 response.setCharacterEncoding(utf8);
906 response.setContentType(applicationJsonContentType);
907 request.setCharacterEncoding(utf8);
909 PrintWriter out = response.getWriter();
911 String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
912 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
913 out.write(j.toString());
918 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
919 response.setCharacterEncoding(utf8);
920 request.setCharacterEncoding(utf8);
921 PrintWriter out = response.getWriter();
922 out.write(e.getMessage());
927 @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
928 public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
930 boolean duplicateflag = false;
931 boolean isFakeUpdate = false;
932 boolean fromAPI = false;
933 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
936 ObjectMapper mapper = new ObjectMapper();
937 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
938 JsonNode root = mapper.readTree(request.getReader());
939 VarbindDictionary varbindDictionary;
940 String userId = null;
942 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
945 //check if update operation or create, get id for data to be updated and update attributeData
946 if ((update).equals(request.getParameter(operation))) {
947 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
948 VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
949 int id = data.getId();
952 varbindDictionary.setId(1);
954 varbindDictionary.setId(id);
956 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
959 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
960 userId = root.get(userid).textValue();
962 if(varbindDictionary.getId() == 0){
963 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
964 if(!duplicateData.isEmpty()){
965 duplicateflag = true;
967 varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
968 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
969 commonClassDao.save(varbindDictionary);
973 varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
974 varbindDictionary.setModifiedDate(new Date());
975 commonClassDao.update(varbindDictionary);
978 String responseString = "";
980 responseString = duplicateResponseString;
982 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
986 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
988 responseString = "Exists";
990 responseString = successMsg;
993 ModelAndView result = new ModelAndView();
994 result.setViewName(responseString);
997 response.setCharacterEncoding(utf8);
998 response.setContentType(applicationJsonContentType);
999 request.setCharacterEncoding(utf8);
1001 PrintWriter out = response.getWriter();
1002 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1003 out.write(j.toString());
1006 }catch (Exception e){
1007 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1008 response.setCharacterEncoding(utf8);
1009 request.setCharacterEncoding(utf8);
1010 PrintWriter out = response.getWriter();
1011 out.write(e.getMessage());
1016 @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1017 public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
1019 ObjectMapper mapper = new ObjectMapper();
1020 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1021 JsonNode root = mapper.readTree(request.getReader());
1022 VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
1023 commonClassDao.delete(varbindDictionary);
1024 response.setCharacterEncoding(utf8);
1025 response.setContentType(applicationJsonContentType);
1026 request.setCharacterEncoding(utf8);
1028 PrintWriter out = response.getWriter();
1030 String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
1031 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1032 out.write(j.toString());
1036 catch (Exception e){
1037 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1038 response.setCharacterEncoding(utf8);
1039 request.setCharacterEncoding(utf8);
1040 PrintWriter out = response.getWriter();
1041 out.write(e.getMessage());