2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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;
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;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
36 import org.apache.commons.compress.utils.IOUtils;
37 import org.onap.policy.common.logging.flexlogger.FlexLogger;
38 import org.onap.policy.common.logging.flexlogger.Logger;
39 import org.onap.policy.rest.dao.CommonClassDao;
40 import org.onap.policy.rest.jpa.ActionList;
41 import org.onap.policy.rest.jpa.ActionPolicyDict;
42 import org.onap.policy.rest.jpa.AddressGroup;
43 import org.onap.policy.rest.jpa.Attribute;
44 import org.onap.policy.rest.jpa.BRMSController;
45 import org.onap.policy.rest.jpa.BRMSDependency;
46 import org.onap.policy.rest.jpa.BRMSParamTemplate;
47 import org.onap.policy.rest.jpa.Category;
48 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
49 import org.onap.policy.rest.jpa.ClosedLoopSite;
50 import org.onap.policy.rest.jpa.Datatype;
51 import org.onap.policy.rest.jpa.DecisionSettings;
52 import org.onap.policy.rest.jpa.DescriptiveScope;
53 import org.onap.policy.rest.jpa.GroupServiceList;
54 import org.onap.policy.rest.jpa.MicroServiceModels;
55 import org.onap.policy.rest.jpa.OnapName;
56 import org.onap.policy.rest.jpa.PEPOptions;
57 import org.onap.policy.rest.jpa.PrefixList;
58 import org.onap.policy.rest.jpa.ProtocolList;
59 import org.onap.policy.rest.jpa.SecurityZone;
60 import org.onap.policy.rest.jpa.ServiceList;
61 import org.onap.policy.rest.jpa.TermList;
62 import org.onap.policy.rest.jpa.UserInfo;
63 import org.onap.policy.rest.jpa.VNFType;
64 import org.onap.policy.rest.jpa.VSCLAction;
65 import org.onap.policy.rest.jpa.VarbindDictionary;
66 import org.onap.policy.rest.jpa.Zone;
67 import org.springframework.beans.factory.annotation.Autowired;
68 import org.springframework.stereotype.Controller;
69 import org.springframework.web.bind.annotation.RequestMapping;
71 import com.fasterxml.jackson.databind.DeserializationFeature;
72 import com.fasterxml.jackson.databind.ObjectMapper;
74 import au.com.bytecode.opencsv.CSVReader;
78 public class DictionaryImportController {
79 private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class);
81 private String newFile;
83 private static CommonClassDao commonClassDao;
84 private static final String DESCRIPTION= "description";
87 public DictionaryImportController(CommonClassDao commonClassDao){
88 DictionaryImportController.commonClassDao = commonClassDao;
91 public DictionaryImportController(){}
94 @RequestMapping(value={"/dictionary/import_dictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
95 public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{
96 ObjectMapper mapper = new ObjectMapper();
97 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
98 String userId = request.getParameter("userId");
99 String dictionaryName = request.getParameter("dictionaryName");
101 if(dictionaryName == null || dictionaryName.isEmpty()){
102 LOGGER.error("dictionaryName is null/empty");
103 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
104 response.getWriter().write("Error");
108 boolean dictionaryImportExists = false;
110 File file = new File(dictionaryName);
111 OutputStream outputStream = new FileOutputStream(file);
112 IOUtils.copy(request.getInputStream(), outputStream);
113 outputStream.close();
114 this.newFile = file.toString();
115 CSVReader csvReader = new CSVReader(new FileReader(this.newFile));
116 List<String[]> dictSheet = csvReader.readAll();
117 if(dictionaryName.startsWith("Attribute")){
118 dictionaryImportExists = true;
119 for(int i = 1; i< dictSheet.size(); i++){
120 Attribute attribute = new Attribute("");
121 UserInfo userinfo = new UserInfo();
122 userinfo.setUserLoginId(userId);
123 attribute.setUserCreatedBy(userinfo);
124 attribute.setUserModifiedBy(userinfo);
125 String[] rows = dictSheet.get(i);
126 for (int j=0 ; j<rows.length; j++ ){
127 if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute ID").equalsIgnoreCase(dictSheet.get(0)[j])){
128 attribute.setXacmlId(rows[j]);
130 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
131 attribute.setDescription(rows[j]);
133 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
134 attribute.setPriority(rows[j]);
136 if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){
137 Datatype dataType = new Datatype();
138 if(("string").equalsIgnoreCase(rows[j])){
140 }else if(("integer").equalsIgnoreCase(rows[j])){
142 }else if(("double").equalsIgnoreCase(rows[j])){
144 }else if(("boolean").equalsIgnoreCase(rows[j])){
146 }else if(("user").equalsIgnoreCase(rows[j])){
149 attribute.setDatatypeBean(dataType);
150 Category category = new Category();
152 attribute.setCategoryBean(category);
154 if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
155 attribute.setAttributeValue(rows[j]);
158 commonClassDao.save(attribute);
161 if(dictionaryName.startsWith("ActionPolicyDictionary")){
162 dictionaryImportExists = true;
163 for(int i = 1; i< dictSheet.size(); i++){
164 ActionPolicyDict attribute = new ActionPolicyDict("", userId);
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 dictionaryImportExists = true;
198 for(int i = 1; i< dictSheet.size(); i++){
199 OnapName attribute = new OnapName("", userId);
200 UserInfo userinfo = new UserInfo();
201 userinfo.setUserLoginId(userId);
202 attribute.setUserCreatedBy(userinfo);
203 attribute.setUserModifiedBy(userinfo);
204 String[] rows = dictSheet.get(i);
205 for (int j=0 ; j<rows.length; j++ ){
206 if(("onap_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Onap Name").equalsIgnoreCase(dictSheet.get(0)[j])){
207 attribute.setOnapName(rows[j]);
209 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
210 attribute.setDescription(rows[j]);
213 commonClassDao.save(attribute);
217 if(dictionaryName.startsWith("MSPolicyDictionary")){
218 dictionaryImportExists = true;
219 for(int i = 1; i< dictSheet.size(); i++){
220 MicroServiceModels attribute = new MicroServiceModels();
221 UserInfo userinfo = new UserInfo();
222 userinfo.setUserLoginId(userId);
223 attribute.setUserCreatedBy(userinfo);
224 String[] rows = dictSheet.get(i);
225 for (int j=0 ; j<rows.length; j++ ){
226 if(("modelName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Micro Service Model").equalsIgnoreCase(dictSheet.get(0)[j])){
227 attribute.setModelName(rows[j]);
229 if(("version").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Model Version").equalsIgnoreCase(dictSheet.get(0)[j])){
230 attribute.setVersion(rows[j]);
232 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
233 attribute.setDescription(rows[j]);
235 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
236 attribute.setDependency(rows[j]);
238 if(("attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
239 attribute.setAttributes(rows[j]);
241 if(("enumValues").equalsIgnoreCase(dictSheet.get(0)[j])){
242 attribute.setEnumValues(rows[j]);
244 if(("Ref Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
245 attribute.setRef_attributes(rows[j]);
247 if(("Sub Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
248 attribute.setSub_attributes(rows[j]);
252 commonClassDao.save(attribute);
256 if(dictionaryName.startsWith("VNFType")){
257 dictionaryImportExists = true;
258 for(int i = 1; i< dictSheet.size(); i++){
259 VNFType attribute = new VNFType("", userId);
260 UserInfo userinfo = new UserInfo();
261 userinfo.setUserLoginId(userId);
262 attribute.setUserCreatedBy(userinfo);
263 attribute.setUserModifiedBy(userinfo);
264 String[] rows = dictSheet.get(i);
265 for (int j=0 ; j<rows.length; j++ ){
266 if(("vnf_type").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VNF Type").equalsIgnoreCase(dictSheet.get(0)[j])){
267 attribute.setVnftype(rows[j]);
269 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
270 attribute.setDescription(rows[j]);
273 commonClassDao.save(attribute);
276 if(dictionaryName.startsWith("VSCLAction")){
277 dictionaryImportExists = true;
278 for(int i = 1; i< dictSheet.size(); i++){
279 VSCLAction attribute = new VSCLAction("", userId);
280 UserInfo userinfo = new UserInfo();
281 userinfo.setUserLoginId(userId);
282 attribute.setUserCreatedBy(userinfo);
283 attribute.setUserModifiedBy(userinfo);
284 String[] rows = dictSheet.get(i);
285 for (int j=0 ; j<rows.length; j++ ){
286 if(("vscl_action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VSCL Action").equalsIgnoreCase(dictSheet.get(0)[j])){
287 attribute.setVsclaction(rows[j]);
289 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
290 attribute.setDescription(rows[j]);
293 commonClassDao.save(attribute);
296 if(dictionaryName.startsWith("ClosedLoopService")){
297 dictionaryImportExists = true;
298 for(int i = 1; i< dictSheet.size(); i++){
299 ClosedLoopD2Services attribute = new ClosedLoopD2Services("", userId);
300 UserInfo userinfo = new UserInfo();
301 userinfo.setUserLoginId(userId);
302 attribute.setUserCreatedBy(userinfo);
303 attribute.setUserModifiedBy(userinfo);
304 String[] rows = dictSheet.get(i);
305 for (int j=0 ; j<rows.length; j++ ){
306 if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){
307 attribute.setServiceName(rows[j]);
309 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
310 attribute.setDescription(rows[j]);
313 commonClassDao.save(attribute);
316 if(dictionaryName.startsWith("ClosedLoopSite")){
317 dictionaryImportExists = true;
318 for(int i = 1; i< dictSheet.size(); i++){
319 ClosedLoopSite attribute = new ClosedLoopSite("", userId);
320 UserInfo userinfo = new UserInfo();
321 userinfo.setUserLoginId(userId);
322 attribute.setUserCreatedBy(userinfo);
323 attribute.setUserModifiedBy(userinfo);
324 String[] rows = dictSheet.get(i);
325 for (int j=0 ; j<rows.length; j++ ){
326 if(("siteName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Site Name").equalsIgnoreCase(dictSheet.get(0)[j])){
327 attribute.setSiteName(rows[j]);
329 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
330 attribute.setDescription(rows[j]);
333 commonClassDao.save(attribute);
336 if(dictionaryName.startsWith("PEPOptions")){
337 dictionaryImportExists = true;
338 for(int i = 1; i< dictSheet.size(); i++){
339 PEPOptions attribute = new PEPOptions("", userId);
340 UserInfo userinfo = new UserInfo();
341 userinfo.setUserLoginId(userId);
342 attribute.setUserCreatedBy(userinfo);
343 attribute.setUserModifiedBy(userinfo);
344 String[] rows = dictSheet.get(i);
345 for (int j=0 ; j<rows.length; j++ ){
346 if(("PEP_NAME").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PEP Name").equalsIgnoreCase(dictSheet.get(0)[j])){
347 attribute.setPepName(rows[j]);
349 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
350 attribute.setDescription(rows[j]);
352 if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){
353 attribute.setActions(rows[j]);
356 commonClassDao.save(attribute);
359 if(dictionaryName.startsWith("VarbindDictionary")){
360 dictionaryImportExists = true;
361 for(int i = 1; i< dictSheet.size(); i++){
362 VarbindDictionary attribute = new VarbindDictionary("", userId);
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(("varbind_Name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Name").equalsIgnoreCase(dictSheet.get(0)[j])){
370 attribute.setVarbindName(rows[j]);
372 if(("varbind_Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Description").equalsIgnoreCase(dictSheet.get(0)[j])){
373 attribute.setVarbindDescription(rows[j]);
375 if(("varbind_oid").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind OID").equalsIgnoreCase(dictSheet.get(0)[j])){
376 attribute.setVarbindOID(rows[j]);
379 commonClassDao.save(attribute);
382 if(dictionaryName.startsWith("BRMSParamDictionary")){
383 dictionaryImportExists = true;
384 for(int i = 1; i< dictSheet.size(); i++){
385 BRMSParamTemplate attribute = new BRMSParamTemplate();
386 UserInfo userinfo = new UserInfo();
387 userinfo.setUserLoginId(userId);
388 attribute.setUserCreatedBy(userinfo);
389 String[] rows = dictSheet.get(i);
390 for (int j=0 ; j<rows.length; j++ ){
391 if(("param_template_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Rule Name").equalsIgnoreCase(dictSheet.get(0)[j])){
392 attribute.setRuleName(rows[j]);
394 if(("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
395 attribute.setDescription(rows[j]);
397 if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){
398 attribute.setRule(rows[j]);
401 commonClassDao.save(attribute);
404 if(dictionaryName.startsWith("BRMSControllerDictionary")){
405 dictionaryImportExists = true;
406 for(int i = 1; i< dictSheet.size(); i++){
407 BRMSController attribute = new BRMSController();
408 UserInfo userinfo = new UserInfo();
409 userinfo.setUserLoginId(userId);
410 attribute.setUserCreatedBy(userinfo);
411 String[] rows = dictSheet.get(i);
412 for (int j=0 ; j<rows.length; j++ ){
413 if(("controllerName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Controller Name").equalsIgnoreCase(dictSheet.get(0)[j])){
414 attribute.setControllerName(rows[j]);
416 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
417 attribute.setDescription(rows[j]);
419 if(("controller").equalsIgnoreCase(dictSheet.get(0)[j])){
420 attribute.setController(rows[j]);
423 commonClassDao.save(attribute);
426 if(dictionaryName.startsWith("BRMSDependencyDictionary")){
427 dictionaryImportExists = true;
428 for(int i = 1; i< dictSheet.size(); i++){
429 BRMSDependency attribute = new BRMSDependency();
430 UserInfo userinfo = new UserInfo();
431 userinfo.setUserLoginId(userId);
432 attribute.setUserCreatedBy(userinfo);
433 String[] rows = dictSheet.get(i);
434 for (int j=0 ; j<rows.length; j++ ){
435 if(("dependencyName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Dependency Name").equalsIgnoreCase(dictSheet.get(0)[j])){
436 attribute.setDependencyName(rows[j]);
438 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
439 attribute.setDescription(rows[j]);
441 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
442 attribute.setDependency(rows[j]);
445 commonClassDao.save(attribute);
448 if(dictionaryName.startsWith("Settings")){
449 dictionaryImportExists = true;
450 for(int i = 1; i< dictSheet.size(); i++){
451 DecisionSettings attribute = new DecisionSettings("", userId);
452 UserInfo userinfo = new UserInfo();
453 userinfo.setUserLoginId(userId);
454 attribute.setUserCreatedBy(userinfo);
455 attribute.setUserModifiedBy(userinfo);
456 String[] rows = dictSheet.get(i);
457 for (int j=0 ; j<rows.length; j++ ){
458 if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Settings ID").equalsIgnoreCase(dictSheet.get(0)[j])){
459 attribute.setXacmlId(rows[j]);
461 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
462 attribute.setDescription(rows[j]);
464 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
465 attribute.setPriority(rows[j]);
467 if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){
468 Datatype dataType = new Datatype();
469 if(("string").equalsIgnoreCase(rows[j])){
471 }else if(("integer").equalsIgnoreCase(rows[j])){
473 }else if(("double").equalsIgnoreCase(rows[j])){
475 }else if(("boolean").equalsIgnoreCase(rows[j])){
477 }else if(("user").equalsIgnoreCase(rows[j])){
480 attribute.setDatatypeBean(dataType);
483 commonClassDao.save(attribute);
486 if(dictionaryName.startsWith("PrefixList")){
487 dictionaryImportExists = true;
488 for(int i = 1; i< dictSheet.size(); i++){
489 PrefixList attribute = new PrefixList("", userId);
490 String[] rows = dictSheet.get(i);
491 for (int j=0 ; j<rows.length; j++ ){
492 if(("prefixListName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Name").equalsIgnoreCase(dictSheet.get(0)[j])){
493 attribute.setPrefixListName(rows[j]);
495 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
496 attribute.setPrefixListValue(rows[j]);
498 if(("prefixListValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Value").equalsIgnoreCase(dictSheet.get(0)[j])){
499 attribute.setDescription(rows[j]);
502 commonClassDao.save(attribute);
505 if(dictionaryName.startsWith("SecurityZone")){
506 dictionaryImportExists = true;
507 for(int i = 1; i< dictSheet.size(); i++){
508 SecurityZone attribute = new SecurityZone("", userId);
509 String[] rows = dictSheet.get(i);
510 for (int j=0 ; j<rows.length; j++ ){
511 if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){
512 attribute.setZoneName(rows[j]);
514 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
515 attribute.setZoneValue(rows[j]);
518 commonClassDao.save(attribute);
521 if(dictionaryName.startsWith("Zone")){
522 dictionaryImportExists = true;
523 for(int i = 1; i< dictSheet.size(); i++){
524 Zone attribute = new Zone("", userId);
525 String[] rows = dictSheet.get(i);
526 for (int j=0 ; j<rows.length; j++ ){
527 if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){
528 attribute.setZoneName(rows[j]);
530 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
531 attribute.setZoneValue(rows[j]);
534 commonClassDao.save(attribute);
537 if(dictionaryName.startsWith("ServiceList")){
538 dictionaryImportExists = true;
539 for(int i = 1; i< dictSheet.size(); i++){
540 ServiceList attribute = new ServiceList("", userId);
541 String[] rows = dictSheet.get(i);
542 for (int j=0 ; j<rows.length; j++ ){
543 if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){
544 attribute.setServiceName(rows[j]);
546 if(("serviceDesc").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
547 attribute.setServiceDescription(rows[j]);
549 if(("serviceType").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Type").equalsIgnoreCase(dictSheet.get(0)[j])){
550 attribute.setServiceType(rows[j]);
552 if(("serviceTrasProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Transport Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
553 attribute.setServiceTransProtocol(rows[j]);
555 if(("serviceAppProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("APP Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
556 attribute.setServiceAppProtocol(rows[j]);
558 if(("servicePorts").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Ports").equalsIgnoreCase(dictSheet.get(0)[j])){
559 attribute.setServicePorts(rows[j]);
562 commonClassDao.save(attribute);
565 if(dictionaryName.startsWith("ServiceGroup")){
566 dictionaryImportExists = true;
567 for(int i = 1; i< dictSheet.size(); i++){
568 GroupServiceList attribute = new GroupServiceList("", userId);
569 String[] rows = dictSheet.get(i);
570 for (int j=0 ; j<rows.length; j++ ){
571 if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){
572 attribute.setGroupName(rows[j]);
574 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service List").equalsIgnoreCase(dictSheet.get(0)[j])){
575 attribute.setServiceList(rows[j]);
578 commonClassDao.save(attribute);
581 if(dictionaryName.startsWith("AddressGroup")){
582 dictionaryImportExists = true;
583 for(int i = 1; i< dictSheet.size(); i++){
584 AddressGroup attribute = new AddressGroup("", userId);
585 String[] rows = dictSheet.get(i);
586 for (int j=0 ; j<rows.length; j++ ){
587 if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){
588 attribute.setGroupName(rows[j]);
590 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Prefix List").equalsIgnoreCase(dictSheet.get(0)[j])){
591 attribute.setServiceList(rows[j]);
593 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
594 attribute.setDescription(rows[j]);
597 commonClassDao.save(attribute);
600 if(dictionaryName.startsWith("ProtocolList")){
601 dictionaryImportExists = true;
602 for(int i = 1; i< dictSheet.size(); i++){
603 ProtocolList attribute = new ProtocolList("", userId);
604 String[] rows = dictSheet.get(i);
605 for (int j=0 ; j<rows.length; j++ ){
606 if(("protocolName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Protocol Name").equalsIgnoreCase(dictSheet.get(0)[j])){
607 attribute.setProtocolName(rows[j]);
609 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
610 attribute.setDescription(rows[j]);
613 commonClassDao.save(attribute);
616 if(dictionaryName.startsWith("ActionList")){
617 dictionaryImportExists = true;
618 for(int i = 1; i< dictSheet.size(); i++){
619 ActionList attribute = new ActionList("", userId);
620 String[] rows = dictSheet.get(i);
621 for (int j=0 ; j<rows.length; j++ ){
622 if(("actionName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action Name").equalsIgnoreCase(dictSheet.get(0)[j])){
623 attribute.setActionName(rows[j]);
625 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
626 attribute.setDescription(rows[j]);
629 commonClassDao.save(attribute);
632 if(dictionaryName.startsWith("TermList")){
633 dictionaryImportExists = true;
634 for(int i = 1; i< dictSheet.size(); i++){
635 TermList attribute = new TermList("", userId);
636 UserInfo userinfo = new UserInfo();
637 userinfo.setUserLoginId(userId);
638 attribute.setUserCreatedBy(userinfo);
639 attribute.setUserModifiedBy(userinfo);
640 String[] rows = dictSheet.get(i);
641 for (int j=0 ; j<rows.length; j++ ){
642 if(("termName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Term-Name").equalsIgnoreCase(dictSheet.get(0)[j])){
643 attribute.setTermName(rows[j]);
645 if(("Term-Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("termDescription").equalsIgnoreCase(dictSheet.get(0)[j])){
646 attribute.setDescription(rows[j]);
648 if(("fromZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("From Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
649 attribute.setFromZones(rows[j]);
651 if(("toZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("To Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
652 attribute.setToZones(rows[j]);
654 if(("srcIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
655 attribute.setSrcIPList(rows[j]);
657 if(("destIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
658 attribute.setDestIPList(rows[j]);
660 if(("srcPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
661 attribute.setSrcPortList(rows[j]);
663 if(("destPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
664 attribute.setDestPortList(rows[j]);
666 if(("action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action List").equalsIgnoreCase(dictSheet.get(0)[j])){
667 attribute.setAction(rows[j]);
670 commonClassDao.save(attribute);
673 if(dictionaryName.startsWith("SearchCriteria")){
674 dictionaryImportExists = true;
675 for(int i = 1; i< dictSheet.size(); i++){
676 DescriptiveScope attribute = new DescriptiveScope("", userId);
677 UserInfo userinfo = new UserInfo();
678 userinfo.setUserLoginId(userId);
679 attribute.setUserCreatedBy(userinfo);
680 attribute.setUserModifiedBy(userinfo);
681 String[] rows = dictSheet.get(i);
682 for (int j=0 ; j<rows.length; j++ ){
683 if(("descriptiveScopeName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Descriptive Scope Name").equalsIgnoreCase(dictSheet.get(0)[j])){
684 attribute.setScopeName(rows[j]);
686 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
687 attribute.setDescription(rows[j]);
689 if(("search").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Search Criteria").equalsIgnoreCase(dictSheet.get(0)[j])){
690 attribute.setSearch(rows[j]);
693 commonClassDao.save(attribute);
700 if(!dictionaryImportExists){
701 response.setStatus(HttpServletResponse.SC_OK);
702 response.getWriter().write("Dictionary Import failed. Hence the following dictionary doen't support import function : "+ dictionaryName);
704 response.setStatus(HttpServletResponse.SC_OK);
705 response.getWriter().write("Success");
708 LOGGER.error("Exception Occured while importing dictionary"+e);
709 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
710 response.getWriter().write("Error");