Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / controller / ClosedLoopDictionaryController.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.LinkedHashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32
33 import org.json.JSONObject;
34 import org.openecomp.policy.pap.xacml.rest.adapters.GridData;
35 import org.openecomp.policy.pap.xacml.rest.util.JsonMessage;
36 import org.openecomp.policy.rest.dao.PEPOptionsDao;
37 import org.openecomp.policy.rest.dao.ServiceDictionaryDao;
38 import org.openecomp.policy.rest.dao.SiteDictionaryDao;
39 import org.openecomp.policy.rest.dao.UserInfoDao;
40 import org.openecomp.policy.rest.dao.VNFTypeDao;
41 import org.openecomp.policy.rest.dao.VSCLActionDao;
42 import org.openecomp.policy.rest.dao.VarbindDictionaryDao;
43 import org.openecomp.policy.rest.jpa.ClosedLoopD2Services;
44 import org.openecomp.policy.rest.jpa.ClosedLoopSite;
45 import org.openecomp.policy.rest.jpa.PEPOptions;
46 import org.openecomp.policy.rest.jpa.UserInfo;
47 import org.openecomp.policy.rest.jpa.VNFType;
48 import org.openecomp.policy.rest.jpa.VSCLAction;
49 import org.openecomp.policy.rest.jpa.VarbindDictionary;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.http.MediaType;
52 import org.springframework.stereotype.Controller;
53 import org.springframework.web.bind.annotation.RequestMapping;
54 import org.springframework.web.servlet.ModelAndView;
55
56 import com.fasterxml.jackson.databind.DeserializationFeature;
57 import com.fasterxml.jackson.databind.JsonNode;
58 import com.fasterxml.jackson.databind.ObjectMapper;
59
60 @Controller
61 public class ClosedLoopDictionaryController{
62
63         @Autowired
64         VSCLActionDao vsclActionDao;
65         
66         @Autowired
67         VNFTypeDao vnfTypeDao;
68         
69         @Autowired
70         PEPOptionsDao pepOptionsDao;
71         
72         @Autowired
73         VarbindDictionaryDao varbindDao;
74         
75         @Autowired
76         ServiceDictionaryDao closedLoopServiceDao;
77         
78         @Autowired
79         SiteDictionaryDao closedLoopSiteDao;
80         
81         @Autowired
82         UserInfoDao userInfoDao;
83         
84         public UserInfo getUserInfo(String loginId){
85                 UserInfo name = userInfoDao.getUserInfoByLoginId(loginId);
86                 return name;    
87         }
88         
89         
90         @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
91         public void getVSCLActionDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
92                 try{
93                         Map<String, Object> model = new HashMap<String, Object>();
94                         ObjectMapper mapper = new ObjectMapper();
95                         model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(vsclActionDao.getVsclActionDataByName()));
96                         org.openecomp.policy.pap.xacml.rest.util.JsonMessage msg = new org.openecomp.policy.pap.xacml.rest.util.JsonMessage(mapper.writeValueAsString(model));
97                         JSONObject j = new JSONObject(msg);
98                         response.getWriter().write(j.toString());
99                 }
100                 catch (Exception e){
101                         e.printStackTrace();
102                 }
103         }
104         
105         
106         @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
107         public void getVSCLActionDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
108                 try{
109                         Map<String, Object> model = new HashMap<String, Object>();
110                         ObjectMapper mapper = new ObjectMapper();
111                         model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(vsclActionDao.getVSCLActionData()));
112                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
113                         JSONObject j = new JSONObject(msg);
114                         response.getWriter().write(j.toString());
115                 }
116                 catch (Exception e){
117                         e.printStackTrace();
118                 }
119         }
120         
121         @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
122         public void getVNFTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
123                 try{
124                         Map<String, Object> model = new HashMap<String, Object>();
125                         ObjectMapper mapper = new ObjectMapper();
126                         model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(vnfTypeDao.getVNFTypeDataByName()));
127                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
128                         JSONObject j = new JSONObject(msg);
129                         response.getWriter().write(j.toString());
130                 }
131                 catch (Exception e){
132                         e.printStackTrace();
133                 }
134         }
135                 
136         @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
137         public void getVNFTypeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
138                 try{
139                         Map<String, Object> model = new HashMap<String, Object>();
140                         ObjectMapper mapper = new ObjectMapper();
141                         model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(vnfTypeDao.getVNFTypeData()));
142                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
143                         JSONObject j = new JSONObject(msg);
144                         response.getWriter().write(j.toString());
145                 }
146                 catch (Exception e){
147                         e.printStackTrace();
148                 }
149         }
150         
151         @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
152         public void getPEPOptionsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
153                 try{
154                         Map<String, Object> model = new HashMap<String, Object>();
155                         ObjectMapper mapper = new ObjectMapper();
156                         model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(pepOptionsDao.getPEPOptionsDataByName()));
157                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
158                         JSONObject j = new JSONObject(msg);
159                         response.getWriter().write(j.toString());
160                 }
161                 catch (Exception e){
162                         e.printStackTrace();
163                 }
164         }
165         
166         @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
167         public void getPEPOptionsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
168                 try{
169                         Map<String, Object> model = new HashMap<String, Object>();
170                         ObjectMapper mapper = new ObjectMapper();
171                         model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(pepOptionsDao.getPEPOptionsData()));
172                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
173                         JSONObject j = new JSONObject(msg);
174                         response.getWriter().write(j.toString());
175                 }
176                 catch (Exception e){
177                         e.printStackTrace();
178                 }
179         }
180         
181         @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
182         public void getVarbindDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
183                 try{
184                         Map<String, Object> model = new HashMap<String, Object>();
185                         ObjectMapper mapper = new ObjectMapper();
186                         model.put("varbindDictionaryDatas", mapper.writeValueAsString(varbindDao.getVarbindDataByName()));
187                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
188                         JSONObject j = new JSONObject(msg);
189                         response.getWriter().write(j.toString());
190                 }
191                 catch (Exception e){
192                         e.printStackTrace();
193                 }
194         }
195         
196         @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
197         public void getVarbindDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
198                 try{
199                         Map<String, Object> model = new HashMap<String, Object>();
200                         ObjectMapper mapper = new ObjectMapper();
201                         model.put("varbindDictionaryDatas", mapper.writeValueAsString(varbindDao.getVarbindDictionaryData()));
202                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
203                         JSONObject j = new JSONObject(msg);
204                         response.getWriter().write(j.toString());
205                 }
206                 catch (Exception e){
207                         e.printStackTrace();
208                 }
209         }
210         
211         @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
212         public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
213                 try{
214                         Map<String, Object> model = new HashMap<String, Object>();
215                         ObjectMapper mapper = new ObjectMapper();
216                         model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(closedLoopServiceDao.getCLServiceDictDataByName()));
217                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
218                         JSONObject j = new JSONObject(msg);
219                         response.getWriter().write(j.toString());
220                 }
221                 catch (Exception e){
222                         e.printStackTrace();
223                 }
224         }
225         
226         @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
227         public void getClosedLoopServiceDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
228                 try{
229                         Map<String, Object> model = new HashMap<String, Object>();
230                         ObjectMapper mapper = new ObjectMapper();
231                         model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(closedLoopServiceDao.getClosedLoopD2ServicesData()));
232                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
233                         JSONObject j = new JSONObject(msg);
234                         response.getWriter().write(j.toString());
235                 }
236                 catch (Exception e){
237                         e.printStackTrace();
238                 }
239         }
240         
241         @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
242         public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
243                 try{
244                         Map<String, Object> model = new HashMap<String, Object>();
245                         ObjectMapper mapper = new ObjectMapper();
246                         model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(closedLoopSiteDao.getCLSiteDataByName()));
247                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
248                         JSONObject j = new JSONObject(msg);
249                         response.getWriter().write(j.toString());
250                 }
251                 catch (Exception e){
252                         e.printStackTrace();
253                 }
254         }
255         
256         @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
257         public void getClosedLoopSiteDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
258                 try{
259                         Map<String, Object> model = new HashMap<String, Object>();
260                         ObjectMapper mapper = new ObjectMapper();
261                         model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(closedLoopSiteDao.getClosedLoopSiteData()));
262                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
263                         JSONObject j = new JSONObject(msg);
264                         response.getWriter().write(j.toString());
265                 }
266                 catch (Exception e){
267                         e.printStackTrace();
268                 }
269         }
270         
271         @RequestMapping(value={"/cl_dictionary/save_vsclAction.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
272           public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{
273             try {
274                 boolean duplicateflag = false;
275                       ObjectMapper mapper = new ObjectMapper();
276                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
277                       JsonNode root = mapper.readTree(request.getReader());
278                       VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
279                       String userId = root.get("loginId").textValue();
280                       if(vSCLAction.getId() == 0){
281                           CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
282                           List<Object> duplicateData =  entry.CheckDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class);
283                           if(!duplicateData.isEmpty()){
284                                   duplicateflag = true;
285                           }else{
286                                   vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
287                                   vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
288                                   vsclActionDao.Save(vSCLAction);
289                           }
290                       }else{
291                           vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
292                           vsclActionDao.update(vSCLAction); 
293                       } 
294                       response.setCharacterEncoding("UTF-8");
295                       response.setContentType("application / json");
296                       request.setCharacterEncoding("UTF-8");
297                       
298                       PrintWriter out = response.getWriter();
299                       String responseString = "";
300                           if(duplicateflag){
301                                 responseString = "Duplicate";
302                           }else{
303                                 responseString = mapper.writeValueAsString(this.vsclActionDao.getVSCLActionData());
304                           }       
305                       JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
306                       
307                       out.write(j.toString());
308                       
309                       return null;
310             }
311             catch (Exception e){
312               response.setCharacterEncoding("UTF-8");
313               request.setCharacterEncoding("UTF-8");
314               PrintWriter out = response.getWriter();
315               out.write(e.getMessage());
316             }
317             return null;
318           }
319         
320         @RequestMapping(value={"/cl_dictionary/remove_VsclAction.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
321           public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
322             try{
323               ObjectMapper mapper = new ObjectMapper();
324               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
325               JsonNode root = mapper.readTree(request.getReader());
326               VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
327               vsclActionDao.delete(vSCLAction);
328               response.setCharacterEncoding("UTF-8");
329               response.setContentType("application / json");
330               request.setCharacterEncoding("UTF-8");
331               
332               PrintWriter out = response.getWriter();
333               
334               String responseString = mapper.writeValueAsString(this.vsclActionDao.getVSCLActionData());
335               JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
336               out.write(j.toString());
337               
338               return null;
339             }
340             catch (Exception e){
341               System.out.println(e);
342               response.setCharacterEncoding("UTF-8");
343               request.setCharacterEncoding("UTF-8");
344               PrintWriter out = response.getWriter();
345               out.write(e.getMessage());
346             }
347             return null;
348           }
349         
350         @RequestMapping(value={"/cl_dictionary/save_vnfType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
351           public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{
352             try {
353                 boolean duplicateflag = false;
354               ObjectMapper mapper = new ObjectMapper();
355               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
356               JsonNode root = mapper.readTree(request.getReader());
357               VNFType vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
358                   String userId = root.get("loginId").textValue();
359               if(vNFType.getId() == 0){
360                   CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
361                   List<Object> duplicateData =  entry.CheckDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class);
362                   if(!duplicateData.isEmpty()){
363                         duplicateflag = true;
364                   }else{
365                           vNFType.setUserCreatedBy(this.getUserInfo(userId));
366                           vNFType.setUserModifiedBy(this.getUserInfo(userId));
367                           vnfTypeDao.Save(vNFType);
368                   }      
369               }else{
370                   vNFType.setUserModifiedBy(this.getUserInfo(userId));
371                   vnfTypeDao.update(vNFType); 
372               } 
373               response.setCharacterEncoding("UTF-8");
374               response.setContentType("application / json");
375               request.setCharacterEncoding("UTF-8");
376               
377               PrintWriter out = response.getWriter();
378               String responseString = "";
379                         if(duplicateflag){
380                                 responseString = "Duplicate";
381                         }else{
382                                 responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData());
383                         } 
384               JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
385               
386               out.write(j.toString());
387               
388               return null;
389             }
390             catch (Exception e){
391               response.setCharacterEncoding("UTF-8");
392               request.setCharacterEncoding("UTF-8");
393               PrintWriter out = response.getWriter();
394               out.write(e.getMessage());
395             }
396             return null;
397           }
398         
399         @RequestMapping(value={"/cl_dictionary/remove_vnfType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
400           public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception {
401             try{
402                       ObjectMapper mapper = new ObjectMapper();
403                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
404                       JsonNode root = mapper.readTree(request.getReader());
405                       VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
406                       vnfTypeDao.delete(vNFType);
407                       response.setCharacterEncoding("UTF-8");
408                       response.setContentType("application / json");
409                       request.setCharacterEncoding("UTF-8");
410                       
411                       PrintWriter out = response.getWriter();
412                       
413                       String responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData());
414                       JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
415                       out.write(j.toString());
416                       
417                       return null;
418                     }
419                     catch (Exception e){
420                       System.out.println(e);
421                       response.setCharacterEncoding("UTF-8");
422                       request.setCharacterEncoding("UTF-8");
423                       PrintWriter out = response.getWriter();
424                       out.write(e.getMessage());
425                     }
426                     return null;
427           }
428         
429         @RequestMapping(value={"/cl_dictionary/save_pepOptions.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
430           public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{
431             try {
432                 boolean duplicateflag = false;
433                       ObjectMapper mapper = new ObjectMapper();
434                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
435                       JsonNode root = mapper.readTree(request.getReader());
436                       PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
437                       GridData gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
438                       String userId = root.get("loginId").textValue();
439                       String actions = "";
440                                 int counter = 0;
441                                 if(gridData.getAttributes().size() > 0){
442                                         for(Object attribute : gridData.getAttributes()){
443                                                 if(attribute instanceof LinkedHashMap<?, ?>){
444                                                         String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
445                                                         String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
446                                                         if(counter>0){
447                                                                 actions = actions + ":#@";
448                                                         }
449                                                         actions = actions + key + "=#@";
450                                                         actions = actions + value;
451                                                         counter ++;
452                                                 }
453                                         }
454                                 }
455                                 pEPOptions.setActions(actions);
456                       if(pEPOptions.getId() == 0){
457                           CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
458                           List<Object> duplicateData =  entry.CheckDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class);
459                           if(!duplicateData.isEmpty()){
460                                 duplicateflag = true;
461                           }else{
462                                   pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
463                                   pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
464                                   pepOptionsDao.Save(pEPOptions);
465                           }      
466                       }else{
467                           pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
468                           pepOptionsDao.update(pEPOptions); 
469                       } 
470                       response.setCharacterEncoding("UTF-8");
471                       response.setContentType("application / json");
472                       request.setCharacterEncoding("UTF-8");
473                       
474                       PrintWriter out = response.getWriter();
475                       String responseString = "";
476                       if(duplicateflag){
477                         responseString = "Duplicate";
478                       }else{
479                           responseString = mapper.writeValueAsString(this.pepOptionsDao.getPEPOptionsData());
480                       } 
481                       JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
482                       
483                       out.write(j.toString());
484                       
485                       return null;
486                     }
487                     catch (Exception e){
488                       response.setCharacterEncoding("UTF-8");
489                       request.setCharacterEncoding("UTF-8");
490                       PrintWriter out = response.getWriter();
491                       out.write(e.getMessage());
492                     }
493             return null;
494           }
495         
496         @RequestMapping(value={"/cl_dictionary/remove_pepOptions.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
497           public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception {
498             try{
499               ObjectMapper mapper = new ObjectMapper();
500               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
501               JsonNode root = mapper.readTree(request.getReader());
502               PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
503               pepOptionsDao.delete(pEPOptions);
504               response.setCharacterEncoding("UTF-8");
505               response.setContentType("application / json");
506               request.setCharacterEncoding("UTF-8");
507               
508               PrintWriter out = response.getWriter();
509               
510               String responseString = mapper.writeValueAsString(this.pepOptionsDao.getPEPOptionsData());
511               JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
512               out.write(j.toString());
513               
514               return null;
515             }
516             catch (Exception e){
517               System.out.println(e);
518               response.setCharacterEncoding("UTF-8");
519               request.setCharacterEncoding("UTF-8");
520               PrintWriter out = response.getWriter();
521               out.write(e.getMessage());
522             }
523             return null;
524           }
525         
526         @RequestMapping(value={"/cl_dictionary/save_service.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
527           public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{
528             try {
529                 boolean duplicateflag = false;
530               ObjectMapper mapper = new ObjectMapper();
531               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
532               JsonNode root = mapper.readTree(request.getReader());
533               ClosedLoopD2Services serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
534               String userId = root.get("loginId").textValue();
535               if(serviceData.getId() == 0){
536                   CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
537                   List<Object> duplicateData =  entry.CheckDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class);
538                   if(!duplicateData.isEmpty()){
539                         duplicateflag = true;
540                   }else{
541                           serviceData.setUserCreatedBy(this.getUserInfo(userId));
542                           serviceData.setUserModifiedBy(this.getUserInfo(userId));
543                           closedLoopServiceDao.Save(serviceData);
544                   }
545               }else{
546                   serviceData.setUserModifiedBy(this.getUserInfo(userId));
547                   closedLoopServiceDao.update(serviceData); 
548               } 
549               response.setCharacterEncoding("UTF-8");
550               response.setContentType("application / json");
551               request.setCharacterEncoding("UTF-8");
552               
553               PrintWriter out = response.getWriter();
554               String responseString = "";
555               if(duplicateflag){
556                 responseString = "Duplicate";
557               }else{
558                   responseString = mapper.writeValueAsString(this.closedLoopServiceDao.getClosedLoopD2ServicesData());
559               } 
560               JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
561               
562               out.write(j.toString());
563               
564               return null;
565             }
566             catch (Exception e){
567               response.setCharacterEncoding("UTF-8");
568               request.setCharacterEncoding("UTF-8");
569               PrintWriter out = response.getWriter();
570               out.write(e.getMessage());
571             }
572             return null;
573           }
574         
575         @RequestMapping(value={"/cl_dictionary/remove_Service.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
576           public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception {
577             try{
578               ObjectMapper mapper = new ObjectMapper();
579               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
580               JsonNode root = mapper.readTree(request.getReader());
581               ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
582               closedLoopServiceDao.delete(closedLoopD2Services);
583               response.setCharacterEncoding("UTF-8");
584               response.setContentType("application / json");
585               request.setCharacterEncoding("UTF-8");
586               
587               PrintWriter out = response.getWriter();
588               
589               String responseString = mapper.writeValueAsString(this.closedLoopServiceDao.getClosedLoopD2ServicesData());
590               JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
591               out.write(j.toString());
592               
593               return null;
594             }
595             catch (Exception e){
596               System.out.println(e);
597               response.setCharacterEncoding("UTF-8");
598               request.setCharacterEncoding("UTF-8");
599               PrintWriter out = response.getWriter();
600               out.write(e.getMessage());
601             }
602             return null;
603           }
604         
605         @RequestMapping(value={"/cl_dictionary/save_siteName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
606           public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{
607             try {
608                 boolean duplicateflag = false;
609               ObjectMapper mapper = new ObjectMapper();
610               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
611               JsonNode root = mapper.readTree(request.getReader());
612               ClosedLoopSite siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
613               String userId = root.get("loginId").textValue();
614               if(siteData.getId() == 0){
615                   CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
616                   List<Object> duplicateData =  entry.CheckDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class);
617                   if(!duplicateData.isEmpty()){
618                         duplicateflag = true;
619                   }else{
620                           siteData.setUserCreatedBy(this.getUserInfo(userId));
621                           siteData.setUserModifiedBy(this.getUserInfo(userId));
622                           closedLoopSiteDao.Save(siteData);
623                   }
624               }else{
625                   siteData.setUserModifiedBy(this.getUserInfo(userId));
626                   closedLoopSiteDao.update(siteData); 
627               } 
628               response.setCharacterEncoding("UTF-8");
629               response.setContentType("application / json");
630               request.setCharacterEncoding("UTF-8");
631               
632               PrintWriter out = response.getWriter();
633               String responseString = "";
634               if(duplicateflag){
635                 responseString = "Duplicate";
636               }else{
637                 responseString = mapper.writeValueAsString(this.closedLoopSiteDao.getClosedLoopSiteData());
638               } 
639               JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
640               
641               out.write(j.toString());
642               
643               return null;
644             }
645             catch (Exception e){
646               response.setCharacterEncoding("UTF-8");
647               request.setCharacterEncoding("UTF-8");
648               PrintWriter out = response.getWriter();
649               out.write(e.getMessage());
650             }
651             return null;
652           }
653         
654         @RequestMapping(value={"/cl_dictionary/remove_site.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
655           public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception {
656             try{
657               ObjectMapper mapper = new ObjectMapper();
658               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
659               JsonNode root = mapper.readTree(request.getReader());
660               ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
661               closedLoopSiteDao.delete(closedLoopSite);
662               response.setCharacterEncoding("UTF-8");
663               response.setContentType("application / json");
664               request.setCharacterEncoding("UTF-8");
665               
666               PrintWriter out = response.getWriter();
667               
668               String responseString = mapper.writeValueAsString(this.closedLoopSiteDao.getClosedLoopSiteData());
669               JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
670               out.write(j.toString());
671               
672               return null;
673             }
674             catch (Exception e){
675               System.out.println(e);
676               response.setCharacterEncoding("UTF-8");
677               request.setCharacterEncoding("UTF-8");
678               PrintWriter out = response.getWriter();
679               out.write(e.getMessage());
680             }
681             return null;
682           }
683         
684         @RequestMapping(value={"/cl_dictionary/save_varbind.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
685           public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{
686             try {
687                 boolean duplicateflag = false;
688               ObjectMapper mapper = new ObjectMapper();
689               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
690               JsonNode root = mapper.readTree(request.getReader());
691               VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
692               String userId = root.get("loginId").textValue();
693               if(varbindDictionary.getId() == 0){
694                   CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries();
695                   List<Object> duplicateData =  entry.CheckDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class);
696                   if(!duplicateData.isEmpty()){
697                         duplicateflag = true;
698                   }else{
699                           varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
700                           varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
701                           varbindDao.Save(varbindDictionary);
702                   }       
703               }else{
704                   varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
705                   varbindDao.update(varbindDictionary); 
706               } 
707               response.setCharacterEncoding("UTF-8");
708               response.setContentType("application / json");
709               request.setCharacterEncoding("UTF-8");
710               
711               PrintWriter out = response.getWriter();
712               String responseString = "";
713               if(duplicateflag){
714                 responseString = "Duplicate";
715               }else{
716                 responseString = mapper.writeValueAsString(this.varbindDao.getVarbindDictionaryData());
717               }
718               JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
719               
720               out.write(j.toString());
721               
722               return null;
723             }
724             catch (Exception e){
725               response.setCharacterEncoding("UTF-8");
726               request.setCharacterEncoding("UTF-8");
727               PrintWriter out = response.getWriter();
728               out.write(e.getMessage());
729             }
730             return null;
731           }
732         
733         @RequestMapping(value={"/cl_dictionary/remove_varbindDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
734           public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception {
735             try{
736               ObjectMapper mapper = new ObjectMapper();
737               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
738               JsonNode root = mapper.readTree(request.getReader());
739               VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
740               varbindDao.delete(varbindDictionary);
741               response.setCharacterEncoding("UTF-8");
742               response.setContentType("application / json");
743               request.setCharacterEncoding("UTF-8");
744               
745               PrintWriter out = response.getWriter();
746               
747               String responseString = mapper.writeValueAsString(this.varbindDao.getVarbindDictionaryData());
748               JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
749               out.write(j.toString());
750               
751               return null;
752             }
753             catch (Exception e){
754               System.out.println(e);
755               response.setCharacterEncoding("UTF-8");
756               request.setCharacterEncoding("UTF-8");
757               PrintWriter out = response.getWriter();
758               out.write(e.getMessage());
759             }
760             return null;
761           }
762         
763 }
764