2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
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;
24 import java.io.FileOutputStream;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.util.List;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
33 import org.apache.commons.compress.utils.IOUtils;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.pap.xacml.rest.DictionaryNames;
37 import org.onap.policy.rest.dao.CommonClassDao;
38 import org.onap.policy.rest.jpa.ActionList;
39 import org.onap.policy.rest.jpa.ActionPolicyDict;
40 import org.onap.policy.rest.jpa.AddressGroup;
41 import org.onap.policy.rest.jpa.Attribute;
42 import org.onap.policy.rest.jpa.BRMSController;
43 import org.onap.policy.rest.jpa.BRMSDependency;
44 import org.onap.policy.rest.jpa.BRMSParamTemplate;
45 import org.onap.policy.rest.jpa.Category;
46 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
47 import org.onap.policy.rest.jpa.ClosedLoopSite;
48 import org.onap.policy.rest.jpa.Datatype;
49 import org.onap.policy.rest.jpa.DecisionSettings;
50 import org.onap.policy.rest.jpa.DescriptiveScope;
51 import org.onap.policy.rest.jpa.GroupServiceList;
52 import org.onap.policy.rest.jpa.MicroServiceModels;
53 import org.onap.policy.rest.jpa.OnapName;
54 import org.onap.policy.rest.jpa.PEPOptions;
55 import org.onap.policy.rest.jpa.PrefixList;
56 import org.onap.policy.rest.jpa.ProtocolList;
57 import org.onap.policy.rest.jpa.SecurityZone;
58 import org.onap.policy.rest.jpa.ServiceList;
59 import org.onap.policy.rest.jpa.TermList;
60 import org.onap.policy.rest.jpa.UserInfo;
61 import org.onap.policy.rest.jpa.VNFType;
62 import org.onap.policy.rest.jpa.VSCLAction;
63 import org.onap.policy.rest.jpa.VarbindDictionary;
64 import org.onap.policy.rest.jpa.Zone;
65 import org.springframework.beans.factory.annotation.Autowired;
66 import org.springframework.stereotype.Controller;
67 import org.springframework.web.bind.annotation.RequestMapping;
68 import org.springframework.web.bind.annotation.RequestMethod;
70 import com.fasterxml.jackson.databind.DeserializationFeature;
71 import com.fasterxml.jackson.databind.ObjectMapper;
73 import au.com.bytecode.opencsv.CSVReader;
77 public class DictionaryImportController {
78 private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class);
80 private static CommonClassDao commonClassDao;
81 private static final String DESCRIPTION= "description";
82 private static final String ERROR= "Error";
83 private static final String DEPENDENCY= "dependency";
86 public DictionaryImportController(CommonClassDao commonClassDao){
87 setCommonClassDao(commonClassDao);
90 public static void setCommonClassDao(CommonClassDao commonClassDao) {
91 DictionaryImportController.commonClassDao = commonClassDao;
94 public DictionaryImportController(){
98 @RequestMapping(value={"/dictionary/import_dictionary"}, method={RequestMethod.POST})
99 public void importDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{
100 ObjectMapper mapper = new ObjectMapper();
101 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
102 String userId = request.getParameter("userId");
103 String dictionaryName = request.getParameter("dictionaryName");
105 if(dictionaryName == null || dictionaryName.isEmpty()){
106 LOGGER.error("dictionaryName is null/empty");
107 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
108 response.getWriter().write(ERROR);
112 // fix Fortify Path Manipulation issue
113 if(!isValidDictionaryName(dictionaryName)){
114 LOGGER.error("dictionaryName is invalid");
115 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
116 response.getWriter().write(ERROR);
119 File file = new File(dictionaryName);
120 try(OutputStream outputStream = new FileOutputStream(file); 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]) || "Attribute ID".equalsIgnoreCase(dictSheet.get(0)[j])){
134 attribute.setXacmlId(rows[j]);
136 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
137 attribute.setDescription(rows[j]);
139 if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){
140 attribute.setPriority(rows[j]);
142 if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "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]) || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])){
161 attribute.setAttributeValue(rows[j]);
164 commonClassDao.save(attribute);
167 if(dictionaryName.startsWith("ActionPolicyDictionary")){
168 for(int i = 1; i< dictSheet.size(); i++){
169 ActionPolicyDict attribute = new ActionPolicyDict();
170 UserInfo userinfo = new UserInfo();
171 userinfo.setUserLoginId(userId);
172 attribute.setUserCreatedBy(userinfo);
173 attribute.setUserModifiedBy(userinfo);
174 String[] rows = dictSheet.get(i);
175 for (int j=0 ; j<rows.length; j++ ){
176 if("attribute_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Name".equalsIgnoreCase(dictSheet.get(0)[j])){
177 attribute.setAttributeName(rows[j]);
179 if("body".equalsIgnoreCase(dictSheet.get(0)[j])){
180 attribute.setBody(rows[j]);
182 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
183 attribute.setDescription(rows[j]);
185 if("headers".equalsIgnoreCase(dictSheet.get(0)[j])){
186 attribute.setHeader(rows[j]);
188 if("method".equalsIgnoreCase(dictSheet.get(0)[j])){
189 attribute.setMethod(rows[j]);
191 if("type".equalsIgnoreCase(dictSheet.get(0)[j])){
192 attribute.setType(rows[j]);
194 if("url".equalsIgnoreCase(dictSheet.get(0)[j])){
195 attribute.setUrl(rows[j]);
198 commonClassDao.save(attribute);
201 if(dictionaryName.startsWith("OnapName")){
202 for(int i = 1; i< dictSheet.size(); i++){
203 OnapName attribute = new OnapName();
204 UserInfo userinfo = new UserInfo();
205 userinfo.setUserLoginId(userId);
206 attribute.setUserCreatedBy(userinfo);
207 attribute.setUserModifiedBy(userinfo);
208 String[] rows = dictSheet.get(i);
209 for (int j=0 ; j<rows.length; j++ ){
210 if("onap_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Onap Name".equalsIgnoreCase(dictSheet.get(0)[j])){
211 attribute.setOnapName(rows[j]);
213 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
214 attribute.setDescription(rows[j]);
217 commonClassDao.save(attribute);
221 if(dictionaryName.startsWith("MSPolicyDictionary")){
222 for(int i = 1; i< dictSheet.size(); i++){
223 MicroServiceModels attribute = new MicroServiceModels();
224 UserInfo userinfo = new UserInfo();
225 userinfo.setUserLoginId(userId);
226 attribute.setUserCreatedBy(userinfo);
227 String[] rows = dictSheet.get(i);
228 for (int j=0 ; j<rows.length; j++ ){
229 if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Micro Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){
230 attribute.setModelName(rows[j]);
232 if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){
233 attribute.setVersion(rows[j]);
235 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
236 attribute.setDescription(rows[j]);
238 if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){
239 attribute.setDependency(rows[j]);
241 if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
242 attribute.setAttributes(rows[j]);
244 if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){
245 attribute.setEnumValues(rows[j]);
247 if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
248 attribute.setRef_attributes(rows[j]);
250 if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
251 attribute.setSub_attributes(rows[j]);
253 if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
254 attribute.setAnnotation(rows[j]);
258 commonClassDao.save(attribute);
262 if(dictionaryName.startsWith("OptimizationPolicyDictionary")){
263 for(int i = 1; i< dictSheet.size(); i++){
264 MicroServiceModels attribute = new MicroServiceModels();
265 UserInfo userinfo = new UserInfo();
266 userinfo.setUserLoginId(userId);
267 attribute.setUserCreatedBy(userinfo);
268 String[] rows = dictSheet.get(i);
269 for (int j=0 ; j<rows.length; j++ ){
270 if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Optimization Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){
271 attribute.setModelName(rows[j]);
273 if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){
274 attribute.setVersion(rows[j]);
276 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
277 attribute.setDescription(rows[j]);
279 if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){
280 attribute.setDependency(rows[j]);
282 if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
283 attribute.setAttributes(rows[j]);
285 if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){
286 attribute.setEnumValues(rows[j]);
288 if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
289 attribute.setRef_attributes(rows[j]);
291 if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
292 attribute.setSub_attributes(rows[j]);
294 if("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
295 attribute.setAnnotation(rows[j]);
299 commonClassDao.save(attribute);
303 if(dictionaryName.startsWith("VNFType")){
304 for(int i = 1; i< dictSheet.size(); i++){
305 VNFType attribute = new VNFType();
306 UserInfo userinfo = new UserInfo();
307 userinfo.setUserLoginId(userId);
308 attribute.setUserCreatedBy(userinfo);
309 attribute.setUserModifiedBy(userinfo);
310 String[] rows = dictSheet.get(i);
311 for (int j=0 ; j<rows.length; j++ ){
312 if("vnf_type".equalsIgnoreCase(dictSheet.get(0)[j]) || "VNF Type".equalsIgnoreCase(dictSheet.get(0)[j])){
313 attribute.setVnftype(rows[j]);
315 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
316 attribute.setDescription(rows[j]);
319 commonClassDao.save(attribute);
322 if(dictionaryName.startsWith("VSCLAction")){
323 for(int i = 1; i< dictSheet.size(); i++){
324 VSCLAction attribute = new VSCLAction();
325 UserInfo userinfo = new UserInfo();
326 userinfo.setUserLoginId(userId);
327 attribute.setUserCreatedBy(userinfo);
328 attribute.setUserModifiedBy(userinfo);
329 String[] rows = dictSheet.get(i);
330 for (int j=0 ; j<rows.length; j++ ){
331 if("vscl_action".equalsIgnoreCase(dictSheet.get(0)[j]) || "VSCL Action".equalsIgnoreCase(dictSheet.get(0)[j])){
332 attribute.setVsclaction(rows[j]);
334 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
335 attribute.setDescription(rows[j]);
338 commonClassDao.save(attribute);
341 if(dictionaryName.startsWith("ClosedLoopService")){
342 for(int i = 1; i< dictSheet.size(); i++){
343 ClosedLoopD2Services attribute = new ClosedLoopD2Services();
344 UserInfo userinfo = new UserInfo();
345 userinfo.setUserLoginId(userId);
346 attribute.setUserCreatedBy(userinfo);
347 attribute.setUserModifiedBy(userinfo);
348 String[] rows = dictSheet.get(i);
349 for (int j=0 ; j<rows.length; j++ ){
350 if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){
351 attribute.setServiceName(rows[j]);
353 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
354 attribute.setDescription(rows[j]);
357 commonClassDao.save(attribute);
360 if(dictionaryName.startsWith("ClosedLoopSite")){
361 for(int i = 1; i< dictSheet.size(); i++){
362 ClosedLoopSite attribute = new ClosedLoopSite();
363 UserInfo userinfo = new UserInfo();
364 userinfo.setUserLoginId(userId);
365 attribute.setUserCreatedBy(userinfo);
366 attribute.setUserModifiedBy(userinfo);
367 String[] rows = dictSheet.get(i);
368 for (int j=0 ; j<rows.length; j++ ){
369 if("siteName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Site Name".equalsIgnoreCase(dictSheet.get(0)[j])){
370 attribute.setSiteName(rows[j]);
372 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
373 attribute.setDescription(rows[j]);
376 commonClassDao.save(attribute);
379 if(dictionaryName.startsWith("PEPOptions")){
380 for(int i = 1; i< dictSheet.size(); i++){
381 PEPOptions attribute = new PEPOptions();
382 UserInfo userinfo = new UserInfo();
383 userinfo.setUserLoginId(userId);
384 attribute.setUserCreatedBy(userinfo);
385 attribute.setUserModifiedBy(userinfo);
386 String[] rows = dictSheet.get(i);
387 for (int j=0 ; j<rows.length; j++ ){
388 if("PEP_NAME".equalsIgnoreCase(dictSheet.get(0)[j]) || "PEP Name".equalsIgnoreCase(dictSheet.get(0)[j])){
389 attribute.setPepName(rows[j]);
391 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
392 attribute.setDescription(rows[j]);
394 if("Actions".equalsIgnoreCase(dictSheet.get(0)[j])){
395 attribute.setActions(rows[j]);
398 commonClassDao.save(attribute);
401 if(dictionaryName.startsWith("VarbindDictionary")){
402 for(int i = 1; i< dictSheet.size(); i++){
403 VarbindDictionary attribute = new VarbindDictionary();
404 UserInfo userinfo = new UserInfo();
405 userinfo.setUserLoginId(userId);
406 attribute.setUserCreatedBy(userinfo);
407 attribute.setUserModifiedBy(userinfo);
408 String[] rows = dictSheet.get(i);
409 for (int j=0 ; j<rows.length; j++ ){
410 if("varbind_Name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Name".equalsIgnoreCase(dictSheet.get(0)[j])){
411 attribute.setVarbindName(rows[j]);
413 if("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])){
414 attribute.setVarbindDescription(rows[j]);
416 if("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])){
417 attribute.setVarbindOID(rows[j]);
420 commonClassDao.save(attribute);
423 if(dictionaryName.startsWith("BRMSParamDictionary")){
424 for(int i = 1; i< dictSheet.size(); i++){
425 BRMSParamTemplate attribute = new BRMSParamTemplate();
426 UserInfo userinfo = new UserInfo();
427 userinfo.setUserLoginId(userId);
428 attribute.setUserCreatedBy(userinfo);
429 String[] rows = dictSheet.get(i);
430 for (int j=0 ; j<rows.length; j++ ){
431 if("param_template_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Rule Name".equalsIgnoreCase(dictSheet.get(0)[j])){
432 attribute.setRuleName(rows[j]);
434 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
435 attribute.setDescription(rows[j]);
437 if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){
438 attribute.setRule(rows[j]);
441 commonClassDao.save(attribute);
444 if(dictionaryName.startsWith("BRMSControllerDictionary")){
445 for(int i = 1; i< dictSheet.size(); i++){
446 BRMSController attribute = new BRMSController();
447 UserInfo userinfo = new UserInfo();
448 userinfo.setUserLoginId(userId);
449 attribute.setUserCreatedBy(userinfo);
450 String[] rows = dictSheet.get(i);
451 for (int j=0 ; j<rows.length; j++ ){
452 if("controllerName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Controller Name".equalsIgnoreCase(dictSheet.get(0)[j])){
453 attribute.setControllerName(rows[j]);
455 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
456 attribute.setDescription(rows[j]);
458 if("controller".equalsIgnoreCase(dictSheet.get(0)[j])){
459 attribute.setController(rows[j]);
462 commonClassDao.save(attribute);
465 if(dictionaryName.startsWith("BRMSDependencyDictionary")){
466 for(int i = 1; i< dictSheet.size(); i++){
467 BRMSDependency attribute = new BRMSDependency();
468 UserInfo userinfo = new UserInfo();
469 userinfo.setUserLoginId(userId);
470 attribute.setUserCreatedBy(userinfo);
471 String[] rows = dictSheet.get(i);
472 for (int j=0 ; j<rows.length; j++ ){
473 if("dependencyName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Dependency Name".equalsIgnoreCase(dictSheet.get(0)[j])){
474 attribute.setDependencyName(rows[j]);
476 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
477 attribute.setDescription(rows[j]);
479 if(DEPENDENCY.equalsIgnoreCase(dictSheet.get(0)[j])){
480 attribute.setDependency(rows[j]);
483 commonClassDao.save(attribute);
486 if(dictionaryName.startsWith("Settings")){
487 for(int i = 1; i< dictSheet.size(); i++){
488 DecisionSettings attribute = new DecisionSettings();
489 UserInfo userinfo = new UserInfo();
490 userinfo.setUserLoginId(userId);
491 attribute.setUserCreatedBy(userinfo);
492 attribute.setUserModifiedBy(userinfo);
493 String[] rows = dictSheet.get(i);
494 for (int j=0 ; j<rows.length; j++ ){
495 if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Settings ID".equalsIgnoreCase(dictSheet.get(0)[j])){
496 attribute.setXacmlId(rows[j]);
498 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
499 attribute.setDescription(rows[j]);
501 if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){
502 attribute.setPriority(rows[j]);
504 if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
505 Datatype dataType = new Datatype();
506 if("string".equalsIgnoreCase(rows[j])){
508 }else if("integer".equalsIgnoreCase(rows[j])){
510 }else if("double".equalsIgnoreCase(rows[j])){
512 }else if("boolean".equalsIgnoreCase(rows[j])){
514 }else if("user".equalsIgnoreCase(rows[j])){
517 attribute.setDatatypeBean(dataType);
520 commonClassDao.save(attribute);
523 if(dictionaryName.startsWith("PrefixList")){
524 for(int i = 1; i< dictSheet.size(); i++){
525 PrefixList attribute = new PrefixList();
526 String[] rows = dictSheet.get(i);
527 for (int j=0 ; j<rows.length; j++ ){
528 if("prefixListName".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Name".equalsIgnoreCase(dictSheet.get(0)[j])){
529 attribute.setPrefixListName(rows[j]);
531 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
532 attribute.setPrefixListValue(rows[j]);
534 if("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])){
535 attribute.setDescription(rows[j]);
538 commonClassDao.save(attribute);
541 if(dictionaryName.startsWith("SecurityZone")){
542 for(int i = 1; i< dictSheet.size(); i++){
543 SecurityZone attribute = new SecurityZone();
544 String[] rows = dictSheet.get(i);
545 for (int j=0 ; j<rows.length; j++ ){
546 if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){
547 attribute.setZoneName(rows[j]);
549 if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
550 attribute.setZoneValue(rows[j]);
553 commonClassDao.save(attribute);
556 if(dictionaryName.startsWith("Zone")){
557 for(int i = 1; i< dictSheet.size(); i++){
558 Zone attribute = new Zone();
559 String[] rows = dictSheet.get(i);
560 for (int j=0 ; j<rows.length; j++ ){
561 if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){
562 attribute.setZoneName(rows[j]);
564 if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
565 attribute.setZoneValue(rows[j]);
568 commonClassDao.save(attribute);
571 if(dictionaryName.startsWith("ServiceList")){
572 for(int i = 1; i< dictSheet.size(); i++){
573 ServiceList attribute = new ServiceList();
574 String[] rows = dictSheet.get(i);
575 for (int j=0 ; j<rows.length; j++ ){
576 if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){
577 attribute.setServiceName(rows[j]);
579 if("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j]) || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
580 attribute.setServiceDescription(rows[j]);
582 if("serviceType".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])){
583 attribute.setServiceType(rows[j]);
585 if("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){
586 attribute.setServiceTransProtocol(rows[j]);
588 if("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){
589 attribute.setServiceAppProtocol(rows[j]);
591 if("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j]) || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])){
592 attribute.setServicePorts(rows[j]);
595 commonClassDao.save(attribute);
598 if(dictionaryName.startsWith("ServiceGroup")){
599 for(int i = 1; i< dictSheet.size(); i++){
600 GroupServiceList attribute = new GroupServiceList();
601 String[] rows = dictSheet.get(i);
602 for (int j=0 ; j<rows.length; j++ ){
603 if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){
604 attribute.setGroupName(rows[j]);
606 if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){
607 attribute.setServiceList(rows[j]);
610 commonClassDao.save(attribute);
613 if(dictionaryName.startsWith("AddressGroup")){
614 for(int i = 1; i< dictSheet.size(); i++){
615 AddressGroup attribute = new AddressGroup();
616 String[] rows = dictSheet.get(i);
617 for (int j=0 ; j<rows.length; j++ ){
618 if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){
619 attribute.setGroupName(rows[j]);
621 if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])){
622 attribute.setServiceList(rows[j]);
624 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
625 attribute.setDescription(rows[j]);
628 commonClassDao.save(attribute);
631 if(dictionaryName.startsWith("ProtocolList")){
632 for(int i = 1; i< dictSheet.size(); i++){
633 ProtocolList attribute = new ProtocolList();
634 String[] rows = dictSheet.get(i);
635 for (int j=0 ; j<rows.length; j++ ){
636 if("protocolName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Protocol Name".equalsIgnoreCase(dictSheet.get(0)[j])){
637 attribute.setProtocolName(rows[j]);
639 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
640 attribute.setDescription(rows[j]);
643 commonClassDao.save(attribute);
646 if(dictionaryName.startsWith("ActionList")){
647 for(int i = 1; i< dictSheet.size(); i++){
648 ActionList attribute = new ActionList();
649 String[] rows = dictSheet.get(i);
650 for (int j=0 ; j<rows.length; j++ ){
651 if("actionName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action Name".equalsIgnoreCase(dictSheet.get(0)[j])){
652 attribute.setActionName(rows[j]);
654 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
655 attribute.setDescription(rows[j]);
658 commonClassDao.save(attribute);
661 if(dictionaryName.startsWith("TermList")){
662 for(int i = 1; i< dictSheet.size(); i++){
663 TermList attribute = new TermList();
664 UserInfo userinfo = new UserInfo();
665 userinfo.setUserLoginId(userId);
666 attribute.setUserCreatedBy(userinfo);
667 attribute.setUserModifiedBy(userinfo);
668 String[] rows = dictSheet.get(i);
669 for (int j=0 ; j<rows.length; j++ ){
670 if("termName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Term-Name".equalsIgnoreCase(dictSheet.get(0)[j])){
671 attribute.setTermName(rows[j]);
673 if("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])){
674 attribute.setDescription(rows[j]);
676 if("fromZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])){
677 attribute.setFromZones(rows[j]);
679 if("toZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])){
680 attribute.setToZones(rows[j]);
682 if("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){
683 attribute.setSrcIPList(rows[j]);
685 if("destIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){
686 attribute.setDestIPList(rows[j]);
688 if("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){
689 attribute.setSrcPortList(rows[j]);
691 if("destPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){
692 attribute.setDestPortList(rows[j]);
694 if("action".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])){
695 attribute.setAction(rows[j]);
698 commonClassDao.save(attribute);
701 if(dictionaryName.startsWith("SearchCriteria")){
702 for(int i = 1; i< dictSheet.size(); i++){
703 DescriptiveScope attribute = new DescriptiveScope();
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("descriptiveScopeName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Descriptive Scope Name".equalsIgnoreCase(dictSheet.get(0)[j])){
711 attribute.setScopeName(rows[j]);
713 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
714 attribute.setDescription(rows[j]);
716 if("search".equalsIgnoreCase(dictSheet.get(0)[j]) || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])){
717 attribute.setSearch(rows[j]);
720 commonClassDao.save(attribute);
724 response.setStatus(HttpServletResponse.SC_OK);
725 response.getWriter().write("Success");
727 LOGGER.error("Exception Occured while importing dictionary"+e);
728 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
729 response.getWriter().write(ERROR);
731 if(file != null && file.exists()){
732 boolean deleted = file.delete();
733 LOGGER.error("Imported File has been deleted: "+deleted);
738 public boolean isValidDictionaryName(String dictionaryName){
740 String nameCheck = dictionaryName.replace(".csv", "");
742 DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
745 case ActionPolicyDictionary:
747 case MSPolicyDictionary:
748 case OptimizationPolicyDictionary:
751 case ClosedLoopService:
754 case VarbindDictionary:
755 case BRMSParamDictionary:
756 case BRMSControllerDictionary:
757 case BRMSDependencyDictionary:
774 LOGGER.error("Dictionary not exits: " +dictionaryName +e);