Commit 07ab5f64 authored by Nguyen Ha's avatar Nguyen Ha

fix sonar

parent 2e0e6f96
...@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -161,12 +162,13 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -161,12 +162,13 @@ public class ScenarioServiceImpl implements ScenarioService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public XSSFWorkbook buildTemplate() { public XSSFWorkbook buildTemplate() throws IOException {
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
XSSFWorkbook workbook = null;
try { try {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet;
Sheet sheet;
workbook = new XSSFWorkbook();
CellStyle styleTitle = WorkBookBuilder.buildDefaultStyleTitle(workbook); CellStyle styleTitle = WorkBookBuilder.buildDefaultStyleTitle(workbook);
CellStyle styleRowHeader = WorkBookBuilder.buildDefaultStyleRowHeader(workbook); CellStyle styleRowHeader = WorkBookBuilder.buildDefaultStyleRowHeader(workbook);
CellStyle styleRow = WorkBookBuilder.buildDefaultStyleRow(workbook); CellStyle styleRow = WorkBookBuilder.buildDefaultStyleRow(workbook);
...@@ -237,17 +239,20 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -237,17 +239,20 @@ public class ScenarioServiceImpl implements ScenarioService {
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
return null; return null;
}finally {
if (workbook != null) workbook.close();
} }
} }
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public Map<String, Object> readAndValidateCustomer(String path, Long scenarioId, Long campaignId, Long companySiteId) { public Map<String, Object> readAndValidateCustomer (String path, Long scenarioId, Long campaignId, Long companySiteId) throws IOException{
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
boolean isValid = true; boolean isValid = true;
XSSFWorkbook workbook = null;
try { try {
List<String> fileHeaderList = new ArrayList<>(); List<String> fileHeaderList = new ArrayList<>();
fileHeaderList.add(BundleUtils.getLangString("scenario.template.questionCode", locale)); fileHeaderList.add(BundleUtils.getLangString("scenario.template.questionCode", locale));
...@@ -261,7 +266,8 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -261,7 +266,8 @@ public class ScenarioServiceImpl implements ScenarioService {
File file = new File(path); File file = new File(path);
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis); workbook = new XSSFWorkbook(fis);
workbook = new XSSFWorkbook(fis);
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(2); Row row = sheet.getRow(2);
...@@ -423,13 +429,16 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -423,13 +429,16 @@ public class ScenarioServiceImpl implements ScenarioService {
} }
} catch (Exception ex) { } catch (Exception ex) {
logger.info(ex.getMessage(), ex); logger.info(ex.getMessage(), ex);
result.put("message", BundleUtils.getLangString("customer.errorValidate", locale));
}finally {
if (workbook != null) workbook.close();
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR); result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
} }
return result; return result;
} }
private boolean validateMappingQuestion(String mappingQuestion, String currentQuestionCode, List<String> lstQuestionCode) { private boolean validateMappingQuestion(String mappingQuestion, String currentQuestionCode, List<String> lstQuestionCode) {
if (mappingQuestion == currentQuestionCode) return false; if (mappingQuestion != null && mappingQuestion.equals(currentQuestionCode)) return false;
String duplicateCode = lstQuestionCode.stream(). String duplicateCode = lstQuestionCode.stream().
filter(p -> (p.equals(mappingQuestion) && p.equals(currentQuestionCode))). filter(p -> (p.equals(mappingQuestion) && p.equals(currentQuestionCode))).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment