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.pap.xacml.rest.util.JsonMessage;
35 import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao;
36 import org.openecomp.policy.rest.dao.PolicyScopeClosedLoopDao;
37 import org.openecomp.policy.rest.dao.PolicyScopeResourceDao;
38 import org.openecomp.policy.rest.dao.PolicyScopeServiceDao;
39 import org.openecomp.policy.rest.dao.PolicyScopeTypeDao;
40 import org.openecomp.policy.rest.dao.UserInfoDao;
41 import org.openecomp.policy.rest.jpa.GroupPolicyScopeList;
42 import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop;
43 import org.openecomp.policy.rest.jpa.PolicyScopeResource;
44 import org.openecomp.policy.rest.jpa.PolicyScopeService;
45 import org.openecomp.policy.rest.jpa.PolicyScopeType;
46 import org.openecomp.policy.rest.jpa.UserInfo;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.http.MediaType;
49 import org.springframework.stereotype.Controller;
50 import org.springframework.web.bind.annotation.RequestMapping;
51 import org.springframework.web.servlet.ModelAndView;
53 import com.fasterxml.jackson.databind.DeserializationFeature;
54 import com.fasterxml.jackson.databind.JsonNode;
55 import com.fasterxml.jackson.databind.ObjectMapper;
58 public class PolicyScopeDictionaryController {
61 GroupPolicyScopeListDao groupPolicyScopeListDao;
64 PolicyScopeClosedLoopDao policyScopeClosedLoopDao;
67 PolicyScopeResourceDao PolicyScopeResourceDao;
70 PolicyScopeTypeDao policyScopeTypeDao;
73 PolicyScopeServiceDao policyScopeServiceDao;
77 UserInfoDao userInfoDao;
79 public UserInfo getUserInfo(String loginId){
80 UserInfo name = userInfoDao.getUserInfoByLoginId(loginId);
84 @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
85 public void getGroupPolicyScopeEntityDataByName(HttpServletRequest request, HttpServletResponse response){
87 Map<String, Object> model = new HashMap<String, Object>();
88 ObjectMapper mapper = new ObjectMapper();
89 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(groupPolicyScopeListDao.getGroupPolicyScopeListDataByName()));
90 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
91 JSONObject j = new JSONObject(msg);
92 response.getWriter().write(j.toString());
99 @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
100 public void getGroupPolicyScopeEntityData(HttpServletRequest request, HttpServletResponse response){
102 Map<String, Object> model = new HashMap<String, Object>();
103 ObjectMapper mapper = new ObjectMapper();
104 model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(groupPolicyScopeListDao.getGroupPolicyScopeListData()));
105 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
106 JSONObject j = new JSONObject(msg);
107 response.getWriter().write(j.toString());
114 @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
115 public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
117 boolean duplicateflag = false;
118 ObjectMapper mapper = new ObjectMapper();
119 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
120 JsonNode root = mapper.readTree(request.getReader());
121 GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
122 GroupPolicyScope groupData = null;
124 groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class);
126 groupData = new GroupPolicyScope();
127 groupData.setResource(root.get("groupPolicyScopeListData1").get("resource").toString().replace("\"", ""));
128 groupData.setClosedloop(root.get("groupPolicyScopeListData1").get("closedloop").toString().replace("\"", ""));
129 groupData.setService(root.get("groupPolicyScopeListData1").get("service").toString().replace("\"", ""));
130 groupData.setType(root.get("groupPolicyScopeListData1").get("type").toString().replace("\"", ""));
133 ArrayList<String> valueList = new ArrayList<String>();
135 String resourceValue = groupData.getResource();
136 String typeValue = groupData.getType();
137 String serviceValue = groupData.getService();
138 String closedLoopValue = groupData.getClosedloop();
139 valueList.add("resource=" + resourceValue);
140 valueList.add("service=" + serviceValue);
141 valueList.add("type=" + typeValue);
142 valueList.add("closedLoopControlName=" + closedLoopValue);
143 list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
144 ecompData.setGroupList(list);
145 if(!ecompData.getGroupName().startsWith("PolicyScope")){
146 String name = "PolicyScope_" + ecompData.getGroupName();
147 ecompData.setGroupName(name);
149 if(ecompData.getId() == 0){
150 CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
151 List<Object> duplicateData = entry.CheckDuplicateEntry(ecompData.getGroupName(), "name", GroupPolicyScopeList.class);
152 if(!duplicateData.isEmpty()){
153 duplicateflag = true;
155 groupPolicyScopeListDao.Save(ecompData);
158 groupPolicyScopeListDao.update(ecompData);
160 response.setCharacterEncoding("UTF-8");
161 response.setContentType("application / json");
162 request.setCharacterEncoding("UTF-8");
164 PrintWriter out = response.getWriter();
165 String responseString = "";
167 responseString = "Duplicate";
169 responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData());
171 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
173 out.write(j.toString());
178 response.setCharacterEncoding("UTF-8");
179 request.setCharacterEncoding("UTF-8");
180 PrintWriter out = response.getWriter();
181 out.write(e.getMessage());
186 @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
187 public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
189 ObjectMapper mapper = new ObjectMapper();
190 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
191 JsonNode root = mapper.readTree(request.getReader());
192 GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class);
193 groupPolicyScopeListDao.delete(ecompData);
194 response.setCharacterEncoding("UTF-8");
195 response.setContentType("application / json");
196 request.setCharacterEncoding("UTF-8");
198 PrintWriter out = response.getWriter();
200 String responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData());
201 JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
202 out.write(j.toString());
207 System.out.println(e);
208 response.setCharacterEncoding("UTF-8");
209 request.setCharacterEncoding("UTF-8");
210 PrintWriter out = response.getWriter();
211 out.write(e.getMessage());
216 @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
217 public void getPSClosedLoopEntityDataByName(HttpServletRequest request, HttpServletResponse response){
219 Map<String, Object> model = new HashMap<String, Object>();
220 ObjectMapper mapper = new ObjectMapper();
221 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(policyScopeClosedLoopDao.getPolicyScopeClosedLoopDataByName()));
222 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
223 JSONObject j = new JSONObject(msg);
224 response.getWriter().write(j.toString());
231 @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
232 public void getPSClosedLoopEntityData(HttpServletRequest request, HttpServletResponse response){
234 Map<String, Object> model = new HashMap<String, Object>();
235 ObjectMapper mapper = new ObjectMapper();
236 model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(policyScopeClosedLoopDao.getPolicyScopeClosedLoopData()));
237 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
238 JSONObject j = new JSONObject(msg);
239 response.getWriter().write(j.toString());
246 @RequestMapping(value={"/ps_dictionary/save_psClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
247 public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
249 boolean duplicateflag = false;
250 ObjectMapper mapper = new ObjectMapper();
251 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
252 JsonNode root = mapper.readTree(request.getReader());
253 PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
254 if(ecompData.getId() == 0){
255 CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
256 List<Object> duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class);
257 if(!duplicateData.isEmpty()){
258 duplicateflag = true;
260 policyScopeClosedLoopDao.Save(ecompData);
263 policyScopeClosedLoopDao.update(ecompData);
265 response.setCharacterEncoding("UTF-8");
266 response.setContentType("application / json");
267 request.setCharacterEncoding("UTF-8");
269 PrintWriter out = response.getWriter();
270 String responseString = "";
272 responseString = "Duplicate";
274 responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData());
276 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
278 out.write(j.toString());
283 response.setCharacterEncoding("UTF-8");
284 request.setCharacterEncoding("UTF-8");
285 PrintWriter out = response.getWriter();
286 out.write(e.getMessage());
291 @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
292 public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
294 ObjectMapper mapper = new ObjectMapper();
295 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
296 JsonNode root = mapper.readTree(request.getReader());
297 PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class);
298 policyScopeClosedLoopDao.delete(ecompData);
299 response.setCharacterEncoding("UTF-8");
300 response.setContentType("application / json");
301 request.setCharacterEncoding("UTF-8");
303 PrintWriter out = response.getWriter();
305 String responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData());
306 JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
307 out.write(j.toString());
312 System.out.println(e);
313 response.setCharacterEncoding("UTF-8");
314 request.setCharacterEncoding("UTF-8");
315 PrintWriter out = response.getWriter();
316 out.write(e.getMessage());
321 @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
322 public void getPSServiceEntityDataByName(HttpServletRequest request, HttpServletResponse response){
324 Map<String, Object> model = new HashMap<String, Object>();
325 ObjectMapper mapper = new ObjectMapper();
326 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(policyScopeServiceDao.getPolicyScopeServiceDataByName()));
327 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
328 JSONObject j = new JSONObject(msg);
329 response.getWriter().write(j.toString());
336 @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
337 public void getPSServiceEntityData(HttpServletRequest request, HttpServletResponse response){
339 Map<String, Object> model = new HashMap<String, Object>();
340 ObjectMapper mapper = new ObjectMapper();
341 model.put("psServiceDictionaryDatas", mapper.writeValueAsString(policyScopeServiceDao.getPolicyScopeServiceData()));
342 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
343 JSONObject j = new JSONObject(msg);
344 response.getWriter().write(j.toString());
351 @RequestMapping(value={"/ps_dictionary/save_psService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
352 public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
354 boolean duplicateflag = false;
355 ObjectMapper mapper = new ObjectMapper();
356 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
357 JsonNode root = mapper.readTree(request.getReader());
358 PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
359 if(ecompData.getId() == 0){
360 CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
361 List<Object> duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class);
362 if(!duplicateData.isEmpty()){
363 duplicateflag = true;
365 policyScopeServiceDao.Save(ecompData);
368 policyScopeServiceDao.update(ecompData);
370 response.setCharacterEncoding("UTF-8");
371 response.setContentType("application / json");
372 request.setCharacterEncoding("UTF-8");
374 PrintWriter out = response.getWriter();
375 String responseString = "";
377 responseString = "Duplicate";
379 responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData());
381 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
383 out.write(j.toString());
388 response.setCharacterEncoding("UTF-8");
389 request.setCharacterEncoding("UTF-8");
390 PrintWriter out = response.getWriter();
391 out.write(e.getMessage());
396 @RequestMapping(value={"/ps_dictionary/remove_PSService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
397 public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
399 ObjectMapper mapper = new ObjectMapper();
400 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
401 JsonNode root = mapper.readTree(request.getReader());
402 PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class);
403 policyScopeServiceDao.delete(ecompData);
404 response.setCharacterEncoding("UTF-8");
405 response.setContentType("application / json");
406 request.setCharacterEncoding("UTF-8");
408 PrintWriter out = response.getWriter();
410 String responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData());
411 JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
412 out.write(j.toString());
417 System.out.println(e);
418 response.setCharacterEncoding("UTF-8");
419 request.setCharacterEncoding("UTF-8");
420 PrintWriter out = response.getWriter();
421 out.write(e.getMessage());
426 @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
427 public void getPSTypeEntityDataByName(HttpServletRequest request, HttpServletResponse response){
429 Map<String, Object> model = new HashMap<String, Object>();
430 ObjectMapper mapper = new ObjectMapper();
431 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(policyScopeTypeDao.getPolicyScopeTypeDataByName()));
432 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
433 JSONObject j = new JSONObject(msg);
434 response.getWriter().write(j.toString());
441 @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
442 public void getPSTypeEntityData(HttpServletRequest request, HttpServletResponse response){
444 Map<String, Object> model = new HashMap<String, Object>();
445 ObjectMapper mapper = new ObjectMapper();
446 model.put("psTypeDictionaryDatas", mapper.writeValueAsString(policyScopeTypeDao.getPolicyScopeTypeData()));
447 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
448 JSONObject j = new JSONObject(msg);
449 response.getWriter().write(j.toString());
456 @RequestMapping(value={"/ps_dictionary/save_psType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
457 public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
459 boolean duplicateflag = false;
460 ObjectMapper mapper = new ObjectMapper();
461 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
462 JsonNode root = mapper.readTree(request.getReader());
463 PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
464 if(ecompData.getId() == 0){
465 CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
466 List<Object> duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class);
467 if(!duplicateData.isEmpty()){
468 duplicateflag = true;
470 policyScopeTypeDao.Save(ecompData);
473 policyScopeTypeDao.update(ecompData);
475 response.setCharacterEncoding("UTF-8");
476 response.setContentType("application / json");
477 request.setCharacterEncoding("UTF-8");
479 PrintWriter out = response.getWriter();
480 String responseString = "";
482 responseString = "Duplicate";
484 responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData());
486 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
488 out.write(j.toString());
493 response.setCharacterEncoding("UTF-8");
494 request.setCharacterEncoding("UTF-8");
495 PrintWriter out = response.getWriter();
496 out.write(e.getMessage());
501 @RequestMapping(value={"/ps_dictionary/remove_PSType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
502 public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
504 ObjectMapper mapper = new ObjectMapper();
505 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
506 JsonNode root = mapper.readTree(request.getReader());
507 PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class);
508 policyScopeTypeDao.delete(ecompData);
509 response.setCharacterEncoding("UTF-8");
510 response.setContentType("application / json");
511 request.setCharacterEncoding("UTF-8");
513 PrintWriter out = response.getWriter();
515 String responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData());
516 JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
517 out.write(j.toString());
522 System.out.println(e);
523 response.setCharacterEncoding("UTF-8");
524 request.setCharacterEncoding("UTF-8");
525 PrintWriter out = response.getWriter();
526 out.write(e.getMessage());
531 @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
532 public void getPSResourceEntityDataByName(HttpServletRequest request, HttpServletResponse response){
534 Map<String, Object> model = new HashMap<String, Object>();
535 ObjectMapper mapper = new ObjectMapper();
536 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(PolicyScopeResourceDao.getPolicyScopeResourceDataByName()));
537 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
538 JSONObject j = new JSONObject(msg);
539 response.getWriter().write(j.toString());
546 @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
547 public void getPSResourceEntityData(HttpServletRequest request, HttpServletResponse response){
549 Map<String, Object> model = new HashMap<String, Object>();
550 ObjectMapper mapper = new ObjectMapper();
551 model.put("psResourceDictionaryDatas", mapper.writeValueAsString(PolicyScopeResourceDao.getPolicyScopeResourceData()));
552 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
553 JSONObject j = new JSONObject(msg);
554 response.getWriter().write(j.toString());
561 @RequestMapping(value={"/ps_dictionary/save_psResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
562 public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
564 boolean duplicateflag = false;
565 ObjectMapper mapper = new ObjectMapper();
566 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
567 JsonNode root = mapper.readTree(request.getReader());
568 PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
569 if(ecompData.getId() == 0){
570 CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
571 List<Object> duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class);
572 if(!duplicateData.isEmpty()){
573 duplicateflag = true;
575 PolicyScopeResourceDao.Save(ecompData);
578 PolicyScopeResourceDao.update(ecompData);
580 response.setCharacterEncoding("UTF-8");
581 response.setContentType("application / json");
582 request.setCharacterEncoding("UTF-8");
584 PrintWriter out = response.getWriter();
585 String responseString = "";
587 responseString = "Duplicate";
589 responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData());
591 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
593 out.write(j.toString());
598 response.setCharacterEncoding("UTF-8");
599 request.setCharacterEncoding("UTF-8");
600 PrintWriter out = response.getWriter();
601 out.write(e.getMessage());
606 @RequestMapping(value={"/ps_dictionary/remove_PSResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
607 public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
609 ObjectMapper mapper = new ObjectMapper();
610 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
611 JsonNode root = mapper.readTree(request.getReader());
612 PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class);
613 PolicyScopeResourceDao.delete(ecompData);
614 response.setCharacterEncoding("UTF-8");
615 response.setContentType("application / json");
616 request.setCharacterEncoding("UTF-8");
618 PrintWriter out = response.getWriter();
620 String responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData());
621 JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
622 out.write(j.toString());
627 System.out.println(e);
628 response.setCharacterEncoding("UTF-8");
629 request.setCharacterEncoding("UTF-8");
630 PrintWriter out = response.getWriter();
631 out.write(e.getMessage());
637 class GroupPolicyScope{
642 public String getResource() {
645 public void setResource(String resource) {
646 this.resource = resource;
648 public String getType() {
651 public void setType(String type) {
654 public String getService() {
657 public void setService(String service) {
658 this.service = service;
660 public String getClosedloop() {
663 public void setClosedloop(String closedloop) {
664 this.closedloop = closedloop;