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.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          * This is an empty constructor
 
  94         public ClosedLoopDictionaryController(){}
 
  96         public UserInfo getUserInfo(String loginId){
 
  97                 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
 
 101         @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 102         public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
 
 104                         Map<String, Object> model = new HashMap<>();
 
 105                         ObjectMapper mapper = new ObjectMapper();
 
 106                         model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, vsclaction)));
 
 107                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 108                         JSONObject j = new JSONObject(msg);
 
 109                         response.getWriter().write(j.toString());
 
 112                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 117         @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 118         public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
 
 120                         Map<String, Object> model = new HashMap<>();
 
 121                         ObjectMapper mapper = new ObjectMapper();
 
 122                         model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
 
 123                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 124                         JSONObject j = new JSONObject(msg);
 
 125                         response.addHeader(successMapKey, successMessage); 
 
 126                         response.addHeader(operation, getDictionary);
 
 127                         response.getWriter().write(j.toString());
 
 130                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 131                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 132                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 136         @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 137         public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
 
 139                         Map<String, Object> model = new HashMap<>();
 
 140                         ObjectMapper mapper = new ObjectMapper();
 
 141                         model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, vnftype)));
 
 142                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 143                         JSONObject j = new JSONObject(msg);
 
 144                         response.addHeader(successMapKey, successMessage); 
 
 145                         response.addHeader(operation, getDictionary);
 
 146                         response.getWriter().write(j.toString());
 
 149                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 153         @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 154         public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
 
 156                         Map<String, Object> model = new HashMap<>();
 
 157                         ObjectMapper mapper = new ObjectMapper();
 
 158                         model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
 
 159                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 160                         JSONObject j = new JSONObject(msg);
 
 161                         response.addHeader(successMapKey, successMessage); 
 
 162                         response.addHeader(operation, getDictionary);
 
 163                         response.getWriter().write(j.toString());
 
 166                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 167                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 168                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 172         @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 173         public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
 
 175                         Map<String, Object> model = new HashMap<>();
 
 176                         ObjectMapper mapper = new ObjectMapper();
 
 177                         model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, pepName)));
 
 178                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 179                         JSONObject j = new JSONObject(msg);
 
 180                         response.getWriter().write(j.toString());
 
 183                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 187         @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 188         public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
 
 190                         Map<String, Object> model = new HashMap<>();
 
 191                         ObjectMapper mapper = new ObjectMapper();
 
 192                         model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
 
 193                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 194                         JSONObject j = new JSONObject(msg);
 
 195                         response.addHeader(successMapKey, successMessage); 
 
 196                         response.addHeader(operation, getDictionary);
 
 197                         response.getWriter().write(j.toString());
 
 200                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 201                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 202                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 206         @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 207         public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
 
 209                         Map<String, Object> model = new HashMap<>();
 
 210                         ObjectMapper mapper = new ObjectMapper();
 
 211                         model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, varbindName)));
 
 212                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 213                         JSONObject j = new JSONObject(msg);
 
 214                         response.getWriter().write(j.toString());
 
 217                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 221         @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 222         public void getVarbindDictionaryEntityData(HttpServletResponse response){
 
 224                         Map<String, Object> model = new HashMap<>();
 
 225                         ObjectMapper mapper = new ObjectMapper();
 
 226                         model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
 
 227                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 228                         JSONObject j = new JSONObject(msg);
 
 229                         response.addHeader(successMapKey, successMessage); 
 
 230                         response.addHeader(operation, getDictionary);
 
 231                         response.getWriter().write(j.toString());
 
 234                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 235                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 236                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 240         @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 241         public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
 
 243                         Map<String, Object> model = new HashMap<>();
 
 244                         ObjectMapper mapper = new ObjectMapper();
 
 245                         model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, serviceName)));
 
 246                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 247                         JSONObject j = new JSONObject(msg);
 
 248                         response.getWriter().write(j.toString());
 
 251                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 255         @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 256         public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
 
 258                         Map<String, Object> model = new HashMap<>();
 
 259                         ObjectMapper mapper = new ObjectMapper();
 
 260                         model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
 
 261                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 262                         JSONObject j = new JSONObject(msg);
 
 263                         response.addHeader(successMapKey, successMessage); 
 
 264                         response.addHeader(operation, getDictionary);
 
 265                         response.getWriter().write(j.toString());
 
 268                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 269                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 270                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 274         @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 275         public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
 
 277                         Map<String, Object> model = new HashMap<>();
 
 278                         ObjectMapper mapper = new ObjectMapper();
 
 279                         model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, siteName)));
 
 280                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 281                         JSONObject j = new JSONObject(msg);
 
 282                         response.getWriter().write(j.toString());
 
 285                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 289         @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 290         public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
 
 292                         Map<String, Object> model = new HashMap<>();
 
 293                         ObjectMapper mapper = new ObjectMapper();
 
 294                         model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
 
 295                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 296                         JSONObject j = new JSONObject(msg);
 
 297                         response.addHeader(successMapKey, successMessage); 
 
 298                         response.addHeader(operation, getDictionary);
 
 299                         response.getWriter().write(j.toString());
 
 302                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 303                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 304                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 308         @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 309         public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
 
 311                         boolean duplicateflag = false;
 
 312                         boolean isFakeUpdate = false;
 
 313                         boolean fromAPI = false;
 
 314                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 317                         ObjectMapper mapper = new ObjectMapper();
 
 318                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 319                         JsonNode root = mapper.readTree(request.getReader());
 
 320                         VSCLAction vSCLAction;
 
 321                         String userId = null;
 
 323                                 vSCLAction = (VSCLAction)mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
 
 326                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 327                                 if ((update).equals(request.getParameter(operation))) {
 
 328                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
 
 329                                         VSCLAction data = (VSCLAction) duplicateData.get(0);
 
 330                                         int id = data.getId();
 
 335                                                 vSCLAction.setId(id);
 
 338                                         vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
 
 342                                 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
 
 343                                 userId = root.get(userid).textValue();
 
 345                         if(vSCLAction.getId() == 0){
 
 346                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
 
 347                                 if(!duplicateData.isEmpty()){
 
 348                                         duplicateflag = true;
 
 350                                         vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
 
 351                                         vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
 
 352                                         vSCLAction.setModifiedDate(new Date());
 
 353                                         commonClassDao.save(vSCLAction);
 
 357                                         vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
 
 358                                         commonClassDao.update(vSCLAction); 
 
 362                         String responseString = "";
 
 364                                 responseString = duplicateResponseString;
 
 366                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
 
 369                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 371                                                 responseString = "Exists";
 
 373                                                 responseString = successMsg;
 
 377                                 ModelAndView result = new ModelAndView();
 
 378                                 result.setViewName(responseString);
 
 381                                 response.setCharacterEncoding(utf8);
 
 382                                 response.setContentType(applicationJsonContentType); 
 
 383                                 request.setCharacterEncoding(utf8);
 
 385                                 PrintWriter out = response.getWriter();
 
 386                                 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
 
 387                                 out.write(j.toString());
 
 392                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 393                         response.setCharacterEncoding(utf8);
 
 394                         request.setCharacterEncoding(utf8);
 
 395                         PrintWriter out = response.getWriter();
 
 396                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 401         @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 402         public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 404                         ObjectMapper mapper = new ObjectMapper();
 
 405                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 406                         JsonNode root = mapper.readTree(request.getReader());
 
 407                         VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
 
 408                         commonClassDao.delete(vSCLAction);
 
 409                         response.setCharacterEncoding(utf8);
 
 410                         response.setContentType(applicationJsonContentType);
 
 411                         request.setCharacterEncoding(utf8);
 
 413                         PrintWriter out = response.getWriter();
 
 415                         String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
 
 416                         JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
 
 417                         out.write(j.toString());
 
 422                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 423                         response.setCharacterEncoding(utf8);
 
 424                         request.setCharacterEncoding(utf8);
 
 425                         PrintWriter out = response.getWriter();
 
 426                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 431         @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 432         public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 434                         boolean duplicateflag = false;
 
 435                         boolean isFakeUpdate = false;
 
 436                         boolean fromAPI = false;
 
 438                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 441                         ObjectMapper mapper = new ObjectMapper();
 
 442                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 443                         JsonNode root = mapper.readTree(request.getReader());
 
 445                         String userId = null;
 
 448                                 vNFType = (VNFType)mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
 
 451                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 452                                 if ((update).equals(request.getParameter(operation))) {
 
 453                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
 
 454                                         VNFType data = (VNFType) duplicateData.get(0);
 
 455                                         int id = data.getId();
 
 462                                         vNFType.setUserCreatedBy(this.getUserInfo(userId));
 
 465                                 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
 
 466                                 userId = root.get(userid).textValue();
 
 468                         if(vNFType.getId() == 0){
 
 469                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
 
 470                                 if(!duplicateData.isEmpty()){
 
 471                                         duplicateflag = true;
 
 473                                         vNFType.setUserCreatedBy(this.getUserInfo(userId));
 
 474                                         vNFType.setUserModifiedBy(this.getUserInfo(userId));
 
 475                                         commonClassDao.save(vNFType);
 
 479                                         vNFType.setUserModifiedBy(this.getUserInfo(userId));
 
 480                                         vNFType.setModifiedDate(new Date());
 
 481                                         commonClassDao.update(vNFType); 
 
 484                         String responseString = "";
 
 486                                 responseString = duplicateResponseString;
 
 488                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
 
 491                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 493                                                 responseString = "Exists";
 
 495                                                 responseString = successMsg;
 
 498                                 ModelAndView result = new ModelAndView();
 
 499                                 result.setViewName(responseString);
 
 502                                 response.setCharacterEncoding(utf8);
 
 503                                 response.setContentType(applicationJsonContentType);
 
 504                                 request.setCharacterEncoding(utf8);
 
 506                                 PrintWriter out = response.getWriter();
 
 507                                 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
 
 508                                 out.write(j.toString()); 
 
 513                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 514                         response.setCharacterEncoding(utf8);
 
 515                         request.setCharacterEncoding(utf8);
 
 516                         PrintWriter out = response.getWriter();
 
 517                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 522         @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 523         public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 525                         ObjectMapper mapper = new ObjectMapper();
 
 526                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 527                         JsonNode root = mapper.readTree(request.getReader());
 
 528                         VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
 
 529                         commonClassDao.delete(vNFType);
 
 530                         response.setCharacterEncoding(utf8);
 
 531                         response.setContentType(applicationJsonContentType);
 
 532                         request.setCharacterEncoding(utf8);
 
 534                         PrintWriter out = response.getWriter();
 
 536                         String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
 
 537                         JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
 
 538                         out.write(j.toString());
 
 543                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 544                         response.setCharacterEncoding(utf8);
 
 545                         request.setCharacterEncoding(utf8);
 
 546                         PrintWriter out = response.getWriter();
 
 547                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 552         @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 553         public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 555                         boolean duplicateflag = false;
 
 556             boolean isFakeUpdate = false;
 
 557             boolean fromAPI = false;
 
 558             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 561                         ObjectMapper mapper = new ObjectMapper();
 
 562                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 563                         JsonNode root = mapper.readTree(request.getReader());
 
 564             PEPOptions pEPOptions;
 
 566             String userId = null;
 
 568                 pEPOptions = (PEPOptions)mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class);
 
 569                 gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
 
 572                 //check if update operation or create, get id for data to be updated and update attributeData
 
 573                 if ((update).equals(request.getParameter(operation))) {
 
 574                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
 
 575                     PEPOptions data = (PEPOptions) duplicateData.get(0);
 
 576                     int id = data.getId();
 
 581                         pEPOptions.setId(id);
 
 583                     pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
 
 586                 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
 
 587                 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
 
 588                 userId = root.get(userid).textValue();
 
 592                         if(!gridData.getAttributes().isEmpty()){
 
 593                                 for(Object attribute : gridData.getAttributes()){
 
 594                                         if(attribute instanceof LinkedHashMap<?, ?>){
 
 595                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
 
 596                                                 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
 
 598                                                         actions = actions + ":#@";
 
 600                                                 actions = actions + key + "=#@";
 
 601                                                 actions = actions + value;
 
 606                         pEPOptions.setActions(actions);
 
 607                         if(pEPOptions.getId() == 0){
 
 608                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
 
 609                                 if(!duplicateData.isEmpty()){
 
 610                                         duplicateflag = true;
 
 612                                         pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
 
 613                                         pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
 
 614                                         commonClassDao.save(pEPOptions);
 
 618                                         pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
 
 619                                         pEPOptions.setModifiedDate(new Date());
 
 620                                         commonClassDao.update(pEPOptions);
 
 623             String responseString = "";
 
 625                 responseString = duplicateResponseString;
 
 627                 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
 
 630                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 632                         responseString = "Exists";
 
 634                         responseString = successMsg;
 
 638                 ModelAndView result = new ModelAndView();
 
 639                 result.setViewName(responseString);
 
 642                 response.setCharacterEncoding(utf8);
 
 643                 response.setContentType(applicationJsonContentType);
 
 644                 request.setCharacterEncoding(utf8);
 
 646                 PrintWriter out = response.getWriter();
 
 647                 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
 
 648                 out.write(j.toString());
 
 652         }catch (Exception e){
 
 653                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 654                         response.setCharacterEncoding(utf8);
 
 655                         request.setCharacterEncoding(utf8);
 
 656                         PrintWriter out = response.getWriter();
 
 657                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 662         @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 663         public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 665                         ObjectMapper mapper = new ObjectMapper();
 
 666                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 667                         JsonNode root = mapper.readTree(request.getReader());
 
 668                         PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
 
 669                         commonClassDao.delete(pEPOptions);
 
 670                         response.setCharacterEncoding(utf8);
 
 671                         response.setContentType(applicationJsonContentType);
 
 672                         request.setCharacterEncoding(utf8);
 
 674                         PrintWriter out = response.getWriter();
 
 676                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
 
 677                         JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
 
 678                         out.write(j.toString());
 
 683                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 684                         response.setCharacterEncoding(utf8);
 
 685                         request.setCharacterEncoding(utf8);
 
 686                         PrintWriter out = response.getWriter();
 
 687                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 692         @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 693         public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 695                         boolean duplicateflag = false;
 
 696             boolean isFakeUpdate = false;
 
 697             boolean fromAPI = false;
 
 698             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 701                         ObjectMapper mapper = new ObjectMapper();
 
 702                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 703                         JsonNode root = mapper.readTree(request.getReader());
 
 704             ClosedLoopD2Services serviceData;
 
 705             String userId = null;
 
 707                 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
 
 710                 //check if update operation or create, get id for data to be updated and update attributeData
 
 711                 if ((update).equals(request.getParameter(operation))) {
 
 712                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
 
 713                     ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
 
 714                     int id = data.getId();
 
 717                         serviceData.setId(1);
 
 719                         serviceData.setId(id);
 
 721                     serviceData.setUserCreatedBy(this.getUserInfo(userId));
 
 724                 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
 
 725                 userId = root.get(userid).textValue();
 
 727                         if(serviceData.getId() == 0){
 
 728                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
 
 729                                 if(!duplicateData.isEmpty()){
 
 730                                         duplicateflag = true;
 
 732                                         serviceData.setUserCreatedBy(this.getUserInfo(userId));
 
 733                                         serviceData.setUserModifiedBy(this.getUserInfo(userId));
 
 734                                         commonClassDao.save(serviceData);
 
 738                                         serviceData.setUserModifiedBy(this.getUserInfo(userId));
 
 739                                         serviceData.setModifiedDate(new Date());
 
 740                                         commonClassDao.update(serviceData); 
 
 743             String responseString = "";
 
 745                 responseString = duplicateResponseString;
 
 747                 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
 
 750                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 752                         responseString = "Exists";
 
 754                         responseString = successMsg;
 
 757                 ModelAndView result = new ModelAndView();
 
 758                 result.setViewName(responseString);
 
 761                 response.setCharacterEncoding(utf8);
 
 762                 response.setContentType(applicationJsonContentType);
 
 763                 request.setCharacterEncoding(utf8);
 
 765                 PrintWriter out = response.getWriter();
 
 766                 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
 
 767                 out.write(j.toString());
 
 770         }catch (Exception e){
 
 771                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 772                         response.setCharacterEncoding(utf8);
 
 773                         request.setCharacterEncoding(utf8);
 
 774                         PrintWriter out = response.getWriter();
 
 775                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 780         @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 781         public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 783                         ObjectMapper mapper = new ObjectMapper();
 
 784                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 785                         JsonNode root = mapper.readTree(request.getReader());
 
 786                         ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
 
 787                         commonClassDao.delete(closedLoopD2Services);
 
 788                         response.setCharacterEncoding(utf8);
 
 789                         response.setContentType(applicationJsonContentType);
 
 790                         request.setCharacterEncoding(utf8);
 
 792                         PrintWriter out = response.getWriter();
 
 794                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
 
 795                         JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
 
 796                         out.write(j.toString());
 
 801                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 802                         response.setCharacterEncoding(utf8);
 
 803                         request.setCharacterEncoding(utf8);
 
 804                         PrintWriter out = response.getWriter();
 
 805                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 810         @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 811         public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 813                         boolean duplicateflag = false;
 
 814             boolean isFakeUpdate = false;
 
 815             boolean fromAPI = false;
 
 817             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 820                         ObjectMapper mapper = new ObjectMapper();
 
 821                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 822                         JsonNode root = mapper.readTree(request.getReader());
 
 823             ClosedLoopSite siteData;
 
 824             String userId = null;
 
 826                 siteData = (ClosedLoopSite)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
 
 828                 //check if update operation or create, get id for data to be updated and update attributeData
 
 829                 if ((update).equals(request.getParameter(operation))) {
 
 830                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
 
 831                     ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
 
 832                     int id = data.getId();
 
 839                     siteData.setUserCreatedBy(this.getUserInfo(userId));
 
 842                 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
 
 843                 userId = root.get(userid).textValue();
 
 845                         if(siteData.getId() == 0){
 
 846                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
 
 847                                 if(!duplicateData.isEmpty()){
 
 848                                         duplicateflag = true;
 
 850                                         siteData.setUserCreatedBy(this.getUserInfo(userId));
 
 851                                         siteData.setUserModifiedBy(this.getUserInfo(userId));
 
 852                                         commonClassDao.save(siteData);
 
 856                                         siteData.setUserModifiedBy(this.getUserInfo(userId));
 
 857                                         siteData.setModifiedDate(new Date());
 
 858                                         commonClassDao.update(siteData);
 
 861             String responseString = "";
 
 863                 responseString = duplicateResponseString;
 
 865                 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
 
 869                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 871                         responseString = "Exists";
 
 873                         responseString = successMsg;
 
 876                 ModelAndView result = new ModelAndView();
 
 877                 result.setViewName(responseString);
 
 880                 response.setCharacterEncoding(utf8);
 
 881                 response.setContentType(applicationJsonContentType);
 
 882                 request.setCharacterEncoding(utf8);
 
 884                 PrintWriter out = response.getWriter();
 
 885                 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
 
 886                 out.write(j.toString());
 
 889         }catch (Exception e){
 
 890                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 891                         response.setCharacterEncoding(utf8);
 
 892                         request.setCharacterEncoding(utf8);
 
 893                         PrintWriter out = response.getWriter();
 
 894                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 899         @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 900         public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 902                         ObjectMapper mapper = new ObjectMapper();
 
 903                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 904                         JsonNode root = mapper.readTree(request.getReader());
 
 905                         ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
 
 906                         commonClassDao.delete(closedLoopSite);
 
 907                         response.setCharacterEncoding(utf8);
 
 908                         response.setContentType(applicationJsonContentType);
 
 909                         request.setCharacterEncoding(utf8);
 
 911                         PrintWriter out = response.getWriter();
 
 913                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
 
 914                         JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
 
 915                         out.write(j.toString());
 
 920                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
 921                         response.setCharacterEncoding(utf8);
 
 922                         request.setCharacterEncoding(utf8);
 
 923                         PrintWriter out = response.getWriter();
 
 924                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
 929         @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 930         public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 932                         boolean duplicateflag = false;
 
 933             boolean isFakeUpdate = false;
 
 934             boolean fromAPI = false;
 
 935             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 938                         ObjectMapper mapper = new ObjectMapper();
 
 939                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 940                         JsonNode root = mapper.readTree(request.getReader());
 
 941             VarbindDictionary varbindDictionary;
 
 942             String userId = null;
 
 944                 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
 
 947                 //check if update operation or create, get id for data to be updated and update attributeData
 
 948                 if ((update).equals(request.getParameter(operation))) {
 
 949                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
 
 950                     VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
 
 951                     int id = data.getId();
 
 954                         varbindDictionary.setId(1);
 
 956                         varbindDictionary.setId(id);
 
 958                     varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
 
 961                 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
 
 962                 userId = root.get(userid).textValue();
 
 964                         if(varbindDictionary.getId() == 0){
 
 965                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
 
 966                                 if(!duplicateData.isEmpty()){
 
 967                                         duplicateflag = true;
 
 969                                         varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
 
 970                                         varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
 
 971                                         commonClassDao.save(varbindDictionary);
 
 975                                         varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
 
 976                                         varbindDictionary.setModifiedDate(new Date());
 
 977                                         commonClassDao.update(varbindDictionary);
 
 980             String responseString = "";
 
 982                 responseString = duplicateResponseString;
 
 984                 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
 
 988                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 990                         responseString = "Exists";
 
 992                         responseString = successMsg;
 
 995                 ModelAndView result = new ModelAndView();
 
 996                 result.setViewName(responseString);
 
 999                 response.setCharacterEncoding(utf8);
 
1000                 response.setContentType(applicationJsonContentType);
 
1001                 request.setCharacterEncoding(utf8);
 
1003                 PrintWriter out = response.getWriter();
 
1004                 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
 
1005                 out.write(j.toString());
 
1008         }catch (Exception e){
 
1009                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
1010                         response.setCharacterEncoding(utf8);
 
1011                         request.setCharacterEncoding(utf8);
 
1012                         PrintWriter out = response.getWriter();
 
1013                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
1018         @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
1019         public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
1021                         ObjectMapper mapper = new ObjectMapper();
 
1022                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
1023                         JsonNode root = mapper.readTree(request.getReader());
 
1024                         VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
 
1025                         commonClassDao.delete(varbindDictionary);
 
1026                         response.setCharacterEncoding(utf8);
 
1027                         response.setContentType(applicationJsonContentType);
 
1028                         request.setCharacterEncoding(utf8);
 
1030                         PrintWriter out = response.getWriter();
 
1032                         String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
 
1033                         JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
 
1034                         out.write(j.toString());
 
1038                 catch (Exception e){
 
1039                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
 
1040                         response.setCharacterEncoding(utf8);
 
1041                         request.setCharacterEncoding(utf8);
 
1042                         PrintWriter out = response.getWriter();
 
1043                         out.write(PolicyUtils.CATCH_EXCEPTION);
 
1048     public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
 
1049         commonClassDao = commonClassDaoImpl;