Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / controller / PolicyScopeDictionaryController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.pap.xacml.rest.controller;
22
23 import java.io.PrintWriter;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
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;
52
53 import com.fasterxml.jackson.databind.DeserializationFeature;
54 import com.fasterxml.jackson.databind.JsonNode;
55 import com.fasterxml.jackson.databind.ObjectMapper;
56
57 @Controller
58 public class PolicyScopeDictionaryController {
59
60         @Autowired
61         GroupPolicyScopeListDao groupPolicyScopeListDao;
62         
63         @Autowired
64         PolicyScopeClosedLoopDao  policyScopeClosedLoopDao;
65         
66         @Autowired
67         PolicyScopeResourceDao PolicyScopeResourceDao;
68         
69         @Autowired
70         PolicyScopeTypeDao policyScopeTypeDao;
71         
72         @Autowired
73         PolicyScopeServiceDao policyScopeServiceDao;
74         
75
76         @Autowired
77         UserInfoDao userInfoDao;
78         
79         public UserInfo getUserInfo(String loginId){
80                 UserInfo name = userInfoDao.getUserInfoByLoginId(loginId);
81                 return name;    
82         }
83         
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){
86                 try{
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());
93                 }
94                 catch (Exception e){
95                         e.printStackTrace();
96                 }
97         }
98         
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){
101                 try{
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());
108                 }
109                 catch (Exception e){
110                         e.printStackTrace();
111                 }
112         }
113         
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{
116                 try {
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;
123                         try{
124                                  groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class);
125                         }catch(Exception e){
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("\"", ""));
131                         }
132                         
133                         ArrayList<String> valueList = new ArrayList<String>();
134                         String list = null;
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);
148                         }
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;
154                                 }else{
155                                         groupPolicyScopeListDao.Save(ecompData);
156                                 }
157                         }else{
158                                 groupPolicyScopeListDao.update(ecompData); 
159                         } 
160                         response.setCharacterEncoding("UTF-8");
161                         response.setContentType("application / json");
162                         request.setCharacterEncoding("UTF-8");
163
164                         PrintWriter out = response.getWriter();
165                         String responseString = "";
166                         if(duplicateflag){
167                                 responseString = "Duplicate";
168                         }else{
169                                 responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData());
170                         }
171                         JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
172
173                         out.write(j.toString());
174
175                         return null;
176                 }
177                 catch (Exception e){
178                         response.setCharacterEncoding("UTF-8");
179                         request.setCharacterEncoding("UTF-8");
180                         PrintWriter out = response.getWriter();
181                         out.write(e.getMessage());
182                 }
183                 return null;
184         }
185
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 {
188                 try{
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");
197
198                         PrintWriter out = response.getWriter();
199
200                         String responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData());
201                         JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}");
202                         out.write(j.toString());
203
204                         return null;
205                 }
206                 catch (Exception e){
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());
212                 }
213                 return null;
214         }
215         
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){
218                 try{
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());
225                 }
226                 catch (Exception e){
227                         e.printStackTrace();
228                 }
229         }
230         
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){
233                 try{
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());
240                 }
241                 catch (Exception e){
242                         e.printStackTrace();
243                 }
244         }
245         
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{
248                 try {
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;
259                                 }else{
260                                         policyScopeClosedLoopDao.Save(ecompData);
261                                 }
262                         }else{
263                                 policyScopeClosedLoopDao.update(ecompData); 
264                         } 
265                         response.setCharacterEncoding("UTF-8");
266                         response.setContentType("application / json");
267                         request.setCharacterEncoding("UTF-8");
268
269                         PrintWriter out = response.getWriter();
270                         String responseString = "";
271                         if(duplicateflag){
272                                 responseString = "Duplicate";
273                         }else{
274                                 responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData());
275                         }        
276                         JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
277
278                         out.write(j.toString());
279
280                         return null;
281                 }
282                 catch (Exception e){
283                         response.setCharacterEncoding("UTF-8");
284                         request.setCharacterEncoding("UTF-8");
285                         PrintWriter out = response.getWriter();
286                         out.write(e.getMessage());
287                 }
288                 return null;
289         }
290
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 {
293                 try{
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");
302
303                         PrintWriter out = response.getWriter();
304
305                         String responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData());
306                         JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}");
307                         out.write(j.toString());
308
309                         return null;
310                 }
311                 catch (Exception e){
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());
317                 }
318                 return null;
319         }
320         
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){
323                 try{
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());
330                 }
331                 catch (Exception e){
332                         e.printStackTrace();
333                 }
334         }
335         
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){
338                 try{
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());
345                 }
346                 catch (Exception e){
347                         e.printStackTrace();
348                 }
349         }
350         
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{
353                 try {
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;
364                                 }else{
365                                         policyScopeServiceDao.Save(ecompData);
366                                 }
367                         }else{
368                                 policyScopeServiceDao.update(ecompData); 
369                         } 
370                         response.setCharacterEncoding("UTF-8");
371                         response.setContentType("application / json");
372                         request.setCharacterEncoding("UTF-8");
373
374                         PrintWriter out = response.getWriter();
375                         String responseString = "";
376                         if(duplicateflag){
377                                 responseString = "Duplicate";
378                         }else{
379                                 responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData());
380                         }       
381                         JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
382
383                         out.write(j.toString());
384
385                         return null;
386                 }
387                 catch (Exception e){
388                         response.setCharacterEncoding("UTF-8");
389                         request.setCharacterEncoding("UTF-8");
390                         PrintWriter out = response.getWriter();
391                         out.write(e.getMessage());
392                 }
393                 return null;
394         }
395
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 {
398                 try{
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");
407
408                         PrintWriter out = response.getWriter();
409
410                         String responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData());
411                         JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}");
412                         out.write(j.toString());
413
414                         return null;
415                 }
416                 catch (Exception e){
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());
422                 }
423                 return null;
424         }
425         
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){
428                 try{
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());
435                 }
436                 catch (Exception e){
437                         e.printStackTrace();
438                 }
439         }
440         
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){
443                 try{
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());
450                 }
451                 catch (Exception e){
452                         e.printStackTrace();
453                 }
454         }
455         
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{
458                 try {
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;
469                                 }else{
470                                         policyScopeTypeDao.Save(ecompData);
471                                 }
472                         }else{
473                                 policyScopeTypeDao.update(ecompData); 
474                         } 
475                         response.setCharacterEncoding("UTF-8");
476                         response.setContentType("application / json");
477                         request.setCharacterEncoding("UTF-8");
478
479                         PrintWriter out = response.getWriter();
480                         String responseString = "";
481                         if(duplicateflag){
482                                 responseString = "Duplicate";
483                         }else{
484                                 responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData());
485                         } 
486                         JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
487
488                         out.write(j.toString());
489
490                         return null;
491                 }
492                 catch (Exception e){
493                         response.setCharacterEncoding("UTF-8");
494                         request.setCharacterEncoding("UTF-8");
495                         PrintWriter out = response.getWriter();
496                         out.write(e.getMessage());
497                 }
498                 return null;
499         }
500
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 {
503                 try{
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");
512
513                         PrintWriter out = response.getWriter();
514
515                         String responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData());
516                         JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}");
517                         out.write(j.toString());
518
519                         return null;
520                 }
521                 catch (Exception e){
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());
527                 }
528                 return null;
529         }
530         
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){
533                 try{
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());
540                 }
541                 catch (Exception e){
542                         e.printStackTrace();
543                 }
544         }
545         
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){
548                 try{
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());
555                 }
556                 catch (Exception e){
557                         e.printStackTrace();
558                 }
559         }
560         
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{
563                 try {
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;
574                                 }else{
575                                         PolicyScopeResourceDao.Save(ecompData);
576                                 }
577                         }else{
578                                 PolicyScopeResourceDao.update(ecompData); 
579                         } 
580                         response.setCharacterEncoding("UTF-8");
581                         response.setContentType("application / json");
582                         request.setCharacterEncoding("UTF-8");
583
584                         PrintWriter out = response.getWriter();
585                         String responseString = "";
586                         if(duplicateflag){
587                                 responseString = "Duplicate";
588                         }else{
589                                 responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData());
590                         }         
591                         JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
592
593                         out.write(j.toString());
594
595                         return null;
596                 }
597                 catch (Exception e){
598                         response.setCharacterEncoding("UTF-8");
599                         request.setCharacterEncoding("UTF-8");
600                         PrintWriter out = response.getWriter();
601                         out.write(e.getMessage());
602                 }
603                 return null;
604         }
605
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 {
608                 try{
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");
617
618                         PrintWriter out = response.getWriter();
619
620                         String responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData());
621                         JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}");
622                         out.write(j.toString());
623
624                         return null;
625                 }
626                 catch (Exception e){
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());
632                 }
633                 return null;
634         }
635 }
636
637         class GroupPolicyScope{
638         String resource;
639         String type;
640         String service;
641         String closedloop;
642         public String getResource() {
643                 return resource;
644         }
645         public void setResource(String resource) {
646                 this.resource = resource;
647         }
648         public String getType() {
649                 return type;
650         }
651         public void setType(String type) {
652                 this.type = type;
653         }
654         public String getService() {
655                 return service;
656         }
657         public void setService(String service) {
658                 this.service = service;
659         }
660         public String getClosedloop() {
661                 return closedloop;
662         }
663         public void setClosedloop(String closedloop) {
664                 this.closedloop = closedloop;
665         }
666         
667 }