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