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";
84 public DictionaryImportController(CommonClassDao commonClassDao){
85 DictionaryImportController.commonClassDao = commonClassDao;
88 public DictionaryImportController(){
93 @RequestMapping(value={"/dictionary/import_dictionary"}, method={RequestMethod.POST})
94 public void importDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{
95 ObjectMapper mapper = new ObjectMapper();
96 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
97 String userId = request.getParameter("userId");
98 String dictionaryName = request.getParameter("dictionaryName");
100 if(dictionaryName == null || dictionaryName.isEmpty()){
101 LOGGER.error("dictionaryName is null/empty");
102 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
103 response.getWriter().write("Error");
107 // fix Fortify Path Manipulation issue
108 if(!isValidDictionaryName(dictionaryName)){
109 LOGGER.error("dictionaryName is invalid");
110 response.setStatus(HttpServletResponse.SC_OK);
111 response.getWriter().write("Dictionary Import failed. Hence the following dictionary doen't support import function : "+ dictionaryName);
114 File file = new File(dictionaryName);
115 try(OutputStream outputStream = new FileOutputStream(file); FileReader fileReader = new FileReader(file.toString())){
116 IOUtils.copy(request.getInputStream(), outputStream);
117 CSVReader csvReader = new CSVReader(fileReader);
118 List<String[]> dictSheet = csvReader.readAll();
119 if(dictionaryName.startsWith("Attribute")){
120 for(int i = 1; i< dictSheet.size(); i++){
121 Attribute attribute = new Attribute("");
122 UserInfo userinfo = new UserInfo();
123 userinfo.setUserLoginId(userId);
124 attribute.setUserCreatedBy(userinfo);
125 attribute.setUserModifiedBy(userinfo);
126 String[] rows = dictSheet.get(i);
127 for (int j=0 ; j<rows.length; j++ ){
128 if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute ID".equalsIgnoreCase(dictSheet.get(0)[j])){
129 attribute.setXacmlId(rows[j]);
131 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
132 attribute.setDescription(rows[j]);
134 if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){
135 attribute.setPriority(rows[j]);
137 if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
138 Datatype dataType = new Datatype();
139 if("string".equalsIgnoreCase(rows[j])){
141 }else if("integer".equalsIgnoreCase(rows[j])){
143 }else if("double".equalsIgnoreCase(rows[j])){
145 }else if("boolean".equalsIgnoreCase(rows[j])){
147 }else if("user".equalsIgnoreCase(rows[j])){
150 attribute.setDatatypeBean(dataType);
151 Category category = new Category();
153 attribute.setCategoryBean(category);
155 if("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])){
156 attribute.setAttributeValue(rows[j]);
159 commonClassDao.save(attribute);
162 if(dictionaryName.startsWith("ActionPolicyDictionary")){
163 for(int i = 1; i< dictSheet.size(); i++){
164 ActionPolicyDict attribute = new ActionPolicyDict();
165 UserInfo userinfo = new UserInfo();
166 userinfo.setUserLoginId(userId);
167 attribute.setUserCreatedBy(userinfo);
168 attribute.setUserModifiedBy(userinfo);
169 String[] rows = dictSheet.get(i);
170 for (int j=0 ; j<rows.length; j++ ){
171 if("attribute_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Name".equalsIgnoreCase(dictSheet.get(0)[j])){
172 attribute.setAttributeName(rows[j]);
174 if("body".equalsIgnoreCase(dictSheet.get(0)[j])){
175 attribute.setBody(rows[j]);
177 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
178 attribute.setDescription(rows[j]);
180 if("headers".equalsIgnoreCase(dictSheet.get(0)[j])){
181 attribute.setHeader(rows[j]);
183 if("method".equalsIgnoreCase(dictSheet.get(0)[j])){
184 attribute.setMethod(rows[j]);
186 if("type".equalsIgnoreCase(dictSheet.get(0)[j])){
187 attribute.setType(rows[j]);
189 if("url".equalsIgnoreCase(dictSheet.get(0)[j])){
190 attribute.setUrl(rows[j]);
193 commonClassDao.save(attribute);
196 if(dictionaryName.startsWith("OnapName")){
197 for(int i = 1; i< dictSheet.size(); i++){
198 OnapName attribute = new OnapName();
199 UserInfo userinfo = new UserInfo();
200 userinfo.setUserLoginId(userId);
201 attribute.setUserCreatedBy(userinfo);
202 attribute.setUserModifiedBy(userinfo);
203 String[] rows = dictSheet.get(i);
204 for (int j=0 ; j<rows.length; j++ ){
205 if("onap_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Onap Name".equalsIgnoreCase(dictSheet.get(0)[j])){
206 attribute.setOnapName(rows[j]);
208 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
209 attribute.setDescription(rows[j]);
212 commonClassDao.save(attribute);
216 if(dictionaryName.startsWith("MSPolicyDictionary")){
217 for(int i = 1; i< dictSheet.size(); i++){
218 MicroServiceModels attribute = new MicroServiceModels();
219 UserInfo userinfo = new UserInfo();
220 userinfo.setUserLoginId(userId);
221 attribute.setUserCreatedBy(userinfo);
222 String[] rows = dictSheet.get(i);
223 for (int j=0 ; j<rows.length; j++ ){
224 if("modelName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Micro Service Model".equalsIgnoreCase(dictSheet.get(0)[j])){
225 attribute.setModelName(rows[j]);
227 if("version".equalsIgnoreCase(dictSheet.get(0)[j]) || "Model Version".equalsIgnoreCase(dictSheet.get(0)[j])){
228 attribute.setVersion(rows[j]);
230 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
231 attribute.setDescription(rows[j]);
233 if("dependency".equalsIgnoreCase(dictSheet.get(0)[j])){
234 attribute.setDependency(rows[j]);
236 if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
237 attribute.setAttributes(rows[j]);
239 if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){
240 attribute.setEnumValues(rows[j]);
242 if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
243 attribute.setRef_attributes(rows[j]);
245 if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
246 attribute.setSub_attributes(rows[j]);
250 commonClassDao.save(attribute);
254 if(dictionaryName.startsWith("VNFType")){
255 for(int i = 1; i< dictSheet.size(); i++){
256 VNFType attribute = new VNFType();
257 UserInfo userinfo = new UserInfo();
258 userinfo.setUserLoginId(userId);
259 attribute.setUserCreatedBy(userinfo);
260 attribute.setUserModifiedBy(userinfo);
261 String[] rows = dictSheet.get(i);
262 for (int j=0 ; j<rows.length; j++ ){
263 if("vnf_type".equalsIgnoreCase(dictSheet.get(0)[j]) || "VNF Type".equalsIgnoreCase(dictSheet.get(0)[j])){
264 attribute.setVnftype(rows[j]);
266 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
267 attribute.setDescription(rows[j]);
270 commonClassDao.save(attribute);
273 if(dictionaryName.startsWith("VSCLAction")){
274 for(int i = 1; i< dictSheet.size(); i++){
275 VSCLAction attribute = new VSCLAction();
276 UserInfo userinfo = new UserInfo();
277 userinfo.setUserLoginId(userId);
278 attribute.setUserCreatedBy(userinfo);
279 attribute.setUserModifiedBy(userinfo);
280 String[] rows = dictSheet.get(i);
281 for (int j=0 ; j<rows.length; j++ ){
282 if("vscl_action".equalsIgnoreCase(dictSheet.get(0)[j]) || "VSCL Action".equalsIgnoreCase(dictSheet.get(0)[j])){
283 attribute.setVsclaction(rows[j]);
285 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
286 attribute.setDescription(rows[j]);
289 commonClassDao.save(attribute);
292 if(dictionaryName.startsWith("ClosedLoopService")){
293 for(int i = 1; i< dictSheet.size(); i++){
294 ClosedLoopD2Services attribute = new ClosedLoopD2Services();
295 UserInfo userinfo = new UserInfo();
296 userinfo.setUserLoginId(userId);
297 attribute.setUserCreatedBy(userinfo);
298 attribute.setUserModifiedBy(userinfo);
299 String[] rows = dictSheet.get(i);
300 for (int j=0 ; j<rows.length; j++ ){
301 if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){
302 attribute.setServiceName(rows[j]);
304 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
305 attribute.setDescription(rows[j]);
308 commonClassDao.save(attribute);
311 if(dictionaryName.startsWith("ClosedLoopSite")){
312 for(int i = 1; i< dictSheet.size(); i++){
313 ClosedLoopSite attribute = new ClosedLoopSite();
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("siteName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Site Name".equalsIgnoreCase(dictSheet.get(0)[j])){
321 attribute.setSiteName(rows[j]);
323 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
324 attribute.setDescription(rows[j]);
327 commonClassDao.save(attribute);
330 if(dictionaryName.startsWith("PEPOptions")){
331 for(int i = 1; i< dictSheet.size(); i++){
332 PEPOptions attribute = new PEPOptions();
333 UserInfo userinfo = new UserInfo();
334 userinfo.setUserLoginId(userId);
335 attribute.setUserCreatedBy(userinfo);
336 attribute.setUserModifiedBy(userinfo);
337 String[] rows = dictSheet.get(i);
338 for (int j=0 ; j<rows.length; j++ ){
339 if("PEP_NAME".equalsIgnoreCase(dictSheet.get(0)[j]) || "PEP Name".equalsIgnoreCase(dictSheet.get(0)[j])){
340 attribute.setPepName(rows[j]);
342 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
343 attribute.setDescription(rows[j]);
345 if("Actions".equalsIgnoreCase(dictSheet.get(0)[j])){
346 attribute.setActions(rows[j]);
349 commonClassDao.save(attribute);
352 if(dictionaryName.startsWith("VarbindDictionary")){
353 for(int i = 1; i< dictSheet.size(); i++){
354 VarbindDictionary attribute = new VarbindDictionary();
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("varbind_Name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Name".equalsIgnoreCase(dictSheet.get(0)[j])){
362 attribute.setVarbindName(rows[j]);
364 if("varbind_Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind Description".equalsIgnoreCase(dictSheet.get(0)[j])){
365 attribute.setVarbindDescription(rows[j]);
367 if("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])){
368 attribute.setVarbindOID(rows[j]);
371 commonClassDao.save(attribute);
374 if(dictionaryName.startsWith("BRMSParamDictionary")){
375 for(int i = 1; i< dictSheet.size(); i++){
376 BRMSParamTemplate attribute = new BRMSParamTemplate();
377 UserInfo userinfo = new UserInfo();
378 userinfo.setUserLoginId(userId);
379 attribute.setUserCreatedBy(userinfo);
380 String[] rows = dictSheet.get(i);
381 for (int j=0 ; j<rows.length; j++ ){
382 if("param_template_name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Rule Name".equalsIgnoreCase(dictSheet.get(0)[j])){
383 attribute.setRuleName(rows[j]);
385 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
386 attribute.setDescription(rows[j]);
388 if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){
389 attribute.setRule(rows[j]);
392 commonClassDao.save(attribute);
395 if(dictionaryName.startsWith("BRMSControllerDictionary")){
396 for(int i = 1; i< dictSheet.size(); i++){
397 BRMSController attribute = new BRMSController();
398 UserInfo userinfo = new UserInfo();
399 userinfo.setUserLoginId(userId);
400 attribute.setUserCreatedBy(userinfo);
401 String[] rows = dictSheet.get(i);
402 for (int j=0 ; j<rows.length; j++ ){
403 if("controllerName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Controller Name".equalsIgnoreCase(dictSheet.get(0)[j])){
404 attribute.setControllerName(rows[j]);
406 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
407 attribute.setDescription(rows[j]);
409 if("controller".equalsIgnoreCase(dictSheet.get(0)[j])){
410 attribute.setController(rows[j]);
413 commonClassDao.save(attribute);
416 if(dictionaryName.startsWith("BRMSDependencyDictionary")){
417 for(int i = 1; i< dictSheet.size(); i++){
418 BRMSDependency attribute = new BRMSDependency();
419 UserInfo userinfo = new UserInfo();
420 userinfo.setUserLoginId(userId);
421 attribute.setUserCreatedBy(userinfo);
422 String[] rows = dictSheet.get(i);
423 for (int j=0 ; j<rows.length; j++ ){
424 if("dependencyName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Dependency Name".equalsIgnoreCase(dictSheet.get(0)[j])){
425 attribute.setDependencyName(rows[j]);
427 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
428 attribute.setDescription(rows[j]);
430 if("dependency".equalsIgnoreCase(dictSheet.get(0)[j])){
431 attribute.setDependency(rows[j]);
434 commonClassDao.save(attribute);
437 if(dictionaryName.startsWith("Settings")){
438 for(int i = 1; i< dictSheet.size(); i++){
439 DecisionSettings attribute = new DecisionSettings();
440 UserInfo userinfo = new UserInfo();
441 userinfo.setUserLoginId(userId);
442 attribute.setUserCreatedBy(userinfo);
443 attribute.setUserModifiedBy(userinfo);
444 String[] rows = dictSheet.get(i);
445 for (int j=0 ; j<rows.length; j++ ){
446 if("xacml_id".equalsIgnoreCase(dictSheet.get(0)[j]) || "Settings ID".equalsIgnoreCase(dictSheet.get(0)[j])){
447 attribute.setXacmlId(rows[j]);
449 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
450 attribute.setDescription(rows[j]);
452 if("priority".equalsIgnoreCase(dictSheet.get(0)[j])){
453 attribute.setPriority(rows[j]);
455 if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
456 Datatype dataType = new Datatype();
457 if("string".equalsIgnoreCase(rows[j])){
459 }else if("integer".equalsIgnoreCase(rows[j])){
461 }else if("double".equalsIgnoreCase(rows[j])){
463 }else if("boolean".equalsIgnoreCase(rows[j])){
465 }else if("user".equalsIgnoreCase(rows[j])){
468 attribute.setDatatypeBean(dataType);
471 commonClassDao.save(attribute);
474 if(dictionaryName.startsWith("PrefixList")){
475 for(int i = 1; i< dictSheet.size(); i++){
476 PrefixList attribute = new PrefixList();
477 String[] rows = dictSheet.get(i);
478 for (int j=0 ; j<rows.length; j++ ){
479 if("prefixListName".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Name".equalsIgnoreCase(dictSheet.get(0)[j])){
480 attribute.setPrefixListName(rows[j]);
482 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
483 attribute.setPrefixListValue(rows[j]);
485 if("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])){
486 attribute.setDescription(rows[j]);
489 commonClassDao.save(attribute);
492 if(dictionaryName.startsWith("SecurityZone")){
493 for(int i = 1; i< dictSheet.size(); i++){
494 SecurityZone attribute = new SecurityZone();
495 String[] rows = dictSheet.get(i);
496 for (int j=0 ; j<rows.length; j++ ){
497 if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){
498 attribute.setZoneName(rows[j]);
500 if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
501 attribute.setZoneValue(rows[j]);
504 commonClassDao.save(attribute);
507 if(dictionaryName.startsWith("Zone")){
508 for(int i = 1; i< dictSheet.size(); i++){
509 Zone attribute = new Zone();
510 String[] rows = dictSheet.get(i);
511 for (int j=0 ; j<rows.length; j++ ){
512 if("zoneName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Name".equalsIgnoreCase(dictSheet.get(0)[j])){
513 attribute.setZoneName(rows[j]);
515 if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
516 attribute.setZoneValue(rows[j]);
519 commonClassDao.save(attribute);
522 if(dictionaryName.startsWith("ServiceList")){
523 for(int i = 1; i< dictSheet.size(); i++){
524 ServiceList attribute = new ServiceList();
525 String[] rows = dictSheet.get(i);
526 for (int j=0 ; j<rows.length; j++ ){
527 if("serviceName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Name".equalsIgnoreCase(dictSheet.get(0)[j])){
528 attribute.setServiceName(rows[j]);
530 if("serviceDesc".equalsIgnoreCase(dictSheet.get(0)[j]) || DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
531 attribute.setServiceDescription(rows[j]);
533 if("serviceType".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service Type".equalsIgnoreCase(dictSheet.get(0)[j])){
534 attribute.setServiceType(rows[j]);
536 if("serviceTrasProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) || "Transport Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){
537 attribute.setServiceTransProtocol(rows[j]);
539 if("serviceAppProtocol".equalsIgnoreCase(dictSheet.get(0)[j]) || "APP Protocol".equalsIgnoreCase(dictSheet.get(0)[j])){
540 attribute.setServiceAppProtocol(rows[j]);
542 if("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j]) || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])){
543 attribute.setServicePorts(rows[j]);
546 commonClassDao.save(attribute);
549 if(dictionaryName.startsWith("ServiceGroup")){
550 for(int i = 1; i< dictSheet.size(); i++){
551 GroupServiceList attribute = new GroupServiceList();
552 String[] rows = dictSheet.get(i);
553 for (int j=0 ; j<rows.length; j++ ){
554 if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){
555 attribute.setGroupName(rows[j]);
557 if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){
558 attribute.setServiceList(rows[j]);
561 commonClassDao.save(attribute);
564 if(dictionaryName.startsWith("AddressGroup")){
565 for(int i = 1; i< dictSheet.size(); i++){
566 AddressGroup attribute = new AddressGroup();
567 String[] rows = dictSheet.get(i);
568 for (int j=0 ; j<rows.length; j++ ){
569 if("name".equalsIgnoreCase(dictSheet.get(0)[j]) || "Group Name".equalsIgnoreCase(dictSheet.get(0)[j])){
570 attribute.setGroupName(rows[j]);
572 if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Prefix List".equalsIgnoreCase(dictSheet.get(0)[j])){
573 attribute.setServiceList(rows[j]);
575 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
576 attribute.setDescription(rows[j]);
579 commonClassDao.save(attribute);
582 if(dictionaryName.startsWith("ProtocolList")){
583 for(int i = 1; i< dictSheet.size(); i++){
584 ProtocolList attribute = new ProtocolList();
585 String[] rows = dictSheet.get(i);
586 for (int j=0 ; j<rows.length; j++ ){
587 if("protocolName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Protocol Name".equalsIgnoreCase(dictSheet.get(0)[j])){
588 attribute.setProtocolName(rows[j]);
590 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
591 attribute.setDescription(rows[j]);
594 commonClassDao.save(attribute);
597 if(dictionaryName.startsWith("ActionList")){
598 for(int i = 1; i< dictSheet.size(); i++){
599 ActionList attribute = new ActionList();
600 String[] rows = dictSheet.get(i);
601 for (int j=0 ; j<rows.length; j++ ){
602 if("actionName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action Name".equalsIgnoreCase(dictSheet.get(0)[j])){
603 attribute.setActionName(rows[j]);
605 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
606 attribute.setDescription(rows[j]);
609 commonClassDao.save(attribute);
612 if(dictionaryName.startsWith("TermList")){
613 for(int i = 1; i< dictSheet.size(); i++){
614 TermList attribute = new TermList();
615 UserInfo userinfo = new UserInfo();
616 userinfo.setUserLoginId(userId);
617 attribute.setUserCreatedBy(userinfo);
618 attribute.setUserModifiedBy(userinfo);
619 String[] rows = dictSheet.get(i);
620 for (int j=0 ; j<rows.length; j++ ){
621 if("termName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Term-Name".equalsIgnoreCase(dictSheet.get(0)[j])){
622 attribute.setTermName(rows[j]);
624 if("Term-Description".equalsIgnoreCase(dictSheet.get(0)[j]) || "termDescription".equalsIgnoreCase(dictSheet.get(0)[j])){
625 attribute.setDescription(rows[j]);
627 if("fromZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "From Zone".equalsIgnoreCase(dictSheet.get(0)[j])){
628 attribute.setFromZones(rows[j]);
630 if("toZone".equalsIgnoreCase(dictSheet.get(0)[j]) || "To Zone".equalsIgnoreCase(dictSheet.get(0)[j])){
631 attribute.setToZones(rows[j]);
633 if("srcIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){
634 attribute.setSrcIPList(rows[j]);
636 if("destIPList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-IP-List".equalsIgnoreCase(dictSheet.get(0)[j])){
637 attribute.setDestIPList(rows[j]);
639 if("srcPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Source-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){
640 attribute.setSrcPortList(rows[j]);
642 if("destPortList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Destination-Port-List".equalsIgnoreCase(dictSheet.get(0)[j])){
643 attribute.setDestPortList(rows[j]);
645 if("action".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])){
646 attribute.setAction(rows[j]);
649 commonClassDao.save(attribute);
652 if(dictionaryName.startsWith("SearchCriteria")){
653 for(int i = 1; i< dictSheet.size(); i++){
654 DescriptiveScope attribute = new DescriptiveScope();
655 UserInfo userinfo = new UserInfo();
656 userinfo.setUserLoginId(userId);
657 attribute.setUserCreatedBy(userinfo);
658 attribute.setUserModifiedBy(userinfo);
659 String[] rows = dictSheet.get(i);
660 for (int j=0 ; j<rows.length; j++ ){
661 if("descriptiveScopeName".equalsIgnoreCase(dictSheet.get(0)[j]) || "Descriptive Scope Name".equalsIgnoreCase(dictSheet.get(0)[j])){
662 attribute.setScopeName(rows[j]);
664 if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
665 attribute.setDescription(rows[j]);
667 if("search".equalsIgnoreCase(dictSheet.get(0)[j]) || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])){
668 attribute.setSearch(rows[j]);
671 commonClassDao.save(attribute);
675 response.setStatus(HttpServletResponse.SC_OK);
676 response.getWriter().write("Success");
678 LOGGER.error("Exception Occured while importing dictionary"+e);
679 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
680 response.getWriter().write("Error");
682 if(file != null && file.exists()){
683 boolean deleted = file.delete();
684 LOGGER.error("Imported File has been deleted: "+deleted);
689 public boolean isValidDictionaryName(String dictionaryName){
691 String nameCheck = dictionaryName.replace(".csv", "");
693 DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
696 case ActionPolicyDictionary:
698 case MSPolicyDictionary:
701 case ClosedLoopService:
704 case VarbindDictionary:
705 case BRMSParamDictionary:
706 case BRMSControllerDictionary:
707 case BRMSDependencyDictionary:
724 LOGGER.error("Dictionary not exits: " +dictionaryName +e);