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;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
......@@ -161,12 +162,13 @@ public class ScenarioServiceImpl implements ScenarioService {
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public XSSFWorkbook buildTemplate() {
public XSSFWorkbook buildTemplate() throws IOException {
Locale locale = new Locale("vi", "VN");
XSSFWorkbook workbook = null;
try {
XSSFWorkbook workbook = new XSSFWorkbook();
Sheet sheet;
Sheet sheet;
workbook = new XSSFWorkbook();
CellStyle styleTitle = WorkBookBuilder.buildDefaultStyleTitle(workbook);
CellStyle styleRowHeader = WorkBookBuilder.buildDefaultStyleRowHeader(workbook);
CellStyle styleRow = WorkBookBuilder.buildDefaultStyleRow(workbook);
......@@ -237,17 +239,20 @@ public class ScenarioServiceImpl implements ScenarioService {
} catch (Exception e) {
logger.error(e.getMessage());
return null;
}finally {
if (workbook != null) workbook.close();
}
}
@Override
@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");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Map<String, Object> result = new HashMap<>();
StringBuilder sb = new StringBuilder();
boolean isValid = true;
XSSFWorkbook workbook = null;
try {
List<String> fileHeaderList = new ArrayList<>();
fileHeaderList.add(BundleUtils.getLangString("scenario.template.questionCode", locale));
......@@ -261,7 +266,8 @@ public class ScenarioServiceImpl implements ScenarioService {
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
workbook = new XSSFWorkbook(fis);
workbook = new XSSFWorkbook(fis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(2);
......@@ -423,13 +429,16 @@ public class ScenarioServiceImpl implements ScenarioService {
}
} catch (Exception 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);
}
return result;
}
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().
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