Merge "Added Junits for Policy PAP-REST"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / DictionaryImportController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.controller;
22  /*
23   * 
24   * 
25   * */
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.FileReader;
29 import java.io.IOException;
30 import java.io.OutputStream;
31 import java.util.List;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35
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;
70
71 import com.fasterxml.jackson.databind.DeserializationFeature;
72 import com.fasterxml.jackson.databind.ObjectMapper;
73
74 import au.com.bytecode.opencsv.CSVReader;
75
76
77 @Controller
78 public class DictionaryImportController {
79         private static final Logger LOGGER  = FlexLogger.getLogger(DictionaryImportController.class);
80         
81         private String newFile;
82
83         private static CommonClassDao commonClassDao;
84         private static final String DESCRIPTION= "description";
85         
86         @Autowired
87         public DictionaryImportController(CommonClassDao commonClassDao){
88                 DictionaryImportController.commonClassDao = commonClassDao;
89         }
90         
91         public DictionaryImportController(){}   
92
93
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");
100                 
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");
105                         return;
106                 }
107                                 
108                 boolean dictionaryImportExists = false;
109                 try{
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]);
129                                                 }
130                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
131                                                         attribute.setDescription(rows[j]);
132                                                 }
133                                                 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
134                                                         attribute.setPriority(rows[j]);
135                                                 }
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])){
139                                                                 dataType.setId(26);
140                                                         }else if(("integer").equalsIgnoreCase(rows[j])){
141                                                                 dataType.setId(12);
142                                                         }else if(("double").equalsIgnoreCase(rows[j])){
143                                                                 dataType.setId(25);
144                                                         }else if(("boolean").equalsIgnoreCase(rows[j])){
145                                                                 dataType.setId(18);
146                                                         }else if(("user").equalsIgnoreCase(rows[j])){
147                                                                 dataType.setId(29);
148                                                         }
149                                                         attribute.setDatatypeBean(dataType);
150                                                         Category category = new Category();
151                                                         category.setId(5);
152                                                         attribute.setCategoryBean(category);
153                                                 }
154                                                 if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
155                                                         attribute.setAttributeValue(rows[j]);
156                                                 }
157                                         }
158                                         commonClassDao.save(attribute);
159                                 }
160                         }
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]);
173                                                 }
174                                                 if(("body").equalsIgnoreCase(dictSheet.get(0)[j])){
175                                                         attribute.setBody(rows[j]);
176                                                 }
177                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
178                                                         attribute.setDescription(rows[j]);
179                                                 }
180                                                 if(("headers").equalsIgnoreCase(dictSheet.get(0)[j])){
181                                                         attribute.setHeader(rows[j]);
182                                                 }
183                                                 if(("method").equalsIgnoreCase(dictSheet.get(0)[j])){
184                                                         attribute.setMethod(rows[j]);
185                                                 }
186                                                 if(("type").equalsIgnoreCase(dictSheet.get(0)[j])){
187                                                         attribute.setType(rows[j]);
188                                                 }
189                                                 if(("url").equalsIgnoreCase(dictSheet.get(0)[j])){
190                                                         attribute.setUrl(rows[j]);
191                                                 }
192                                         }
193                                         commonClassDao.save(attribute);
194                                 }
195                         }
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]);
208                                                 }
209                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
210                                                         attribute.setDescription(rows[j]);
211                                                 }
212                                         }
213                                         commonClassDao.save(attribute);
214                                 }
215                         }
216
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]);
228                                                 }
229                                                 if(("version").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Model Version").equalsIgnoreCase(dictSheet.get(0)[j])){
230                                                         attribute.setVersion(rows[j]);
231                                                 }
232                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
233                                                         attribute.setDescription(rows[j]);
234                                                 }
235                                                 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
236                                                         attribute.setDependency(rows[j]);
237                                                 }
238                                                 if(("attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
239                                                         attribute.setAttributes(rows[j]);
240                                                 }
241                                                 if(("enumValues").equalsIgnoreCase(dictSheet.get(0)[j])){
242                                                         attribute.setEnumValues(rows[j]);
243                                                 }
244                                                 if(("Ref Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
245                                                         attribute.setRef_attributes(rows[j]);
246                                                 }
247                                                 if(("Sub Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
248                                                         attribute.setSub_attributes(rows[j]);
249                                                 }
250                                         }
251
252                                         commonClassDao.save(attribute);
253                                 }
254                         }               
255
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]);
268                                                 }
269                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
270                                                         attribute.setDescription(rows[j]);
271                                                 }
272                                         }
273                                         commonClassDao.save(attribute);
274                                 }
275                         }
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]);
288                                                 }
289                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
290                                                         attribute.setDescription(rows[j]);
291                                                 }
292                                         }
293                                         commonClassDao.save(attribute);
294                                 }
295                         }
296                         if(dictionaryName.startsWith("ClosedLoopService")){
297                                 dictionaryImportExists = true;
298                                 for(int i = 1; i< dictSheet.size(); i++){
299                                         ClosedLoopD2Services attribute = new ClosedLoopD2Services();
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]);
308                                                 }
309                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
310                                                         attribute.setDescription(rows[j]);
311                                                 }
312                                         }
313                                         commonClassDao.save(attribute);
314                                 }
315                         }
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]);
328                                                 }
329                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
330                                                         attribute.setDescription(rows[j]);
331                                                 }
332                                         }
333                                         commonClassDao.save(attribute);
334                                 }
335                         }
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]);
348                                                 }
349                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
350                                                         attribute.setDescription(rows[j]);
351                                                 }
352                                                 if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){
353                                                         attribute.setActions(rows[j]);
354                                                 }
355                                         }
356                                         commonClassDao.save(attribute);
357                                 }
358                         }
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]);
371                                                 }
372                                                 if(("varbind_Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Description").equalsIgnoreCase(dictSheet.get(0)[j])){
373                                                         attribute.setVarbindDescription(rows[j]);
374                                                 }
375                                                 if(("varbind_oid").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind OID").equalsIgnoreCase(dictSheet.get(0)[j])){
376                                                         attribute.setVarbindOID(rows[j]);
377                                                 }
378                                         }
379                                         commonClassDao.save(attribute);
380                                 }
381                         }
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]);
393                                                 }
394                                                 if(("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
395                                                         attribute.setDescription(rows[j]);
396                                                 }
397                                                 if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){
398                                                         attribute.setRule(rows[j]);
399                                                 }
400                                         }
401                                         commonClassDao.save(attribute);
402                                 }
403                         }
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]);
415                                                 }
416                                                 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
417                                                         attribute.setDescription(rows[j]);
418                                                 }
419                                                 if(("controller").equalsIgnoreCase(dictSheet.get(0)[j])){
420                                                         attribute.setController(rows[j]);
421                                                 }
422                                         }
423                                         commonClassDao.save(attribute);
424                                 }
425                         }
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]);
437                                                 }
438                                                 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
439                                                         attribute.setDescription(rows[j]);
440                                                 }
441                                                 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
442                                                         attribute.setDependency(rows[j]);
443                                                 }
444                                         }
445                                         commonClassDao.save(attribute);
446                                 }
447                         }
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]);
460                                                 }
461                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
462                                                         attribute.setDescription(rows[j]);
463                                                 }
464                                                 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
465                                                         attribute.setPriority(rows[j]);
466                                                 }
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])){
470                                                                 dataType.setId(26);
471                                                         }else if(("integer").equalsIgnoreCase(rows[j])){
472                                                                 dataType.setId(12);
473                                                         }else if(("double").equalsIgnoreCase(rows[j])){
474                                                                 dataType.setId(25);
475                                                         }else if(("boolean").equalsIgnoreCase(rows[j])){
476                                                                 dataType.setId(18);
477                                                         }else if(("user").equalsIgnoreCase(rows[j])){
478                                                                 dataType.setId(29);
479                                                         }
480                                                         attribute.setDatatypeBean(dataType);
481                                                 }
482                                         }
483                                         commonClassDao.save(attribute);
484                                 }
485                         }
486                         if(dictionaryName.startsWith("PrefixList")){
487                                 dictionaryImportExists = true;
488                                 for(int i = 1; i< dictSheet.size(); i++){
489                                         PrefixList attribute = new PrefixList();
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]);
494                                                 }
495                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
496                                                         attribute.setPrefixListValue(rows[j]);
497                                                 }
498                                                 if(("prefixListValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Value").equalsIgnoreCase(dictSheet.get(0)[j])){
499                                                         attribute.setDescription(rows[j]);
500                                                 }
501                                         }
502                                         commonClassDao.save(attribute);
503                                 }
504                         }
505                         if(dictionaryName.startsWith("SecurityZone")){
506                                 dictionaryImportExists = true;
507                                 for(int i = 1; i< dictSheet.size(); i++){
508                                         SecurityZone attribute = new SecurityZone();
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]);
513                                                 }
514                                                 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
515                                                         attribute.setZoneValue(rows[j]);
516                                                 }
517                                         }
518                                         commonClassDao.save(attribute);
519                                 }
520                         }
521                         if(dictionaryName.startsWith("Zone")){
522                                 dictionaryImportExists = true;
523                                 for(int i = 1; i< dictSheet.size(); i++){
524                                         Zone attribute = new Zone();
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]);
529                                                 }
530                                                 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
531                                                         attribute.setZoneValue(rows[j]);
532                                                 }
533                                         }
534                                         commonClassDao.save(attribute);
535                                 }
536                         }
537                         if(dictionaryName.startsWith("ServiceList")){
538                                 dictionaryImportExists = true;
539                                 for(int i = 1; i< dictSheet.size(); i++){
540                                         ServiceList attribute = new ServiceList();
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]);
545                                                 }
546                                                 if(("serviceDesc").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
547                                                         attribute.setServiceDescription(rows[j]);
548                                                 }
549                                                 if(("serviceType").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Service Type").equalsIgnoreCase(dictSheet.get(0)[j])){
550                                                         attribute.setServiceType(rows[j]);
551                                                 }
552                                                 if(("serviceTrasProtocol").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Transport Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
553                                                         attribute.setServiceTransProtocol(rows[j]);
554                                                 }
555                                                 if(("serviceAppProtocol").equalsIgnoreCase(dictSheet.get(0)[j])  || ("APP Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
556                                                         attribute.setServiceAppProtocol(rows[j]);
557                                                 }
558                                                 if(("servicePorts").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Ports").equalsIgnoreCase(dictSheet.get(0)[j])){
559                                                         attribute.setServicePorts(rows[j]);
560                                                 }
561                                         }
562                                         commonClassDao.save(attribute);
563                                 }
564                         }
565                         if(dictionaryName.startsWith("ServiceGroup")){
566                                 dictionaryImportExists = true;
567                                 for(int i = 1; i< dictSheet.size(); i++){
568                                         GroupServiceList attribute = new GroupServiceList();
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]);
573                                                 }
574                                                 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Service List").equalsIgnoreCase(dictSheet.get(0)[j])){
575                                                         attribute.setServiceList(rows[j]);
576                                                 }
577                                         }
578                                         commonClassDao.save(attribute);
579                                 }
580                         }
581                         if(dictionaryName.startsWith("AddressGroup")){
582                                 dictionaryImportExists = true;
583                                 for(int i = 1; i< dictSheet.size(); i++){
584                                         AddressGroup attribute = new AddressGroup();
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]);
589                                                 }
590                                                 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Prefix List").equalsIgnoreCase(dictSheet.get(0)[j])){
591                                                         attribute.setServiceList(rows[j]);
592                                                 }
593                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
594                                                         attribute.setDescription(rows[j]);
595                                                 }
596                                         }
597                                         commonClassDao.save(attribute);
598                                 }
599                         }
600                         if(dictionaryName.startsWith("ProtocolList")){
601                                 dictionaryImportExists = true;
602                                 for(int i = 1; i< dictSheet.size(); i++){
603                                         ProtocolList attribute = new ProtocolList();
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]);
608                                                 }
609                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
610                                                         attribute.setDescription(rows[j]);
611                                                 }
612                                         }
613                                         commonClassDao.save(attribute);
614                                 }
615                         }
616                         if(dictionaryName.startsWith("ActionList")){
617                                 dictionaryImportExists = true;
618                                 for(int i = 1; i< dictSheet.size(); i++){
619                                         ActionList attribute = new ActionList();
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]);
624                                                 }
625                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
626                                                         attribute.setDescription(rows[j]);
627                                                 }
628                                         }
629                                         commonClassDao.save(attribute);
630                                 }
631                         }
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]);
644                                                 }
645                                                 if(("Term-Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("termDescription").equalsIgnoreCase(dictSheet.get(0)[j])){
646                                                         attribute.setDescription(rows[j]);
647                                                 }
648                                                 if(("fromZone").equalsIgnoreCase(dictSheet.get(0)[j])  || ("From Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
649                                                         attribute.setFromZones(rows[j]);
650                                                 }
651                                                 if(("toZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("To Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
652                                                         attribute.setToZones(rows[j]);
653                                                 }
654                                                 if(("srcIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
655                                                         attribute.setSrcIPList(rows[j]);
656                                                 }
657                                                 if(("destIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
658                                                         attribute.setDestIPList(rows[j]);
659                                                 }
660                                                 if(("srcPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
661                                                         attribute.setSrcPortList(rows[j]);
662                                                 }
663                                                 if(("destPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
664                                                         attribute.setDestPortList(rows[j]);
665                                                 }
666                                                 if(("action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action List").equalsIgnoreCase(dictSheet.get(0)[j])){
667                                                         attribute.setAction(rows[j]);
668                                                 }
669                                         }
670                                         commonClassDao.save(attribute);
671                                 }
672                         }
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]);
685                                                 }
686                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
687                                                         attribute.setDescription(rows[j]);
688                                                 }
689                                                 if(("search").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Search Criteria").equalsIgnoreCase(dictSheet.get(0)[j])){
690                                                         attribute.setSearch(rows[j]);
691                                                 }
692                                         }
693                                         commonClassDao.save(attribute);
694                                 }
695                         }
696                         csvReader.close();
697                         if(file.exists()){
698                                 file.delete();
699                         }
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);
703                         }else{
704                                 response.setStatus(HttpServletResponse.SC_OK);
705                                 response.getWriter().write("Success");
706                         }
707                 }catch(Exception e){
708                         LOGGER.error("Exception Occured while importing dictionary"+e);
709                         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
710                         response.getWriter().write("Error");
711                 }
712         }
713 }