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;
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.pap.xacml.rest.DisctionaryNames;
40 import org.onap.policy.rest.dao.CommonClassDao;
41 import org.onap.policy.rest.jpa.ActionList;
42 import org.onap.policy.rest.jpa.ActionPolicyDict;
43 import org.onap.policy.rest.jpa.AddressGroup;
44 import org.onap.policy.rest.jpa.Attribute;
45 import org.onap.policy.rest.jpa.BRMSController;
46 import org.onap.policy.rest.jpa.BRMSDependency;
47 import org.onap.policy.rest.jpa.BRMSParamTemplate;
48 import org.onap.policy.rest.jpa.Category;
49 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
50 import org.onap.policy.rest.jpa.ClosedLoopSite;
51 import org.onap.policy.rest.jpa.Datatype;
52 import org.onap.policy.rest.jpa.DecisionSettings;
53 import org.onap.policy.rest.jpa.DescriptiveScope;
54 import org.onap.policy.rest.jpa.GroupServiceList;
55 import org.onap.policy.rest.jpa.MicroServiceModels;
56 import org.onap.policy.rest.jpa.OnapName;
57 import org.onap.policy.rest.jpa.PEPOptions;
58 import org.onap.policy.rest.jpa.PrefixList;
59 import org.onap.policy.rest.jpa.ProtocolList;
60 import org.onap.policy.rest.jpa.SecurityZone;
61 import org.onap.policy.rest.jpa.ServiceList;
62 import org.onap.policy.rest.jpa.TermList;
63 import org.onap.policy.rest.jpa.UserInfo;
64 import org.onap.policy.rest.jpa.VNFType;
65 import org.onap.policy.rest.jpa.VSCLAction;
66 import org.onap.policy.rest.jpa.VarbindDictionary;
67 import org.onap.policy.rest.jpa.Zone;
68 import org.springframework.beans.factory.annotation.Autowired;
69 import org.springframework.stereotype.Controller;
70 import org.springframework.web.bind.annotation.RequestMapping;
72 import com.fasterxml.jackson.databind.DeserializationFeature;
73 import com.fasterxml.jackson.databind.ObjectMapper;
75 import au.com.bytecode.opencsv.CSVReader;
79 public class DictionaryImportController {
80 private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class);
82 private String newFile;
84 private static CommonClassDao commonClassDao;
85 private static final String DESCRIPTION= "description";
88 public DictionaryImportController(CommonClassDao commonClassDao){
89 DictionaryImportController.commonClassDao = commonClassDao;
92 public DictionaryImportController(){}
95 @RequestMapping(value={"/dictionary/import_dictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
96 public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{
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");
117 boolean dictionaryImportExists = false;
119 File file = new File(dictionaryName);
120 OutputStream outputStream = new FileOutputStream(file);
121 IOUtils.copy(request.getInputStream(), outputStream);
122 outputStream.close();
123 this.newFile = file.toString();
124 CSVReader csvReader = new CSVReader(new FileReader(this.newFile));
125 List<String[]> dictSheet = csvReader.readAll();
126 if(dictionaryName.startsWith("Attribute")){
127 dictionaryImportExists = true;
128 for(int i = 1; i< dictSheet.size(); i++){
129 Attribute attribute = new Attribute("");
130 UserInfo userinfo = new UserInfo();
131 userinfo.setUserLoginId(userId);
132 attribute.setUserCreatedBy(userinfo);
133 attribute.setUserModifiedBy(userinfo);
134 String[] rows = dictSheet.get(i);
135 for (int j=0 ; j<rows.length; j++ ){
136 if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute ID").equalsIgnoreCase(dictSheet.get(0)[j])){
137 attribute.setXacmlId(rows[j]);
139 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
140 attribute.setDescription(rows[j]);
142 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
143 attribute.setPriority(rows[j]);
145 if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){
146 Datatype dataType = new Datatype();
147 if(("string").equalsIgnoreCase(rows[j])){
149 }else if(("integer").equalsIgnoreCase(rows[j])){
151 }else if(("double").equalsIgnoreCase(rows[j])){
153 }else if(("boolean").equalsIgnoreCase(rows[j])){
155 }else if(("user").equalsIgnoreCase(rows[j])){
158 attribute.setDatatypeBean(dataType);
159 Category category = new Category();
161 attribute.setCategoryBean(category);
163 if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
164 attribute.setAttributeValue(rows[j]);
167 commonClassDao.save(attribute);
170 if(dictionaryName.startsWith("ActionPolicyDictionary")){
171 dictionaryImportExists = true;
172 for(int i = 1; i< dictSheet.size(); i++){
173 ActionPolicyDict attribute = new ActionPolicyDict();
174 UserInfo userinfo = new UserInfo();
175 userinfo.setUserLoginId(userId);
176 attribute.setUserCreatedBy(userinfo);
177 attribute.setUserModifiedBy(userinfo);
178 String[] rows = dictSheet.get(i);
179 for (int j=0 ; j<rows.length; j++ ){
180 if(("attribute_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Name").equalsIgnoreCase(dictSheet.get(0)[j])){
181 attribute.setAttributeName(rows[j]);
183 if(("body").equalsIgnoreCase(dictSheet.get(0)[j])){
184 attribute.setBody(rows[j]);
186 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
187 attribute.setDescription(rows[j]);
189 if(("headers").equalsIgnoreCase(dictSheet.get(0)[j])){
190 attribute.setHeader(rows[j]);
192 if(("method").equalsIgnoreCase(dictSheet.get(0)[j])){
193 attribute.setMethod(rows[j]);
195 if(("type").equalsIgnoreCase(dictSheet.get(0)[j])){
196 attribute.setType(rows[j]);
198 if(("url").equalsIgnoreCase(dictSheet.get(0)[j])){
199 attribute.setUrl(rows[j]);
202 commonClassDao.save(attribute);
205 if(dictionaryName.startsWith("OnapName")){
206 dictionaryImportExists = true;
207 for(int i = 1; i< dictSheet.size(); i++){
208 OnapName attribute = new OnapName();
209 UserInfo userinfo = new UserInfo();
210 userinfo.setUserLoginId(userId);
211 attribute.setUserCreatedBy(userinfo);
212 attribute.setUserModifiedBy(userinfo);
213 String[] rows = dictSheet.get(i);
214 for (int j=0 ; j<rows.length; j++ ){
215 if(("onap_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Onap Name").equalsIgnoreCase(dictSheet.get(0)[j])){
216 attribute.setOnapName(rows[j]);
218 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
219 attribute.setDescription(rows[j]);
222 commonClassDao.save(attribute);
226 if(dictionaryName.startsWith("MSPolicyDictionary")){
227 dictionaryImportExists = true;
228 for(int i = 1; i< dictSheet.size(); i++){
229 MicroServiceModels attribute = new MicroServiceModels();
230 UserInfo userinfo = new UserInfo();
231 userinfo.setUserLoginId(userId);
232 attribute.setUserCreatedBy(userinfo);
233 String[] rows = dictSheet.get(i);
234 for (int j=0 ; j<rows.length; j++ ){
235 if(("modelName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Micro Service Model").equalsIgnoreCase(dictSheet.get(0)[j])){
236 attribute.setModelName(rows[j]);
238 if(("version").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Model Version").equalsIgnoreCase(dictSheet.get(0)[j])){
239 attribute.setVersion(rows[j]);
241 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
242 attribute.setDescription(rows[j]);
244 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
245 attribute.setDependency(rows[j]);
247 if(("attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
248 attribute.setAttributes(rows[j]);
250 if(("enumValues").equalsIgnoreCase(dictSheet.get(0)[j])){
251 attribute.setEnumValues(rows[j]);
253 if(("Ref Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
254 attribute.setRef_attributes(rows[j]);
256 if(("Sub Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
257 attribute.setSub_attributes(rows[j]);
261 commonClassDao.save(attribute);
265 if(dictionaryName.startsWith("VNFType")){
266 dictionaryImportExists = true;
267 for(int i = 1; i< dictSheet.size(); i++){
268 VNFType attribute = new VNFType();
269 UserInfo userinfo = new UserInfo();
270 userinfo.setUserLoginId(userId);
271 attribute.setUserCreatedBy(userinfo);
272 attribute.setUserModifiedBy(userinfo);
273 String[] rows = dictSheet.get(i);
274 for (int j=0 ; j<rows.length; j++ ){
275 if(("vnf_type").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VNF Type").equalsIgnoreCase(dictSheet.get(0)[j])){
276 attribute.setVnftype(rows[j]);
278 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
279 attribute.setDescription(rows[j]);
282 commonClassDao.save(attribute);
285 if(dictionaryName.startsWith("VSCLAction")){
286 dictionaryImportExists = true;
287 for(int i = 1; i< dictSheet.size(); i++){
288 VSCLAction attribute = new VSCLAction();
289 UserInfo userinfo = new UserInfo();
290 userinfo.setUserLoginId(userId);
291 attribute.setUserCreatedBy(userinfo);
292 attribute.setUserModifiedBy(userinfo);
293 String[] rows = dictSheet.get(i);
294 for (int j=0 ; j<rows.length; j++ ){
295 if(("vscl_action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VSCL Action").equalsIgnoreCase(dictSheet.get(0)[j])){
296 attribute.setVsclaction(rows[j]);
298 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
299 attribute.setDescription(rows[j]);
302 commonClassDao.save(attribute);
305 if(dictionaryName.startsWith("ClosedLoopService")){
306 dictionaryImportExists = true;
307 for(int i = 1; i< dictSheet.size(); i++){
308 ClosedLoopD2Services attribute = new ClosedLoopD2Services();
309 UserInfo userinfo = new UserInfo();
310 userinfo.setUserLoginId(userId);
311 attribute.setUserCreatedBy(userinfo);
312 attribute.setUserModifiedBy(userinfo);
313 String[] rows = dictSheet.get(i);
314 for (int j=0 ; j<rows.length; j++ ){
315 if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){
316 attribute.setServiceName(rows[j]);
318 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
319 attribute.setDescription(rows[j]);
322 commonClassDao.save(attribute);
325 if(dictionaryName.startsWith("ClosedLoopSite")){
326 dictionaryImportExists = true;
327 for(int i = 1; i< dictSheet.size(); i++){
328 ClosedLoopSite attribute = new ClosedLoopSite();
329 UserInfo userinfo = new UserInfo();
330 userinfo.setUserLoginId(userId);
331 attribute.setUserCreatedBy(userinfo);
332 attribute.setUserModifiedBy(userinfo);
333 String[] rows = dictSheet.get(i);
334 for (int j=0 ; j<rows.length; j++ ){
335 if(("siteName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Site Name").equalsIgnoreCase(dictSheet.get(0)[j])){
336 attribute.setSiteName(rows[j]);
338 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
339 attribute.setDescription(rows[j]);
342 commonClassDao.save(attribute);
345 if(dictionaryName.startsWith("PEPOptions")){
346 dictionaryImportExists = true;
347 for(int i = 1; i< dictSheet.size(); i++){
348 PEPOptions attribute = new PEPOptions();
349 UserInfo userinfo = new UserInfo();
350 userinfo.setUserLoginId(userId);
351 attribute.setUserCreatedBy(userinfo);
352 attribute.setUserModifiedBy(userinfo);
353 String[] rows = dictSheet.get(i);
354 for (int j=0 ; j<rows.length; j++ ){
355 if(("PEP_NAME").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PEP Name").equalsIgnoreCase(dictSheet.get(0)[j])){
356 attribute.setPepName(rows[j]);
358 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
359 attribute.setDescription(rows[j]);
361 if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){
362 attribute.setActions(rows[j]);
365 commonClassDao.save(attribute);
368 if(dictionaryName.startsWith("VarbindDictionary")){
369 dictionaryImportExists = true;
370 for(int i = 1; i< dictSheet.size(); i++){
371 VarbindDictionary attribute = new VarbindDictionary();
372 UserInfo userinfo = new UserInfo();
373 userinfo.setUserLoginId(userId);
374 attribute.setUserCreatedBy(userinfo);
375 attribute.setUserModifiedBy(userinfo);
376 String[] rows = dictSheet.get(i);
377 for (int j=0 ; j<rows.length; j++ ){
378 if(("varbind_Name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Name").equalsIgnoreCase(dictSheet.get(0)[j])){
379 attribute.setVarbindName(rows[j]);
381 if(("varbind_Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Description").equalsIgnoreCase(dictSheet.get(0)[j])){
382 attribute.setVarbindDescription(rows[j]);
384 if(("varbind_oid").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind OID").equalsIgnoreCase(dictSheet.get(0)[j])){
385 attribute.setVarbindOID(rows[j]);
388 commonClassDao.save(attribute);
391 if(dictionaryName.startsWith("BRMSParamDictionary")){
392 dictionaryImportExists = true;
393 for(int i = 1; i< dictSheet.size(); i++){
394 BRMSParamTemplate attribute = new BRMSParamTemplate();
395 UserInfo userinfo = new UserInfo();
396 userinfo.setUserLoginId(userId);
397 attribute.setUserCreatedBy(userinfo);
398 String[] rows = dictSheet.get(i);
399 for (int j=0 ; j<rows.length; j++ ){
400 if(("param_template_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Rule Name").equalsIgnoreCase(dictSheet.get(0)[j])){
401 attribute.setRuleName(rows[j]);
403 if(("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
404 attribute.setDescription(rows[j]);
406 if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){
407 attribute.setRule(rows[j]);
410 commonClassDao.save(attribute);
413 if(dictionaryName.startsWith("BRMSControllerDictionary")){
414 dictionaryImportExists = true;
415 for(int i = 1; i< dictSheet.size(); i++){
416 BRMSController attribute = new BRMSController();
417 UserInfo userinfo = new UserInfo();
418 userinfo.setUserLoginId(userId);
419 attribute.setUserCreatedBy(userinfo);
420 String[] rows = dictSheet.get(i);
421 for (int j=0 ; j<rows.length; j++ ){
422 if(("controllerName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Controller Name").equalsIgnoreCase(dictSheet.get(0)[j])){
423 attribute.setControllerName(rows[j]);
425 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
426 attribute.setDescription(rows[j]);
428 if(("controller").equalsIgnoreCase(dictSheet.get(0)[j])){
429 attribute.setController(rows[j]);
432 commonClassDao.save(attribute);
435 if(dictionaryName.startsWith("BRMSDependencyDictionary")){
436 dictionaryImportExists = true;
437 for(int i = 1; i< dictSheet.size(); i++){
438 BRMSDependency attribute = new BRMSDependency();
439 UserInfo userinfo = new UserInfo();
440 userinfo.setUserLoginId(userId);
441 attribute.setUserCreatedBy(userinfo);
442 String[] rows = dictSheet.get(i);
443 for (int j=0 ; j<rows.length; j++ ){
444 if(("dependencyName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Dependency Name").equalsIgnoreCase(dictSheet.get(0)[j])){
445 attribute.setDependencyName(rows[j]);
447 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
448 attribute.setDescription(rows[j]);
450 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
451 attribute.setDependency(rows[j]);
454 commonClassDao.save(attribute);
457 if(dictionaryName.startsWith("Settings")){
458 dictionaryImportExists = true;
459 for(int i = 1; i< dictSheet.size(); i++){
460 DecisionSettings attribute = new DecisionSettings();
461 UserInfo userinfo = new UserInfo();
462 userinfo.setUserLoginId(userId);
463 attribute.setUserCreatedBy(userinfo);
464 attribute.setUserModifiedBy(userinfo);
465 String[] rows = dictSheet.get(i);
466 for (int j=0 ; j<rows.length; j++ ){
467 if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Settings ID").equalsIgnoreCase(dictSheet.get(0)[j])){
468 attribute.setXacmlId(rows[j]);
470 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
471 attribute.setDescription(rows[j]);
473 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
474 attribute.setPriority(rows[j]);
476 if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){
477 Datatype dataType = new Datatype();
478 if(("string").equalsIgnoreCase(rows[j])){
480 }else if(("integer").equalsIgnoreCase(rows[j])){
482 }else if(("double").equalsIgnoreCase(rows[j])){
484 }else if(("boolean").equalsIgnoreCase(rows[j])){
486 }else if(("user").equalsIgnoreCase(rows[j])){
489 attribute.setDatatypeBean(dataType);
492 commonClassDao.save(attribute);
495 if(dictionaryName.startsWith("PrefixList")){
496 dictionaryImportExists = true;
497 for(int i = 1; i< dictSheet.size(); i++){
498 PrefixList attribute = new PrefixList();
499 String[] rows = dictSheet.get(i);
500 for (int j=0 ; j<rows.length; j++ ){
501 if(("prefixListName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Name").equalsIgnoreCase(dictSheet.get(0)[j])){
502 attribute.setPrefixListName(rows[j]);
504 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
505 attribute.setPrefixListValue(rows[j]);
507 if(("prefixListValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Value").equalsIgnoreCase(dictSheet.get(0)[j])){
508 attribute.setDescription(rows[j]);
511 commonClassDao.save(attribute);
514 if(dictionaryName.startsWith("SecurityZone")){
515 dictionaryImportExists = true;
516 for(int i = 1; i< dictSheet.size(); i++){
517 SecurityZone attribute = new SecurityZone();
518 String[] rows = dictSheet.get(i);
519 for (int j=0 ; j<rows.length; j++ ){
520 if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){
521 attribute.setZoneName(rows[j]);
523 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
524 attribute.setZoneValue(rows[j]);
527 commonClassDao.save(attribute);
530 if(dictionaryName.startsWith("Zone")){
531 dictionaryImportExists = true;
532 for(int i = 1; i< dictSheet.size(); i++){
533 Zone attribute = new Zone();
534 String[] rows = dictSheet.get(i);
535 for (int j=0 ; j<rows.length; j++ ){
536 if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){
537 attribute.setZoneName(rows[j]);
539 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
540 attribute.setZoneValue(rows[j]);
543 commonClassDao.save(attribute);
546 if(dictionaryName.startsWith("ServiceList")){
547 dictionaryImportExists = true;
548 for(int i = 1; i< dictSheet.size(); i++){
549 ServiceList attribute = new ServiceList();
550 String[] rows = dictSheet.get(i);
551 for (int j=0 ; j<rows.length; j++ ){
552 if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){
553 attribute.setServiceName(rows[j]);
555 if(("serviceDesc").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
556 attribute.setServiceDescription(rows[j]);
558 if(("serviceType").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Type").equalsIgnoreCase(dictSheet.get(0)[j])){
559 attribute.setServiceType(rows[j]);
561 if(("serviceTrasProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Transport Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
562 attribute.setServiceTransProtocol(rows[j]);
564 if(("serviceAppProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("APP Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
565 attribute.setServiceAppProtocol(rows[j]);
567 if(("servicePorts").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Ports").equalsIgnoreCase(dictSheet.get(0)[j])){
568 attribute.setServicePorts(rows[j]);
571 commonClassDao.save(attribute);
574 if(dictionaryName.startsWith("ServiceGroup")){
575 dictionaryImportExists = true;
576 for(int i = 1; i< dictSheet.size(); i++){
577 GroupServiceList attribute = new GroupServiceList();
578 String[] rows = dictSheet.get(i);
579 for (int j=0 ; j<rows.length; j++ ){
580 if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){
581 attribute.setGroupName(rows[j]);
583 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service List").equalsIgnoreCase(dictSheet.get(0)[j])){
584 attribute.setServiceList(rows[j]);
587 commonClassDao.save(attribute);
590 if(dictionaryName.startsWith("AddressGroup")){
591 dictionaryImportExists = true;
592 for(int i = 1; i< dictSheet.size(); i++){
593 AddressGroup attribute = new AddressGroup();
594 String[] rows = dictSheet.get(i);
595 for (int j=0 ; j<rows.length; j++ ){
596 if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){
597 attribute.setGroupName(rows[j]);
599 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Prefix List").equalsIgnoreCase(dictSheet.get(0)[j])){
600 attribute.setServiceList(rows[j]);
602 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
603 attribute.setDescription(rows[j]);
606 commonClassDao.save(attribute);
609 if(dictionaryName.startsWith("ProtocolList")){
610 dictionaryImportExists = true;
611 for(int i = 1; i< dictSheet.size(); i++){
612 ProtocolList attribute = new ProtocolList();
613 String[] rows = dictSheet.get(i);
614 for (int j=0 ; j<rows.length; j++ ){
615 if(("protocolName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Protocol Name").equalsIgnoreCase(dictSheet.get(0)[j])){
616 attribute.setProtocolName(rows[j]);
618 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
619 attribute.setDescription(rows[j]);
622 commonClassDao.save(attribute);
625 if(dictionaryName.startsWith("ActionList")){
626 dictionaryImportExists = true;
627 for(int i = 1; i< dictSheet.size(); i++){
628 ActionList attribute = new ActionList();
629 String[] rows = dictSheet.get(i);
630 for (int j=0 ; j<rows.length; j++ ){
631 if(("actionName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action Name").equalsIgnoreCase(dictSheet.get(0)[j])){
632 attribute.setActionName(rows[j]);
634 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
635 attribute.setDescription(rows[j]);
638 commonClassDao.save(attribute);
641 if(dictionaryName.startsWith("TermList")){
642 dictionaryImportExists = true;
643 for(int i = 1; i< dictSheet.size(); i++){
644 TermList attribute = new TermList();
645 UserInfo userinfo = new UserInfo();
646 userinfo.setUserLoginId(userId);
647 attribute.setUserCreatedBy(userinfo);
648 attribute.setUserModifiedBy(userinfo);
649 String[] rows = dictSheet.get(i);
650 for (int j=0 ; j<rows.length; j++ ){
651 if(("termName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Term-Name").equalsIgnoreCase(dictSheet.get(0)[j])){
652 attribute.setTermName(rows[j]);
654 if(("Term-Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("termDescription").equalsIgnoreCase(dictSheet.get(0)[j])){
655 attribute.setDescription(rows[j]);
657 if(("fromZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("From Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
658 attribute.setFromZones(rows[j]);
660 if(("toZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("To Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
661 attribute.setToZones(rows[j]);
663 if(("srcIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
664 attribute.setSrcIPList(rows[j]);
666 if(("destIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
667 attribute.setDestIPList(rows[j]);
669 if(("srcPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
670 attribute.setSrcPortList(rows[j]);
672 if(("destPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
673 attribute.setDestPortList(rows[j]);
675 if(("action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action List").equalsIgnoreCase(dictSheet.get(0)[j])){
676 attribute.setAction(rows[j]);
679 commonClassDao.save(attribute);
682 if(dictionaryName.startsWith("SearchCriteria")){
683 dictionaryImportExists = true;
684 for(int i = 1; i< dictSheet.size(); i++){
685 DescriptiveScope attribute = new DescriptiveScope();
686 UserInfo userinfo = new UserInfo();
687 userinfo.setUserLoginId(userId);
688 attribute.setUserCreatedBy(userinfo);
689 attribute.setUserModifiedBy(userinfo);
690 String[] rows = dictSheet.get(i);
691 for (int j=0 ; j<rows.length; j++ ){
692 if(("descriptiveScopeName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Descriptive Scope Name").equalsIgnoreCase(dictSheet.get(0)[j])){
693 attribute.setScopeName(rows[j]);
695 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
696 attribute.setDescription(rows[j]);
698 if(("search").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Search Criteria").equalsIgnoreCase(dictSheet.get(0)[j])){
699 attribute.setSearch(rows[j]);
702 commonClassDao.save(attribute);
709 if(!dictionaryImportExists){
710 response.setStatus(HttpServletResponse.SC_OK);
711 response.getWriter().write("Dictionary Import failed. Hence the following dictionary doen't support import function : "+ dictionaryName);
713 response.setStatus(HttpServletResponse.SC_OK);
714 response.getWriter().write("Success");
717 LOGGER.error("Exception Occured while importing dictionary"+e);
718 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
719 response.getWriter().write("Error");
723 public boolean isValidDictionaryName(String dictionaryName){
725 if(dictionaryName.startsWith(DisctionaryNames.Attribute.toString())){
728 if(dictionaryName.startsWith(DisctionaryNames.ActionPolicyDictionary.toString())){
731 if(dictionaryName.startsWith(DisctionaryNames.OnapName.toString())){
734 if(dictionaryName.startsWith(DisctionaryNames.MSPolicyDictionary.toString())){
737 if(dictionaryName.startsWith(DisctionaryNames.VNFType.toString())){
740 if(dictionaryName.startsWith(DisctionaryNames.VSCLAction.toString())){
743 if(dictionaryName.startsWith(DisctionaryNames.ClosedLoopService.toString())){
746 if(dictionaryName.startsWith(DisctionaryNames.ClosedLoopSite.toString())){
749 if(dictionaryName.startsWith(DisctionaryNames.PEPOptions.toString())){
752 if(dictionaryName.startsWith(DisctionaryNames.VarbindDictionary.toString())){
755 if(dictionaryName.startsWith(DisctionaryNames.BRMSParamDictionary.toString())){
758 if(dictionaryName.startsWith(DisctionaryNames.BRMSControllerDictionary.toString())){
761 if(dictionaryName.startsWith(DisctionaryNames.BRMSDependencyDictionary.toString())){
764 if(dictionaryName.startsWith(DisctionaryNames.Settings.toString())){
767 if(dictionaryName.startsWith(DisctionaryNames.PrefixList.toString())){
770 if(dictionaryName.startsWith(DisctionaryNames.SecurityZone.toString())){
773 if(dictionaryName.startsWith(DisctionaryNames.Zone.toString())){
776 if(dictionaryName.startsWith(DisctionaryNames.ServiceList.toString())){
779 if(dictionaryName.startsWith(DisctionaryNames.ServiceGroup.toString())){
782 if(dictionaryName.startsWith(DisctionaryNames.AddressGroup.toString())){
785 if(dictionaryName.startsWith(DisctionaryNames.ProtocolList.toString())){
788 if(dictionaryName.startsWith(DisctionaryNames.ActionList.toString())){
791 if(dictionaryName.startsWith(DisctionaryNames.TermList.toString())){
794 if(dictionaryName.startsWith(DisctionaryNames.SearchCriteria.toString())){