fix(测试跟踪): 功能用例导入失败后依然创建了模块
--bug=1028167 --user=陈建星 【测试跟踪】功能用例导入-excel导入-导入失败-却新建了excel表里的路径文件夹 https://www.tapd.cn/55049933/s/1398321
This commit is contained in:
parent
7045bc0ef3
commit
0b6210d9e4
|
@ -2,18 +2,34 @@ package io.metersphere.commons.exception;
|
||||||
|
|
||||||
public class MSException extends RuntimeException {
|
public class MSException extends RuntimeException {
|
||||||
|
|
||||||
|
private Object detail;
|
||||||
|
|
||||||
private MSException(String message) {
|
private MSException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MSException(String message, Object detail) {
|
||||||
|
super(message);
|
||||||
|
this.detail = detail;
|
||||||
|
}
|
||||||
|
|
||||||
private MSException(Throwable t) {
|
private MSException(Throwable t) {
|
||||||
super(t);
|
super(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MSException(Throwable t, Object detail) {
|
||||||
|
super(t);
|
||||||
|
this.detail = detail;
|
||||||
|
}
|
||||||
|
|
||||||
public static void throwException(String message) {
|
public static void throwException(String message) {
|
||||||
throw new MSException(message);
|
throw new MSException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void throwException(String message, Object detail) {
|
||||||
|
throw new MSException(message, detail);
|
||||||
|
}
|
||||||
|
|
||||||
public static MSException getException(String message) {
|
public static MSException getException(String message) {
|
||||||
throw new MSException(message);
|
throw new MSException(message);
|
||||||
}
|
}
|
||||||
|
@ -21,4 +37,12 @@ public class MSException extends RuntimeException {
|
||||||
public static void throwException(Throwable t) {
|
public static void throwException(Throwable t) {
|
||||||
throw new MSException(t);
|
throw new MSException(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void throwException(Throwable t, Object detail) {
|
||||||
|
throw new MSException(t, detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getDetail() {
|
||||||
|
return detail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.base.domain.TestCase;
|
||||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||||
import io.metersphere.base.mapper.TestCaseMapper;
|
import io.metersphere.base.mapper.TestCaseMapper;
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.*;
|
||||||
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.PageUtils;
|
import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
import io.metersphere.commons.utils.SessionUtils;
|
||||||
|
@ -290,7 +291,16 @@ public class TestCaseController {
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ_IMPORT)
|
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ_IMPORT)
|
||||||
public ExcelResponse testCaseImport(@RequestPart("request") TestCaseImportRequest request, @RequestPart("file") MultipartFile file, HttpServletRequest httpRequest) {
|
public ExcelResponse testCaseImport(@RequestPart("request") TestCaseImportRequest request, @RequestPart("file") MultipartFile file, HttpServletRequest httpRequest) {
|
||||||
baseCheckPermissionService.checkProjectOwner(request.getProjectId());
|
baseCheckPermissionService.checkProjectOwner(request.getProjectId());
|
||||||
|
try {
|
||||||
return testCaseService.testCaseImport(file, request, httpRequest);
|
return testCaseService.testCaseImport(file, request, httpRequest);
|
||||||
|
} catch (MSException e) {
|
||||||
|
Object detail = e.getDetail();
|
||||||
|
// 如果异常信息里带了 ExcelResponse,则返回提示信息
|
||||||
|
if (detail instanceof ExcelResponse) {
|
||||||
|
return (ExcelResponse) detail;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/check/permission/{projectId}")
|
@GetMapping("/check/permission/{projectId}")
|
||||||
|
|
|
@ -1087,11 +1087,17 @@ public class TestCaseService {
|
||||||
int nextNum = getNextNum(request.getProjectId());
|
int nextNum = getNextNum(request.getProjectId());
|
||||||
importCreateNum.set(nextNum);
|
importCreateNum.set(nextNum);
|
||||||
}
|
}
|
||||||
|
ExcelResponse excelResponse;
|
||||||
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
|
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
|
||||||
return testCaseXmindImport(multipartFile, request, httpRequest);
|
excelResponse = testCaseXmindImport(multipartFile, request, httpRequest);
|
||||||
} else {
|
} else {
|
||||||
return testCaseExcelImport(multipartFile, request, httpRequest);
|
excelResponse = testCaseExcelImport(multipartFile, request, httpRequest);
|
||||||
}
|
}
|
||||||
|
if (BooleanUtils.isFalse(excelResponse.getSuccess())) {
|
||||||
|
// 如果导入失败,创建的模块需要回滚,则抛出异常
|
||||||
|
MSException.throwException("import error", excelResponse);
|
||||||
|
}
|
||||||
|
return excelResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TestCase> getTestCaseForImport(String projectId) {
|
private List<TestCase> getTestCaseForImport(String projectId) {
|
||||||
|
|
Loading…
Reference in New Issue