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