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.openecomp.policy.pap.xacml.rest.controller;
23 import java.io.PrintWriter;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
32 import org.apache.commons.lang.StringUtils;
33 import org.json.JSONObject;
34 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
35 import org.openecomp.policy.common.logging.flexlogger.Logger;
36 import org.openecomp.policy.pap.xacml.rest.util.JsonMessage;
37 import org.openecomp.policy.rest.dao.CommonClassDao;
38 import org.openecomp.policy.rest.jpa.GroupPolicyScopeList;
39 import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop;
40 import org.openecomp.policy.rest.jpa.PolicyScopeResource;
41 import org.openecomp.policy.rest.jpa.PolicyScopeService;
42 import org.openecomp.policy.rest.jpa.PolicyScopeType;
43 import org.openecomp.policy.rest.jpa.UserInfo;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.http.MediaType;
46 import org.springframework.stereotype.Controller;
47 import org.springframework.web.bind.annotation.RequestMapping;
48 import org.springframework.web.servlet.ModelAndView;
50 import com.fasterxml.jackson.databind.DeserializationFeature;
51 import com.fasterxml.jackson.databind.JsonNode;
52 import com.fasterxml.jackson.databind.ObjectMapper;
55 public class PolicyScopeDictionaryController {
57 private static final Logger LOGGER = FlexLogger.getLogger(PolicyScopeDictionaryController.class);
59 private static CommonClassDao commonClassDao;
62 public PolicyScopeDictionaryController(CommonClassDao commonClassDao){
63 PolicyScopeDictionaryController.commonClassDao = commonClassDao;
66 public PolicyScopeDictionaryController(){}
68 private static String SUCCESSMAPKEY = "successMapKey";
70 public UserInfo getUserInfo(String loginId){
71 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
75 @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
76 public void getGroupPolicyScopeEntityDataByName(HttpServletRequest request, HttpServletResponse response){
78 Map<String, Object> model = new HashMap<>();
79 ObjectMapper mapper = new ObjectMapper();
80 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")));
81 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
82 JSONObject j = new JSONObject(msg);
83 response.getWriter().write(j.toString());
86 LOGGER.error("Exception Occured"+e);
90 @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
91 public void getGroupPolicyScopeEntityData(HttpServletRequest request, HttpServletResponse response){
93 Map<String, Object> model = new HashMap<>();
94 ObjectMapper mapper = new ObjectMapper();
95 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class)));
96 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
97 JSONObject j = new JSONObject(msg);
98 response.addHeader(SUCCESSMAPKEY, "success");
99 response.addHeader("operation", "getDictionary");
100 response.getWriter().write(j.toString());
103 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
104 response.addHeader("error", "dictionaryDBQuery");
109 @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
110 public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
112 boolean duplicateflag = false;
113 boolean isFakeUpdate = false;
114 boolean duplicateGroupFlag = false;
115 boolean fromAPI = false;
116 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
120 ObjectMapper mapper = new ObjectMapper();
121 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
122 JsonNode root = mapper.readTree(request.getReader());
123 //GroupPolicyScopeList gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
124 GroupPolicyScopeList gpdata = null;
125 GroupPolicyScope groupData = null;
127 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class);
129 groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class);
131 groupData = new GroupPolicyScope();
132 groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", ""));
133 groupData.setClosedloop(root.get("dictionaryFields").get("closedloop").toString().replace("\"", ""));
134 groupData.setService(root.get("dictionaryFields").get("service").toString().replace("\"", ""));
135 groupData.setType(root.get("dictionaryFields").get("type").toString().replace("\"", ""));
138 if(!gpdata.getGroupName().startsWith("PolicyScope")){
139 String name = "PolicyScope_" + gpdata.getGroupName();
140 gpdata.setGroupName(name);
143 //check if update operation or create, get id for data to be updated and update attributeData
144 if (request.getParameter("operation").equals("update")) {
146 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
148 for (int i =0; i< duplicateData.size(); i++){
149 GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
162 gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
165 groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class);
167 groupData = new GroupPolicyScope();
168 groupData.setResource(root.get("groupPolicyScopeListData1").get("resource").toString().replace("\"", ""));
169 groupData.setClosedloop(root.get("groupPolicyScopeListData1").get("closedloop").toString().replace("\"", ""));
170 groupData.setService(root.get("groupPolicyScopeListData1").get("service").toString().replace("\"", ""));
171 groupData.setType(root.get("groupPolicyScopeListData1").get("type").toString().replace("\"", ""));
173 if(!gpdata.getGroupName().startsWith("PolicyScope")){
174 String name = "PolicyScope_" + gpdata.getGroupName();
175 gpdata.setGroupName(name);
179 ArrayList<String> valueList = new ArrayList<>();
181 String resourceValue = groupData.getResource();
182 String typeValue = groupData.getType();
183 String serviceValue = groupData.getService();
184 String closedLoopValue = groupData.getClosedloop();
185 valueList.add("resource=" + resourceValue);
186 valueList.add("service=" + serviceValue);
187 valueList.add("type=" + typeValue);
188 valueList.add("closedLoopControlName=" + closedLoopValue);
189 list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
190 gpdata.setGroupList(list);
191 if(!gpdata.getGroupName().startsWith("PolicyScope")){
192 String name = "PolicyScope_" + gpdata.getGroupName();
193 gpdata.setGroupName(name);
195 if(gpdata.getId() == 0){
196 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
197 if(!duplicateData.isEmpty()){
198 duplicateflag = true;
200 duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
201 if(!duplicateData.isEmpty()){
202 duplicateGroupFlag = true;
204 commonClassDao.save(gpdata);
209 List<Object> duplicateGroupList = commonClassDao.checkExistingGroupListforUpdate(gpdata.getGroupList(), gpdata.getGroupName());
210 if(!duplicateGroupList.isEmpty()) {
211 duplicateGroupFlag = true;
213 commonClassDao.update(gpdata);
217 String responseString = "";
219 responseString = "Duplicate";
220 }else if(duplicateGroupFlag){
221 responseString = "DuplicateGroup";
223 responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
227 if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("DuplicateGroup")) {
229 responseString = "Exists";
231 responseString = "Success";
235 ModelAndView result = new ModelAndView();
236 result.setViewName(responseString);
240 response.setCharacterEncoding("UTF-8");
241 response.setContentType("application / json");
242 request.setCharacterEncoding("UTF-8");
244 PrintWriter out = response.getWriter();
245 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
246 out.write(j.toString());
249 }catch (Exception e){
250 response.setCharacterEncoding("UTF-8");
251 request.setCharacterEncoding("UTF-8");
252 PrintWriter out = response.getWriter();
253 out.write(e.getMessage());
258 @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
259 public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
261 ObjectMapper mapper = new ObjectMapper();
262 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
263 JsonNode root = mapper.readTree(request.getReader());
264 GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
265 commonClassDao.delete(ecompData);
266 response.setCharacterEncoding("UTF-8");
267 response.setContentType("application / json");
268 request.setCharacterEncoding("UTF-8");
270 PrintWriter out = response.getWriter();
272 String responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
273 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
274 out.write(j.toString());
279 System.out.println(e);
280 response.setCharacterEncoding("UTF-8");
281 request.setCharacterEncoding("UTF-8");
282 PrintWriter out = response.getWriter();
283 out.write(e.getMessage());
288 @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
289 public void getPSClosedLoopEntityDataByName(HttpServletRequest request, HttpServletResponse response){
291 Map<String, Object> model = new HashMap<>();
292 ObjectMapper mapper = new ObjectMapper();
293 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")));
294 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
295 JSONObject j = new JSONObject(msg);
296 response.getWriter().write(j.toString());
299 LOGGER.error("Exception Occured"+e);
303 @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
304 public void getPSClosedLoopEntityData(HttpServletRequest request, HttpServletResponse response){
306 Map<String, Object> model = new HashMap<>();
307 ObjectMapper mapper = new ObjectMapper();
308 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class)));
309 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
310 JSONObject j = new JSONObject(msg);
311 response.addHeader(SUCCESSMAPKEY, "success");
312 response.addHeader("operation", "getDictionary");
313 response.getWriter().write(j.toString());
316 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
317 response.addHeader("error", "dictionaryDBQuery");
322 @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
323 public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
325 boolean duplicateflag = false;
326 boolean isFakeUpdate = false;
327 boolean fromAPI = false;
328 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
331 ObjectMapper mapper = new ObjectMapper();
332 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
333 JsonNode root = mapper.readTree(request.getReader());
334 PolicyScopeClosedLoop ecompData;
336 ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.class);
338 //check if update operation or create, get id for data to be updated and update attributeData
339 if (request.getParameter("operation").equals("update")) {
340 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class);
342 for (int i =0; i< duplicateData.size(); i++){
343 PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
356 ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
358 if(ecompData.getId() == 0){
359 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class);
360 if(!duplicateData.isEmpty()){
361 duplicateflag = true;
363 commonClassDao.save(ecompData);
367 commonClassDao.update(ecompData);
370 String responseString = "";
372 responseString = "Duplicate";
374 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
378 if (responseString!=null && !responseString.equals("Duplicate")) {
380 responseString = "Exists";
382 responseString = "Success";
385 ModelAndView result = new ModelAndView();
386 result.setViewName(responseString);
389 response.setCharacterEncoding("UTF-8");
390 response.setContentType("application / json");
391 request.setCharacterEncoding("UTF-8");
393 PrintWriter out = response.getWriter();
394 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
396 out.write(j.toString());
401 }catch (Exception e){
402 response.setCharacterEncoding("UTF-8");
403 request.setCharacterEncoding("UTF-8");
404 PrintWriter out = response.getWriter();
405 out.write(e.getMessage());
410 @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
411 public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
413 ObjectMapper mapper = new ObjectMapper();
414 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
415 JsonNode root = mapper.readTree(request.getReader());
416 PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class);
417 commonClassDao.delete(ecompData);
418 response.setCharacterEncoding("UTF-8");
419 response.setContentType("application / json");
420 request.setCharacterEncoding("UTF-8");
422 PrintWriter out = response.getWriter();
424 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
425 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
426 out.write(j.toString());
431 System.out.println(e);
432 response.setCharacterEncoding("UTF-8");
433 request.setCharacterEncoding("UTF-8");
434 PrintWriter out = response.getWriter();
435 out.write(e.getMessage());
440 @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
441 public void getPSServiceEntityDataByName(HttpServletRequest request, HttpServletResponse response){
443 Map<String, Object> model = new HashMap<>();
444 ObjectMapper mapper = new ObjectMapper();
445 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")));
446 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
447 JSONObject j = new JSONObject(msg);
448 response.getWriter().write(j.toString());
451 LOGGER.error("Exception Occured"+e);
455 @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
456 public void getPSServiceEntityData(HttpServletRequest request, HttpServletResponse response){
458 Map<String, Object> model = new HashMap<>();
459 ObjectMapper mapper = new ObjectMapper();
460 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)));
461 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
462 JSONObject j = new JSONObject(msg);
463 response.addHeader(SUCCESSMAPKEY, "success");
464 response.addHeader("operation", "getDictionary");
465 response.getWriter().write(j.toString());
468 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
469 response.addHeader("error", "dictionaryDBQuery");
474 @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
475 public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
477 boolean duplicateflag = false;
478 boolean isFakeUpdate = false;
479 boolean fromAPI = false;
480 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
483 ObjectMapper mapper = new ObjectMapper();
484 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
485 JsonNode root = mapper.readTree(request.getReader());
486 PolicyScopeService ecompData;
488 ecompData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.class);
490 //check if update operation or create, get id for data to be updated and update attributeData
491 if (request.getParameter("operation").equals("update")) {
492 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class);
494 for (int i =0; i< duplicateData.size(); i++){
495 PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
506 ecompData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
508 if(ecompData.getId() == 0){
509 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class);
510 if(!duplicateData.isEmpty()){
511 duplicateflag = true;
513 commonClassDao.save(ecompData);
517 commonClassDao.update(ecompData);
521 String responseString = "";
523 responseString = "Duplicate";
525 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
529 if (responseString!=null && !responseString.equals("Duplicate")) {
531 responseString = "Exists";
533 responseString = "Success";
536 ModelAndView result = new ModelAndView();
537 result.setViewName(responseString);
541 response.setCharacterEncoding("UTF-8");
542 response.setContentType("application / json");
543 request.setCharacterEncoding("UTF-8");
545 PrintWriter out = response.getWriter();
546 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
547 out.write(j.toString());
550 }catch (Exception e){
551 response.setCharacterEncoding("UTF-8");
552 request.setCharacterEncoding("UTF-8");
553 PrintWriter out = response.getWriter();
554 out.write(e.getMessage());
559 @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
560 public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
562 ObjectMapper mapper = new ObjectMapper();
563 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
564 JsonNode root = mapper.readTree(request.getReader());
565 PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class);
566 commonClassDao.delete(ecompData);
567 response.setCharacterEncoding("UTF-8");
568 response.setContentType("application / json");
569 request.setCharacterEncoding("UTF-8");
571 PrintWriter out = response.getWriter();
573 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
574 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
575 out.write(j.toString());
580 System.out.println(e);
581 response.setCharacterEncoding("UTF-8");
582 request.setCharacterEncoding("UTF-8");
583 PrintWriter out = response.getWriter();
584 out.write(e.getMessage());
589 @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
590 public void getPSTypeEntityDataByName(HttpServletRequest request, HttpServletResponse response){
592 Map<String, Object> model = new HashMap<>();
593 ObjectMapper mapper = new ObjectMapper();
594 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")));
595 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
596 JSONObject j = new JSONObject(msg);
597 response.getWriter().write(j.toString());
600 LOGGER.error("Exception Occured"+e);
604 @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
605 public void getPSTypeEntityData(HttpServletRequest request, HttpServletResponse response){
607 Map<String, Object> model = new HashMap<>();
608 ObjectMapper mapper = new ObjectMapper();
609 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class)));
610 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
611 JSONObject j = new JSONObject(msg);
612 response.addHeader(SUCCESSMAPKEY, "success");
613 response.addHeader("operation", "getDictionary");
614 response.getWriter().write(j.toString());
617 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
618 response.addHeader("error", "dictionaryDBQuery");
623 @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
624 public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
626 boolean duplicateflag = false;
627 boolean isFakeUpdate = false;
628 boolean fromAPI = false;
629 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
632 ObjectMapper mapper = new ObjectMapper();
633 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
634 JsonNode root = mapper.readTree(request.getReader());
635 PolicyScopeType ecompData;
637 ecompData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.class);
639 //check if update operation or create, get id for data to be updated and update attributeData
640 if (request.getParameter("operation").equals("update")) {
641 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class);
643 for (int i =0; i< duplicateData.size(); i++){
644 PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
657 ecompData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
659 if(ecompData.getId() == 0){
660 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class);
661 if(!duplicateData.isEmpty()){
662 duplicateflag = true;
664 commonClassDao.save(ecompData);
668 commonClassDao.update(ecompData);
671 String responseString = "";
673 responseString = "Duplicate";
675 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
679 if (responseString!=null && !responseString.equals("Duplicate")) {
681 responseString = "Exists";
683 responseString = "Success";
687 ModelAndView result = new ModelAndView();
688 result.setViewName(responseString);
693 response.setCharacterEncoding("UTF-8");
694 response.setContentType("application / json");
695 request.setCharacterEncoding("UTF-8");
697 PrintWriter out = response.getWriter();
698 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
700 out.write(j.toString());
705 }catch (Exception e){
706 response.setCharacterEncoding("UTF-8");
707 request.setCharacterEncoding("UTF-8");
708 PrintWriter out = response.getWriter();
709 out.write(e.getMessage());
714 @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
715 public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
717 ObjectMapper mapper = new ObjectMapper();
718 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
719 JsonNode root = mapper.readTree(request.getReader());
720 PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class);
721 commonClassDao.delete(ecompData);
722 response.setCharacterEncoding("UTF-8");
723 response.setContentType("application / json");
724 request.setCharacterEncoding("UTF-8");
726 PrintWriter out = response.getWriter();
728 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
729 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
730 out.write(j.toString());
735 System.out.println(e);
736 response.setCharacterEncoding("UTF-8");
737 request.setCharacterEncoding("UTF-8");
738 PrintWriter out = response.getWriter();
739 out.write(e.getMessage());
744 @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
745 public void getPSResourceEntityDataByName(HttpServletRequest request, HttpServletResponse response){
747 Map<String, Object> model = new HashMap<>();
748 ObjectMapper mapper = new ObjectMapper();
749 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")));
750 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
751 JSONObject j = new JSONObject(msg);
752 response.getWriter().write(j.toString());
755 LOGGER.error("Exception Occured"+e);
759 @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
760 public void getPSResourceEntityData(HttpServletRequest request, HttpServletResponse response){
762 Map<String, Object> model = new HashMap<>();
763 ObjectMapper mapper = new ObjectMapper();
764 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class)));
765 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
766 JSONObject j = new JSONObject(msg);
767 response.addHeader("successMapKey", "success");
768 response.addHeader("operation", "getDictionary");
769 response.getWriter().write(j.toString());
772 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
773 response.addHeader("error", "dictionaryDBQuery");
778 @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
779 public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
781 boolean duplicateflag = false;
782 boolean isFakeUpdate = false;
783 boolean fromAPI = false;
784 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
787 ObjectMapper mapper = new ObjectMapper();
788 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
789 JsonNode root = mapper.readTree(request.getReader());
790 PolicyScopeResource ecompData;
792 ecompData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.class);
794 //check if update operation or create, get id for data to be updated and update attributeData
795 if (request.getParameter("operation").equals("update")) {
796 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class);
798 PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
809 ecompData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
811 if(ecompData.getId() == 0){
812 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class);
813 if(!duplicateData.isEmpty()){
814 duplicateflag = true;
816 commonClassDao.save(ecompData);
820 commonClassDao.update(ecompData);
823 String responseString = "";
825 responseString = "Duplicate";
827 responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
831 if (responseString!=null && !responseString.equals("Duplicate")) {
833 responseString = "Exists";
835 responseString = "Success";
839 ModelAndView result = new ModelAndView();
840 result.setViewName(responseString);
845 response.setCharacterEncoding("UTF-8");
846 response.setContentType("application / json");
847 request.setCharacterEncoding("UTF-8");
849 PrintWriter out = response.getWriter();
850 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
852 out.write(j.toString());
857 }catch (Exception e){
858 response.setCharacterEncoding("UTF-8");
859 request.setCharacterEncoding("UTF-8");
860 PrintWriter out = response.getWriter();
861 out.write(e.getMessage());
866 @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
867 public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
869 ObjectMapper mapper = new ObjectMapper();
870 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
871 JsonNode root = mapper.readTree(request.getReader());
872 PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class);
873 commonClassDao.delete(ecompData);
874 response.setCharacterEncoding("UTF-8");
875 response.setContentType("application / json");
876 request.setCharacterEncoding("UTF-8");
878 PrintWriter out = response.getWriter();
880 String responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
881 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
882 out.write(j.toString());
887 System.out.println(e);
888 response.setCharacterEncoding("UTF-8");
889 request.setCharacterEncoding("UTF-8");
890 PrintWriter out = response.getWriter();
891 out.write(e.getMessage());
897 class GroupPolicyScope{
902 public String getResource() {
905 public void setResource(String resource) {
906 this.resource = resource;
908 public String getType() {
911 public void setType(String type) {
914 public String getService() {
917 public void setService(String service) {
918 this.service = service;
920 public String getClosedloop() {
923 public void setClosedloop(String closedloop) {
924 this.closedloop = closedloop;