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.onap.policy.utils.PolicyUtils;
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;
62 private static String successMapKey = "successMapKey";
63 private static String exceptionOccured = "Exception Occured";
64 private static String successMessage = "success";
65 private static String operation = "operation";
66 private static String getDictionary = "getDictionary";
67 private static String errorMsg = "error";
68 private static String dictionaryDBQuery = "dictionaryDBQuery";
69 private static String apiflag = "apiflag";
70 private static String groupPolicyScopeListData1 = "groupPolicyScopeListData1";
71 private static String policyScope= "PolicyScope";
72 private static String update = "update";
73 private static String duplicateResponseString = "Duplicate";
74 private static String successMsg = "Success";
75 private static String existsResponseString = "Exists";
76 private static String utf8 = "UTF-8";
77 private static String applicationJsonContentType = "application / json";
79 * This is an empty constructor
81 public PolicyScopeDictionaryController(){}
84 public PolicyScopeDictionaryController(CommonClassDao commonClassDao){
85 PolicyScopeDictionaryController.commonClassDao = commonClassDao;
89 public UserInfo getUserInfo(String loginId){
90 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
93 @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
94 public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){
96 Map<String, Object> model = new HashMap<>();
97 ObjectMapper mapper = new ObjectMapper();
98 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")));
99 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
100 JSONObject j = new JSONObject(msg);
101 response.getWriter().write(j.toString());
104 LOGGER.error(exceptionOccured+e);
108 @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
109 public void getGroupPolicyScopeEntityData(HttpServletResponse response){
111 Map<String, Object> model = new HashMap<>();
112 ObjectMapper mapper = new ObjectMapper();
113 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)));
114 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
115 JSONObject j = new JSONObject(msg);
116 response.addHeader(successMapKey, successMessage);
117 response.addHeader(operation, getDictionary);
118 response.getWriter().write(j.toString());
121 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
122 response.addHeader(errorMsg, dictionaryDBQuery);
127 @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
128 public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
130 boolean duplicateflag = false;
131 boolean isFakeUpdate = false;
132 boolean duplicateGroupFlag = false;
133 boolean fromAPI = false;
134 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
138 ObjectMapper mapper = new ObjectMapper();
139 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
140 JsonNode root = mapper.readTree(request.getReader());
141 GroupPolicyScopeList gpdata = null;
142 GroupPolicyScope groupData = null;
144 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class);
146 groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
148 groupData = new GroupPolicyScope();
149 groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", ""));
150 groupData.setClosedloop(root.get("dictionaryFields").get("closedloop").toString().replace("\"", ""));
151 groupData.setService(root.get("dictionaryFields").get("service").toString().replace("\"", ""));
152 groupData.setType(root.get("dictionaryFields").get("type").toString().replace("\"", ""));
156 if(!gpdata.getGroupName().startsWith(policyScope)){
157 String name = "PolicyScope_" + gpdata.getGroupName();
158 gpdata.setGroupName(name);
161 //check if update operation or create, get id for data to be updated and update attributeData
162 if ((update).equals(request.getParameter(operation))) {
164 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
166 for (int i =0; i< duplicateData.size(); i++){
167 GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
180 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
183 groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
186 groupData = new GroupPolicyScope();
187 groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", ""));
188 groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", ""));
189 groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", ""));
190 groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", ""));
192 if(!gpdata.getGroupName().startsWith(policyScope)){
193 String name = "PolicyScope_" + gpdata.getGroupName();
194 gpdata.setGroupName(name);
198 ArrayList<String> valueList = new ArrayList<>();
199 String resourceValue = groupData.getResource();
200 String typeValue = groupData.getType();
201 String serviceValue = groupData.getService();
202 String closedLoopValue = groupData.getClosedloop();
203 valueList.add("resource=" + resourceValue);
204 valueList.add("service=" + serviceValue);
205 valueList.add("type=" + typeValue);
206 valueList.add("closedLoopControlName=" + closedLoopValue);
207 String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
208 gpdata.setGroupList(list);
209 if(!gpdata.getGroupName().startsWith(policyScope)){
210 String name = "PolicyScope_" + gpdata.getGroupName();
211 gpdata.setGroupName(name);
213 if(gpdata.getId() == 0){
214 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
215 if(!duplicateData.isEmpty()){
216 duplicateflag = true;
218 duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
219 if(!duplicateData.isEmpty()){
220 duplicateGroupFlag = true;
222 commonClassDao.save(gpdata);
227 List<Object> duplicateGroupList = commonClassDao.checkExistingGroupListforUpdate(gpdata.getGroupList(), gpdata.getGroupName());
228 if(!duplicateGroupList.isEmpty()) {
229 duplicateGroupFlag = true;
231 commonClassDao.update(gpdata);
235 String responseString = "";
237 responseString = duplicateResponseString;
238 }else if(duplicateGroupFlag){
239 responseString = "DuplicateGroup";
241 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
245 if (responseString!=null && !(duplicateResponseString).equals(responseString) && !("DuplicateGroup").equals(responseString)) {
247 responseString = existsResponseString;
249 responseString = successMsg;
253 ModelAndView result = new ModelAndView();
254 result.setViewName(responseString);
258 response.setCharacterEncoding(utf8);
259 response.setContentType(applicationJsonContentType);
260 request.setCharacterEncoding(utf8);
262 PrintWriter out = response.getWriter();
263 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
264 out.write(j.toString());
267 }catch (Exception e){
269 response.setCharacterEncoding(utf8);
270 request.setCharacterEncoding(utf8);
271 PrintWriter out = response.getWriter();
272 out.write(PolicyUtils.CATCH_EXCEPTION);
277 @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
278 public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
280 ObjectMapper mapper = new ObjectMapper();
281 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
282 JsonNode root = mapper.readTree(request.getReader());
283 GroupPolicyScopeList onapData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
284 commonClassDao.delete(onapData);
285 response.setCharacterEncoding(utf8);
286 response.setContentType(applicationJsonContentType);
287 request.setCharacterEncoding(utf8);
289 PrintWriter out = response.getWriter();
291 String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
292 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
293 out.write(j.toString());
299 response.setCharacterEncoding(utf8);
300 request.setCharacterEncoding(utf8);
301 PrintWriter out = response.getWriter();
302 out.write(PolicyUtils.CATCH_EXCEPTION);
307 @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
308 public void getPSClosedLoopEntityDataByName(HttpServletResponse response){
310 Map<String, Object> model = new HashMap<>();
311 ObjectMapper mapper = new ObjectMapper();
312 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")));
313 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
314 JSONObject j = new JSONObject(msg);
315 response.getWriter().write(j.toString());
318 LOGGER.error(exceptionOccured+e);
322 @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
323 public void getPSClosedLoopEntityData(HttpServletResponse response){
325 Map<String, Object> model = new HashMap<>();
326 ObjectMapper mapper = new ObjectMapper();
327 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)));
328 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
329 JSONObject j = new JSONObject(msg);
330 response.addHeader(successMapKey, successMessage);
331 response.addHeader(operation, getDictionary);
332 response.getWriter().write(j.toString());
335 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
336 response.addHeader(errorMsg, dictionaryDBQuery);
341 @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
342 public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
344 boolean duplicateflag = false;
345 boolean isFakeUpdate = false;
346 boolean fromAPI = false;
347 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
350 ObjectMapper mapper = new ObjectMapper();
351 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
352 JsonNode root = mapper.readTree(request.getReader());
353 PolicyScopeClosedLoop onapData;
355 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.class);
357 //check if update operation or create, get id for data to be updated and update attributeData
358 if ((update).equals(request.getParameter(operation))) {
359 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
361 for (int i =0; i< duplicateData.size(); i++){
362 PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
375 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
377 if(onapData.getId() == 0){
378 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
379 if(!duplicateData.isEmpty()){
380 duplicateflag = true;
382 commonClassDao.save(onapData);
386 commonClassDao.update(onapData);
389 String responseString = "";
391 responseString = duplicateResponseString;
393 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
397 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
399 responseString = existsResponseString;
401 responseString = successMsg;
404 ModelAndView result = new ModelAndView();
405 result.setViewName(responseString);
408 response.setCharacterEncoding(utf8);
409 response.setContentType(applicationJsonContentType);
410 request.setCharacterEncoding(utf8);
412 PrintWriter out = response.getWriter();
413 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
415 out.write(j.toString());
420 }catch (Exception e){
421 response.setCharacterEncoding(utf8);
422 request.setCharacterEncoding(utf8);
423 PrintWriter out = response.getWriter();
424 out.write(PolicyUtils.CATCH_EXCEPTION);
430 @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
431 public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
433 ObjectMapper mapper = new ObjectMapper();
434 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
435 JsonNode root = mapper.readTree(request.getReader());
436 PolicyScopeClosedLoop onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class);
437 commonClassDao.delete(onapData);
438 response.setCharacterEncoding(utf8);
439 response.setContentType(applicationJsonContentType);
440 request.setCharacterEncoding(utf8);
442 PrintWriter out = response.getWriter();
444 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
445 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
446 out.write(j.toString());
452 response.setCharacterEncoding(utf8);
453 request.setCharacterEncoding(utf8);
454 PrintWriter out = response.getWriter();
455 out.write(PolicyUtils.CATCH_EXCEPTION);
460 @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
461 public void getPSServiceEntityDataByName(HttpServletResponse response){
463 Map<String, Object> model = new HashMap<>();
464 ObjectMapper mapper = new ObjectMapper();
465 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")));
466 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
467 JSONObject j = new JSONObject(msg);
468 response.getWriter().write(j.toString());
471 LOGGER.error(exceptionOccured+e);
475 @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
476 public void getPSServiceEntityData(HttpServletResponse response){
478 Map<String, Object> model = new HashMap<>();
479 ObjectMapper mapper = new ObjectMapper();
480 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)));
481 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
482 JSONObject j = new JSONObject(msg);
483 response.addHeader(successMapKey, successMessage);
484 response.addHeader(operation, getDictionary);
485 response.getWriter().write(j.toString());
488 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
489 response.addHeader(errorMsg, dictionaryDBQuery);
494 @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
495 public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
497 boolean duplicateflag = false;
498 boolean isFakeUpdate = false;
499 boolean fromAPI = false;
500 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
503 ObjectMapper mapper = new ObjectMapper();
504 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
505 JsonNode root = mapper.readTree(request.getReader());
506 PolicyScopeService onapData;
508 onapData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.class);
510 //check if update operation or create, get id for data to be updated and update attributeData
511 if ((update).equals(request.getParameter(operation))) {
512 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
514 for (int i =0; i< duplicateData.size(); i++){
515 PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
526 onapData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
528 if(onapData.getId() == 0){
529 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
530 if(!duplicateData.isEmpty()){
531 duplicateflag = true;
533 commonClassDao.save(onapData);
537 commonClassDao.update(onapData);
541 String responseString = "";
543 responseString = duplicateResponseString;
545 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
549 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
551 responseString = existsResponseString;
553 responseString = successMsg;
556 ModelAndView result = new ModelAndView();
557 result.setViewName(responseString);
561 response.setCharacterEncoding(utf8);
562 response.setContentType(applicationJsonContentType);
563 request.setCharacterEncoding(utf8);
565 PrintWriter out = response.getWriter();
566 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
567 out.write(j.toString());
570 }catch (Exception e){
571 response.setCharacterEncoding(utf8);
572 request.setCharacterEncoding(utf8);
573 PrintWriter out = response.getWriter();
574 out.write(PolicyUtils.CATCH_EXCEPTION);
580 @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
581 public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
583 ObjectMapper mapper = new ObjectMapper();
584 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
585 JsonNode root = mapper.readTree(request.getReader());
586 PolicyScopeService onapData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class);
587 commonClassDao.delete(onapData);
588 response.setCharacterEncoding(utf8);
589 response.setContentType(applicationJsonContentType);
590 request.setCharacterEncoding(utf8);
592 PrintWriter out = response.getWriter();
594 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
595 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
596 out.write(j.toString());
602 response.setCharacterEncoding(utf8);
603 request.setCharacterEncoding(utf8);
604 PrintWriter out = response.getWriter();
605 out.write(PolicyUtils.CATCH_EXCEPTION);
610 @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
611 public void getPSTypeEntityDataByName(HttpServletResponse response){
613 Map<String, Object> model = new HashMap<>();
614 ObjectMapper mapper = new ObjectMapper();
615 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")));
616 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
617 JSONObject j = new JSONObject(msg);
618 response.getWriter().write(j.toString());
621 LOGGER.error(exceptionOccured+e);
625 @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
626 public void getPSTypeEntityData(HttpServletResponse response){
628 Map<String, Object> model = new HashMap<>();
629 ObjectMapper mapper = new ObjectMapper();
630 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)));
631 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
632 JSONObject j = new JSONObject(msg);
633 response.addHeader(successMapKey, successMessage);
634 response.addHeader(operation, getDictionary);
635 response.getWriter().write(j.toString());
638 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
639 response.addHeader(errorMsg, dictionaryDBQuery);
644 @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
645 public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
647 boolean duplicateflag = false;
648 boolean isFakeUpdate = false;
649 boolean fromAPI = false;
650 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
653 ObjectMapper mapper = new ObjectMapper();
654 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
655 JsonNode root = mapper.readTree(request.getReader());
656 PolicyScopeType onapData;
658 onapData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.class);
660 //check if update operation or create, get id for data to be updated and update attributeData
661 if ((update).equals(request.getParameter(operation))) {
662 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
664 for (int i =0; i< duplicateData.size(); i++){
665 PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
678 onapData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
680 if(onapData.getId() == 0){
681 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
682 if(!duplicateData.isEmpty()){
683 duplicateflag = true;
685 commonClassDao.save(onapData);
689 commonClassDao.update(onapData);
692 String responseString = "";
694 responseString = duplicateResponseString;
696 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
700 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
702 responseString = existsResponseString;
704 responseString = successMsg;
708 ModelAndView result = new ModelAndView();
709 result.setViewName(responseString);
714 response.setCharacterEncoding(utf8);
715 response.setContentType(applicationJsonContentType);
716 request.setCharacterEncoding(utf8);
718 PrintWriter out = response.getWriter();
719 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
721 out.write(j.toString());
726 }catch (Exception e){
727 response.setCharacterEncoding(utf8);
728 request.setCharacterEncoding(utf8);
729 PrintWriter out = response.getWriter();
730 out.write(PolicyUtils.CATCH_EXCEPTION);
736 @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
737 public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
739 ObjectMapper mapper = new ObjectMapper();
740 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
741 JsonNode root = mapper.readTree(request.getReader());
742 PolicyScopeType onapData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class);
743 commonClassDao.delete(onapData);
744 response.setCharacterEncoding(utf8);
745 response.setContentType(applicationJsonContentType);
746 request.setCharacterEncoding(utf8);
748 PrintWriter out = response.getWriter();
750 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
751 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
752 out.write(j.toString());
758 response.setCharacterEncoding(utf8);
759 request.setCharacterEncoding(utf8);
760 PrintWriter out = response.getWriter();
761 out.write(PolicyUtils.CATCH_EXCEPTION);
766 @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
767 public void getPSResourceEntityDataByName(HttpServletResponse response){
769 Map<String, Object> model = new HashMap<>();
770 ObjectMapper mapper = new ObjectMapper();
771 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")));
772 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
773 JSONObject j = new JSONObject(msg);
774 response.getWriter().write(j.toString());
777 LOGGER.error(exceptionOccured+e);
781 @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
782 public void getPSResourceEntityData(HttpServletResponse response){
784 Map<String, Object> model = new HashMap<>();
785 ObjectMapper mapper = new ObjectMapper();
786 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)));
787 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
788 JSONObject j = new JSONObject(msg);
789 response.addHeader("successMapKey", successMessage);
790 response.addHeader(operation, getDictionary);
791 response.getWriter().write(j.toString());
795 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
796 response.addHeader(errorMsg, dictionaryDBQuery);
801 @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
802 public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
804 boolean duplicateflag = false;
805 boolean isFakeUpdate = false;
806 boolean fromAPI = false;
807 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
810 ObjectMapper mapper = new ObjectMapper();
811 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
812 JsonNode root = mapper.readTree(request.getReader());
813 PolicyScopeResource onapData;
815 onapData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.class);
817 //check if update operation or create, get id for data to be updated and update attributeData
818 if ((update).equals(request.getParameter(operation))) {
819 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
820 PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
821 int id = data.getId();
831 onapData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
833 if(onapData.getId() == 0){
834 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
835 if(!duplicateData.isEmpty()){
836 duplicateflag = true;
838 commonClassDao.save(onapData);
842 commonClassDao.update(onapData);
845 String responseString = "";
847 responseString = duplicateResponseString;
849 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
853 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
855 responseString = existsResponseString;
857 responseString = successMsg;
861 ModelAndView result = new ModelAndView();
862 result.setViewName(responseString);
867 response.setCharacterEncoding(utf8);
868 response.setContentType(applicationJsonContentType);
869 request.setCharacterEncoding(utf8);
871 PrintWriter out = response.getWriter();
872 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
874 out.write(j.toString());
879 }catch (Exception e){
881 response.setCharacterEncoding(utf8);
882 request.setCharacterEncoding(utf8);
883 PrintWriter out = response.getWriter();
884 out.write(PolicyUtils.CATCH_EXCEPTION);
889 @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
890 public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
892 ObjectMapper mapper = new ObjectMapper();
893 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
894 JsonNode root = mapper.readTree(request.getReader());
895 PolicyScopeResource onapData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class);
896 commonClassDao.delete(onapData);
897 response.setCharacterEncoding(utf8);
898 response.setContentType(applicationJsonContentType);
899 request.setCharacterEncoding(utf8);
901 PrintWriter out = response.getWriter();
903 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
904 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
905 out.write(j.toString());
911 response.setCharacterEncoding(utf8);
912 request.setCharacterEncoding(utf8);
913 PrintWriter out = response.getWriter();
914 out.write(PolicyUtils.CATCH_EXCEPTION);
920 class GroupPolicyScope{
925 public String getResource() {
928 public void setResource(String resource) {
929 this.resource = resource;
931 public String getType() {
934 public void setType(String type) {
937 public String getService() {
940 public void setService(String service) {
941 this.service = service;
943 public String getClosedloop() {
946 public void setClosedloop(String closedloop) {
947 this.closedloop = closedloop;