Merge branch 'master' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
2bad9f925d
|
@ -15,7 +15,7 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<shiro.version>1.5.1</shiro.version>
|
||||
<shiro.version>1.6.0</shiro.version>
|
||||
<java.version>1.8</java.version>
|
||||
<jmeter.version>5.2.1</jmeter.version>
|
||||
<nacos.version>1.1.3</nacos.version>
|
||||
|
|
|
@ -9,10 +9,7 @@ import io.metersphere.commons.utils.LogUtil;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -21,10 +18,8 @@ import java.util.Optional;
|
|||
public abstract class ApiImportAbstractParser implements ApiImportParser {
|
||||
|
||||
protected String getApiTestStr(InputStream source) {
|
||||
BufferedReader bufferedReader;
|
||||
StringBuilder testStr = null;
|
||||
try {
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(source, StandardCharsets.UTF_8));
|
||||
try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(source, StandardCharsets.UTF_8))) {
|
||||
testStr = new StringBuilder();
|
||||
String inputStr;
|
||||
while ((inputStr = bufferedReader.readLine()) != null) {
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.lang.reflect.ParameterizedType;
|
|||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> {
|
||||
public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> implements AutoCloseable {
|
||||
|
||||
protected List<ExcelErrData<T>> errList = new ArrayList<>();
|
||||
|
||||
|
@ -153,6 +153,8 @@ public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> {
|
|||
return errList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.easyExcelI18nTranslator.resetExcelProperty();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.exception.ExcelException;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
@ -13,7 +12,7 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
public class EasyExcelExporter {
|
||||
public class EasyExcelExporter implements AutoCloseable {
|
||||
|
||||
EasyExcelI18nTranslator easyExcelI18nTranslator;
|
||||
|
||||
|
@ -47,6 +46,7 @@ public class EasyExcelExporter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
easyExcelI18nTranslator.resetExcelProperty();
|
||||
}
|
||||
|
|
|
@ -273,16 +273,12 @@ public class TestCaseService {
|
|||
|
||||
Set<String> userIds = userRoleMapper.selectByExample(userRoleExample).stream().map(UserRole::getUserId).collect(Collectors.toSet());
|
||||
|
||||
EasyExcelListener easyExcelListener = null;
|
||||
try {
|
||||
easyExcelListener = new TestCaseDataListener(this, projectId, testCaseNames, userIds);
|
||||
try (EasyExcelListener easyExcelListener = new TestCaseDataListener(this, projectId, testCaseNames, userIds)) {
|
||||
EasyExcelFactory.read(multipartFile.getInputStream(), TestCaseExcelData.class, easyExcelListener).sheet().doRead();
|
||||
errList = easyExcelListener.getErrList();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException(e.getMessage());
|
||||
} finally {
|
||||
easyExcelListener.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -316,15 +312,11 @@ public class TestCaseService {
|
|||
}
|
||||
|
||||
public void testCaseTemplateExport(HttpServletResponse response) {
|
||||
EasyExcelExporter easyExcelExporter = null;
|
||||
try {
|
||||
easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class);
|
||||
try (EasyExcelExporter easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class)) {
|
||||
easyExcelExporter.export(response, generateExportTemplate(),
|
||||
Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet"));
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
} finally {
|
||||
easyExcelExporter.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,15 +390,11 @@ public class TestCaseService {
|
|||
}
|
||||
|
||||
public void testCaseExport(HttpServletResponse response, TestCaseBatchRequest request) {
|
||||
EasyExcelExporter easyExcelExporter = null;
|
||||
try {
|
||||
easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class);
|
||||
try (EasyExcelExporter easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class)) {
|
||||
easyExcelExporter.export(response, generateTestCaseExcel(request),
|
||||
Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet"));
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
} finally {
|
||||
easyExcelExporter.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue