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