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