Fix final 10 vulnerabilities in policy/engine
[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-2018 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.util.Date;
25 import java.util.List;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.onap.policy.pap.xacml.rest.adapters.GridData;
31 import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
32 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
33 import org.onap.policy.rest.dao.CommonClassDao;
34 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
35 import org.onap.policy.rest.jpa.ClosedLoopSite;
36 import org.onap.policy.rest.jpa.OnapName;
37 import org.onap.policy.rest.jpa.PEPOptions;
38 import org.onap.policy.rest.jpa.UserInfo;
39 import org.onap.policy.rest.jpa.VNFType;
40 import org.onap.policy.rest.jpa.VSCLAction;
41 import org.onap.policy.rest.jpa.VarbindDictionary;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.http.MediaType;
44 import org.springframework.stereotype.Controller;
45 import org.springframework.web.bind.annotation.RequestMapping;
46 import org.springframework.web.bind.annotation.RequestMethod;
47 import org.springframework.web.servlet.ModelAndView;
48
49 import com.fasterxml.jackson.databind.DeserializationFeature;
50 import com.fasterxml.jackson.databind.JsonNode;
51 import com.fasterxml.jackson.databind.ObjectMapper;
52
53 @Controller
54 public class ClosedLoopDictionaryController{
55
56         private static CommonClassDao commonClassDao;
57         private static String vsclaction = "vsclaction";
58         private static String operation = "operation";
59         private static String vnftype = "vnftype";
60         private static String pepName = "pepName";
61         private static String varbindName = "varbindName";
62         private static String serviceName = "serviceName";
63         private static String siteName = "siteName";
64         private static String dictionaryFields = "dictionaryFields";
65         private static String duplicateResponseString = "Duplicate";
66         private static String userid = "userid";
67         private static String vsclActionDatas = "vsclActionDictionaryDatas";
68         private static String vnfTypeDatas = "vnfTypeDictionaryDatas";
69         private static String pepOptionDatas = "pepOptionsDictionaryDatas";
70         private static String varbindDatas = "varbindDictionaryDatas";
71         private static String closedLoopDatas = "closedLoopServiceDictionaryDatas";
72         private static String closedLoopSiteDatas = "closedLoopSiteDictionaryDatas";
73         
74         @Autowired
75         public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
76                 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
77         }
78         
79         public void setCommonClassDao(CommonClassDao commonClassDao){
80                 ClosedLoopDictionaryController.commonClassDao = commonClassDao;
81         }
82
83         public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
84         commonClassDao = commonClassDaoImpl;
85     }
86         
87         public ClosedLoopDictionaryController(){
88                 super();
89         }
90
91         private DictionaryUtils getDictionaryUtilsInstance(){
92                 return DictionaryUtils.getDictionaryUtils();
93         }
94         
95         @RequestMapping(value={"/get_VSCLActionDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
96         public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
97                 DictionaryUtils utils = getDictionaryUtilsInstance();
98                 utils.getDataByEntity(response, vsclActionDatas, vsclaction, VSCLAction.class);
99         }
100
101
102         @RequestMapping(value={"/get_VSCLActionData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
103         public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
104                 DictionaryUtils utils = getDictionaryUtilsInstance();
105                 utils.getData(response, vsclActionDatas, VSCLAction.class);
106         }
107
108         @RequestMapping(value={"/get_VNFTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
109         public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
110                 DictionaryUtils utils = getDictionaryUtilsInstance();
111                 utils.getDataByEntity(response, vnfTypeDatas, vnftype, VNFType.class);
112         }
113
114         @RequestMapping(value={"/get_VNFTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
115         public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
116                 DictionaryUtils utils = getDictionaryUtilsInstance();
117                 utils.getData(response, vnfTypeDatas, VNFType.class);
118         }
119
120         @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
121         public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
122                 DictionaryUtils utils = getDictionaryUtilsInstance();
123                 utils.getDataByEntity(response, pepOptionDatas, pepName, PEPOptions.class);
124         }
125
126         @RequestMapping(value={"/get_PEPOptionsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
127         public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
128                 DictionaryUtils utils = getDictionaryUtilsInstance();
129                 utils.getData(response, pepOptionDatas, PEPOptions.class);
130         }
131
132         @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
133         public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
134                 DictionaryUtils utils = getDictionaryUtilsInstance();
135                 utils.getDataByEntity(response, varbindDatas, varbindName, VarbindDictionary.class);
136         }
137
138         @RequestMapping(value={"/get_VarbindDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
139         public void getVarbindDictionaryEntityData(HttpServletResponse response){
140                 DictionaryUtils utils = getDictionaryUtilsInstance();
141                 utils.getData(response, varbindDatas, VarbindDictionary.class);
142         }
143
144         @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
145         public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
146                 DictionaryUtils utils = getDictionaryUtilsInstance();
147                 utils.getDataByEntity(response, closedLoopDatas, serviceName, ClosedLoopD2Services.class);
148         }
149
150         @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
151         public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
152                 DictionaryUtils utils = getDictionaryUtilsInstance();
153                 utils.getData(response, closedLoopDatas, ClosedLoopD2Services.class);
154         }
155
156         @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
157         public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
158                 DictionaryUtils utils = getDictionaryUtilsInstance();
159                 utils.getDataByEntity(response, closedLoopSiteDatas, siteName, ClosedLoopSite.class);
160         }
161
162         @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
163         public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
164                 DictionaryUtils utils = getDictionaryUtilsInstance();
165                 utils.getData(response, closedLoopSiteDatas, ClosedLoopSite.class);
166         }
167
168         @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={RequestMethod.POST})
169         public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
170                 DictionaryUtils utils = getDictionaryUtilsInstance();
171                 try {
172                         boolean fromAPI = utils.isRequestFromAPI(request);
173                         ObjectMapper mapper = new ObjectMapper();
174                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
175                         JsonNode root = mapper.readTree(request.getReader());
176                         VSCLAction vSCLAction;
177                         String userId = null;
178                         if (fromAPI) {
179                                 vSCLAction = mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
180                                 userId = "API";
181                         } else {
182                                 vSCLAction = mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
183                                 userId = root.get(userid).textValue();
184                         }
185                         UserInfo userInfo = utils.getUserInfo(userId);
186
187                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
188                         boolean duplicateflag = false;
189                         if(!duplicateData.isEmpty()){
190                                 VSCLAction data = (VSCLAction) duplicateData.get(0);
191                                 if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
192                                         vSCLAction.setId(data.getId());
193                                 }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
194                                                 (request.getParameter(operation) == null && (data.getId() != vSCLAction.getId()))){
195                                         duplicateflag = true;
196                                 }
197                         }
198                         String responseString = null;
199                         if(!duplicateflag){
200                                 vSCLAction.setUserModifiedBy(userInfo);
201                                 if(vSCLAction.getId() == 0){
202                                         vSCLAction.setUserCreatedBy(userInfo);
203                                         commonClassDao.save(vSCLAction);
204                                 }else{
205                                         vSCLAction.setModifiedDate(new Date());
206                                         commonClassDao.update(vSCLAction); 
207                                 } 
208                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
209                         }else{
210                                 responseString = duplicateResponseString;
211                         }
212
213                         if(fromAPI){
214                                 return utils.getResultForApi(responseString);
215                         }else{
216                                 utils.setResponseData(response, vsclActionDatas, responseString);
217                         }
218                 }catch(Exception e){
219                         utils.setErrorResponseData(response, e);
220                 }
221                 return null;
222         }
223
224         @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={RequestMethod.POST})
225         public void removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
226                 DictionaryUtils utils = getDictionaryUtilsInstance();
227                 utils.removeData(request, response, vsclActionDatas, OnapName.class);
228         }
229
230         @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={RequestMethod.POST})
231         public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
232                 DictionaryUtils utils = getDictionaryUtilsInstance();
233                 try {
234                         boolean fromAPI = utils.isRequestFromAPI(request);
235                         ObjectMapper mapper = new ObjectMapper();
236                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
237                         JsonNode root = mapper.readTree(request.getReader());
238                         VNFType vNFType;
239                         String userId = null;
240                         if (fromAPI) {
241                                 vNFType = mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
242                                 userId = "API";
243                         } else {
244                                 vNFType = mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
245                                 userId = root.get(userid).textValue();
246                         }
247                         UserInfo userInfo = utils.getUserInfo(userId);
248                         
249                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
250                         boolean duplicateflag = false;
251                         if(!duplicateData.isEmpty()){
252                                 VNFType data = (VNFType) duplicateData.get(0);
253                                 if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
254                                         vNFType.setId(data.getId());
255                                 }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
256                                                 (request.getParameter(operation) == null && (data.getId() != vNFType.getId()))){
257                                         duplicateflag = true;
258                                 }
259                         }
260                         String responseString = null;
261                         if(!duplicateflag){
262                                 vNFType.setUserModifiedBy(userInfo);
263                                 if(vNFType.getId() == 0){
264                                         vNFType.setUserCreatedBy(userInfo);
265                                         commonClassDao.save(vNFType);
266                                 }else{
267                                         vNFType.setModifiedDate(new Date());
268                                         commonClassDao.update(vNFType); 
269                                 } 
270                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
271                         }else{
272                                 responseString = duplicateResponseString;
273                         }
274          
275                         if(fromAPI){
276                                 return utils.getResultForApi(responseString);
277                         }else{
278                                 utils.setResponseData(response, vnfTypeDatas, responseString);
279                         }
280                 }catch(Exception e){
281                         utils.setErrorResponseData(response, e);
282                 }
283                 return null;
284         }
285
286         @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={RequestMethod.POST})
287         public void removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
288                 DictionaryUtils utils = getDictionaryUtilsInstance();
289                 utils.removeData(request, response, vnfTypeDatas, VNFType.class);
290         }
291
292         @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={RequestMethod.POST})
293         public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
294                 DictionaryUtils utils = getDictionaryUtilsInstance();
295                 try {
296                         boolean fromAPI = utils.isRequestFromAPI(request);
297                         ObjectMapper mapper = new ObjectMapper();
298                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
299                         JsonNode root = mapper.readTree(request.getReader());
300             PEPOptions pEPOptions;
301             GridData gridData;
302             String userId = null;
303             if(fromAPI){
304                 pEPOptions = mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class);
305                 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
306                 userId = "API";
307             }else{
308                 pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
309                 gridData = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
310                 userId = root.get(userid).textValue();
311             }
312             UserInfo userInfo = utils.getUserInfo(userId);
313             
314                         if(!gridData.getAttributes().isEmpty()){
315                                 pEPOptions.setActions(utils.appendKeyValue(gridData.getAttributes(), ":#@", "=#@"));
316                         }
317                         
318                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
319                         boolean duplicateflag = false;
320                         if(!duplicateData.isEmpty()){
321                                 PEPOptions data = (PEPOptions) duplicateData.get(0);
322                                 if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
323                                         pEPOptions.setId(data.getId());
324                                 }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
325                                                 (request.getParameter(operation) == null && (data.getId() != pEPOptions.getId()))){
326                                         duplicateflag = true;
327                                 }
328                         }
329                         String responseString = null;
330                         if(!duplicateflag){
331                                 pEPOptions.setUserModifiedBy(userInfo);
332                                 if(pEPOptions.getId() == 0){
333                                         pEPOptions.setUserCreatedBy(userInfo);
334                                         commonClassDao.save(pEPOptions);
335                                 }else{
336                                         pEPOptions.setModifiedDate(new Date());
337                                         commonClassDao.update(pEPOptions); 
338                                 } 
339                                 responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
340                         }else{
341                                 responseString = duplicateResponseString;
342                         }
343                         
344                         if(fromAPI){
345                                 return utils.getResultForApi(responseString);
346                         }else{
347                                 utils.setResponseData(response, pepOptionDatas, responseString);
348                         }
349         }catch(Exception e){
350                 utils.setErrorResponseData(response, e);
351                 }
352                 return null;
353         }
354
355         @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={RequestMethod.POST})
356         public void removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
357                 DictionaryUtils utils = getDictionaryUtilsInstance();
358                 utils.removeData(request, response, pepOptionDatas, VNFType.class);
359         }
360
361         @RequestMapping(value={"/cl_dictionary/save_service"}, method={RequestMethod.POST})
362         public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
363                 DictionaryUtils utils = getDictionaryUtilsInstance();
364                 try {
365                         boolean fromAPI = utils.isRequestFromAPI(request);
366                         ObjectMapper mapper = new ObjectMapper();
367                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
368                         JsonNode root = mapper.readTree(request.getReader());
369             ClosedLoopD2Services serviceData;
370             String userId = null;
371             if(fromAPI){
372                 serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
373                 userId = "API";
374             } else {
375                 serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
376                 userId = root.get(userid).textValue();
377             }
378             UserInfo userInfo = utils.getUserInfo(userId);
379                         
380                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
381                         boolean duplicateflag = false;
382                         if(!duplicateData.isEmpty()){
383                                 ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
384                                 if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
385                                         serviceData.setId(data.getId());
386                                 }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
387                                                 (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))){
388                                         duplicateflag = true;
389                                 }
390                         }
391                         String responseString = null;
392                         if(!duplicateflag){
393                                 serviceData.setUserModifiedBy(userInfo);
394                                 if(serviceData.getId() == 0){
395                                         serviceData.setUserCreatedBy(userInfo);
396                                         commonClassDao.save(serviceData);
397                                 }else{
398                                         serviceData.setModifiedDate(new Date());
399                                         commonClassDao.update(serviceData); 
400                                 } 
401                                 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
402                         }else{
403                                 responseString = duplicateResponseString;
404                         }
405             if(fromAPI){
406                                 return utils.getResultForApi(responseString);
407                         }else{
408                                 utils.setResponseData(response, closedLoopDatas, responseString);
409                         }
410         }catch(Exception e){
411                 utils.setErrorResponseData(response, e);
412                 }
413                 return null;
414         }
415
416         @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={RequestMethod.POST})
417         public void removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
418                 DictionaryUtils utils = getDictionaryUtilsInstance();
419                 utils.removeData(request, response, closedLoopDatas, VNFType.class);
420         }
421
422         @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={RequestMethod.POST})
423         public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
424                 DictionaryUtils utils = getDictionaryUtilsInstance();
425                 try {
426                         boolean fromAPI = utils.isRequestFromAPI(request);
427                         ObjectMapper mapper = new ObjectMapper();
428                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
429                         JsonNode root = mapper.readTree(request.getReader());
430             ClosedLoopSite siteData;
431             String userId = null;
432             if(fromAPI){
433                 siteData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
434                 userId = "API";
435             }else{
436                 siteData = mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
437                 userId = root.get(userid).textValue();
438             }
439             UserInfo userInfo = utils.getUserInfo(userId);
440             
441             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
442                         boolean duplicateflag = false;
443                         if(!duplicateData.isEmpty()){
444                                 ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
445                                 if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
446                                         siteData.setId(data.getId());
447                                 }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
448                                                 (request.getParameter(operation) == null && (data.getId() != siteData.getId()))){
449                                         duplicateflag = true;
450                                 }
451                         }
452             String responseString = null;
453                         if(!duplicateflag){
454                                 siteData.setUserModifiedBy(userInfo);
455                                 if(siteData.getId() == 0){
456                                         siteData.setUserCreatedBy(userInfo);
457                                         commonClassDao.save(siteData);
458                                 }else{
459                                         siteData.setModifiedDate(new Date());
460                                         commonClassDao.update(siteData); 
461                                 } 
462                                 responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
463                         }else{
464                                 responseString = duplicateResponseString;
465                         }
466             if(fromAPI){
467                                 return utils.getResultForApi(responseString);
468                         }else{
469                                 utils.setResponseData(response, closedLoopSiteDatas, responseString);
470                         }
471         }catch (Exception e){
472                 utils.setErrorResponseData(response, e);
473                 }
474                 return null;
475         }
476
477         @RequestMapping(value={"/cl_dictionary/remove_site"}, method={RequestMethod.POST})
478         public void removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
479                 DictionaryUtils utils = getDictionaryUtilsInstance();
480                 utils.removeData(request, response, closedLoopSiteDatas, VNFType.class);
481         }
482
483         @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={RequestMethod.POST})
484         public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
485                 DictionaryUtils utils = getDictionaryUtilsInstance();
486                 try {
487                         boolean fromAPI = utils.isRequestFromAPI(request);
488                         ObjectMapper mapper = new ObjectMapper();
489                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
490                         JsonNode root = mapper.readTree(request.getReader());
491             VarbindDictionary varbindDictionary;
492             String userId = null;
493             if(fromAPI){
494                 varbindDictionary = mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
495                 userId = "API";
496             }else{
497                 varbindDictionary = mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
498                 userId = root.get(userid).textValue();
499             }
500             UserInfo userInfo = utils.getUserInfo(userId);
501                         
502                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
503                         boolean duplicateflag = false;
504                         if(!duplicateData.isEmpty()){
505                                 VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
506                                 if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
507                                         varbindDictionary.setId(data.getId());
508                                 }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
509                                                 (request.getParameter(operation) == null && (data.getId() != varbindDictionary.getId()))){
510                                         duplicateflag = true;
511                                 }
512                         }
513                         
514                         String responseString = null;
515                         if(!duplicateflag){
516                                 varbindDictionary.setUserModifiedBy(userInfo);
517                                 if(varbindDictionary.getId() == 0){
518                                         varbindDictionary.setUserCreatedBy(userInfo);
519                                         commonClassDao.save(varbindDictionary);
520                                 }else{
521                                         varbindDictionary.setModifiedDate(new Date());
522                                         commonClassDao.update(varbindDictionary); 
523                                 } 
524                                 responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
525                         }else{
526                                 responseString = duplicateResponseString;
527                         }            
528             if(fromAPI){
529                                 return utils.getResultForApi(responseString);
530                         }else{
531                                 utils.setResponseData(response, varbindDatas, responseString);
532                         }
533         }catch (Exception e){
534                 utils.setErrorResponseData(response, e);
535                 }
536                 return null;
537         }
538
539         @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={RequestMethod.POST})
540         public void removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
541                 DictionaryUtils utils = getDictionaryUtilsInstance();
542                 utils.removeData(request, response, varbindDatas, VNFType.class);
543         }
544 }