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.ArrayList;
 
  26 import java.util.HashMap;
 
  27 import java.util.List;
 
  30 import javax.servlet.http.HttpServletRequest;
 
  31 import javax.servlet.http.HttpServletResponse;
 
  33 import org.apache.commons.lang.StringUtils;
 
  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.util.JsonMessage;
 
  38 import org.onap.policy.rest.dao.CommonClassDao;
 
  39 import org.onap.policy.rest.jpa.GroupPolicyScopeList;
 
  40 import org.onap.policy.rest.jpa.PolicyScopeClosedLoop;
 
  41 import org.onap.policy.rest.jpa.PolicyScopeResource;
 
  42 import org.onap.policy.rest.jpa.PolicyScopeService;
 
  43 import org.onap.policy.rest.jpa.PolicyScopeType;
 
  44 import org.onap.policy.rest.jpa.UserInfo;
 
  45 import org.springframework.beans.factory.annotation.Autowired;
 
  46 import org.springframework.http.MediaType;
 
  47 import org.springframework.stereotype.Controller;
 
  48 import org.springframework.web.bind.annotation.RequestMapping;
 
  49 import org.springframework.web.servlet.ModelAndView;
 
  51 import com.fasterxml.jackson.databind.DeserializationFeature;
 
  52 import com.fasterxml.jackson.databind.JsonNode;
 
  53 import com.fasterxml.jackson.databind.ObjectMapper;
 
  56 public class PolicyScopeDictionaryController {
 
  58         private static final Logger LOGGER  = FlexLogger.getLogger(PolicyScopeDictionaryController.class);
 
  60         private static CommonClassDao commonClassDao;
 
  61         private static String successMapKey = "successMapKey";
 
  62         private static String exceptionOccured = "Exception Occured";
 
  63         private static String successMessage = "success";
 
  64         private static String operation = "operation";
 
  65         private static String getDictionary =  "getDictionary";
 
  66         private static String errorMsg  = "error";
 
  67         private static String dictionaryDBQuery = "dictionaryDBQuery";
 
  68         private static String apiflag = "apiflag";
 
  69         private static String groupPolicyScopeListData1 = "groupPolicyScopeListData1";
 
  70         private static String policyScope= "PolicyScope";
 
  71         private static String update = "update";
 
  72         private static String duplicateResponseString = "Duplicate";
 
  73         private static String successMsg = "Success";
 
  74         private static String existsResponseString = "Exists";
 
  75         private static String utf8 = "UTF-8";
 
  76         private static String applicationJsonContentType = "application / json";
 
  78          * This is an empty constructor
 
  80         public PolicyScopeDictionaryController(){}      
 
  83         public PolicyScopeDictionaryController(CommonClassDao commonClassDao){
 
  84                 PolicyScopeDictionaryController.commonClassDao = commonClassDao;
 
  88         public UserInfo getUserInfo(String loginId){
 
  89                 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); 
 
  92         @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
  93         public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){
 
  95                         Map<String, Object> model = new HashMap<>();
 
  96                         ObjectMapper mapper = new ObjectMapper();
 
  97                         model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")));
 
  98                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
  99                         JSONObject j = new JSONObject(msg);
 
 100                         response.getWriter().write(j.toString());
 
 103                         LOGGER.error(exceptionOccured+e);
 
 107         @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 108         public void getGroupPolicyScopeEntityData(HttpServletResponse response){
 
 110                         Map<String, Object> model = new HashMap<>();
 
 111                         ObjectMapper mapper = new ObjectMapper();
 
 112                         model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)));
 
 113                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 114                         JSONObject j = new JSONObject(msg);
 
 115                         response.addHeader(successMapKey, successMessage); 
 
 116                         response.addHeader(operation, getDictionary);
 
 117                         response.getWriter().write(j.toString());
 
 120                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 121                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 126         @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 127         public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 129                         boolean duplicateflag = false;
 
 130                         boolean isFakeUpdate = false;
 
 131                         boolean duplicateGroupFlag = false;
 
 132                         boolean fromAPI = false;
 
 133                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 137                         ObjectMapper mapper = new ObjectMapper();
 
 138                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 139                         JsonNode root = mapper.readTree(request.getReader());
 
 140                         GroupPolicyScopeList gpdata = null;
 
 141                         GroupPolicyScope groupData = null;
 
 143                                 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class);
 
 145                                         groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
 
 147                                         groupData = new GroupPolicyScope();
 
 148                                         groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", ""));
 
 149                                         groupData.setClosedloop(root.get("dictionaryFields").get("closedloop").toString().replace("\"", ""));
 
 150                                         groupData.setService(root.get("dictionaryFields").get("service").toString().replace("\"", ""));
 
 151                                         groupData.setType(root.get("dictionaryFields").get("type").toString().replace("\"", ""));
 
 155                                 if(!gpdata.getGroupName().startsWith(policyScope)){
 
 156                                         String name = "PolicyScope_" + gpdata.getGroupName();
 
 157                                         gpdata.setGroupName(name);
 
 160                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 161                                 if ((update).equals(request.getParameter(operation))) {
 
 163                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
 
 165                                         for (int i =0; i< duplicateData.size(); i++){
 
 166                                                 GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
 
 179                                 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
 
 182                                         groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
 
 185                                         groupData = new GroupPolicyScope();
 
 186                                         groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", ""));
 
 187                                         groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", ""));
 
 188                                         groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", ""));
 
 189                                         groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", ""));
 
 191                                 if(!gpdata.getGroupName().startsWith(policyScope)){
 
 192                                         String name = "PolicyScope_" + gpdata.getGroupName();
 
 193                                         gpdata.setGroupName(name);
 
 197                         ArrayList<String> valueList = new ArrayList<>();
 
 198                         String resourceValue = groupData.getResource();
 
 199                         String typeValue = groupData.getType();
 
 200                         String serviceValue = groupData.getService();
 
 201                         String closedLoopValue = groupData.getClosedloop();
 
 202                         valueList.add("resource=" + resourceValue);
 
 203                         valueList.add("service=" + serviceValue);
 
 204                         valueList.add("type=" + typeValue);
 
 205                         valueList.add("closedLoopControlName="  + closedLoopValue);
 
 206                         String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
 
 207                         gpdata.setGroupList(list);
 
 208                         if(!gpdata.getGroupName().startsWith(policyScope)){
 
 209                                 String name = "PolicyScope_" + gpdata.getGroupName();
 
 210                                 gpdata.setGroupName(name);
 
 212                         if(gpdata.getId() == 0){
 
 213                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
 
 214                                 if(!duplicateData.isEmpty()){
 
 215                                         duplicateflag = true;
 
 217                                         duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
 
 218                                         if(!duplicateData.isEmpty()){
 
 219                                                 duplicateGroupFlag = true;
 
 221                                                 commonClassDao.save(gpdata);
 
 226                                         List<Object> duplicateGroupList =  commonClassDao.checkExistingGroupListforUpdate(gpdata.getGroupList(), gpdata.getGroupName());
 
 227                                         if(!duplicateGroupList.isEmpty()) {
 
 228                                                 duplicateGroupFlag = true;
 
 230                                                 commonClassDao.update(gpdata); 
 
 234                         String responseString = "";
 
 236                                 responseString = duplicateResponseString;
 
 237                         }else if(duplicateGroupFlag){
 
 238                                 responseString = "DuplicateGroup";
 
 240                                 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
 
 244                                 if (responseString!=null && !(duplicateResponseString).equals(responseString) && !("DuplicateGroup").equals(responseString)) {
 
 246                                                 responseString = existsResponseString;
 
 248                                                 responseString = successMsg;
 
 252                                 ModelAndView result = new ModelAndView();
 
 253                                 result.setViewName(responseString);
 
 257                                 response.setCharacterEncoding(utf8);
 
 258                                 response.setContentType(applicationJsonContentType);
 
 259                                 request.setCharacterEncoding(utf8);
 
 261                                 PrintWriter out = response.getWriter();
 
 262                                 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
 
 263                                 out.write(j.toString());
 
 266                 }catch (Exception e){
 
 268                         response.setCharacterEncoding(utf8);
 
 269                         request.setCharacterEncoding(utf8);
 
 270                         PrintWriter out = response.getWriter();
 
 271                         out.write(e.getMessage());
 
 276         @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 277         public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 279                         ObjectMapper mapper = new ObjectMapper();
 
 280                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 281                         JsonNode root = mapper.readTree(request.getReader());
 
 282                         GroupPolicyScopeList onapData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
 
 283                         commonClassDao.delete(onapData);
 
 284                         response.setCharacterEncoding(utf8);
 
 285                         response.setContentType(applicationJsonContentType);
 
 286                         request.setCharacterEncoding(utf8);
 
 288                         PrintWriter out = response.getWriter();
 
 290                         String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
 
 291                         JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
 
 292                         out.write(j.toString());
 
 298                         response.setCharacterEncoding(utf8);
 
 299                         request.setCharacterEncoding(utf8);
 
 300                         PrintWriter out = response.getWriter();
 
 301                         out.write(e.getMessage());
 
 306         @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 307         public void getPSClosedLoopEntityDataByName(HttpServletResponse response){
 
 309                         Map<String, Object> model = new HashMap<>();
 
 310                         ObjectMapper mapper = new ObjectMapper();
 
 311                         model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")));
 
 312                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 313                         JSONObject j = new JSONObject(msg);
 
 314                         response.getWriter().write(j.toString());
 
 317                         LOGGER.error(exceptionOccured+e);
 
 321         @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 322         public void getPSClosedLoopEntityData(HttpServletResponse response){
 
 324                         Map<String, Object> model = new HashMap<>();
 
 325                         ObjectMapper mapper = new ObjectMapper();
 
 326                         model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)));
 
 327                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 328                         JSONObject j = new JSONObject(msg);
 
 329                         response.addHeader(successMapKey, successMessage); 
 
 330                         response.addHeader(operation, getDictionary);
 
 331                         response.getWriter().write(j.toString());
 
 334                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 335                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 340         @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 341         public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 343                         boolean duplicateflag = false;
 
 344                         boolean isFakeUpdate = false;
 
 345                         boolean fromAPI = false;
 
 346                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 349                         ObjectMapper mapper = new ObjectMapper();
 
 350                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 351                         JsonNode root = mapper.readTree(request.getReader());
 
 352                         PolicyScopeClosedLoop onapData;
 
 354                                 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.class);
 
 356                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 357                                 if ((update).equals(request.getParameter(operation))) {
 
 358                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
 
 360                                         for (int i =0; i< duplicateData.size(); i++){
 
 361                                                 PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
 
 374                                 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
 
 376                         if(onapData.getId() == 0){
 
 377                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
 
 378                                 if(!duplicateData.isEmpty()){
 
 379                                         duplicateflag = true;
 
 381                                         commonClassDao.save(onapData);
 
 385                                         commonClassDao.update(onapData); 
 
 388                         String responseString = "";
 
 390                                 responseString = duplicateResponseString;
 
 392                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
 
 396                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 398                                                 responseString = existsResponseString;
 
 400                                                 responseString = successMsg;
 
 403                                 ModelAndView result = new ModelAndView();
 
 404                                 result.setViewName(responseString);
 
 407                                 response.setCharacterEncoding(utf8);
 
 408                                 response.setContentType(applicationJsonContentType);
 
 409                                 request.setCharacterEncoding(utf8);
 
 411                                 PrintWriter out = response.getWriter();
 
 412                                 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
 
 414                                 out.write(j.toString());
 
 419                 }catch (Exception e){
 
 420                         response.setCharacterEncoding(utf8);
 
 421                         request.setCharacterEncoding(utf8);
 
 422                         PrintWriter out = response.getWriter();
 
 423                         out.write(e.getMessage());
 
 429         @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 430         public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 432                         ObjectMapper mapper = new ObjectMapper();
 
 433                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 434                         JsonNode root = mapper.readTree(request.getReader());
 
 435                         PolicyScopeClosedLoop onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class);
 
 436                         commonClassDao.delete(onapData);
 
 437                         response.setCharacterEncoding(utf8);
 
 438                         response.setContentType(applicationJsonContentType);
 
 439                         request.setCharacterEncoding(utf8);
 
 441                         PrintWriter out = response.getWriter();
 
 443                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
 
 444                         JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
 
 445                         out.write(j.toString());
 
 451                         response.setCharacterEncoding(utf8);
 
 452                         request.setCharacterEncoding(utf8);
 
 453                         PrintWriter out = response.getWriter();
 
 454                         out.write(e.getMessage());
 
 459         @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 460         public void getPSServiceEntityDataByName(HttpServletResponse response){
 
 462                         Map<String, Object> model = new HashMap<>();
 
 463                         ObjectMapper mapper = new ObjectMapper();
 
 464                         model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")));
 
 465                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 466                         JSONObject j = new JSONObject(msg);
 
 467                         response.getWriter().write(j.toString());
 
 470                         LOGGER.error(exceptionOccured+e);
 
 474         @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 475         public void getPSServiceEntityData(HttpServletResponse response){
 
 477                         Map<String, Object> model = new HashMap<>();
 
 478                         ObjectMapper mapper = new ObjectMapper();
 
 479                         model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)));
 
 480                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 481                         JSONObject j = new JSONObject(msg);
 
 482                         response.addHeader(successMapKey, successMessage); 
 
 483                         response.addHeader(operation, getDictionary);
 
 484                         response.getWriter().write(j.toString());
 
 487                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 488                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 493         @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 494         public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 496                         boolean duplicateflag = false;
 
 497                         boolean isFakeUpdate = false;
 
 498                         boolean fromAPI = false;
 
 499                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 502                         ObjectMapper mapper = new ObjectMapper();
 
 503                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 504                         JsonNode root = mapper.readTree(request.getReader());
 
 505                         PolicyScopeService onapData;
 
 507                                 onapData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.class);
 
 509                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 510                                 if ((update).equals(request.getParameter(operation))) {
 
 511                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
 
 513                                         for (int i =0; i< duplicateData.size(); i++){
 
 514                                                 PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
 
 525                                 onapData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
 
 527                         if(onapData.getId() == 0){
 
 528                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
 
 529                                 if(!duplicateData.isEmpty()){
 
 530                                         duplicateflag = true;
 
 532                                         commonClassDao.save(onapData);
 
 536                                         commonClassDao.update(onapData); 
 
 540                         String responseString = "";
 
 542                                 responseString = duplicateResponseString;
 
 544                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
 
 548                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 550                                                 responseString = existsResponseString;
 
 552                                                 responseString = successMsg;
 
 555                                 ModelAndView result = new ModelAndView();
 
 556                                 result.setViewName(responseString);
 
 560                                 response.setCharacterEncoding(utf8);
 
 561                                 response.setContentType(applicationJsonContentType);
 
 562                                 request.setCharacterEncoding(utf8);
 
 564                                 PrintWriter out = response.getWriter();
 
 565                                 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
 
 566                                 out.write(j.toString());
 
 569                 }catch (Exception e){
 
 570                         response.setCharacterEncoding(utf8);
 
 571                         request.setCharacterEncoding(utf8);
 
 572                         PrintWriter out = response.getWriter();
 
 573                         out.write(e.getMessage());
 
 579         @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 580         public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 582                         ObjectMapper mapper = new ObjectMapper();
 
 583                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 584                         JsonNode root = mapper.readTree(request.getReader());
 
 585                         PolicyScopeService onapData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class);
 
 586                         commonClassDao.delete(onapData);
 
 587                         response.setCharacterEncoding(utf8);
 
 588                         response.setContentType(applicationJsonContentType);
 
 589                         request.setCharacterEncoding(utf8);
 
 591                         PrintWriter out = response.getWriter();
 
 593                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
 
 594                         JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
 
 595                         out.write(j.toString());
 
 601                         response.setCharacterEncoding(utf8);
 
 602                         request.setCharacterEncoding(utf8);
 
 603                         PrintWriter out = response.getWriter();
 
 604                         out.write(e.getMessage());
 
 609         @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 610         public void getPSTypeEntityDataByName(HttpServletResponse response){
 
 612                         Map<String, Object> model = new HashMap<>();
 
 613                         ObjectMapper mapper = new ObjectMapper();
 
 614                         model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")));
 
 615                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 616                         JSONObject j = new JSONObject(msg);
 
 617                         response.getWriter().write(j.toString());
 
 620                         LOGGER.error(exceptionOccured+e);
 
 624         @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 625         public void getPSTypeEntityData(HttpServletResponse response){
 
 627                         Map<String, Object> model = new HashMap<>();
 
 628                         ObjectMapper mapper = new ObjectMapper();
 
 629                         model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)));
 
 630                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 631                         JSONObject j = new JSONObject(msg);
 
 632                         response.addHeader(successMapKey, successMessage); 
 
 633                         response.addHeader(operation, getDictionary);
 
 634                         response.getWriter().write(j.toString());
 
 637                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 638                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 643         @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 644         public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 646                         boolean duplicateflag = false;
 
 647                         boolean isFakeUpdate = false;
 
 648                         boolean fromAPI = false;
 
 649                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 652                         ObjectMapper mapper = new ObjectMapper();
 
 653                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 654                         JsonNode root = mapper.readTree(request.getReader());
 
 655                         PolicyScopeType onapData;
 
 657                                 onapData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.class);
 
 659                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 660                                 if ((update).equals(request.getParameter(operation))) {
 
 661                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
 
 663                                         for (int i =0; i< duplicateData.size(); i++){
 
 664                                                 PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
 
 677                                 onapData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
 
 679                         if(onapData.getId() == 0){
 
 680                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
 
 681                                 if(!duplicateData.isEmpty()){
 
 682                                         duplicateflag = true;
 
 684                                         commonClassDao.save(onapData);
 
 688                                         commonClassDao.update(onapData); 
 
 691                         String responseString = "";
 
 693                                 responseString = duplicateResponseString;
 
 695                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
 
 699                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 701                                                 responseString = existsResponseString;
 
 703                                                 responseString = successMsg;
 
 707                                 ModelAndView result = new ModelAndView();
 
 708                                 result.setViewName(responseString);
 
 713                                 response.setCharacterEncoding(utf8);
 
 714                                 response.setContentType(applicationJsonContentType);
 
 715                                 request.setCharacterEncoding(utf8);
 
 717                                 PrintWriter out = response.getWriter();
 
 718                                 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
 
 720                                 out.write(j.toString());
 
 725                 }catch (Exception e){
 
 726                         response.setCharacterEncoding(utf8);
 
 727                         request.setCharacterEncoding(utf8);
 
 728                         PrintWriter out = response.getWriter();
 
 729                         out.write(e.getMessage());
 
 735         @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 736         public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 738                         ObjectMapper mapper = new ObjectMapper();
 
 739                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 740                         JsonNode root = mapper.readTree(request.getReader());
 
 741                         PolicyScopeType onapData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class);
 
 742                         commonClassDao.delete(onapData);
 
 743                         response.setCharacterEncoding(utf8);
 
 744                         response.setContentType(applicationJsonContentType);
 
 745                         request.setCharacterEncoding(utf8);
 
 747                         PrintWriter out = response.getWriter();
 
 749                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
 
 750                         JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
 
 751                         out.write(j.toString());
 
 757                         response.setCharacterEncoding(utf8);
 
 758                         request.setCharacterEncoding(utf8);
 
 759                         PrintWriter out = response.getWriter();
 
 760                         out.write(e.getMessage());
 
 765         @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 766         public void getPSResourceEntityDataByName(HttpServletResponse response){
 
 768                         Map<String, Object> model = new HashMap<>();
 
 769                         ObjectMapper mapper = new ObjectMapper();
 
 770                         model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")));
 
 771                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 772                         JSONObject j = new JSONObject(msg);
 
 773                         response.getWriter().write(j.toString());
 
 776                         LOGGER.error(exceptionOccured+e);
 
 780         @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
 
 781         public void getPSResourceEntityData(HttpServletResponse response){
 
 783                         Map<String, Object> model = new HashMap<>();
 
 784                         ObjectMapper mapper = new ObjectMapper();
 
 785                         model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)));
 
 786                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
 
 787                         JSONObject j = new JSONObject(msg);
 
 788                         response.addHeader("successMapKey", successMessage); 
 
 789                         response.addHeader(operation, getDictionary);
 
 790                         response.getWriter().write(j.toString());
 
 794                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
 
 795                         response.addHeader(errorMsg, dictionaryDBQuery);
 
 800         @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 801         public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
 
 803                         boolean duplicateflag = false;
 
 804                         boolean isFakeUpdate = false;
 
 805                         boolean fromAPI = false;
 
 806                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
 
 809                         ObjectMapper mapper = new ObjectMapper();
 
 810                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 811                         JsonNode root = mapper.readTree(request.getReader());
 
 812                         PolicyScopeResource onapData;
 
 814                                 onapData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.class);
 
 816                                 //check if update operation or create, get id for data to be updated and update attributeData
 
 817                                 if ((update).equals(request.getParameter(operation))) {
 
 818                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
 
 819                                         PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
 
 820                                         int id = data.getId();
 
 830                                 onapData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
 
 832                         if(onapData.getId() == 0){
 
 833                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
 
 834                                 if(!duplicateData.isEmpty()){
 
 835                                         duplicateflag = true;
 
 837                                         commonClassDao.save(onapData);
 
 841                                         commonClassDao.update(onapData); 
 
 844                         String responseString = "";
 
 846                                 responseString = duplicateResponseString;
 
 848                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
 
 852                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
 
 854                                                 responseString = existsResponseString;
 
 856                                                 responseString = successMsg;
 
 860                                 ModelAndView result = new ModelAndView();
 
 861                                 result.setViewName(responseString);
 
 866                                 response.setCharacterEncoding(utf8);
 
 867                                 response.setContentType(applicationJsonContentType);
 
 868                                 request.setCharacterEncoding(utf8);
 
 870                                 PrintWriter out = response.getWriter();
 
 871                                 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
 
 873                                 out.write(j.toString());
 
 878                 }catch (Exception e){
 
 880                         response.setCharacterEncoding(utf8);
 
 881                         request.setCharacterEncoding(utf8);
 
 882                         PrintWriter out = response.getWriter();
 
 883                         out.write(e.getMessage());
 
 888         @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
 
 889         public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 891                         ObjectMapper mapper = new ObjectMapper();
 
 892                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
 
 893                         JsonNode root = mapper.readTree(request.getReader());
 
 894                         PolicyScopeResource onapData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class);
 
 895                         commonClassDao.delete(onapData);
 
 896                         response.setCharacterEncoding(utf8);
 
 897                         response.setContentType(applicationJsonContentType);
 
 898                         request.setCharacterEncoding(utf8);
 
 900                         PrintWriter out = response.getWriter();
 
 902                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
 
 903                         JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
 
 904                         out.write(j.toString());
 
 910                         response.setCharacterEncoding(utf8);
 
 911                         request.setCharacterEncoding(utf8);
 
 912                         PrintWriter out = response.getWriter();
 
 913                         out.write(e.getMessage());
 
 919 class GroupPolicyScope{
 
 924         public String getResource() {
 
 927         public void setResource(String resource) {
 
 928                 this.resource = resource;
 
 930         public String getType() {
 
 933         public void setType(String type) {
 
 936         public String getService() {
 
 939         public void setService(String service) {
 
 940                 this.service = service;
 
 942         public String getClosedloop() {
 
 945         public void setClosedloop(String closedloop) {
 
 946                 this.closedloop = closedloop;