Merge "JUnit additions for ONAP-PAP-REST xacml.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.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;
71
72 import com.fasterxml.jackson.databind.DeserializationFeature;
73 import com.fasterxml.jackson.databind.ObjectMapper;
74
75 import au.com.bytecode.opencsv.CSVReader;
76
77
78 @Controller
79 public class DictionaryImportController {
80         private static final Logger LOGGER  = FlexLogger.getLogger(DictionaryImportController.class);
81         
82         private String newFile;
83
84         private static CommonClassDao commonClassDao;
85         private static final String DESCRIPTION= "description";
86         
87         @Autowired
88         public DictionaryImportController(CommonClassDao commonClassDao){
89                 DictionaryImportController.commonClassDao = commonClassDao;
90         }
91         
92         public DictionaryImportController(){}   
93
94
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");
101                 
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");
106                         return;
107                 }
108                 
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");
114                         return;                 
115                 }
116                                 
117                 boolean dictionaryImportExists = false;
118                 try{
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]);
138                                                 }
139                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
140                                                         attribute.setDescription(rows[j]);
141                                                 }
142                                                 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
143                                                         attribute.setPriority(rows[j]);
144                                                 }
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])){
148                                                                 dataType.setId(26);
149                                                         }else if(("integer").equalsIgnoreCase(rows[j])){
150                                                                 dataType.setId(12);
151                                                         }else if(("double").equalsIgnoreCase(rows[j])){
152                                                                 dataType.setId(25);
153                                                         }else if(("boolean").equalsIgnoreCase(rows[j])){
154                                                                 dataType.setId(18);
155                                                         }else if(("user").equalsIgnoreCase(rows[j])){
156                                                                 dataType.setId(29);
157                                                         }
158                                                         attribute.setDatatypeBean(dataType);
159                                                         Category category = new Category();
160                                                         category.setId(5);
161                                                         attribute.setCategoryBean(category);
162                                                 }
163                                                 if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
164                                                         attribute.setAttributeValue(rows[j]);
165                                                 }
166                                         }
167                                         commonClassDao.save(attribute);
168                                 }
169                         }
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]);
182                                                 }
183                                                 if(("body").equalsIgnoreCase(dictSheet.get(0)[j])){
184                                                         attribute.setBody(rows[j]);
185                                                 }
186                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
187                                                         attribute.setDescription(rows[j]);
188                                                 }
189                                                 if(("headers").equalsIgnoreCase(dictSheet.get(0)[j])){
190                                                         attribute.setHeader(rows[j]);
191                                                 }
192                                                 if(("method").equalsIgnoreCase(dictSheet.get(0)[j])){
193                                                         attribute.setMethod(rows[j]);
194                                                 }
195                                                 if(("type").equalsIgnoreCase(dictSheet.get(0)[j])){
196                                                         attribute.setType(rows[j]);
197                                                 }
198                                                 if(("url").equalsIgnoreCase(dictSheet.get(0)[j])){
199                                                         attribute.setUrl(rows[j]);
200                                                 }
201                                         }
202                                         commonClassDao.save(attribute);
203                                 }
204                         }
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]);
217                                                 }
218                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
219                                                         attribute.setDescription(rows[j]);
220                                                 }
221                                         }
222                                         commonClassDao.save(attribute);
223                                 }
224                         }
225
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]);
237                                                 }
238                                                 if(("version").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Model Version").equalsIgnoreCase(dictSheet.get(0)[j])){
239                                                         attribute.setVersion(rows[j]);
240                                                 }
241                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
242                                                         attribute.setDescription(rows[j]);
243                                                 }
244                                                 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
245                                                         attribute.setDependency(rows[j]);
246                                                 }
247                                                 if(("attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
248                                                         attribute.setAttributes(rows[j]);
249                                                 }
250                                                 if(("enumValues").equalsIgnoreCase(dictSheet.get(0)[j])){
251                                                         attribute.setEnumValues(rows[j]);
252                                                 }
253                                                 if(("Ref Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
254                                                         attribute.setRef_attributes(rows[j]);
255                                                 }
256                                                 if(("Sub Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
257                                                         attribute.setSub_attributes(rows[j]);
258                                                 }
259                                         }
260
261                                         commonClassDao.save(attribute);
262                                 }
263                         }               
264
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]);
277                                                 }
278                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
279                                                         attribute.setDescription(rows[j]);
280                                                 }
281                                         }
282                                         commonClassDao.save(attribute);
283                                 }
284                         }
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]);
297                                                 }
298                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
299                                                         attribute.setDescription(rows[j]);
300                                                 }
301                                         }
302                                         commonClassDao.save(attribute);
303                                 }
304                         }
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]);
317                                                 }
318                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
319                                                         attribute.setDescription(rows[j]);
320                                                 }
321                                         }
322                                         commonClassDao.save(attribute);
323                                 }
324                         }
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]);
337                                                 }
338                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
339                                                         attribute.setDescription(rows[j]);
340                                                 }
341                                         }
342                                         commonClassDao.save(attribute);
343                                 }
344                         }
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]);
357                                                 }
358                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
359                                                         attribute.setDescription(rows[j]);
360                                                 }
361                                                 if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){
362                                                         attribute.setActions(rows[j]);
363                                                 }
364                                         }
365                                         commonClassDao.save(attribute);
366                                 }
367                         }
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]);
380                                                 }
381                                                 if(("varbind_Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Description").equalsIgnoreCase(dictSheet.get(0)[j])){
382                                                         attribute.setVarbindDescription(rows[j]);
383                                                 }
384                                                 if(("varbind_oid").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind OID").equalsIgnoreCase(dictSheet.get(0)[j])){
385                                                         attribute.setVarbindOID(rows[j]);
386                                                 }
387                                         }
388                                         commonClassDao.save(attribute);
389                                 }
390                         }
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]);
402                                                 }
403                                                 if(("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
404                                                         attribute.setDescription(rows[j]);
405                                                 }
406                                                 if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){
407                                                         attribute.setRule(rows[j]);
408                                                 }
409                                         }
410                                         commonClassDao.save(attribute);
411                                 }
412                         }
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]);
424                                                 }
425                                                 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
426                                                         attribute.setDescription(rows[j]);
427                                                 }
428                                                 if(("controller").equalsIgnoreCase(dictSheet.get(0)[j])){
429                                                         attribute.setController(rows[j]);
430                                                 }
431                                         }
432                                         commonClassDao.save(attribute);
433                                 }
434                         }
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]);
446                                                 }
447                                                 if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){
448                                                         attribute.setDescription(rows[j]);
449                                                 }
450                                                 if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
451                                                         attribute.setDependency(rows[j]);
452                                                 }
453                                         }
454                                         commonClassDao.save(attribute);
455                                 }
456                         }
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]);
469                                                 }
470                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
471                                                         attribute.setDescription(rows[j]);
472                                                 }
473                                                 if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
474                                                         attribute.setPriority(rows[j]);
475                                                 }
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])){
479                                                                 dataType.setId(26);
480                                                         }else if(("integer").equalsIgnoreCase(rows[j])){
481                                                                 dataType.setId(12);
482                                                         }else if(("double").equalsIgnoreCase(rows[j])){
483                                                                 dataType.setId(25);
484                                                         }else if(("boolean").equalsIgnoreCase(rows[j])){
485                                                                 dataType.setId(18);
486                                                         }else if(("user").equalsIgnoreCase(rows[j])){
487                                                                 dataType.setId(29);
488                                                         }
489                                                         attribute.setDatatypeBean(dataType);
490                                                 }
491                                         }
492                                         commonClassDao.save(attribute);
493                                 }
494                         }
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]);
503                                                 }
504                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
505                                                         attribute.setPrefixListValue(rows[j]);
506                                                 }
507                                                 if(("prefixListValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Value").equalsIgnoreCase(dictSheet.get(0)[j])){
508                                                         attribute.setDescription(rows[j]);
509                                                 }
510                                         }
511                                         commonClassDao.save(attribute);
512                                 }
513                         }
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]);
522                                                 }
523                                                 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
524                                                         attribute.setZoneValue(rows[j]);
525                                                 }
526                                         }
527                                         commonClassDao.save(attribute);
528                                 }
529                         }
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]);
538                                                 }
539                                                 if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){
540                                                         attribute.setZoneValue(rows[j]);
541                                                 }
542                                         }
543                                         commonClassDao.save(attribute);
544                                 }
545                         }
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]);
554                                                 }
555                                                 if(("serviceDesc").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){
556                                                         attribute.setServiceDescription(rows[j]);
557                                                 }
558                                                 if(("serviceType").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Service Type").equalsIgnoreCase(dictSheet.get(0)[j])){
559                                                         attribute.setServiceType(rows[j]);
560                                                 }
561                                                 if(("serviceTrasProtocol").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Transport Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
562                                                         attribute.setServiceTransProtocol(rows[j]);
563                                                 }
564                                                 if(("serviceAppProtocol").equalsIgnoreCase(dictSheet.get(0)[j])  || ("APP Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){
565                                                         attribute.setServiceAppProtocol(rows[j]);
566                                                 }
567                                                 if(("servicePorts").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Ports").equalsIgnoreCase(dictSheet.get(0)[j])){
568                                                         attribute.setServicePorts(rows[j]);
569                                                 }
570                                         }
571                                         commonClassDao.save(attribute);
572                                 }
573                         }
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]);
582                                                 }
583                                                 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Service List").equalsIgnoreCase(dictSheet.get(0)[j])){
584                                                         attribute.setServiceList(rows[j]);
585                                                 }
586                                         }
587                                         commonClassDao.save(attribute);
588                                 }
589                         }
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]);
598                                                 }
599                                                 if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j])  || ("Prefix List").equalsIgnoreCase(dictSheet.get(0)[j])){
600                                                         attribute.setServiceList(rows[j]);
601                                                 }
602                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
603                                                         attribute.setDescription(rows[j]);
604                                                 }
605                                         }
606                                         commonClassDao.save(attribute);
607                                 }
608                         }
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]);
617                                                 }
618                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
619                                                         attribute.setDescription(rows[j]);
620                                                 }
621                                         }
622                                         commonClassDao.save(attribute);
623                                 }
624                         }
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]);
633                                                 }
634                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
635                                                         attribute.setDescription(rows[j]);
636                                                 }
637                                         }
638                                         commonClassDao.save(attribute);
639                                 }
640                         }
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]);
653                                                 }
654                                                 if(("Term-Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("termDescription").equalsIgnoreCase(dictSheet.get(0)[j])){
655                                                         attribute.setDescription(rows[j]);
656                                                 }
657                                                 if(("fromZone").equalsIgnoreCase(dictSheet.get(0)[j])  || ("From Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
658                                                         attribute.setFromZones(rows[j]);
659                                                 }
660                                                 if(("toZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("To Zone").equalsIgnoreCase(dictSheet.get(0)[j])){
661                                                         attribute.setToZones(rows[j]);
662                                                 }
663                                                 if(("srcIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
664                                                         attribute.setSrcIPList(rows[j]);
665                                                 }
666                                                 if(("destIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){
667                                                         attribute.setDestIPList(rows[j]);
668                                                 }
669                                                 if(("srcPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
670                                                         attribute.setSrcPortList(rows[j]);
671                                                 }
672                                                 if(("destPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){
673                                                         attribute.setDestPortList(rows[j]);
674                                                 }
675                                                 if(("action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action List").equalsIgnoreCase(dictSheet.get(0)[j])){
676                                                         attribute.setAction(rows[j]);
677                                                 }
678                                         }
679                                         commonClassDao.save(attribute);
680                                 }
681                         }
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]);
694                                                 }
695                                                 if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
696                                                         attribute.setDescription(rows[j]);
697                                                 }
698                                                 if(("search").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Search Criteria").equalsIgnoreCase(dictSheet.get(0)[j])){
699                                                         attribute.setSearch(rows[j]);
700                                                 }
701                                         }
702                                         commonClassDao.save(attribute);
703                                 }
704                         }
705                         csvReader.close();
706                         if(file.exists()){
707                                 file.delete();
708                         }
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);
712                         }else{
713                                 response.setStatus(HttpServletResponse.SC_OK);
714                                 response.getWriter().write("Success");
715                         }
716                 }catch(Exception e){
717                         LOGGER.error("Exception Occured while importing dictionary"+e);
718                         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
719                         response.getWriter().write("Error");
720                 }
721         }
722         
723         public boolean isValidDictionaryName(String dictionaryName){
724                 
725                 if(dictionaryName.startsWith(DisctionaryNames.Attribute.toString())){
726                         return true;
727                 }
728                 if(dictionaryName.startsWith(DisctionaryNames.ActionPolicyDictionary.toString())){
729                         return true;
730                 }
731                 if(dictionaryName.startsWith(DisctionaryNames.OnapName.toString())){
732                         return true;
733                 }
734                 if(dictionaryName.startsWith(DisctionaryNames.MSPolicyDictionary.toString())){
735                         return true;
736                 }
737                 if(dictionaryName.startsWith(DisctionaryNames.VNFType.toString())){
738                         return true;
739                 }
740                 if(dictionaryName.startsWith(DisctionaryNames.VSCLAction.toString())){
741                         return true;
742                 }
743                 if(dictionaryName.startsWith(DisctionaryNames.ClosedLoopService.toString())){
744                         return true;
745                 }
746                 if(dictionaryName.startsWith(DisctionaryNames.ClosedLoopSite.toString())){
747                         return true;
748                 }
749                 if(dictionaryName.startsWith(DisctionaryNames.PEPOptions.toString())){
750                         return true;
751                 }
752                 if(dictionaryName.startsWith(DisctionaryNames.VarbindDictionary.toString())){
753                         return true;
754                 }
755                 if(dictionaryName.startsWith(DisctionaryNames.BRMSParamDictionary.toString())){
756                         return true;
757                 }
758                 if(dictionaryName.startsWith(DisctionaryNames.BRMSControllerDictionary.toString())){
759                         return true;
760                 }
761                 if(dictionaryName.startsWith(DisctionaryNames.BRMSDependencyDictionary.toString())){
762                         return true;
763                 }
764                 if(dictionaryName.startsWith(DisctionaryNames.Settings.toString())){
765                         return true;
766                 }
767                 if(dictionaryName.startsWith(DisctionaryNames.PrefixList.toString())){
768                         return true;
769                 }
770                 if(dictionaryName.startsWith(DisctionaryNames.SecurityZone.toString())){
771                         return true;
772                 }
773                 if(dictionaryName.startsWith(DisctionaryNames.Zone.toString())){
774                         return true;
775                 }
776                 if(dictionaryName.startsWith(DisctionaryNames.ServiceList.toString())){
777                         return true;
778                 }
779                 if(dictionaryName.startsWith(DisctionaryNames.ServiceGroup.toString())){
780                         return true;
781                 }
782                 if(dictionaryName.startsWith(DisctionaryNames.AddressGroup.toString())){
783                         return true;
784                 }
785                 if(dictionaryName.startsWith(DisctionaryNames.ProtocolList.toString())){
786                         return true;
787                 }
788                 if(dictionaryName.startsWith(DisctionaryNames.ActionList.toString())){
789                         return true;
790                 }
791                 if(dictionaryName.startsWith(DisctionaryNames.TermList.toString())){
792                         return true;
793                 }
794                 if(dictionaryName.startsWith(DisctionaryNames.SearchCriteria.toString())){
795                         return true;
796                 }
797                 return false;
798         }
799 }