Merge "Technical debt reduction"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / ClosedLoopDictionaryController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-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.onap.policy.pap.xacml.rest.controller;
22
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.util.Date;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33
34 import org.json.JSONObject;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.pap.xacml.rest.adapters.GridData;
38 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
39 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
40 import org.onap.policy.rest.dao.CommonClassDao;
41 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
42 import org.onap.policy.rest.jpa.ClosedLoopSite;
43 import org.onap.policy.rest.jpa.PEPOptions;
44 import org.onap.policy.rest.jpa.UserInfo;
45 import org.onap.policy.rest.jpa.VNFType;
46 import org.onap.policy.rest.jpa.VSCLAction;
47 import org.onap.policy.rest.jpa.VarbindDictionary;
48 import org.onap.policy.utils.PolicyUtils;
49 import org.onap.policy.xacml.api.XACMLErrorConstants;
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         private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class);
64
65         private static CommonClassDao commonClassDao;
66         private static String vsclaction = "vsclaction";
67         private static String successMapKey = "successMapKey";
68         private static String successMessage = "success";
69         private static String operation = "operation";
70         private static String getDictionary = "getDictionary";
71         private static String dictionaryDBQuery = "dictionaryDBQuery";
72         private static String errorMsg  = "error";
73         private static String vnftype = "vnftype";
74         private static String pepName = "pepName";
75         private static String varbindName = "varbindName";
76         private static String serviceName = "serviceName";
77         private static String siteName = "siteName";
78         private static String apiflag = "apiflag";
79         private static String dictionaryFields = "dictionaryFields";
80         private static String update = "update";
81         private static String duplicateResponseString = "Duplicate";
82         private static String userid = "userid";
83         private static String utf8 = "UTF-8";
84         private static String applicationJsonContentType = "application / json";
85         private static String successMsg = "Success";
86         
87         @Autowired
88         public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
89                 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
90         }
91         /*
92          * This is an empty constructor
93          */
94         public ClosedLoopDictionaryController(){}
95
96         public UserInfo getUserInfo(String loginId){
97                 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
98         }
99
100
101         @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
102         public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
103                 try{
104                         Map<String, Object> model = new HashMap<>();
105                         ObjectMapper mapper = new ObjectMapper();
106                         model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, vsclaction)));
107                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
108                         JSONObject j = new JSONObject(msg);
109                         response.getWriter().write(j.toString());
110                 }
111                 catch (Exception e){
112                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
113                 }
114         }
115
116
117         @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
118         public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
119                 try{
120                         Map<String, Object> model = new HashMap<>();
121                         ObjectMapper mapper = new ObjectMapper();
122                         model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)));
123                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
124                         JSONObject j = new JSONObject(msg);
125                         response.addHeader(successMapKey, successMessage); 
126                         response.addHeader(operation, getDictionary);
127                         response.getWriter().write(j.toString());
128                 }
129                 catch (Exception e){
130                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
131                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
132                         response.addHeader(errorMsg, dictionaryDBQuery);
133                 }
134         }
135
136         @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
137         public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
138                 try{
139                         Map<String, Object> model = new HashMap<>();
140                         ObjectMapper mapper = new ObjectMapper();
141                         model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, vnftype)));
142                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
143                         JSONObject j = new JSONObject(msg);
144                         response.addHeader(successMapKey, successMessage); 
145                         response.addHeader(operation, getDictionary);
146                         response.getWriter().write(j.toString());
147                 }
148                 catch (Exception e){
149                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
150                 }
151         }
152
153         @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
154         public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
155                 try{
156                         Map<String, Object> model = new HashMap<>();
157                         ObjectMapper mapper = new ObjectMapper();
158                         model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.class)));
159                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
160                         JSONObject j = new JSONObject(msg);
161                         response.addHeader(successMapKey, successMessage); 
162                         response.addHeader(operation, getDictionary);
163                         response.getWriter().write(j.toString());
164                 }
165                 catch (Exception e){
166                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
167                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
168                         response.addHeader(errorMsg, dictionaryDBQuery);
169                 }
170         }
171
172         @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
173         public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
174                 try{
175                         Map<String, Object> model = new HashMap<>();
176                         ObjectMapper mapper = new ObjectMapper();
177                         model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, pepName)));
178                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
179                         JSONObject j = new JSONObject(msg);
180                         response.getWriter().write(j.toString());
181                 }
182                 catch (Exception e){
183                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
184                 }
185         }
186
187         @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
188         public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
189                 try{
190                         Map<String, Object> model = new HashMap<>();
191                         ObjectMapper mapper = new ObjectMapper();
192                         model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)));
193                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
194                         JSONObject j = new JSONObject(msg);
195                         response.addHeader(successMapKey, successMessage); 
196                         response.addHeader(operation, getDictionary);
197                         response.getWriter().write(j.toString());
198                 }
199                 catch (Exception e){
200                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
201                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
202                         response.addHeader(errorMsg, dictionaryDBQuery);
203                 }
204         }
205
206         @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
207         public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
208                 try{
209                         Map<String, Object> model = new HashMap<>();
210                         ObjectMapper mapper = new ObjectMapper();
211                         model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, varbindName)));
212                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
213                         JSONObject j = new JSONObject(msg);
214                         response.getWriter().write(j.toString());
215                 }
216                 catch (Exception e){
217                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
218                 }
219         }
220
221         @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
222         public void getVarbindDictionaryEntityData(HttpServletResponse response){
223                 try{
224                         Map<String, Object> model = new HashMap<>();
225                         ObjectMapper mapper = new ObjectMapper();
226                         model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)));
227                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
228                         JSONObject j = new JSONObject(msg);
229                         response.addHeader(successMapKey, successMessage); 
230                         response.addHeader(operation, getDictionary);
231                         response.getWriter().write(j.toString());
232                 }
233                 catch (Exception e){
234                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
235                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
236                         response.addHeader(errorMsg, dictionaryDBQuery);
237                 }
238         }
239
240         @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
241         public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
242                 try{
243                         Map<String, Object> model = new HashMap<>();
244                         ObjectMapper mapper = new ObjectMapper();
245                         model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, serviceName)));
246                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
247                         JSONObject j = new JSONObject(msg);
248                         response.getWriter().write(j.toString());
249                 }
250                 catch (Exception e){
251                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
252                 }
253         }
254
255         @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
256         public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
257                 try{
258                         Map<String, Object> model = new HashMap<>();
259                         ObjectMapper mapper = new ObjectMapper();
260                         model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)));
261                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
262                         JSONObject j = new JSONObject(msg);
263                         response.addHeader(successMapKey, successMessage); 
264                         response.addHeader(operation, getDictionary);
265                         response.getWriter().write(j.toString());
266                 }
267                 catch (Exception e){
268                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
269                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
270                         response.addHeader(errorMsg, dictionaryDBQuery);
271                 }
272         }
273
274         @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
275         public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
276                 try{
277                         Map<String, Object> model = new HashMap<>();
278                         ObjectMapper mapper = new ObjectMapper();
279                         model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, siteName)));
280                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
281                         JSONObject j = new JSONObject(msg);
282                         response.getWriter().write(j.toString());
283                 }
284                 catch (Exception e){
285                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
286                 }
287         }
288
289         @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
290         public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
291                 try{
292                         Map<String, Object> model = new HashMap<>();
293                         ObjectMapper mapper = new ObjectMapper();
294                         model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)));
295                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
296                         JSONObject j = new JSONObject(msg);
297                         response.addHeader(successMapKey, successMessage); 
298                         response.addHeader(operation, getDictionary);
299                         response.getWriter().write(j.toString());
300                 }
301                 catch (Exception e){
302                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
303                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
304                         response.addHeader(errorMsg, dictionaryDBQuery);
305                 }
306         }
307
308         @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
309         public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
310                 try {
311                         boolean duplicateflag = false;
312                         boolean isFakeUpdate = false;
313                         boolean fromAPI = false;
314                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
315                                 fromAPI = true;
316                         }
317                         ObjectMapper mapper = new ObjectMapper();
318                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
319                         JsonNode root = mapper.readTree(request.getReader());
320                         VSCLAction vSCLAction;
321                         String userId = null;
322                         if (fromAPI) {
323                                 vSCLAction = (VSCLAction)mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
324                                 userId = "API";
325
326                                 //check if update operation or create, get id for data to be updated and update attributeData
327                                 if ((update).equals(request.getParameter(operation))) {
328                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
329                                         VSCLAction data = (VSCLAction) duplicateData.get(0);
330                                         int id = data.getId();
331                                         if(id==0){
332                                                 isFakeUpdate=true;
333                                                 vSCLAction.setId(1);
334                                         } else {
335                                                 vSCLAction.setId(id);
336                                         }
337
338                                         vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
339                                 }
340
341                         } else {
342                                 vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
343                                 userId = root.get(userid).textValue();
344                         }
345                         if(vSCLAction.getId() == 0){
346                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
347                                 if(!duplicateData.isEmpty()){
348                                         duplicateflag = true;
349                                 }else{
350                                         vSCLAction.setUserCreatedBy(this.getUserInfo(userId));
351                                         vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
352                                         vSCLAction.setModifiedDate(new Date());
353                                         commonClassDao.save(vSCLAction);
354                                 }
355                         }else{
356                                 if(!isFakeUpdate) {
357                                         vSCLAction.setUserModifiedBy(this.getUserInfo(userId));
358                                         commonClassDao.update(vSCLAction); 
359                                 }
360                         }
361
362                         String responseString = "";
363                         if(duplicateflag){
364                                 responseString = duplicateResponseString;
365                         }else{
366                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
367                         }       
368                         if (fromAPI) {
369                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
370                                         if(isFakeUpdate) {
371                                                 responseString = "Exists";
372                                         } else {
373                                                 responseString = successMsg;
374                                         }               
375
376                                 }
377                                 ModelAndView result = new ModelAndView();
378                                 result.setViewName(responseString);
379                                 return result;
380                         } else {
381                                 response.setCharacterEncoding(utf8);
382                                 response.setContentType(applicationJsonContentType); 
383                                 request.setCharacterEncoding(utf8);
384
385                                 PrintWriter out = response.getWriter();
386                                 JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
387                                 out.write(j.toString());
388                                 return null;
389                         }
390                 }
391                 catch (Exception e){
392                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
393                         response.setCharacterEncoding(utf8);
394                         request.setCharacterEncoding(utf8);
395                         PrintWriter out = response.getWriter();
396                         out.write(PolicyUtils.CATCH_EXCEPTION);
397                 }
398                 return null;
399         }
400
401         @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
402         public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
403                 try{
404                         ObjectMapper mapper = new ObjectMapper();
405                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
406                         JsonNode root = mapper.readTree(request.getReader());
407                         VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class);
408                         commonClassDao.delete(vSCLAction);
409                         response.setCharacterEncoding(utf8);
410                         response.setContentType(applicationJsonContentType);
411                         request.setCharacterEncoding(utf8);
412
413                         PrintWriter out = response.getWriter();
414
415                         String responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
416                         JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}");
417                         out.write(j.toString());
418
419                         return null;
420                 }
421                 catch (Exception e){
422                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
423                         response.setCharacterEncoding(utf8);
424                         request.setCharacterEncoding(utf8);
425                         PrintWriter out = response.getWriter();
426                         out.write(PolicyUtils.CATCH_EXCEPTION);
427                 }
428                 return null;
429         }
430
431         @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
432         public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
433                 try {
434                         boolean duplicateflag = false;
435                         boolean isFakeUpdate = false;
436                         boolean fromAPI = false;
437
438                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
439                                 fromAPI = true;
440                         }
441                         ObjectMapper mapper = new ObjectMapper();
442                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
443                         JsonNode root = mapper.readTree(request.getReader());
444                         VNFType vNFType;
445                         String userId = null;
446
447                         if (fromAPI) {
448                                 vNFType = (VNFType)mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
449                                 userId = "API";
450
451                                 //check if update operation or create, get id for data to be updated and update attributeData
452                                 if ((update).equals(request.getParameter(operation))) {
453                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
454                                         VNFType data = (VNFType) duplicateData.get(0);
455                                         int id = data.getId();
456                                         if(id==0){
457                                                 isFakeUpdate=true;
458                                                 vNFType.setId(1);
459                                         } else {
460                                                 vNFType.setId(id);
461                                         }
462                                         vNFType.setUserCreatedBy(this.getUserInfo(userId));
463                                 }
464                         } else {
465                                 vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
466                                 userId = root.get(userid).textValue();
467                         }
468                         if(vNFType.getId() == 0){
469                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
470                                 if(!duplicateData.isEmpty()){
471                                         duplicateflag = true;
472                                 }else{
473                                         vNFType.setUserCreatedBy(this.getUserInfo(userId));
474                                         vNFType.setUserModifiedBy(this.getUserInfo(userId));
475                                         commonClassDao.save(vNFType);
476                                 }        
477                         }else{
478                                 if(!isFakeUpdate) {
479                                         vNFType.setUserModifiedBy(this.getUserInfo(userId));
480                                         vNFType.setModifiedDate(new Date());
481                                         commonClassDao.update(vNFType); 
482                                 }
483                         } 
484                         String responseString = "";
485                         if(duplicateflag){
486                                 responseString = duplicateResponseString;
487                         }else{
488                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
489                         } 
490                         if (fromAPI) {
491                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
492                                         if(isFakeUpdate) {
493                                                 responseString = "Exists";
494                                         } else {
495                                                 responseString = successMsg;
496                                         }        
497                                 }
498                                 ModelAndView result = new ModelAndView();
499                                 result.setViewName(responseString);
500                                 return result; 
501                         } else {
502                                 response.setCharacterEncoding(utf8);
503                                 response.setContentType(applicationJsonContentType);
504                                 request.setCharacterEncoding(utf8);
505
506                                 PrintWriter out = response.getWriter();
507                                 JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
508                                 out.write(j.toString()); 
509                                 return null;
510                         }
511                 } 
512                 catch (Exception e){
513                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
514                         response.setCharacterEncoding(utf8);
515                         request.setCharacterEncoding(utf8);
516                         PrintWriter out = response.getWriter();
517                         out.write(PolicyUtils.CATCH_EXCEPTION);
518                 }
519                 return null;
520         }
521
522         @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
523         public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
524                 try{
525                         ObjectMapper mapper = new ObjectMapper();
526                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
527                         JsonNode root = mapper.readTree(request.getReader());
528                         VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class);
529                         commonClassDao.delete(vNFType);
530                         response.setCharacterEncoding(utf8);
531                         response.setContentType(applicationJsonContentType);
532                         request.setCharacterEncoding(utf8);
533
534                         PrintWriter out = response.getWriter();
535
536                         String responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
537                         JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}");
538                         out.write(j.toString());
539
540                         return null;
541                 }
542                 catch (Exception e){
543                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
544                         response.setCharacterEncoding(utf8);
545                         request.setCharacterEncoding(utf8);
546                         PrintWriter out = response.getWriter();
547                         out.write(PolicyUtils.CATCH_EXCEPTION);
548                 }
549                 return null;
550         }
551
552         @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
553         public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
554                 try {
555                         boolean duplicateflag = false;
556             boolean isFakeUpdate = false;
557             boolean fromAPI = false;
558             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
559                 fromAPI = true;
560             }
561                         ObjectMapper mapper = new ObjectMapper();
562                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
563                         JsonNode root = mapper.readTree(request.getReader());
564             PEPOptions pEPOptions;
565             GridData gridData;
566             String userId = null;
567             if (fromAPI) {
568                 pEPOptions = (PEPOptions)mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class);
569                 gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
570                 userId = "API";
571                 
572                 //check if update operation or create, get id for data to be updated and update attributeData
573                 if ((update).equals(request.getParameter(operation))) {
574                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
575                     PEPOptions data = (PEPOptions) duplicateData.get(0);
576                     int id = data.getId();
577                     if(id==0){
578                         isFakeUpdate=true;
579                         pEPOptions.setId(1);
580                     } else {
581                         pEPOptions.setId(id);
582                     }
583                     pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
584                 }
585             } else {
586                 pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
587                 gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
588                 userId = root.get(userid).textValue();
589             }
590                         String actions = "";
591                         int counter = 0;
592                         if(!gridData.getAttributes().isEmpty()){
593                                 for(Object attribute : gridData.getAttributes()){
594                                         if(attribute instanceof LinkedHashMap<?, ?>){
595                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString();
596                                                 String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString();
597                                                 if(counter>0){
598                                                         actions = actions + ":#@";
599                                                 }
600                                                 actions = actions + key + "=#@";
601                                                 actions = actions + value;
602                                                 counter ++;
603                                         }
604                                 }
605                         }
606                         pEPOptions.setActions(actions);
607                         if(pEPOptions.getId() == 0){
608                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
609                                 if(!duplicateData.isEmpty()){
610                                         duplicateflag = true;
611                                 }else{
612                                         pEPOptions.setUserCreatedBy(this.getUserInfo(userId));
613                                         pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
614                                         commonClassDao.save(pEPOptions);
615                                 }        
616                         }else{
617                                 if(!isFakeUpdate){
618                                         pEPOptions.setUserModifiedBy(this.getUserInfo(userId));
619                                         pEPOptions.setModifiedDate(new Date());
620                                         commonClassDao.update(pEPOptions);
621                                 }
622                         }
623             String responseString = "";
624             if(duplicateflag){
625                 responseString = duplicateResponseString;
626             }else{
627                 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
628             } 
629             if (fromAPI) {
630                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
631                     if(isFakeUpdate){
632                         responseString = "Exists";
633                     } else {
634                         responseString = successMsg;
635                     } 
636                 }
637                 
638                 ModelAndView result = new ModelAndView();
639                 result.setViewName(responseString);
640                 return result;
641             } else {
642                 response.setCharacterEncoding(utf8);
643                 response.setContentType(applicationJsonContentType);
644                 request.setCharacterEncoding(utf8);
645  
646                 PrintWriter out = response.getWriter();
647                 JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
648                 out.write(j.toString());
649                 return null;
650             }
651  
652         }catch (Exception e){
653                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
654                         response.setCharacterEncoding(utf8);
655                         request.setCharacterEncoding(utf8);
656                         PrintWriter out = response.getWriter();
657                         out.write(PolicyUtils.CATCH_EXCEPTION);
658                 }
659                 return null;
660         }
661
662         @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
663         public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
664                 try{
665                         ObjectMapper mapper = new ObjectMapper();
666                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
667                         JsonNode root = mapper.readTree(request.getReader());
668                         PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class);
669                         commonClassDao.delete(pEPOptions);
670                         response.setCharacterEncoding(utf8);
671                         response.setContentType(applicationJsonContentType);
672                         request.setCharacterEncoding(utf8);
673
674                         PrintWriter out = response.getWriter();
675
676                         String responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
677                         JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}");
678                         out.write(j.toString());
679
680                         return null;
681                 }
682                 catch (Exception e){
683                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
684                         response.setCharacterEncoding(utf8);
685                         request.setCharacterEncoding(utf8);
686                         PrintWriter out = response.getWriter();
687                         out.write(PolicyUtils.CATCH_EXCEPTION);
688                 }
689                 return null;
690         }
691
692         @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
693         public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
694                 try {
695                         boolean duplicateflag = false;
696             boolean isFakeUpdate = false;
697             boolean fromAPI = false;
698             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
699                 fromAPI = true;
700             }
701                         ObjectMapper mapper = new ObjectMapper();
702                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
703                         JsonNode root = mapper.readTree(request.getReader());
704             ClosedLoopD2Services serviceData;
705             String userId = null;
706             if (fromAPI) {
707                 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
708                 userId = "API";
709                 
710                 //check if update operation or create, get id for data to be updated and update attributeData
711                 if ((update).equals(request.getParameter(operation))) {
712                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
713                     ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
714                     int id = data.getId();
715                     if(id==0){
716                         isFakeUpdate=true;
717                         serviceData.setId(1);
718                     } else {
719                         serviceData.setId(id);
720                     }
721                     serviceData.setUserCreatedBy(this.getUserInfo(userId));
722                 }
723             } else {
724                 serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
725                 userId = root.get(userid).textValue();
726             }
727                         if(serviceData.getId() == 0){
728                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
729                                 if(!duplicateData.isEmpty()){
730                                         duplicateflag = true;
731                                 }else{
732                                         serviceData.setUserCreatedBy(this.getUserInfo(userId));
733                                         serviceData.setUserModifiedBy(this.getUserInfo(userId));
734                                         commonClassDao.save(serviceData);
735                                 }
736                         }else{
737                                 if(!isFakeUpdate){
738                                         serviceData.setUserModifiedBy(this.getUserInfo(userId));
739                                         serviceData.setModifiedDate(new Date());
740                                         commonClassDao.update(serviceData); 
741                                 }
742                         }
743             String responseString = "";
744             if(duplicateflag){
745                 responseString = duplicateResponseString;
746             }else{
747                 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
748             } 
749             if (fromAPI) {
750                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
751                     if(isFakeUpdate){
752                         responseString = "Exists";
753                     } else {
754                         responseString = successMsg;
755                     }
756                 }
757                 ModelAndView result = new ModelAndView();
758                 result.setViewName(responseString);
759                 return result;
760             } else {
761                 response.setCharacterEncoding(utf8);
762                 response.setContentType(applicationJsonContentType);
763                 request.setCharacterEncoding(utf8);
764  
765                 PrintWriter out = response.getWriter();
766                 JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
767                 out.write(j.toString());
768                 return null;
769             }
770         }catch (Exception e){
771                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
772                         response.setCharacterEncoding(utf8);
773                         request.setCharacterEncoding(utf8);
774                         PrintWriter out = response.getWriter();
775                         out.write(PolicyUtils.CATCH_EXCEPTION);
776                 }
777                 return null;
778         }
779
780         @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
781         public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
782                 try{
783                         ObjectMapper mapper = new ObjectMapper();
784                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
785                         JsonNode root = mapper.readTree(request.getReader());
786                         ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class);
787                         commonClassDao.delete(closedLoopD2Services);
788                         response.setCharacterEncoding(utf8);
789                         response.setContentType(applicationJsonContentType);
790                         request.setCharacterEncoding(utf8);
791
792                         PrintWriter out = response.getWriter();
793
794                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
795                         JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}");
796                         out.write(j.toString());
797
798                         return null;
799                 }
800                 catch (Exception e){
801                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
802                         response.setCharacterEncoding(utf8);
803                         request.setCharacterEncoding(utf8);
804                         PrintWriter out = response.getWriter();
805                         out.write(PolicyUtils.CATCH_EXCEPTION);
806                 }
807                 return null;
808         }
809
810         @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
811         public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
812                 try {
813                         boolean duplicateflag = false;
814             boolean isFakeUpdate = false;
815             boolean fromAPI = false;
816             
817             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
818                 fromAPI = true;
819             }
820                         ObjectMapper mapper = new ObjectMapper();
821                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
822                         JsonNode root = mapper.readTree(request.getReader());
823             ClosedLoopSite siteData;
824             String userId = null;
825             if (fromAPI) {
826                 siteData = (ClosedLoopSite)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
827                 userId = "API";
828                 //check if update operation or create, get id for data to be updated and update attributeData
829                 if ((update).equals(request.getParameter(operation))) {
830                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
831                     ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
832                     int id = data.getId();
833                     if(id==0){
834                         isFakeUpdate=true;
835                         siteData.setId(1);
836                     } else {
837                         siteData.setId(id);
838                     }
839                     siteData.setUserCreatedBy(this.getUserInfo(userId));
840                 }
841             } else {
842                 siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
843                 userId = root.get(userid).textValue();
844             }
845                         if(siteData.getId() == 0){
846                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
847                                 if(!duplicateData.isEmpty()){
848                                         duplicateflag = true;
849                                 }else{
850                                         siteData.setUserCreatedBy(this.getUserInfo(userId));
851                                         siteData.setUserModifiedBy(this.getUserInfo(userId));
852                                         commonClassDao.save(siteData);
853                                 }
854                         }else{
855                                 if(!isFakeUpdate) {
856                                         siteData.setUserModifiedBy(this.getUserInfo(userId));
857                                         siteData.setModifiedDate(new Date());
858                                         commonClassDao.update(siteData);
859                                 }
860                         }
861             String responseString = "";
862             if(duplicateflag){
863                 responseString = duplicateResponseString;
864             }else{
865                 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
866             }   
867             
868             if (fromAPI) {
869                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
870                     if(isFakeUpdate){
871                         responseString = "Exists";
872                     } else {
873                         responseString = successMsg;
874                     }
875                 }
876                 ModelAndView result = new ModelAndView();
877                 result.setViewName(responseString);
878                 return result;
879             } else {
880                 response.setCharacterEncoding(utf8);
881                 response.setContentType(applicationJsonContentType);
882                 request.setCharacterEncoding(utf8);
883  
884                 PrintWriter out = response.getWriter();
885                 JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
886                 out.write(j.toString());
887                 return null;
888             }
889         }catch (Exception e){
890                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
891                         response.setCharacterEncoding(utf8);
892                         request.setCharacterEncoding(utf8);
893                         PrintWriter out = response.getWriter();
894                         out.write(PolicyUtils.CATCH_EXCEPTION);
895                 }
896                 return null;
897         }
898
899         @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
900         public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
901                 try{
902                         ObjectMapper mapper = new ObjectMapper();
903                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
904                         JsonNode root = mapper.readTree(request.getReader());
905                         ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class);
906                         commonClassDao.delete(closedLoopSite);
907                         response.setCharacterEncoding(utf8);
908                         response.setContentType(applicationJsonContentType);
909                         request.setCharacterEncoding(utf8);
910
911                         PrintWriter out = response.getWriter();
912
913                         String responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
914                         JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}");
915                         out.write(j.toString());
916
917                         return null;
918                 }
919                 catch (Exception e){
920                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
921                         response.setCharacterEncoding(utf8);
922                         request.setCharacterEncoding(utf8);
923                         PrintWriter out = response.getWriter();
924                         out.write(PolicyUtils.CATCH_EXCEPTION);
925                 }
926                 return null;
927         }
928
929         @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
930         public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
931                 try {
932                         boolean duplicateflag = false;
933             boolean isFakeUpdate = false;
934             boolean fromAPI = false;
935             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
936                 fromAPI = true;
937             }
938                         ObjectMapper mapper = new ObjectMapper();
939                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
940                         JsonNode root = mapper.readTree(request.getReader());
941             VarbindDictionary varbindDictionary;
942             String userId = null;
943             if (fromAPI) {
944                 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
945                 userId = "API";
946                 
947                 //check if update operation or create, get id for data to be updated and update attributeData
948                 if ((update).equals(request.getParameter(operation))) {
949                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
950                     VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
951                     int id = data.getId();
952                     if(id==0){
953                         isFakeUpdate=true;
954                         varbindDictionary.setId(1);
955                     } else {
956                         varbindDictionary.setId(id);
957                     }
958                     varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
959                 }
960             } else {
961                 varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
962                 userId = root.get(userid).textValue();
963             }
964                         if(varbindDictionary.getId() == 0){
965                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
966                                 if(!duplicateData.isEmpty()){
967                                         duplicateflag = true;
968                                 }else{
969                                         varbindDictionary.setUserCreatedBy(this.getUserInfo(userId));
970                                         varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
971                                         commonClassDao.save(varbindDictionary);
972                                 }         
973                         }else{
974                                 if(!isFakeUpdate){
975                                         varbindDictionary.setUserModifiedBy(this.getUserInfo(userId));
976                                         varbindDictionary.setModifiedDate(new Date());
977                                         commonClassDao.update(varbindDictionary);
978                                 }
979                         }
980             String responseString = "";
981             if(duplicateflag){
982                 responseString = duplicateResponseString;
983             }else{
984                 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
985             }
986             
987             if (fromAPI) {
988                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
989                     if(isFakeUpdate){
990                         responseString = "Exists";
991                     } else {
992                         responseString = successMsg;
993                     }
994                 }
995                 ModelAndView result = new ModelAndView();
996                 result.setViewName(responseString);
997                 return result;
998             } else {
999                 response.setCharacterEncoding(utf8);
1000                 response.setContentType(applicationJsonContentType);
1001                 request.setCharacterEncoding(utf8);
1002  
1003                 PrintWriter out = response.getWriter();
1004                 JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1005                 out.write(j.toString());
1006                 return null;
1007             }
1008         }catch (Exception e){
1009                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1010                         response.setCharacterEncoding(utf8);
1011                         request.setCharacterEncoding(utf8);
1012                         PrintWriter out = response.getWriter();
1013                         out.write(PolicyUtils.CATCH_EXCEPTION);
1014                 }
1015                 return null;
1016         }
1017
1018         @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1019         public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
1020                 try{
1021                         ObjectMapper mapper = new ObjectMapper();
1022                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1023                         JsonNode root = mapper.readTree(request.getReader());
1024                         VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class);
1025                         commonClassDao.delete(varbindDictionary);
1026                         response.setCharacterEncoding(utf8);
1027                         response.setContentType(applicationJsonContentType);
1028                         request.setCharacterEncoding(utf8);
1029
1030                         PrintWriter out = response.getWriter();
1031
1032                         String responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
1033                         JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}");
1034                         out.write(j.toString());
1035
1036                         return null;
1037                 }
1038                 catch (Exception e){
1039                         LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e);
1040                         response.setCharacterEncoding(utf8);
1041                         request.setCharacterEncoding(utf8);
1042                         PrintWriter out = response.getWriter();
1043                         out.write(PolicyUtils.CATCH_EXCEPTION);
1044                 }
1045                 return null;
1046         }
1047         
1048     public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
1049         commonClassDao = commonClassDaoImpl;
1050     }
1051
1052 }
1053