2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
88 public void setCommonClassDao(CommonClassDao commonClassDao){
89 PolicyScopeDictionaryController.commonClassDao = commonClassDao;
92 public UserInfo getUserInfo(String loginId){
93 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
96 @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
97 public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){
99 Map<String, Object> model = new HashMap<>();
100 ObjectMapper mapper = new ObjectMapper();
101 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")));
102 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
103 JSONObject j = new JSONObject(msg);
104 response.getWriter().write(j.toString());
107 LOGGER.error(exceptionOccured+e);
111 @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
112 public void getGroupPolicyScopeEntityData(HttpServletResponse response){
114 Map<String, Object> model = new HashMap<>();
115 ObjectMapper mapper = new ObjectMapper();
116 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)));
117 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
118 JSONObject j = new JSONObject(msg);
119 response.addHeader(successMapKey, successMessage);
120 response.addHeader(operation, getDictionary);
121 response.getWriter().write(j.toString());
124 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
125 response.addHeader(errorMsg, dictionaryDBQuery);
130 @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
131 public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
133 boolean duplicateflag = false;
134 boolean isFakeUpdate = false;
135 boolean duplicateGroupFlag = false;
136 boolean fromAPI = false;
137 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
141 ObjectMapper mapper = new ObjectMapper();
142 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
143 JsonNode root = mapper.readTree(request.getReader());
144 GroupPolicyScopeList gpdata = null;
145 GroupPolicyScope groupData = null;
147 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class);
149 groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
151 groupData = new GroupPolicyScope();
152 groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", ""));
153 groupData.setClosedloop(root.get("dictionaryFields").get("closedloop").toString().replace("\"", ""));
154 groupData.setService(root.get("dictionaryFields").get("service").toString().replace("\"", ""));
155 groupData.setType(root.get("dictionaryFields").get("type").toString().replace("\"", ""));
159 if(!gpdata.getGroupName().startsWith(policyScope)){
160 String name = "PolicyScope_" + gpdata.getGroupName();
161 gpdata.setGroupName(name);
164 //check if update operation or create, get id for data to be updated and update attributeData
165 if ((update).equals(request.getParameter(operation))) {
167 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
169 for (int i =0; i< duplicateData.size(); i++){
170 GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
183 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
186 groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
189 groupData = new GroupPolicyScope();
190 groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", ""));
191 groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", ""));
192 groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", ""));
193 groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", ""));
195 if(!gpdata.getGroupName().startsWith(policyScope)){
196 String name = "PolicyScope_" + gpdata.getGroupName();
197 gpdata.setGroupName(name);
201 ArrayList<String> valueList = new ArrayList<>();
202 String resourceValue = groupData.getResource();
203 String typeValue = groupData.getType();
204 String serviceValue = groupData.getService();
205 String closedLoopValue = groupData.getClosedloop();
206 valueList.add("resource=" + resourceValue);
207 valueList.add("service=" + serviceValue);
208 valueList.add("type=" + typeValue);
209 valueList.add("closedLoopControlName=" + closedLoopValue);
210 String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
211 gpdata.setGroupList(list);
212 if(!gpdata.getGroupName().startsWith(policyScope)){
213 String name = "PolicyScope_" + gpdata.getGroupName();
214 gpdata.setGroupName(name);
216 if(gpdata.getId() == 0){
217 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
218 if(!duplicateData.isEmpty()){
219 duplicateflag = true;
221 duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
222 if(!duplicateData.isEmpty()){
223 duplicateGroupFlag = true;
225 commonClassDao.save(gpdata);
230 List<Object> duplicateGroupList = commonClassDao.checkExistingGroupListforUpdate(gpdata.getGroupList(), gpdata.getGroupName());
231 if(!duplicateGroupList.isEmpty()) {
232 duplicateGroupFlag = true;
234 commonClassDao.update(gpdata);
238 String responseString = "";
240 responseString = duplicateResponseString;
241 }else if(duplicateGroupFlag){
242 responseString = "DuplicateGroup";
244 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
248 if (responseString!=null && !(duplicateResponseString).equals(responseString) && !("DuplicateGroup").equals(responseString)) {
250 responseString = existsResponseString;
252 responseString = successMsg;
256 ModelAndView result = new ModelAndView();
257 result.setViewName(responseString);
261 response.setCharacterEncoding(utf8);
262 response.setContentType(applicationJsonContentType);
263 request.setCharacterEncoding(utf8);
265 PrintWriter out = response.getWriter();
266 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
267 out.write(j.toString());
270 }catch (Exception e){
272 response.setCharacterEncoding(utf8);
273 request.setCharacterEncoding(utf8);
274 PrintWriter out = response.getWriter();
275 out.write(PolicyUtils.CATCH_EXCEPTION);
280 @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
281 public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
283 ObjectMapper mapper = new ObjectMapper();
284 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
285 JsonNode root = mapper.readTree(request.getReader());
286 GroupPolicyScopeList onapData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
287 commonClassDao.delete(onapData);
288 response.setCharacterEncoding(utf8);
289 response.setContentType(applicationJsonContentType);
290 request.setCharacterEncoding(utf8);
292 PrintWriter out = response.getWriter();
294 String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
295 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
296 out.write(j.toString());
302 response.setCharacterEncoding(utf8);
303 request.setCharacterEncoding(utf8);
304 PrintWriter out = response.getWriter();
305 out.write(PolicyUtils.CATCH_EXCEPTION);
310 @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
311 public void getPSClosedLoopEntityDataByName(HttpServletResponse response){
313 Map<String, Object> model = new HashMap<>();
314 ObjectMapper mapper = new ObjectMapper();
315 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")));
316 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
317 JSONObject j = new JSONObject(msg);
318 response.getWriter().write(j.toString());
321 LOGGER.error(exceptionOccured+e);
325 @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
326 public void getPSClosedLoopEntityData(HttpServletResponse response){
328 Map<String, Object> model = new HashMap<>();
329 ObjectMapper mapper = new ObjectMapper();
330 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)));
331 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
332 JSONObject j = new JSONObject(msg);
333 response.addHeader(successMapKey, successMessage);
334 response.addHeader(operation, getDictionary);
335 response.getWriter().write(j.toString());
338 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
339 response.addHeader(errorMsg, dictionaryDBQuery);
344 @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
345 public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
347 boolean duplicateflag = false;
348 boolean isFakeUpdate = false;
349 boolean fromAPI = false;
350 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
353 ObjectMapper mapper = new ObjectMapper();
354 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
355 JsonNode root = mapper.readTree(request.getReader());
356 PolicyScopeClosedLoop onapData;
358 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.class);
360 //check if update operation or create, get id for data to be updated and update attributeData
361 if ((update).equals(request.getParameter(operation))) {
362 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
364 for (int i =0; i< duplicateData.size(); i++){
365 PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
378 onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
380 if(onapData.getId() == 0){
381 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
382 if(!duplicateData.isEmpty()){
383 duplicateflag = true;
385 commonClassDao.save(onapData);
389 commonClassDao.update(onapData);
392 String responseString = "";
394 responseString = duplicateResponseString;
396 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
400 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
402 responseString = existsResponseString;
404 responseString = successMsg;
407 ModelAndView result = new ModelAndView();
408 result.setViewName(responseString);
411 response.setCharacterEncoding(utf8);
412 response.setContentType(applicationJsonContentType);
413 request.setCharacterEncoding(utf8);
415 PrintWriter out = response.getWriter();
416 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
418 out.write(j.toString());
423 }catch (Exception e){
424 response.setCharacterEncoding(utf8);
425 request.setCharacterEncoding(utf8);
426 PrintWriter out = response.getWriter();
427 out.write(PolicyUtils.CATCH_EXCEPTION);
433 @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
434 public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
436 ObjectMapper mapper = new ObjectMapper();
437 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
438 JsonNode root = mapper.readTree(request.getReader());
439 PolicyScopeClosedLoop onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class);
440 commonClassDao.delete(onapData);
441 response.setCharacterEncoding(utf8);
442 response.setContentType(applicationJsonContentType);
443 request.setCharacterEncoding(utf8);
445 PrintWriter out = response.getWriter();
447 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
448 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
449 out.write(j.toString());
455 response.setCharacterEncoding(utf8);
456 request.setCharacterEncoding(utf8);
457 PrintWriter out = response.getWriter();
458 out.write(PolicyUtils.CATCH_EXCEPTION);
463 @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
464 public void getPSServiceEntityDataByName(HttpServletResponse response){
466 Map<String, Object> model = new HashMap<>();
467 ObjectMapper mapper = new ObjectMapper();
468 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")));
469 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
470 JSONObject j = new JSONObject(msg);
471 response.getWriter().write(j.toString());
474 LOGGER.error(exceptionOccured+e);
478 @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
479 public void getPSServiceEntityData(HttpServletResponse response){
481 Map<String, Object> model = new HashMap<>();
482 ObjectMapper mapper = new ObjectMapper();
483 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)));
484 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
485 JSONObject j = new JSONObject(msg);
486 response.addHeader(successMapKey, successMessage);
487 response.addHeader(operation, getDictionary);
488 response.getWriter().write(j.toString());
491 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
492 response.addHeader(errorMsg, dictionaryDBQuery);
497 @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
498 public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
500 boolean duplicateflag = false;
501 boolean isFakeUpdate = false;
502 boolean fromAPI = false;
503 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
506 ObjectMapper mapper = new ObjectMapper();
507 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
508 JsonNode root = mapper.readTree(request.getReader());
509 PolicyScopeService onapData;
511 onapData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.class);
513 //check if update operation or create, get id for data to be updated and update attributeData
514 if ((update).equals(request.getParameter(operation))) {
515 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
517 for (int i =0; i< duplicateData.size(); i++){
518 PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
529 onapData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
531 if(onapData.getId() == 0){
532 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
533 if(!duplicateData.isEmpty()){
534 duplicateflag = true;
536 commonClassDao.save(onapData);
540 commonClassDao.update(onapData);
544 String responseString = "";
546 responseString = duplicateResponseString;
548 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
552 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
554 responseString = existsResponseString;
556 responseString = successMsg;
559 ModelAndView result = new ModelAndView();
560 result.setViewName(responseString);
564 response.setCharacterEncoding(utf8);
565 response.setContentType(applicationJsonContentType);
566 request.setCharacterEncoding(utf8);
568 PrintWriter out = response.getWriter();
569 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
570 out.write(j.toString());
573 }catch (Exception e){
574 response.setCharacterEncoding(utf8);
575 request.setCharacterEncoding(utf8);
576 PrintWriter out = response.getWriter();
577 out.write(PolicyUtils.CATCH_EXCEPTION);
583 @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
584 public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
586 ObjectMapper mapper = new ObjectMapper();
587 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
588 JsonNode root = mapper.readTree(request.getReader());
589 PolicyScopeService onapData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class);
590 commonClassDao.delete(onapData);
591 response.setCharacterEncoding(utf8);
592 response.setContentType(applicationJsonContentType);
593 request.setCharacterEncoding(utf8);
595 PrintWriter out = response.getWriter();
597 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
598 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
599 out.write(j.toString());
605 response.setCharacterEncoding(utf8);
606 request.setCharacterEncoding(utf8);
607 PrintWriter out = response.getWriter();
608 out.write(PolicyUtils.CATCH_EXCEPTION);
613 @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
614 public void getPSTypeEntityDataByName(HttpServletResponse response){
616 Map<String, Object> model = new HashMap<>();
617 ObjectMapper mapper = new ObjectMapper();
618 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")));
619 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
620 JSONObject j = new JSONObject(msg);
621 response.getWriter().write(j.toString());
624 LOGGER.error(exceptionOccured+e);
628 @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
629 public void getPSTypeEntityData(HttpServletResponse response){
631 Map<String, Object> model = new HashMap<>();
632 ObjectMapper mapper = new ObjectMapper();
633 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)));
634 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
635 JSONObject j = new JSONObject(msg);
636 response.addHeader(successMapKey, successMessage);
637 response.addHeader(operation, getDictionary);
638 response.getWriter().write(j.toString());
641 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
642 response.addHeader(errorMsg, dictionaryDBQuery);
647 @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
648 public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
650 boolean duplicateflag = false;
651 boolean isFakeUpdate = false;
652 boolean fromAPI = false;
653 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
656 ObjectMapper mapper = new ObjectMapper();
657 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
658 JsonNode root = mapper.readTree(request.getReader());
659 PolicyScopeType onapData;
661 onapData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.class);
663 //check if update operation or create, get id for data to be updated and update attributeData
664 if ((update).equals(request.getParameter(operation))) {
665 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
667 for (int i =0; i< duplicateData.size(); i++){
668 PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
681 onapData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
683 if(onapData.getId() == 0){
684 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
685 if(!duplicateData.isEmpty()){
686 duplicateflag = true;
688 commonClassDao.save(onapData);
692 commonClassDao.update(onapData);
695 String responseString = "";
697 responseString = duplicateResponseString;
699 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
703 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
705 responseString = existsResponseString;
707 responseString = successMsg;
711 ModelAndView result = new ModelAndView();
712 result.setViewName(responseString);
717 response.setCharacterEncoding(utf8);
718 response.setContentType(applicationJsonContentType);
719 request.setCharacterEncoding(utf8);
721 PrintWriter out = response.getWriter();
722 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
724 out.write(j.toString());
729 }catch (Exception e){
730 response.setCharacterEncoding(utf8);
731 request.setCharacterEncoding(utf8);
732 PrintWriter out = response.getWriter();
733 out.write(PolicyUtils.CATCH_EXCEPTION);
739 @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
740 public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
742 ObjectMapper mapper = new ObjectMapper();
743 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
744 JsonNode root = mapper.readTree(request.getReader());
745 PolicyScopeType onapData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class);
746 commonClassDao.delete(onapData);
747 response.setCharacterEncoding(utf8);
748 response.setContentType(applicationJsonContentType);
749 request.setCharacterEncoding(utf8);
751 PrintWriter out = response.getWriter();
753 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
754 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
755 out.write(j.toString());
761 response.setCharacterEncoding(utf8);
762 request.setCharacterEncoding(utf8);
763 PrintWriter out = response.getWriter();
764 out.write(PolicyUtils.CATCH_EXCEPTION);
769 @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
770 public void getPSResourceEntityDataByName(HttpServletResponse response){
772 Map<String, Object> model = new HashMap<>();
773 ObjectMapper mapper = new ObjectMapper();
774 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")));
775 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
776 JSONObject j = new JSONObject(msg);
777 response.getWriter().write(j.toString());
780 LOGGER.error(exceptionOccured+e);
784 @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
785 public void getPSResourceEntityData(HttpServletResponse response){
787 Map<String, Object> model = new HashMap<>();
788 ObjectMapper mapper = new ObjectMapper();
789 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)));
790 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
791 JSONObject j = new JSONObject(msg);
792 response.addHeader("successMapKey", successMessage);
793 response.addHeader(operation, getDictionary);
794 response.getWriter().write(j.toString());
798 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
799 response.addHeader(errorMsg, dictionaryDBQuery);
804 @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
805 public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
807 boolean duplicateflag = false;
808 boolean isFakeUpdate = false;
809 boolean fromAPI = false;
810 if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
813 ObjectMapper mapper = new ObjectMapper();
814 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
815 JsonNode root = mapper.readTree(request.getReader());
816 PolicyScopeResource onapData;
818 onapData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.class);
820 //check if update operation or create, get id for data to be updated and update attributeData
821 if ((update).equals(request.getParameter(operation))) {
822 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
823 PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
824 int id = data.getId();
834 onapData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
836 if(onapData.getId() == 0){
837 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
838 if(!duplicateData.isEmpty()){
839 duplicateflag = true;
841 commonClassDao.save(onapData);
845 commonClassDao.update(onapData);
848 String responseString = "";
850 responseString = duplicateResponseString;
852 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
856 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
858 responseString = existsResponseString;
860 responseString = successMsg;
864 ModelAndView result = new ModelAndView();
865 result.setViewName(responseString);
870 response.setCharacterEncoding(utf8);
871 response.setContentType(applicationJsonContentType);
872 request.setCharacterEncoding(utf8);
874 PrintWriter out = response.getWriter();
875 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
877 out.write(j.toString());
882 }catch (Exception e){
884 response.setCharacterEncoding(utf8);
885 request.setCharacterEncoding(utf8);
886 PrintWriter out = response.getWriter();
887 out.write(PolicyUtils.CATCH_EXCEPTION);
892 @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
893 public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
895 ObjectMapper mapper = new ObjectMapper();
896 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
897 JsonNode root = mapper.readTree(request.getReader());
898 PolicyScopeResource onapData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class);
899 commonClassDao.delete(onapData);
900 response.setCharacterEncoding(utf8);
901 response.setContentType(applicationJsonContentType);
902 request.setCharacterEncoding(utf8);
904 PrintWriter out = response.getWriter();
906 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
907 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
908 out.write(j.toString());
914 response.setCharacterEncoding(utf8);
915 request.setCharacterEncoding(utf8);
916 PrintWriter out = response.getWriter();
917 out.write(PolicyUtils.CATCH_EXCEPTION);
923 class GroupPolicyScope{
928 public String getResource() {
931 public void setResource(String resource) {
932 this.resource = resource;
934 public String getType() {
937 public void setType(String type) {
940 public String getService() {
943 public void setService(String service) {
944 this.service = service;
946 public String getClosedloop() {
949 public void setClosedloop(String closedloop) {
950 this.closedloop = closedloop;