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.io.UnsupportedEncodingException;
 
  26 import java.util.ArrayList;
 
  27 import java.util.HashMap;
 
  28 import java.util.List;
 
  31 import javax.servlet.http.HttpServletRequest;
 
  32 import javax.servlet.http.HttpServletResponse;
 
  34 import org.apache.commons.lang.StringUtils;
 
  35 import org.json.JSONObject;
 
  36 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 
  37 import org.onap.policy.common.logging.flexlogger.Logger;
 
  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.GroupPolicyScopeList;
 
  41 import org.onap.policy.rest.jpa.PolicyScopeClosedLoop;
 
  42 import org.onap.policy.rest.jpa.PolicyScopeResource;
 
  43 import org.onap.policy.rest.jpa.PolicyScopeService;
 
  44 import org.onap.policy.rest.jpa.PolicyScopeType;
 
  45 import org.onap.policy.rest.jpa.UserInfo;
 
  46 import org.springframework.beans.factory.annotation.Autowired;
 
  47 import org.springframework.http.MediaType;
 
  48 import org.springframework.stereotype.Controller;
 
  49 import org.springframework.web.bind.annotation.RequestMapping;
 
  50 import org.springframework.web.servlet.ModelAndView;
 
  52 import com.fasterxml.jackson.databind.DeserializationFeature;
 
  53 import com.fasterxml.jackson.databind.JsonNode;
 
  54 import com.fasterxml.jackson.databind.ObjectMapper;
 
  57 public class PolicyScopeDictionaryController {
 
  59         private static final Logger LOGGER  = FlexLogger.getLogger(PolicyScopeDictionaryController.class);
 
  61         private static CommonClassDao commonClassDao;
 
  64         public PolicyScopeDictionaryController(CommonClassDao commonClassDao){
 
  65                 PolicyScopeDictionaryController.commonClassDao = commonClassDao;
 
  68         public PolicyScopeDictionaryController(){}      
 
  70         private static String SUCCESSMAPKEY = "successMapKey";
 
  72         public UserInfo getUserInfo(String loginId){
 
  73                 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
 
  77         @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
  78         public void getGroupPolicyScopeEntityDataByName(HttpServletRequest request, HttpServletResponse response){
 
  80                         Map<String, Object> model = new HashMap<>();
 
  81                         ObjectMapper mapper = new ObjectMapper();
 
  82                         model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")));
 
  83                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
  84                         JSONObject j = new JSONObject(msg);
 
  85                         response.getWriter().write(j.toString());
 
  88                         LOGGER.error("Exception Occured"+e);
 
  92         @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
  93         public void getGroupPolicyScopeEntityData(HttpServletRequest request, HttpServletResponse response){
 
  95                         Map<String, Object> model = new HashMap<>();
 
  96                         ObjectMapper mapper = new ObjectMapper();
 
  97                         model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)));
 
  98                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
  99                         JSONObject j = new JSONObject(msg);
 
 100                         response.addHeader(SUCCESSMAPKEY, "success"); 
 
 101                         response.addHeader("operation", "getDictionary");
 
 102                         response.getWriter().write(j.toString());
 
 105                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 106                         response.addHeader("error", "dictionaryDBQuery");
 
 111         @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 112         public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
 
 114                         boolean duplicateflag = false;
 
 115                         boolean isFakeUpdate = false;
 
 116                         boolean duplicateGroupFlag = false;
 
 117                         boolean fromAPI = false;
 
 118                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
 
 122                         ObjectMapper mapper = new ObjectMapper();
 
 123                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 124                         JsonNode root = mapper.readTree(request.getReader());
 
 125                         //GroupPolicyScopeList gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
 
 126                         GroupPolicyScopeList gpdata = null;
 
 127                         GroupPolicyScope groupData = null;
 
 129                                 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class);
 
 131                                         groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class);
 
 133                                         groupData = new GroupPolicyScope();
 
 134                                         groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", ""));
 
 135                                         groupData.setClosedloop(root.get("dictionaryFields").get("closedloop").toString().replace("\"", ""));
 
 136                                         groupData.setService(root.get("dictionaryFields").get("service").toString().replace("\"", ""));
 
 137                                         groupData.setType(root.get("dictionaryFields").get("type").toString().replace("\"", ""));
 
 141                                 if(!gpdata.getGroupName().startsWith("PolicyScope")){
 
 142                                         String name = "PolicyScope_" + gpdata.getGroupName();
 
 143                                         gpdata.setGroupName(name);
 
 146                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 147                                 if (request.getParameter("operation").equals("update")) {
 
 149                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
 
 151                                         for (int i =0; i< duplicateData.size(); i++){
 
 152                                                 GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
 
 165                                 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
 
 168                                         groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class);
 
 171                                         groupData = new GroupPolicyScope();
 
 172                                         groupData.setResource(root.get("groupPolicyScopeListData1").get("resource").toString().replace("\"", ""));
 
 173                                         groupData.setClosedloop(root.get("groupPolicyScopeListData1").get("closedloop").toString().replace("\"", ""));
 
 174                                         groupData.setService(root.get("groupPolicyScopeListData1").get("service").toString().replace("\"", ""));
 
 175                                         groupData.setType(root.get("groupPolicyScopeListData1").get("type").toString().replace("\"", ""));
 
 177                                 if(!gpdata.getGroupName().startsWith("PolicyScope")){
 
 178                                         String name = "PolicyScope_" + gpdata.getGroupName();
 
 179                                         gpdata.setGroupName(name);
 
 183                         ArrayList<String> valueList = new ArrayList<>();
 
 185                         String resourceValue = groupData.getResource();
 
 186                         String typeValue = groupData.getType();
 
 187                         String serviceValue = groupData.getService();
 
 188                         String closedLoopValue = groupData.getClosedloop();
 
 189                         valueList.add("resource=" + resourceValue);
 
 190                         valueList.add("service=" + serviceValue);
 
 191                         valueList.add("type=" + typeValue);
 
 192                         valueList.add("closedLoopControlName="  + closedLoopValue);
 
 193                         list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
 
 194                         gpdata.setGroupList(list);
 
 195                         if(!gpdata.getGroupName().startsWith("PolicyScope")){
 
 196                                 String name = "PolicyScope_" + gpdata.getGroupName();
 
 197                                 gpdata.setGroupName(name);
 
 199                         if(gpdata.getId() == 0){
 
 200                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
 
 201                                 if(!duplicateData.isEmpty()){
 
 202                                         duplicateflag = true;
 
 204                                         duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
 
 205                                         if(!duplicateData.isEmpty()){
 
 206                                                 duplicateGroupFlag = true;
 
 208                                                 commonClassDao.save(gpdata);
 
 213                                         List<Object> duplicateGroupList =  commonClassDao.checkExistingGroupListforUpdate(gpdata.getGroupList(), gpdata.getGroupName());
 
 214                                         if(!duplicateGroupList.isEmpty()) {
 
 215                                                 duplicateGroupFlag = true;
 
 217                                                 commonClassDao.update(gpdata); 
 
 221                         String responseString = "";
 
 223                                 responseString = "Duplicate";
 
 224                         }else if(duplicateGroupFlag){
 
 225                                 responseString = "DuplicateGroup";
 
 227                                 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
 
 231                                 if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("DuplicateGroup")) {
 
 233                                                 responseString = "Exists";
 
 235                                                 responseString = "Success";
 
 239                                 ModelAndView result = new ModelAndView();
 
 240                                 result.setViewName(responseString);
 
 244                                 response.setCharacterEncoding("UTF-8");
 
 245                                 response.setContentType("application / json");
 
 246                                 request.setCharacterEncoding("UTF-8");
 
 248                                 PrintWriter out = response.getWriter();
 
 249                                 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
 
 250                                 out.write(j.toString());
 
 253                 }catch (Exception e){
 
 255                         response.setCharacterEncoding("UTF-8");
 
 256                         request.setCharacterEncoding("UTF-8");
 
 257                         PrintWriter out = response.getWriter();
 
 258                         out.write(e.getMessage());
 
 264         @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 265         public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
 
 267                         ObjectMapper mapper = new ObjectMapper();
 
 268                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 269                         JsonNode root = mapper.readTree(request.getReader());
 
 270                         GroupPolicyScopeList onapData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
 
 271                         commonClassDao.delete(onapData);
 
 272                         response.setCharacterEncoding("UTF-8");
 
 273                         response.setContentType("application / json");
 
 274                         request.setCharacterEncoding("UTF-8");
 
 276                         PrintWriter out = response.getWriter();
 
 278                         String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
 
 279                         JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
 
 280                         out.write(j.toString());
 
 285                         System.out.println(e);
 
 286                         response.setCharacterEncoding("UTF-8");
 
 287                         request.setCharacterEncoding("UTF-8");
 
 288                         PrintWriter out = response.getWriter();
 
 289                         out.write(e.getMessage());
 
 294         @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 295         public void getPSClosedLoopEntityDataByName(HttpServletRequest request, HttpServletResponse response){
 
 297                         Map<String, Object> model = new HashMap<>();
 
 298                         ObjectMapper mapper = new ObjectMapper();
 
 299                         model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")));
 
 300                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 301                         JSONObject j = new JSONObject(msg);
 
 302                         response.getWriter().write(j.toString());
 
 305                         LOGGER.error("Exception Occured"+e);
 
 309         @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 310         public void getPSClosedLoopEntityData(HttpServletRequest request, HttpServletResponse response){
 
 312                         Map<String, Object> model = new HashMap<>();
 
 313                         ObjectMapper mapper = new ObjectMapper();
 
 314                         model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)));
 
 315                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 316                         JSONObject j = new JSONObject(msg);
 
 317                         response.addHeader(SUCCESSMAPKEY, "success"); 
 
 318                         response.addHeader("operation", "getDictionary");
 
 319                         response.getWriter().write(j.toString());
 
 322                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 323                         response.addHeader("error", "dictionaryDBQuery");
 
 328         @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 329         public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
 
 331                         boolean duplicateflag = false;
 
 332                         boolean isFakeUpdate = false;
 
 333                         boolean fromAPI = false;
 
 334                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
 
 337                         ObjectMapper mapper = new ObjectMapper();
 
 338                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 339                         JsonNode root = mapper.readTree(request.getReader());
 
 340                         PolicyScopeClosedLoop onapData;
 
 342                                 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.class);
 
 344                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 345                                 if (request.getParameter("operation").equals("update")) {
 
 346                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
 
 348                                         for (int i =0; i< duplicateData.size(); i++){
 
 349                                                 PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
 
 362                                 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
 
 364                         if(onapData.getId() == 0){
 
 365                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
 
 366                                 if(!duplicateData.isEmpty()){
 
 367                                         duplicateflag = true;
 
 369                                         commonClassDao.save(onapData);
 
 373                                         commonClassDao.update(onapData); 
 
 376                         String responseString = "";
 
 378                                 responseString = "Duplicate";
 
 380                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
 
 384                                 if (responseString!=null && !responseString.equals("Duplicate")) {
 
 386                                                 responseString = "Exists";
 
 388                                                 responseString = "Success";
 
 391                                 ModelAndView result = new ModelAndView();
 
 392                                 result.setViewName(responseString);
 
 395                                 response.setCharacterEncoding("UTF-8");
 
 396                                 response.setContentType("application / json");
 
 397                                 request.setCharacterEncoding("UTF-8");
 
 399                                 PrintWriter out = response.getWriter();
 
 400                                 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
 
 402                                 out.write(j.toString());
 
 407                 }catch (Exception e){
 
 408                         response.setCharacterEncoding("UTF-8");
 
 409                         request.setCharacterEncoding("UTF-8");
 
 410                         PrintWriter out = response.getWriter();
 
 411                         out.write(e.getMessage());
 
 417         @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 418         public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
 
 420                         ObjectMapper mapper = new ObjectMapper();
 
 421                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 422                         JsonNode root = mapper.readTree(request.getReader());
 
 423                         PolicyScopeClosedLoop onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class);
 
 424                         commonClassDao.delete(onapData);
 
 425                         response.setCharacterEncoding("UTF-8");
 
 426                         response.setContentType("application / json");
 
 427                         request.setCharacterEncoding("UTF-8");
 
 429                         PrintWriter out = response.getWriter();
 
 431                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
 
 432                         JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
 
 433                         out.write(j.toString());
 
 438                         System.out.println(e);
 
 439                         response.setCharacterEncoding("UTF-8");
 
 440                         request.setCharacterEncoding("UTF-8");
 
 441                         PrintWriter out = response.getWriter();
 
 442                         out.write(e.getMessage());
 
 447         @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 448         public void getPSServiceEntityDataByName(HttpServletRequest request, HttpServletResponse response){
 
 450                         Map<String, Object> model = new HashMap<>();
 
 451                         ObjectMapper mapper = new ObjectMapper();
 
 452                         model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")));
 
 453                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 454                         JSONObject j = new JSONObject(msg);
 
 455                         response.getWriter().write(j.toString());
 
 458                         LOGGER.error("Exception Occured"+e);
 
 462         @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 463         public void getPSServiceEntityData(HttpServletRequest request, HttpServletResponse response){
 
 465                         Map<String, Object> model = new HashMap<>();
 
 466                         ObjectMapper mapper = new ObjectMapper();
 
 467                         model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)));
 
 468                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 469                         JSONObject j = new JSONObject(msg);
 
 470                         response.addHeader(SUCCESSMAPKEY, "success"); 
 
 471                         response.addHeader("operation", "getDictionary");
 
 472                         response.getWriter().write(j.toString());
 
 475                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 476                         response.addHeader("error", "dictionaryDBQuery");
 
 481         @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 482         public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
 
 484                         boolean duplicateflag = false;
 
 485                         boolean isFakeUpdate = false;
 
 486                         boolean fromAPI = false;
 
 487                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
 
 490                         ObjectMapper mapper = new ObjectMapper();
 
 491                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 492                         JsonNode root = mapper.readTree(request.getReader());
 
 493                         PolicyScopeService onapData;
 
 495                                 onapData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.class);
 
 497                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 498                                 if (request.getParameter("operation").equals("update")) {
 
 499                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
 
 501                                         for (int i =0; i< duplicateData.size(); i++){
 
 502                                                 PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
 
 513                                 onapData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
 
 515                         if(onapData.getId() == 0){
 
 516                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
 
 517                                 if(!duplicateData.isEmpty()){
 
 518                                         duplicateflag = true;
 
 520                                         commonClassDao.save(onapData);
 
 524                                         commonClassDao.update(onapData); 
 
 528                         String responseString = "";
 
 530                                 responseString = "Duplicate";
 
 532                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
 
 536                                 if (responseString!=null && !responseString.equals("Duplicate")) {
 
 538                                                 responseString = "Exists";
 
 540                                                 responseString = "Success";
 
 543                                 ModelAndView result = new ModelAndView();
 
 544                                 result.setViewName(responseString);
 
 548                                 response.setCharacterEncoding("UTF-8");
 
 549                                 response.setContentType("application / json");
 
 550                                 request.setCharacterEncoding("UTF-8");
 
 552                                 PrintWriter out = response.getWriter();
 
 553                                 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
 
 554                                 out.write(j.toString());
 
 557                 }catch (Exception e){
 
 558                         response.setCharacterEncoding("UTF-8");
 
 559                         request.setCharacterEncoding("UTF-8");
 
 560                         PrintWriter out = response.getWriter();
 
 561                         out.write(e.getMessage());
 
 567         @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 568         public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
 
 570                         ObjectMapper mapper = new ObjectMapper();
 
 571                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 572                         JsonNode root = mapper.readTree(request.getReader());
 
 573                         PolicyScopeService onapData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class);
 
 574                         commonClassDao.delete(onapData);
 
 575                         response.setCharacterEncoding("UTF-8");
 
 576                         response.setContentType("application / json");
 
 577                         request.setCharacterEncoding("UTF-8");
 
 579                         PrintWriter out = response.getWriter();
 
 581                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
 
 582                         JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
 
 583                         out.write(j.toString());
 
 588                         System.out.println(e);
 
 589                         response.setCharacterEncoding("UTF-8");
 
 590                         request.setCharacterEncoding("UTF-8");
 
 591                         PrintWriter out = response.getWriter();
 
 592                         out.write(e.getMessage());
 
 597         @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 598         public void getPSTypeEntityDataByName(HttpServletRequest request, HttpServletResponse response){
 
 600                         Map<String, Object> model = new HashMap<>();
 
 601                         ObjectMapper mapper = new ObjectMapper();
 
 602                         model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")));
 
 603                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 604                         JSONObject j = new JSONObject(msg);
 
 605                         response.getWriter().write(j.toString());
 
 608                         LOGGER.error("Exception Occured"+e);
 
 612         @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 613         public void getPSTypeEntityData(HttpServletRequest request, HttpServletResponse response){
 
 615                         Map<String, Object> model = new HashMap<>();
 
 616                         ObjectMapper mapper = new ObjectMapper();
 
 617                         model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)));
 
 618                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 619                         JSONObject j = new JSONObject(msg);
 
 620                         response.addHeader(SUCCESSMAPKEY, "success"); 
 
 621                         response.addHeader("operation", "getDictionary");
 
 622                         response.getWriter().write(j.toString());
 
 625                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 626                         response.addHeader("error", "dictionaryDBQuery");
 
 631         @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 632         public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
 
 634                         boolean duplicateflag = false;
 
 635                         boolean isFakeUpdate = false;
 
 636                         boolean fromAPI = false;
 
 637                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
 
 640                         ObjectMapper mapper = new ObjectMapper();
 
 641                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 642                         JsonNode root = mapper.readTree(request.getReader());
 
 643                         PolicyScopeType onapData;
 
 645                                 onapData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.class);
 
 647                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 648                                 if (request.getParameter("operation").equals("update")) {
 
 649                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
 
 651                                         for (int i =0; i< duplicateData.size(); i++){
 
 652                                                 PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
 
 665                                 onapData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
 
 667                         if(onapData.getId() == 0){
 
 668                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
 
 669                                 if(!duplicateData.isEmpty()){
 
 670                                         duplicateflag = true;
 
 672                                         commonClassDao.save(onapData);
 
 676                                         commonClassDao.update(onapData); 
 
 679                         String responseString = "";
 
 681                                 responseString = "Duplicate";
 
 683                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
 
 687                                 if (responseString!=null && !responseString.equals("Duplicate")) {
 
 689                                                 responseString = "Exists";
 
 691                                                 responseString = "Success";
 
 695                                 ModelAndView result = new ModelAndView();
 
 696                                 result.setViewName(responseString);
 
 701                                 response.setCharacterEncoding("UTF-8");
 
 702                                 response.setContentType("application / json");
 
 703                                 request.setCharacterEncoding("UTF-8");
 
 705                                 PrintWriter out = response.getWriter();
 
 706                                 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
 
 708                                 out.write(j.toString());
 
 713                 }catch (Exception e){
 
 714                         response.setCharacterEncoding("UTF-8");
 
 715                         request.setCharacterEncoding("UTF-8");
 
 716                         PrintWriter out = response.getWriter();
 
 717                         out.write(e.getMessage());
 
 723         @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 724         public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
 
 726                         ObjectMapper mapper = new ObjectMapper();
 
 727                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 728                         JsonNode root = mapper.readTree(request.getReader());
 
 729                         PolicyScopeType onapData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class);
 
 730                         commonClassDao.delete(onapData);
 
 731                         response.setCharacterEncoding("UTF-8");
 
 732                         response.setContentType("application / json");
 
 733                         request.setCharacterEncoding("UTF-8");
 
 735                         PrintWriter out = response.getWriter();
 
 737                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
 
 738                         JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
 
 739                         out.write(j.toString());
 
 744                         System.out.println(e);
 
 745                         response.setCharacterEncoding("UTF-8");
 
 746                         request.setCharacterEncoding("UTF-8");
 
 747                         PrintWriter out = response.getWriter();
 
 748                         out.write(e.getMessage());
 
 753         @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 754         public void getPSResourceEntityDataByName(HttpServletRequest request, HttpServletResponse response){
 
 756                         Map<String, Object> model = new HashMap<>();
 
 757                         ObjectMapper mapper = new ObjectMapper();
 
 758                         model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")));
 
 759                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 760                         JSONObject j = new JSONObject(msg);
 
 761                         response.getWriter().write(j.toString());
 
 764                         LOGGER.error("Exception Occured"+e);
 
 768         @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 769         public void getPSResourceEntityData(HttpServletRequest request, HttpServletResponse response){
 
 771                         Map<String, Object> model = new HashMap<>();
 
 772                         ObjectMapper mapper = new ObjectMapper();
 
 773                         model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)));
 
 774                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 775                         JSONObject j = new JSONObject(msg);
 
 776                         response.addHeader("successMapKey", "success"); 
 
 777                         response.addHeader("operation", "getDictionary");
 
 778                         response.getWriter().write(j.toString());
 
 782                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 783                         response.addHeader("error", "dictionaryDBQuery");
 
 788         @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 789         public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
 
 791                         boolean duplicateflag = false;
 
 792                         boolean isFakeUpdate = false;
 
 793                         boolean fromAPI = false;
 
 794                         if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
 
 797                         ObjectMapper mapper = new ObjectMapper();
 
 798                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 799                         JsonNode root = mapper.readTree(request.getReader());
 
 800                         PolicyScopeResource onapData;
 
 802                                 onapData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.class);
 
 804                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 805                                 if (request.getParameter("operation").equals("update")) {
 
 806                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
 
 808                                         PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
 
 819                                 onapData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
 
 821                         if(onapData.getId() == 0){
 
 822                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
 
 823                                 if(!duplicateData.isEmpty()){
 
 824                                         duplicateflag = true;
 
 826                                         commonClassDao.save(onapData);
 
 830                                         commonClassDao.update(onapData); 
 
 833                         String responseString = "";
 
 835                                 responseString = "Duplicate";
 
 837                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
 
 841                                 if (responseString!=null && !responseString.equals("Duplicate")) {
 
 843                                                 responseString = "Exists";
 
 845                                                 responseString = "Success";
 
 849                                 ModelAndView result = new ModelAndView();
 
 850                                 result.setViewName(responseString);
 
 855                                 response.setCharacterEncoding("UTF-8");
 
 856                                 response.setContentType("application / json");
 
 857                                 request.setCharacterEncoding("UTF-8");
 
 859                                 PrintWriter out = response.getWriter();
 
 860                                 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
 
 862                                 out.write(j.toString());
 
 867                 }catch (Exception e){
 
 869                         response.setCharacterEncoding("UTF-8");
 
 870                         request.setCharacterEncoding("UTF-8");
 
 871                         PrintWriter out = response.getWriter();
 
 872                         out.write(e.getMessage());
 
 878         @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 879         public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
 
 881                         ObjectMapper mapper = new ObjectMapper();
 
 882                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 883                         JsonNode root = mapper.readTree(request.getReader());
 
 884                         PolicyScopeResource onapData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class);
 
 885                         commonClassDao.delete(onapData);
 
 886                         response.setCharacterEncoding("UTF-8");
 
 887                         response.setContentType("application / json");
 
 888                         request.setCharacterEncoding("UTF-8");
 
 890                         PrintWriter out = response.getWriter();
 
 892                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
 
 893                         JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
 
 894                         out.write(j.toString());
 
 899                         System.out.println(e);
 
 900                         response.setCharacterEncoding("UTF-8");
 
 901                         request.setCharacterEncoding("UTF-8");
 
 902                         PrintWriter out = response.getWriter();
 
 903                         out.write(e.getMessage());
 
 909 class GroupPolicyScope{
 
 914         public String getResource() {
 
 917         public void setResource(String resource) {
 
 918                 this.resource = resource;
 
 920         public String getType() {
 
 923         public void setType(String type) {
 
 926         public String getService() {
 
 929         public void setService(String service) {
 
 930                 this.service = service;
 
 932         public String getClosedloop() {
 
 935         public void setClosedloop(String closedloop) {
 
 936                 this.closedloop = closedloop;