Merge "ONAP code change for log files consolidation"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / DictionaryImportController.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.File;
24 import java.io.FileOutputStream;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.util.List;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32
33 import org.apache.commons.compress.utils.IOUtils;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.pap.xacml.rest.DictionaryNames;
37 import org.onap.policy.rest.dao.CommonClassDao;
38 import org.onap.policy.rest.jpa.ActionList;
39 import org.onap.policy.rest.jpa.ActionPolicyDict;
40 import org.onap.policy.rest.jpa.AddressGroup;
41 import org.onap.policy.rest.jpa.Attribute;
42 import org.onap.policy.rest.jpa.BRMSController;
43 import org.onap.policy.rest.jpa.BRMSDependency;
44 import org.onap.policy.rest.jpa.BRMSParamTemplate;
45 import org.onap.policy.rest.jpa.Category;
46 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
47 import org.onap.policy.rest.jpa.ClosedLoopSite;
48 import org.onap.policy.rest.jpa.Datatype;
49 import org.onap.policy.rest.jpa.DecisionSettings;
50 import org.onap.policy.rest.jpa.DescriptiveScope;
51 import org.onap.policy.rest.jpa.GroupServiceList;
52 import org.onap.policy.rest.jpa.MicroServiceModels;
53 import org.onap.policy.rest.jpa.OnapName;
54 import org.onap.policy.rest.jpa.PEPOptions;
55 import org.onap.policy.rest.jpa.PrefixList;
56 import org.onap.policy.rest.jpa.ProtocolList;
57 import org.onap.policy.rest.jpa.SecurityZone;
58 import org.onap.policy.rest.jpa.ServiceList;
59 import org.onap.policy.rest.jpa.TermList;
60 import org.onap.policy.rest.jpa.UserInfo;
61 import org.onap.policy.rest.jpa.VNFType;
62 import org.onap.policy.rest.jpa.VSCLAction;
63 import org.onap.policy.rest.jpa.VarbindDictionary;
64 import org.onap.policy.rest.jpa.Zone;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.stereotype.Controller;
67 import org.springframework.web.bind.annotation.RequestMapping;
68 import org.springframework.web.bind.annotation.RequestMethod;
69
70 import com.fasterxml.jackson.databind.DeserializationFeature;
71 import com.fasterxml.jackson.databind.ObjectMapper;
72
73 import au.com.bytecode.opencsv.CSVReader;
74
75
76 @Controller
77 public class DictionaryImportController {
78         private static final Logger LOGGER  = FlexLogger.getLogger(DictionaryImportController.class);
79         
80         private static CommonClassDao commonClassDao;
81         private static final String DESCRIPTION= "description";
82         private static final String ERROR= "Error";
83         private static final String DEPENDENCY= "dependency";
84         
85         @Autowired
86         public DictionaryImportController(CommonClassDao commonClassDao){
87                 setCommonClassDao(commonClassDao);
88         }
89         
90         public static void setCommonClassDao(CommonClassDao commonClassDao) {
91                 DictionaryImportController.commonClassDao = commonClassDao;
92         }
93         
94         public DictionaryImportController(){
95                 super();        
96         }
97
98         @RequestMapping(value={"/dictionary/import_dictionary"}, method={RequestMethod.POST})
99         public void importDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{
100                 ObjectMapper mapper = new ObjectMapper();
101                 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
102                 String userId = request.getParameter("userId");
103                 String dictionaryName = request.getParameter("dictionaryName");
104                 
105                 if(dictionaryName == null || dictionaryName.isEmpty()){
106                         LOGGER.error("dictionaryName is null/empty");
107                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
108                         response.getWriter().write(ERROR);
109                         return;
110                 }
111                 
112                 // fix Fortify Path Manipulation issue
113                 if(!isValidDictionaryName(dictionaryName)){
114                         LOGGER.error("dictionaryName is invalid");
115                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
116                         response.getWriter().write(ERROR);
117                         return;                 
118                 }
119                 File file = new File(dictionaryName);   
120                 try(OutputStream outputStream = new FileOutputStream(file); FileReader fileReader = new FileReader(file.toString())){
121                         IOUtils.copy(request.getInputStream(), outputStream);
122                         CSVReader csvReader = new CSVReader(fileReader);
123                         List<String[]> dictSheet = csvReader.readAll();
124                         if(dictionaryName.startsWith("Attribute")){
125                                 for(int i = 1; i< dictSheet.size(); i++){
126                                         Attribute attribute = new Attribute("");
127                                         UserInfo userinfo = new UserInfo();
128                                         userinfo.setUserLoginId(userId);
129                                         attribute.setUserCreatedBy(userinfo);
130                                         attribute.setUserModifiedBy(userinfo);
131                                         String[] rows = dictSheet.get(i);
132                                         for (int j=0 ; j<rows.length; j++ ){
133                                                 if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute ID".equalsIgnoreCase(dictSheet.get(0)[j])){
134                                                         attribute.setXacmlId(rows[j]);
135                                                 }
136                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
137                                                         attribute.setDescription(rows[j]);
138                                                 }
139                                                 if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){
140                                                         attribute.setPriority(rows[j]);
141                                                 }
142                                                 if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
143                                                         Datatype dataType = new Datatype();
144                                                         if("string".equalsIgnoreCase(rows[j])){
145                                                                 dataType.setId(26);
146                                                         }else if("integer".equalsIgnoreCase(rows[j])){
147                                                                 dataType.setId(12);
148                                                         }else if("double".equalsIgnoreCase(rows[j])){
149                                                                 dataType.setId(25);
150                                                         }else if("boolean".equalsIgnoreCase(rows[j])){
151                                                                 dataType.setId(18);
152                                                         }else if("user".equalsIgnoreCase(rows[j])){
153                                                                 dataType.setId(29);
154                                                         }
155                                                         attribute.setDatatypeBean(dataType);
156                                                         Category category = new Category();
157                                                         category.setId(5);
158                                                         attribute.setCategoryBean(category);
159                                                 }
160                                                 if("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])){
161                                                         attribute.setAttributeValue(rows[j]);
162                                                 }
163                                         }
164                                         commonClassDao.save(attribute);
165                                 }
166                         }
167                         if(dictionaryName.startsWith("ActionPolicyDictionary")){
168                                 for(int i = 1; i< dictSheet.size(); i++){
169                                         ActionPolicyDict attribute = new ActionPolicyDict();
170                                         UserInfo userinfo = new UserInfo();
171                                         userinfo.setUserLoginId(userId);
172                                         attribute.setUserCreatedBy(userinfo);
173                                         attribute.setUserModifiedBy(userinfo);
174                                         String[] rows = dictSheet.get(i);
175                                         for (int j=0 ; j<rows.length; j++ ){
176                                                 if("attribute_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Name".equalsIgnoreCase(dictSheet.get(0)[j])){
177                                                         attribute.setAttributeName(rows[j]);
178                                                 }
179                                                 if("body".equalsIgnoreCase(dictSheet.get(0)[j])){
180                                                         attribute.setBody(rows[j]);
181                                                 }
182                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
183                                                         attribute.setDescription(rows[j]);
184                                                 }
185                                                 if("headers".equalsIgnoreCase(dictSheet.get(0)[j])){
186                                                         attribute.setHeader(rows[j]);
187                                                 }
188                                                 if("method".equalsIgnoreCase(dictSheet.get(0)[j])){
189                                                         attribute.setMethod(rows[j]);
190                                                 }
191                                                 if("type".equalsIgnoreCase(dictSheet.get(0)[j])){
192                                                         attribute.setType(rows[j]);
193                                                 }
194                                                 if("url".equalsIgnoreCase(dictSheet.get(0)[j])){
195                                                         attribute.setUrl(rows[j]);
196                                                 }
197                                         }
198                                         commonClassDao.save(attribute);
199                                 }
200                         }
201                         if(dictionaryName.startsWith("OnapName")){
202                                 for(int i = 1; i< dictSheet.size(); i++){
203                                         OnapName attribute = new OnapName();
204                                         UserInfo userinfo = new UserInfo();
205                                         userinfo.setUserLoginId(userId);
206                                         attribute.setUserCreatedBy(userinfo);
207                                         attribute.setUserModifiedBy(userinfo);
208                                         String[] rows = dictSheet.get(i);
209                                         for (int j=0 ; j<rows.length; j++ ){
210                                                 if("onap_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Onap Name".equalsIgnoreCase(dictSheet.get(0)[j])){
211                                                         attribute.setOnapName(rows[j]);
212                                                 }
213                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
214                                                         attribute.setDescription(rows[j]);
215                                                 }
216                                         }
217                                         commonClassDao.save(attribute);
218                                 }
219                         }
220
221                         if(dictionaryName.startsWith("MSPolicyDictionary")){
222                                 for(int i = 1; i< dictSheet.size(); i++){
223                                         MicroServiceModels attribute = new MicroServiceModels();
224                                         UserInfo userinfo = new UserInfo();
225                                         userinfo.setUserLoginId(userId);
226                                         attribute.setUserCreatedBy(userinfo);
227                                         String[] rows = dictSheet.get(i);
228                                         for (int j=0 ; j<rows.length; j++ ){
229                                                 if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Micro Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){
230                                                         attribute.setModelName(rows[j]);
231                                                 }
232                                                 if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){
233                                                         attribute.setVersion(rows[j]);
234                                                 }
235                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
236                                                         attribute.setDescription(rows[j]);
237                                                 }
238                                                 if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){
239                                                         attribute.setDependency(rows[j]);
240                                                 }
241                                                 if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
242                                                         attribute.setAttributes(rows[j]);
243                                                 }
244                                                 if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){
245                                                         attribute.setEnumValues(rows[j]);
246                                                 }
247                                                 if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
248                                                         attribute.setRef_attributes(rows[j]);
249                                                 }
250                                                 if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
251                                                         attribute.setSub_attributes(rows[j]);
252                                                 }
253                                                 if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
254                                                         attribute.setAnnotation(rows[j]);
255                                                 }
256                                         }
257
258                                         commonClassDao.save(attribute);
259                                 }
260                         }               
261
262                         if(dictionaryName.startsWith("OptimizationPolicyDictionary")){
263                                 for(int i = 1; i< dictSheet.size(); i++){
264                                         MicroServiceModels attribute = new MicroServiceModels();
265                                         UserInfo userinfo = new UserInfo();
266                                         userinfo.setUserLoginId(userId);
267                                         attribute.setUserCreatedBy(userinfo);
268                                         String[] rows = dictSheet.get(i);
269                                         for (int j=0 ; j<rows.length; j++ ){
270                                                 if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Optimization Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){
271                                                         attribute.setModelName(rows[j]);
272                                                 }
273                                                 if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){
274                                                         attribute.setVersion(rows[j]);
275                                                 }
276                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
277                                                         attribute.setDescription(rows[j]);
278                                                 }
279                                                 if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){
280                                                         attribute.setDependency(rows[j]);
281                                                 }
282                                                 if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
283                                                         attribute.setAttributes(rows[j]);
284                                                 }
285                                                 if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){
286                                                         attribute.setEnumValues(rows[j]);
287                                                 }
288                                                 if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
289                                                         attribute.setRef_attributes(rows[j]);
290                                                 }
291                                                 if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
292                                                         attribute.setSub_attributes(rows[j]);
293                                                 }
294                                                 if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
295                                                         attribute.setAnnotation(rows[j]);
296                                                 }
297                                         }
298
299                                         commonClassDao.save(attribute);
300                                 }
301                         }               
302
303                         if(dictionaryName.startsWith("VNFType")){
304                                 for(int i = 1; i< dictSheet.size(); i++){
305                                         VNFType attribute = new VNFType();
306                                         UserInfo userinfo = new UserInfo();
307                                         userinfo.setUserLoginId(userId);
308                                         attribute.setUserCreatedBy(userinfo);
309                                         attribute.setUserModifiedBy(userinfo);
310                                         String[] rows = dictSheet.get(i);
311                                         for (int j=0 ; j<rows.length; j++ ){
312                                                 if("vnf_type".equalsIgnoreCase(dictSheet.get(0)[j]) || "VNF Type".equalsIgnoreCase(dictSheet.get(0)[j])){
313                                                         attribute.setVnftype(rows[j]);
314                                                 }
315                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
316                                                         attribute.setDescription(rows[j]);
317                                                 }
318                                         }
319                                         commonClassDao.save(attribute);
320                                 }
321                         }
322                         if(dictionaryName.startsWith("VSCLAction")){
323                                 for(int i = 1; i< dictSheet.size(); i++){
324                                         VSCLAction attribute = new VSCLAction();
325                                         UserInfo userinfo = new UserInfo();
326                                         userinfo.setUserLoginId(userId);
327                                         attribute.setUserCreatedBy(userinfo);
328                                         attribute.setUserModifiedBy(userinfo);
329                                         String[] rows = dictSheet.get(i);
330                                         for (int j=0 ; j<rows.length; j++ ){
331                                                 if("vscl_action".equalsIgnoreCase(dictSheet.get(0)[j]) || "VSCL Action".equalsIgnoreCase(dictSheet.get(0)[j])){
332                                                         attribute.setVsclaction(rows[j]);
333                                                 }
334                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
335                                                         attribute.setDescription(rows[j]);
336                                                 }
337                                         }
338                                         commonClassDao.save(attribute);
339                                 }
340                         }
341                         if(dictionaryName.startsWith("ClosedLoopService")){
342                                 for(int i = 1; i< dictSheet.size(); i++){
343                                         ClosedLoopD2Services attribute = new ClosedLoopD2Services();
344                                         UserInfo userinfo = new UserInfo();
345                                         userinfo.setUserLoginId(userId);
346                                         attribute.setUserCreatedBy(userinfo);
347                                         attribute.setUserModifiedBy(userinfo);
348                                         String[] rows = dictSheet.get(i);
349                                         for (int j=0 ; j<rows.length; j++ ){
350                                                 if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){
351                                                         attribute.setServiceName(rows[j]);
352                                                 }
353                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
354                                                         attribute.setDescription(rows[j]);
355                                                 }
356                                         }
357                                         commonClassDao.save(attribute);
358                                 }
359                         }
360                         if(dictionaryName.startsWith("ClosedLoopSite")){
361                                 for(int i = 1; i< dictSheet.size(); i++){
362                                         ClosedLoopSite attribute = new ClosedLoopSite();
363                                         UserInfo userinfo = new UserInfo();
364                                         userinfo.setUserLoginId(userId);
365                                         attribute.setUserCreatedBy(userinfo);
366                                         attribute.setUserModifiedBy(userinfo);
367                                         String[] rows = dictSheet.get(i);
368                                         for (int j=0 ; j<rows.length; j++ ){
369                                                 if("siteName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Site Name".equalsIgnoreCase(dictSheet.get(0)[j])){
370                                                         attribute.setSiteName(rows[j]);
371                                                 }
372                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
373                                                         attribute.setDescription(rows[j]);
374                                                 }
375                                         }
376                                         commonClassDao.save(attribute);
377                                 }
378                         }
379                         if(dictionaryName.startsWith("PEPOptions")){
380                                 for(int i = 1; i< dictSheet.size(); i++){
381                                         PEPOptions attribute = new PEPOptions();
382                                         UserInfo userinfo = new UserInfo();
383                                         userinfo.setUserLoginId(userId);
384                                         attribute.setUserCreatedBy(userinfo);
385                                         attribute.setUserModifiedBy(userinfo);
386                                         String[] rows = dictSheet.get(i);
387                                         for (int j=0 ; j<rows.length; j++ ){
388                                                 if("PEP_NAME".equalsIgnoreCase(dictSheet.get(0)[j]) || "PEP Name".equalsIgnoreCase(dictSheet.get(0)[j])){
389                                                         attribute.setPepName(rows[j]);
390                                                 }
391                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
392                                                         attribute.setDescription(rows[j]);
393                                                 }
394                                                 if("Actions".equalsIgnoreCase(dictSheet.get(0)[j])){
395                                                         attribute.setActions(rows[j]);
396                                                 }
397                                         }
398                                         commonClassDao.save(attribute);
399                                 }
400                         }
401                         if(dictionaryName.startsWith("VarbindDictionary")){
402                                 for(int i = 1; i< dictSheet.size(); i++){
403                                         VarbindDictionary attribute = new VarbindDictionary();
404                                         UserInfo userinfo = new UserInfo();
405                                         userinfo.setUserLoginId(userId);
406                                         attribute.setUserCreatedBy(userinfo);
407                                         attribute.setUserModifiedBy(userinfo);
408                                         String[] rows = dictSheet.get(i);
409                                         for (int j=0 ; j<rows.length; j++ ){
410                                                 if("varbind_Name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Name".equalsIgnoreCase(dictSheet.get(0)[j])){
411                                                         attribute.setVarbindName(rows[j]);
412                                                 }
413                                                 if("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])){
414                                                         attribute.setVarbindDescription(rows[j]);
415                                                 }
416                                                 if("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])){
417                                                         attribute.setVarbindOID(rows[j]);
418                                                 }
419                                         }
420                                         commonClassDao.save(attribute);
421                                 }
422                         }
423                         if(dictionaryName.startsWith("BRMSParamDictionary")){
424                                 for(int i = 1; i< dictSheet.size(); i++){
425                                         BRMSParamTemplate attribute = new BRMSParamTemplate();
426                                         UserInfo userinfo = new UserInfo();
427                                         userinfo.setUserLoginId(userId);
428                                         attribute.setUserCreatedBy(userinfo);
429                                         String[] rows = dictSheet.get(i);
430                                         for (int j=0 ; j<rows.length; j++ ){
431                                                 if("param_template_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Rule Name".equalsIgnoreCase(dictSheet.get(0)[j])){
432                                                         attribute.setRuleName(rows[j]);
433                                                 }
434                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
435                                                         attribute.setDescription(rows[j]);
436                                                 }
437                                                 if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){
438                                                         attribute.setRule(rows[j]);
439                                                 }
440                                         }
441                                         commonClassDao.save(attribute);
442                                 }
443                         }
444                         if(dictionaryName.startsWith("BRMSControllerDictionary")){
445                                 for(int i = 1; i< dictSheet.size(); i++){
446                                         BRMSController attribute = new BRMSController();
447                                         UserInfo userinfo = new UserInfo();
448                                         userinfo.setUserLoginId(userId);
449                                         attribute.setUserCreatedBy(userinfo);
450                                         String[] rows = dictSheet.get(i);
451                                         for (int j=0 ; j<rows.length; j++ ){
452                                                 if("controllerName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Controller Name".equalsIgnoreCase(dictSheet.get(0)[j])){
453                                                         attribute.setControllerName(rows[j]);
454                                                 }
455                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
456                                                         attribute.setDescription(rows[j]);
457                                                 }
458                                                 if("controller".equalsIgnoreCase(dictSheet.get(0)[j])){
459                                                         attribute.setController(rows[j]);
460                                                 }
461                                         }
462                                         commonClassDao.save(attribute);
463                                 }
464                         }
465                         if(dictionaryName.startsWith("BRMSDependencyDictionary")){
466                                 for(int i = 1; i< dictSheet.size(); i++){
467                                         BRMSDependency attribute = new BRMSDependency();
468                                         UserInfo userinfo = new UserInfo();
469                                         userinfo.setUserLoginId(userId);
470                                         attribute.setUserCreatedBy(userinfo);
471                                         String[] rows = dictSheet.get(i);
472                                         for (int j=0 ; j<rows.length; j++ ){
473                                                 if("dependencyName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Dependency Name".equalsIgnoreCase(dictSheet.get(0)[j])){
474                                                         attribute.setDependencyName(rows[j]);
475                                                 }
476                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
477                                                         attribute.setDescription(rows[j]);
478                                                 }
479                                                 if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){
480                                                         attribute.setDependency(rows[j]);
481                                                 }
482                                         }
483                                         commonClassDao.save(attribute);
484                                 }
485                         }
486                         if(dictionaryName.startsWith("Settings")){
487                                 for(int i = 1; i< dictSheet.size(); i++){
488                                         DecisionSettings attribute = new DecisionSettings();
489                                         UserInfo userinfo = new UserInfo();
490                                         userinfo.setUserLoginId(userId);
491                                         attribute.setUserCreatedBy(userinfo);
492                                         attribute.setUserModifiedBy(userinfo);
493                                         String[] rows = dictSheet.get(i);
494                                         for (int j=0 ; j<rows.length; j++ ){
495                                                 if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Settings ID".equalsIgnoreCase(dictSheet.get(0)[j])){
496                                                         attribute.setXacmlId(rows[j]);
497                                                 }
498                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
499                                                         attribute.setDescription(rows[j]);
500                                                 }
501                                                 if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){
502                                                         attribute.setPriority(rows[j]);
503                                                 }
504                                                 if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
505                                                         Datatype dataType = new Datatype();
506                                                         if("string".equalsIgnoreCase(rows[j])){
507                                                                 dataType.setId(26);
508                                                         }else if("integer".equalsIgnoreCase(rows[j])){
509                                                                 dataType.setId(12);
510                                                         }else if("double".equalsIgnoreCase(rows[j])){
511                                                                 dataType.setId(25);
512                                                         }else if("boolean".equalsIgnoreCase(rows[j])){
513                                                                 dataType.setId(18);
514                                                         }else if("user".equalsIgnoreCase(rows[j])){
515                                                                 dataType.setId(29);
516                                                         }
517                                                         attribute.setDatatypeBean(dataType);
518                                                 }
519                                         }
520                                         commonClassDao.save(attribute);
521                                 }
522                         }
523                         if(dictionaryName.startsWith("PrefixList")){
524                                 for(int i = 1; i< dictSheet.size(); i++){
525                                         PrefixList attribute = new PrefixList();
526                                         String[] rows = dictSheet.get(i);
527                                         for (int j=0 ; j<rows.length; j++ ){
528                                                 if("prefixListName".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Name".equalsIgnoreCase(dictSheet.get(0)[j])){
529                                                         attribute.setPrefixListName(rows[j]);
530                                                 }
531                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
532                                                         attribute.setPrefixListValue(rows[j]);
533                                                 }
534                                                 if("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])){
535                                                         attribute.setDescription(rows[j]);
536                                                 }
537                                         }
538                                         commonClassDao.save(attribute);
539                                 }
540                         }
541                         if(dictionaryName.startsWith("SecurityZone")){
542                                 for(int i = 1; i< dictSheet.size(); i++){
543                                         SecurityZone attribute = new SecurityZone();
544                                         String[] rows = dictSheet.get(i);
545                                         for (int j=0 ; j<rows.length; j++ ){
546                                                 if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){
547                                                         attribute.setZoneName(rows[j]);
548                                                 }
549                                                 if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j])  || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
550                                                         attribute.setZoneValue(rows[j]);
551                                                 }
552                                         }
553                                         commonClassDao.save(attribute);
554                                 }
555                         }
556                         if(dictionaryName.startsWith("Zone")){
557                                 for(int i = 1; i< dictSheet.size(); i++){
558                                         Zone attribute = new Zone();
559                                         String[] rows = dictSheet.get(i);
560                                         for (int j=0 ; j<rows.length; j++ ){
561                                                 if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){
562                                                         attribute.setZoneName(rows[j]);
563                                                 }
564                                                 if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j])  || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
565                                                         attribute.setZoneValue(rows[j]);
566                                                 }
567                                         }
568                                         commonClassDao.save(attribute);
569                                 }
570                         }
571                         if(dictionaryName.startsWith("ServiceList")){
572                                 for(int i = 1; i< dictSheet.size(); i++){
573                                         ServiceList attribute = new ServiceList();
574                                         String[] rows = dictSheet.get(i);
575                                         for (int j=0 ; j<rows.length; j++ ){
576                                                 if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){
577                                                         attribute.setServiceName(rows[j]);
578                                                 }
579                                                 if("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j])  || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
580                                                         attribute.setServiceDescription(rows[j]);
581                                                 }
582                                                 if("serviceType".equalsIgnoreCase(dictSheet.get(0)[j])  || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])){
583                                                         attribute.setServiceType(rows[j]);
584                                                 }
585                                                 if("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j])  || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){
586                                                         attribute.setServiceTransProtocol(rows[j]);
587                                                 }
588                                                 if("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j])  || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){
589                                                         attribute.setServiceAppProtocol(rows[j]);
590                                                 }
591                                                 if("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j])  || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])){
592                                                         attribute.setServicePorts(rows[j]);
593                                                 }
594                                         }
595                                         commonClassDao.save(attribute);
596                                 }
597                         }
598                         if(dictionaryName.startsWith("ServiceGroup")){
599                                 for(int i = 1; i< dictSheet.size(); i++){
600                                         GroupServiceList attribute = new GroupServiceList();
601                                         String[] rows = dictSheet.get(i);
602                                         for (int j=0 ; j<rows.length; j++ ){
603                                                 if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){
604                                                         attribute.setGroupName(rows[j]);
605                                                 }
606                                                 if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])  || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){
607                                                         attribute.setServiceList(rows[j]);
608                                                 }
609                                         }
610                                         commonClassDao.save(attribute);
611                                 }
612                         }
613                         if(dictionaryName.startsWith("AddressGroup")){
614                                 for(int i = 1; i< dictSheet.size(); i++){
615                                         AddressGroup attribute = new AddressGroup();
616                                         String[] rows = dictSheet.get(i);
617                                         for (int j=0 ; j<rows.length; j++ ){
618                                                 if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){
619                                                         attribute.setGroupName(rows[j]);
620                                                 }
621                                                 if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])  || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])){
622                                                         attribute.setServiceList(rows[j]);
623                                                 }
624                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
625                                                         attribute.setDescription(rows[j]);
626                                                 }
627                                         }
628                                         commonClassDao.save(attribute);
629                                 }
630                         }
631                         if(dictionaryName.startsWith("ProtocolList")){
632                                 for(int i = 1; i< dictSheet.size(); i++){
633                                         ProtocolList attribute = new ProtocolList();
634                                         String[] rows = dictSheet.get(i);
635                                         for (int j=0 ; j<rows.length; j++ ){
636                                                 if("protocolName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Protocol Name".equalsIgnoreCase(dictSheet.get(0)[j])){
637                                                         attribute.setProtocolName(rows[j]);
638                                                 }
639                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
640                                                         attribute.setDescription(rows[j]);
641                                                 }
642                                         }
643                                         commonClassDao.save(attribute);
644                                 }
645                         }
646                         if(dictionaryName.startsWith("ActionList")){
647                                 for(int i = 1; i< dictSheet.size(); i++){
648                                         ActionList attribute = new ActionList();
649                                         String[] rows = dictSheet.get(i);
650                                         for (int j=0 ; j<rows.length; j++ ){
651                                                 if("actionName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action Name".equalsIgnoreCase(dictSheet.get(0)[j])){
652                                                         attribute.setActionName(rows[j]);
653                                                 }
654                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
655                                                         attribute.setDescription(rows[j]);
656                                                 }
657                                         }
658                                         commonClassDao.save(attribute);
659                                 }
660                         }
661                         if(dictionaryName.startsWith("TermList")){
662                                 for(int i = 1; i< dictSheet.size(); i++){
663                                         TermList attribute = new TermList();
664                                         UserInfo userinfo = new UserInfo();
665                                         userinfo.setUserLoginId(userId);
666                                         attribute.setUserCreatedBy(userinfo);
667                                         attribute.setUserModifiedBy(userinfo);
668                                         String[] rows = dictSheet.get(i);
669                                         for (int j=0 ; j<rows.length; j++ ){
670                                                 if("termName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Term-Name".equalsIgnoreCase(dictSheet.get(0)[j])){
671                                                         attribute.setTermName(rows[j]);
672                                                 }
673                                                 if("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])){
674                                                         attribute.setDescription(rows[j]);
675                                                 }
676                                                 if("fromZone".equalsIgnoreCase(dictSheet.get(0)[j])  || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])){
677                                                         attribute.setFromZones(rows[j]);
678                                                 }
679                                                 if("toZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])){
680                                                         attribute.setToZones(rows[j]);
681                                                 }
682                                                 if("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){
683                                                         attribute.setSrcIPList(rows[j]);
684                                                 }
685                                                 if("destIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){
686                                                         attribute.setDestIPList(rows[j]);
687                                                 }
688                                                 if("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){
689                                                         attribute.setSrcPortList(rows[j]);
690                                                 }
691                                                 if("destPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){
692                                                         attribute.setDestPortList(rows[j]);
693                                                 }
694                                                 if("action".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])){
695                                                         attribute.setAction(rows[j]);
696                                                 }
697                                         }
698                                         commonClassDao.save(attribute);
699                                 }
700                         }
701                         if(dictionaryName.startsWith("SearchCriteria")){
702                                 for(int i = 1; i< dictSheet.size(); i++){
703                                         DescriptiveScope attribute = new DescriptiveScope();
704                                         UserInfo userinfo = new UserInfo();
705                                         userinfo.setUserLoginId(userId);
706                                         attribute.setUserCreatedBy(userinfo);
707                                         attribute.setUserModifiedBy(userinfo);
708                                         String[] rows = dictSheet.get(i);
709                                         for (int j=0 ; j<rows.length; j++ ){
710                                                 if("descriptiveScopeName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Descriptive Scope Name".equalsIgnoreCase(dictSheet.get(0)[j])){
711                                                         attribute.setScopeName(rows[j]);
712                                                 }
713                                                 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
714                                                         attribute.setDescription(rows[j]);
715                                                 }
716                                                 if("search".equalsIgnoreCase(dictSheet.get(0)[j]) || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])){
717                                                         attribute.setSearch(rows[j]);
718                                                 }
719                                         }
720                                         commonClassDao.save(attribute);
721                                 }
722                         }
723                         csvReader.close();
724                         response.setStatus(HttpServletResponse.SC_OK);
725                         response.getWriter().write("Success");
726                 }catch(Exception e){
727                         LOGGER.error("Exception Occured while importing dictionary"+e);
728                         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
729                         response.getWriter().write(ERROR);
730                 }finally{
731                         if(file != null && file.exists()){
732                                 boolean deleted = file.delete();
733                                 LOGGER.error("Imported File has been deleted: "+deleted);
734                         }
735                 }
736         }
737         
738         public boolean isValidDictionaryName(String dictionaryName){
739                 
740                 String nameCheck = dictionaryName.replace(".csv", "");
741                 try{
742                         DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
743                         switch (mode){
744                                 case Attribute:
745                                 case ActionPolicyDictionary:
746                                 case OnapName:
747                                 case MSPolicyDictionary:
748                                 case OptimizationPolicyDictionary:
749                                 case VNFType:
750                                 case VSCLAction:
751                                 case ClosedLoopService:
752                                 case ClosedLoopSite:
753                                 case PEPOptions:
754                                 case VarbindDictionary:
755                                 case BRMSParamDictionary:
756                                 case BRMSControllerDictionary:
757                                 case BRMSDependencyDictionary:
758                                 case Settings:
759                                 case PrefixList:
760                                 case SecurityZone:
761                                 case Zone:
762                                 case ServiceList:
763                                 case ServiceGroup:
764                                 case AddressGroup:
765                                 case ProtocolList:
766                                 case ActionList:
767                                 case TermList:
768                                 case SearchCriteria:
769                                         return true;
770                                 default:
771                                         return false;
772                         }
773                 }catch(Exception e){
774                         LOGGER.error("Dictionary not exits: " +dictionaryName +e);
775                         return false;
776                 }       
777         }
778 }