-
- File file = new File(dictionaryName);
- OutputStream outputStream = new FileOutputStream(file);
- IOUtils.copy(request.getInputStream(), outputStream);
- outputStream.close();
- this.newFile = file.toString();
- CSVReader csvReader = new CSVReader(new FileReader(this.newFile));
- List<String[]> dictSheet = csvReader.readAll();
- if(dictionaryName.startsWith("Attribute")){
- for(int i = 1; i< dictSheet.size(); i++){
- Attribute attribute = new Attribute("");
- UserInfo userinfo = new UserInfo();
- userinfo.setUserLoginId(userId);
- attribute.setUserCreatedBy(userinfo);
- attribute.setUserModifiedBy(userinfo);
- String[] rows = dictSheet.get(i);
- for (int j=0 ; j<rows.length; j++ ){
- if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute ID").equalsIgnoreCase(dictSheet.get(0)[j])){
- attribute.setXacmlId(rows[j]);
- }
- if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){
- attribute.setDescription(rows[j]);
- }
- if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
- attribute.setPriority(rows[j]);
- }
- if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){
- Datatype dataType = new Datatype();
- if(("string").equalsIgnoreCase(rows[j])){
- dataType.setId(26);
- }else if(("integer").equalsIgnoreCase(rows[j])){
- dataType.setId(12);
- }else if(("double").equalsIgnoreCase(rows[j])){
- dataType.setId(25);
- }else if(("boolean").equalsIgnoreCase(rows[j])){
- dataType.setId(18);
- }else if(("user").equalsIgnoreCase(rows[j])){
- dataType.setId(29);
- }
- attribute.setDatatypeBean(dataType);
- Category category = new Category();
- category.setId(5);
- attribute.setCategoryBean(category);
- }
- if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
- attribute.setAttributeValue(rows[j]);
+
+ if(dictionaryName == null || dictionaryName.isEmpty()){
+ LOGGER.error("dictionaryName is null/empty");
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ response.getWriter().write("Error");
+ return;
+ }
+
+ boolean dictionaryImportExists = false;
+ try{
+ File file = new File(dictionaryName);
+ OutputStream outputStream = new FileOutputStream(file);
+ IOUtils.copy(request.getInputStream(), outputStream);
+ outputStream.close();
+ this.newFile = file.toString();
+ CSVReader csvReader = new CSVReader(new FileReader(this.newFile));
+ List<String[]> dictSheet = csvReader.readAll();
+ if(dictionaryName.startsWith("Attribute")){
+ dictionaryImportExists = true;
+ for(int i = 1; i< dictSheet.size(); i++){
+ Attribute attribute = new Attribute("");
+ UserInfo userinfo = new UserInfo();
+ userinfo.setUserLoginId(userId);
+ attribute.setUserCreatedBy(userinfo);
+ attribute.setUserModifiedBy(userinfo);
+ String[] rows = dictSheet.get(i);
+ for (int j=0 ; j<rows.length; j++ ){
+ if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute ID").equalsIgnoreCase(dictSheet.get(0)[j])){
+ attribute.setXacmlId(rows[j]);
+ }
+ if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
+ attribute.setDescription(rows[j]);
+ }
+ if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){
+ attribute.setPriority(rows[j]);
+ }
+ if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){
+ Datatype dataType = new Datatype();
+ if(("string").equalsIgnoreCase(rows[j])){
+ dataType.setId(26);
+ }else if(("integer").equalsIgnoreCase(rows[j])){
+ dataType.setId(12);
+ }else if(("double").equalsIgnoreCase(rows[j])){
+ dataType.setId(25);
+ }else if(("boolean").equalsIgnoreCase(rows[j])){
+ dataType.setId(18);
+ }else if(("user").equalsIgnoreCase(rows[j])){
+ dataType.setId(29);
+ }
+ attribute.setDatatypeBean(dataType);
+ Category category = new Category();
+ category.setId(5);
+ attribute.setCategoryBean(category);
+ }
+ if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
+ attribute.setAttributeValue(rows[j]);
+ }