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;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.ObjectMapper;
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;
73 public class DictionaryImportController {
74 private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class);
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";
82 public DictionaryImportController(CommonClassDao commonClassDao) {
83 setCommonClassDao(commonClassDao);
86 public static void setCommonClassDao(CommonClassDao commonClassDao) {
87 DictionaryImportController.commonClassDao = commonClassDao;
90 public DictionaryImportController() {
94 @RequestMapping(value = {"/dictionary/import_dictionary"}, method = {RequestMethod.POST})
95 public void importDictionaryData(HttpServletRequest request, HttpServletResponse response)
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");
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);
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);
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]);
135 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
136 attribute.setDescription(rows[j]);
138 if ("priority".equalsIgnoreCase(dictSheet.get(0)[j])) {
139 attribute.setPriority(rows[j]);
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])) {
146 } else if ("integer".equalsIgnoreCase(rows[j])) {
148 } else if ("double".equalsIgnoreCase(rows[j])) {
150 } else if ("boolean".equalsIgnoreCase(rows[j])) {
152 } else if ("user".equalsIgnoreCase(rows[j])) {
155 attribute.setDatatypeBean(dataType);
156 Category category = new Category();
158 attribute.setCategoryBean(category);
160 if ("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j])
161 || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
162 attribute.setAttributeValue(rows[j]);
165 commonClassDao.save(attribute);
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]);
181 if ("body".equalsIgnoreCase(dictSheet.get(0)[j])) {
182 attribute.setBody(rows[j]);
184 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
185 attribute.setDescription(rows[j]);
187 if ("headers".equalsIgnoreCase(dictSheet.get(0)[j])) {
188 attribute.setHeader(rows[j]);
190 if ("method".equalsIgnoreCase(dictSheet.get(0)[j])) {
191 attribute.setMethod(rows[j]);
193 if ("type".equalsIgnoreCase(dictSheet.get(0)[j])) {
194 attribute.setType(rows[j]);
196 if ("url".equalsIgnoreCase(dictSheet.get(0)[j])) {
197 attribute.setUrl(rows[j]);
200 commonClassDao.save(attribute);
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]);
216 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
217 attribute.setDescription(rows[j]);
220 commonClassDao.save(attribute);
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]);
236 if ("version".equalsIgnoreCase(dictSheet.get(0)[j])
237 || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])) {
238 attribute.setVersion(rows[j]);
240 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
241 attribute.setDescription(rows[j]);
243 if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) {
244 attribute.setDependency(rows[j]);
246 if ("attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
247 attribute.setAttributes(rows[j]);
249 if ("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])) {
250 attribute.setEnumValues(rows[j]);
252 if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
253 attribute.setRef_attributes(rows[j]);
255 if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
256 attribute.setSub_attributes(rows[j]);
258 if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
259 attribute.setAnnotation(rows[j]);
263 commonClassDao.save(attribute);
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]);
280 if ("version".equalsIgnoreCase(dictSheet.get(0)[j])
281 || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])) {
282 attribute.setVersion(rows[j]);
284 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
285 attribute.setDescription(rows[j]);
287 if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) {
288 attribute.setDependency(rows[j]);
290 if ("attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
291 attribute.setAttributes(rows[j]);
293 if ("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])) {
294 attribute.setEnumValues(rows[j]);
296 if ("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
297 attribute.setRef_attributes(rows[j]);
299 if ("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])) {
300 attribute.setSub_attributes(rows[j]);
302 if ("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
303 attribute.setAnnotation(rows[j]);
307 commonClassDao.save(attribute);
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]);
324 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
325 attribute.setDescription(rows[j]);
328 commonClassDao.save(attribute);
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]);
344 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
345 attribute.setDescription(rows[j]);
348 commonClassDao.save(attribute);
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]);
364 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
365 attribute.setDescription(rows[j]);
368 commonClassDao.save(attribute);
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]);
384 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
385 attribute.setDescription(rows[j]);
388 commonClassDao.save(attribute);
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]);
404 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
405 attribute.setDescription(rows[j]);
407 if ("Actions".equalsIgnoreCase(dictSheet.get(0)[j])) {
408 attribute.setActions(rows[j]);
411 commonClassDao.save(attribute);
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]);
427 if ("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j])
428 || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])) {
429 attribute.setVarbindDescription(rows[j]);
431 if ("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j])
432 || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])) {
433 attribute.setVarbindOID(rows[j]);
436 commonClassDao.save(attribute);
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]);
451 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
452 attribute.setDescription(rows[j]);
454 if ("rule".equalsIgnoreCase(dictSheet.get(0)[j])) {
455 attribute.setRule(rows[j]);
458 commonClassDao.save(attribute);
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]);
473 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
474 attribute.setDescription(rows[j]);
476 if ("controller".equalsIgnoreCase(dictSheet.get(0)[j])) {
477 attribute.setController(rows[j]);
480 commonClassDao.save(attribute);
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]);
495 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
496 attribute.setDescription(rows[j]);
498 if (DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])) {
499 attribute.setDependency(rows[j]);
502 commonClassDao.save(attribute);
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]);
518 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
519 attribute.setDescription(rows[j]);
521 if ("priority".equalsIgnoreCase(dictSheet.get(0)[j])) {
522 attribute.setPriority(rows[j]);
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])) {
529 } else if ("integer".equalsIgnoreCase(rows[j])) {
531 } else if ("double".equalsIgnoreCase(rows[j])) {
533 } else if ("boolean".equalsIgnoreCase(rows[j])) {
535 } else if ("user".equalsIgnoreCase(rows[j])) {
538 attribute.setDatatypeBean(dataType);
541 commonClassDao.save(attribute);
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]);
553 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
554 attribute.setPrefixListValue(rows[j]);
556 if ("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j])
557 || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
558 attribute.setDescription(rows[j]);
561 commonClassDao.save(attribute);
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]);
573 if ("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j])
574 || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
575 attribute.setZoneValue(rows[j]);
578 commonClassDao.save(attribute);
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]);
590 if ("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j])
591 || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])) {
592 attribute.setZoneValue(rows[j]);
595 commonClassDao.save(attribute);
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]);
607 if ("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j])
608 || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
609 attribute.setServiceDescription(rows[j]);
611 if ("serviceType".equalsIgnoreCase(dictSheet.get(0)[j])
612 || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])) {
613 attribute.setServiceType(rows[j]);
615 if ("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j])
616 || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])) {
617 attribute.setServiceTransProtocol(rows[j]);
619 if ("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j])
620 || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])) {
621 attribute.setServiceAppProtocol(rows[j]);
623 if ("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j])
624 || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])) {
625 attribute.setServicePorts(rows[j]);
628 commonClassDao.save(attribute);
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]);
640 if ("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])
641 || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])) {
642 attribute.setServiceList(rows[j]);
645 commonClassDao.save(attribute);
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]);
657 if ("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])
658 || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])) {
659 attribute.setServiceList(rows[j]);
661 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
662 attribute.setDescription(rows[j]);
665 commonClassDao.save(attribute);
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]);
677 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
678 attribute.setDescription(rows[j]);
681 commonClassDao.save(attribute);
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]);
693 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
694 attribute.setDescription(rows[j]);
697 commonClassDao.save(attribute);
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]);
713 if ("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j])
714 || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])) {
715 attribute.setDescription(rows[j]);
717 if ("fromZone".equalsIgnoreCase(dictSheet.get(0)[j])
718 || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])) {
719 attribute.setFromZones(rows[j]);
721 if ("toZone".equalsIgnoreCase(dictSheet.get(0)[j])
722 || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])) {
723 attribute.setToZones(rows[j]);
725 if ("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j])
726 || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
727 attribute.setSrcIPList(rows[j]);
729 if ("destIPList".equalsIgnoreCase(dictSheet.get(0)[j])
730 || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
731 attribute.setDestIPList(rows[j]);
733 if ("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j])
734 || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
735 attribute.setSrcPortList(rows[j]);
737 if ("destPortList".equalsIgnoreCase(dictSheet.get(0)[j])
738 || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])) {
739 attribute.setDestPortList(rows[j]);
741 if ("action".equalsIgnoreCase(dictSheet.get(0)[j])
742 || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])) {
743 attribute.setAction(rows[j]);
746 commonClassDao.save(attribute);
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]);
762 if (DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])) {
763 attribute.setDescription(rows[j]);
765 if ("search".equalsIgnoreCase(dictSheet.get(0)[j])
766 || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])) {
767 attribute.setSearch(rows[j]);
770 commonClassDao.save(attribute);
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);
781 if (file != null && file.exists()) {
782 boolean deleted = file.delete();
783 LOGGER.error("Imported File has been deleted: " + deleted);
788 public boolean isValidDictionaryName(String dictionaryName) {
790 String nameCheck = dictionaryName.replace(".csv", "");
792 DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
795 case ActionPolicyDictionary:
797 case MSPolicyDictionary:
798 case OptimizationPolicyDictionary:
801 case ClosedLoopService:
804 case VarbindDictionary:
805 case BRMSParamDictionary:
806 case BRMSControllerDictionary:
807 case BRMSDependencyDictionary:
823 } catch (Exception e) {
824 LOGGER.error("Dictionary not exits: " + dictionaryName + e);