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