2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.pap.xacml.rest.controller;
23 import au.com.bytecode.opencsv.CSVReader;
25 import com.fasterxml.jackson.databind.DeserializationFeature;
26 import com.fasterxml.jackson.databind.ObjectMapper;
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;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
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;
76 public class DictionaryImportController {
77 private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class);
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";
85 public DictionaryImportController(CommonClassDao commonClassDao) {
86 setCommonClassDao(commonClassDao);
89 public static void setCommonClassDao(CommonClassDao commonClassDao) {
90 DictionaryImportController.commonClassDao = commonClassDao;
93 public DictionaryImportController() {
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");
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);
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);
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]);
137 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
138 attribute.setDescription(rows[j]);
140 if ("priority".equalsIgnoreCase(dictSheet.get(0)[j])) {
141 attribute.setPriority(rows[j]);
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])) {
148 } else if ("integer".equalsIgnoreCase(rows[j])) {
150 } else if ("double".equalsIgnoreCase(rows[j])) {
152 } else if ("boolean".equalsIgnoreCase(rows[j])) {
154 } else if ("user".equalsIgnoreCase(rows[j])) {
157 attribute.setDatatypeBean(dataType);
158 Category category = new Category();
160 attribute.setCategoryBean(category);
162 if ("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j])
163 || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
164 attribute.setAttributeValue(rows[j]);
167 commonClassDao.save(attribute);
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]);
183 if ("body".equalsIgnoreCase(dictSheet.get(0)[j])) {
184 attribute.setBody(rows[j]);
186 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
187 attribute.setDescription(rows[j]);
189 if ("headers".equalsIgnoreCase(dictSheet.get(0)[j])) {
190 attribute.setHeader(rows[j]);
192 if ("method".equalsIgnoreCase(dictSheet.get(0)[j])) {
193 attribute.setMethod(rows[j]);
195 if ("type".equalsIgnoreCase(dictSheet.get(0)[j])) {
196 attribute.setType(rows[j]);
198 if ("url".equalsIgnoreCase(dictSheet.get(0)[j])) {
199 attribute.setUrl(rows[j]);
202 commonClassDao.save(attribute);
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]);
218 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
219 attribute.setDescription(rows[j]);
222 commonClassDao.save(attribute);
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]);
238 if ("version".equalsIgnoreCase(dictSheet.get(0)[j])
239 || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])) {
240 attribute.setVersion(rows[j]);
242 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
243 attribute.setDescription(rows[j]);
245 if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) {
246 attribute.setDependency(rows[j]);
248 if ("attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
249 attribute.setAttributes(rows[j]);
251 if ("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])) {
252 attribute.setEnumValues(rows[j]);
254 if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
255 attribute.setRef_attributes(rows[j]);
257 if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
258 attribute.setSub_attributes(rows[j]);
260 if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
261 attribute.setAnnotation(rows[j]);
265 commonClassDao.save(attribute);
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]);
281 if ("version".equalsIgnoreCase(dictSheet.get(0)[j])
282 || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])) {
283 attribute.setVersion(rows[j]);
285 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
286 attribute.setDescription(rows[j]);
288 if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) {
289 attribute.setDependency(rows[j]);
291 if ("attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
292 attribute.setAttributes(rows[j]);
294 if ("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])) {
295 attribute.setEnumValues(rows[j]);
297 if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
298 attribute.setRef_attributes(rows[j]);
300 if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
301 attribute.setSub_attributes(rows[j]);
303 if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
304 attribute.setAnnotation(rows[j]);
308 commonClassDao.save(attribute);
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]);
325 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
326 attribute.setDescription(rows[j]);
329 commonClassDao.save(attribute);
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]);
345 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
346 attribute.setDescription(rows[j]);
349 commonClassDao.save(attribute);
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]);
365 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
366 attribute.setDescription(rows[j]);
369 commonClassDao.save(attribute);
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]);
385 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
386 attribute.setDescription(rows[j]);
389 commonClassDao.save(attribute);
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]);
405 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
406 attribute.setDescription(rows[j]);
408 if ("Actions".equalsIgnoreCase(dictSheet.get(0)[j])) {
409 attribute.setActions(rows[j]);
412 commonClassDao.save(attribute);
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]);
428 if ("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j])
429 || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])) {
430 attribute.setVarbindDescription(rows[j]);
432 if ("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j])
433 || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])) {
434 attribute.setVarbindOID(rows[j]);
437 commonClassDao.save(attribute);
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]);
452 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
453 attribute.setDescription(rows[j]);
455 if ("rule".equalsIgnoreCase(dictSheet.get(0)[j])) {
456 attribute.setRule(rows[j]);
459 commonClassDao.save(attribute);
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]);
474 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
475 attribute.setDescription(rows[j]);
477 if ("controller".equalsIgnoreCase(dictSheet.get(0)[j])) {
478 attribute.setController(rows[j]);
481 commonClassDao.save(attribute);
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]);
496 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
497 attribute.setDescription(rows[j]);
499 if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) {
500 attribute.setDependency(rows[j]);
503 commonClassDao.save(attribute);
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]);
519 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
520 attribute.setDescription(rows[j]);
522 if ("priority".equalsIgnoreCase(dictSheet.get(0)[j])) {
523 attribute.setPriority(rows[j]);
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])) {
530 } else if ("integer".equalsIgnoreCase(rows[j])) {
532 } else if ("double".equalsIgnoreCase(rows[j])) {
534 } else if ("boolean".equalsIgnoreCase(rows[j])) {
536 } else if ("user".equalsIgnoreCase(rows[j])) {
539 attribute.setDatatypeBean(dataType);
542 commonClassDao.save(attribute);
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]);
554 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
555 attribute.setPrefixListValue(rows[j]);
557 if ("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j])
558 || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
559 attribute.setDescription(rows[j]);
562 commonClassDao.save(attribute);
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]);
574 if ("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j])
575 || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
576 attribute.setZoneValue(rows[j]);
579 commonClassDao.save(attribute);
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]);
591 if ("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j])
592 || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
593 attribute.setZoneValue(rows[j]);
596 commonClassDao.save(attribute);
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]);
608 if ("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j])
609 || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
610 attribute.setServiceDescription(rows[j]);
612 if ("serviceType".equalsIgnoreCase(dictSheet.get(0)[j])
613 || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])) {
614 attribute.setServiceType(rows[j]);
616 if ("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j])
617 || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])) {
618 attribute.setServiceTransProtocol(rows[j]);
620 if ("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j])
621 || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])) {
622 attribute.setServiceAppProtocol(rows[j]);
624 if ("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j])
625 || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])) {
626 attribute.setServicePorts(rows[j]);
629 commonClassDao.save(attribute);
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]);
641 if ("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])
642 || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])) {
643 attribute.setServiceList(rows[j]);
646 commonClassDao.save(attribute);
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]);
658 if ("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])
659 || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])) {
660 attribute.setServiceList(rows[j]);
662 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
663 attribute.setDescription(rows[j]);
666 commonClassDao.save(attribute);
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]);
678 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
679 attribute.setDescription(rows[j]);
682 commonClassDao.save(attribute);
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]);
694 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
695 attribute.setDescription(rows[j]);
698 commonClassDao.save(attribute);
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]);
714 if ("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j])
715 || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])) {
716 attribute.setDescription(rows[j]);
718 if ("fromZone".equalsIgnoreCase(dictSheet.get(0)[j])
719 || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])) {
720 attribute.setFromZones(rows[j]);
722 if ("toZone".equalsIgnoreCase(dictSheet.get(0)[j])
723 || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])) {
724 attribute.setToZones(rows[j]);
726 if ("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j])
727 || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
728 attribute.setSrcIPList(rows[j]);
730 if ("destIPList".equalsIgnoreCase(dictSheet.get(0)[j])
731 || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
732 attribute.setDestIPList(rows[j]);
734 if ("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j])
735 || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
736 attribute.setSrcPortList(rows[j]);
738 if ("destPortList".equalsIgnoreCase(dictSheet.get(0)[j])
739 || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
740 attribute.setDestPortList(rows[j]);
742 if ("action".equalsIgnoreCase(dictSheet.get(0)[j])
743 || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])) {
744 attribute.setAction(rows[j]);
747 commonClassDao.save(attribute);
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]);
763 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
764 attribute.setDescription(rows[j]);
766 if ("search".equalsIgnoreCase(dictSheet.get(0)[j])
767 || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])) {
768 attribute.setSearch(rows[j]);
771 commonClassDao.save(attribute);
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);
782 if (file != null && file.exists()) {
783 boolean deleted = file.delete();
784 LOGGER.error("Imported File has been deleted: " + deleted);
789 public boolean isValidDictionaryName(String dictionaryName) {
791 String nameCheck = dictionaryName.replace(".csv", "");
793 DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
796 case ActionPolicyDictionary:
798 case MSPolicyDictionary:
799 case OptimizationPolicyDictionary:
802 case ClosedLoopService:
805 case VarbindDictionary:
806 case BRMSParamDictionary:
807 case BRMSControllerDictionary:
808 case BRMSDependencyDictionary:
824 } catch (Exception e) {
825 LOGGER.error("Dictionary not exits: " + dictionaryName + e);