fix(项目设置): 报告分享链接超出有效时间仍可以打开链接

--bug=1018857 --user=李玉号 【项目设置】应用管理-设置报告分享链接-超出有效时间仍可以打开链接
https://www.tapd.cn/55049933/s/1276941
This commit is contained in:
shiziyuan9527 2022-10-25 18:07:53 +08:00 committed by lyh
parent 8c645523f2
commit 37905774ce
13 changed files with 348 additions and 122 deletions

View File

@ -1,7 +1,7 @@
package io.metersphere.controller.plan;
import io.metersphere.api.dto.automation.TestPlanFailureApiDTO;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.ShareInfoService;
import io.metersphere.service.plan.TestPlanApiCaseService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -16,31 +16,31 @@ import java.util.List;
public class ShareTestPlanApiCaseController {
@Resource
BaseShareInfoService baseShareInfoService;
ShareInfoService shareInfoService;
@Resource
TestPlanApiCaseService testPlanApiCaseService;
@GetMapping("/list/failure/{shareId}/{planId}")
public List<TestPlanFailureApiDTO> getApiFailureList(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanApiCaseService.getFailureCases(planId);
}
@GetMapping("/list/errorReport/{shareId}/{planId}")
public List<TestPlanFailureApiDTO> getErrorReportApiCaseList(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanApiCaseService.getErrorReportCases(planId);
}
@GetMapping("/list/unExecute/{shareId}/{planId}")
public List<TestPlanFailureApiDTO> getUnExecuteCases(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanApiCaseService.getUnExecuteCases(planId);
}
@GetMapping("/list/all/{shareId}/{planId}")
public List<TestPlanFailureApiDTO> getApiAllList(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanApiCaseService.getAllCases(planId);
}
}

View File

@ -1,7 +1,7 @@
package io.metersphere.controller.plan;
import io.metersphere.api.dto.ApiReportResult;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.ShareInfoService;
import io.metersphere.service.definition.ApiDefinitionService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -17,11 +17,11 @@ public class ShareTestPlanApiReportController {
@Resource
ApiDefinitionService apiDefinitionService;
@Resource
BaseShareInfoService baseShareInfoService;
ShareInfoService shareInfoService;
@GetMapping("/api/definition/report/getReport/{shareId}/{testId}")
public ApiReportResult getApiReport(@PathVariable String shareId, @PathVariable String testId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return apiDefinitionService.getDbResult(testId);
}
}

View File

@ -1,7 +1,7 @@
package io.metersphere.controller.plan;
import io.metersphere.api.dto.automation.TestPlanFailureScenarioDTO;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.ShareInfoService;
import io.metersphere.service.plan.TestPlanScenarioCaseService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -16,31 +16,31 @@ import java.util.List;
public class ShareTestPlanScenarioCaseController {
@Resource
BaseShareInfoService baseShareInfoService;
ShareInfoService shareInfoService;
@Resource
TestPlanScenarioCaseService testPlanScenarioCaseService;
@GetMapping("/list/failure/{shareId}/{planId}")
public List<TestPlanFailureScenarioDTO> getScenarioFailureList(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanScenarioCaseService.getFailureCases(planId);
}
@GetMapping("/list/all/{shareId}/{planId}")
public List<TestPlanFailureScenarioDTO> getScenarioAllList(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanScenarioCaseService.getAllCases(planId);
}
@GetMapping("/list/errorReport/{shareId}/{planId}")
public List<TestPlanFailureScenarioDTO> getScenarioErrorReportList(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanScenarioCaseService.getErrorReportCases(planId);
}
@GetMapping("/list/unExecute/{shareId}/{planId}")
public List<TestPlanFailureScenarioDTO> getUnExecuteScenarioCases(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanScenarioCaseService.getUnExecuteCases(planId);
}
}

View File

@ -17,14 +17,9 @@ import io.metersphere.dto.PlanReportCaseDTO;
import io.metersphere.dto.RequestResult;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.ShareInfoService;
import io.metersphere.service.scenario.ApiScenarioReportService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@ -37,7 +32,7 @@ public class ApiScenarioReportController {
@Resource
private ApiScenarioReportService apiReportService;
@Resource
private BaseShareInfoService baseShareInfoService;
private ShareInfoService shareInfoService;
@GetMapping("/get/{reportId}")
public ApiScenarioReportResult get(@PathVariable String reportId) {
@ -46,7 +41,7 @@ public class ApiScenarioReportController {
@GetMapping("/get/{shareId}/{reportId}")
public ApiScenarioReportResult get(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return apiReportService.get(reportId, true);
}

View File

@ -5,29 +5,36 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.automation.ApiScenarioReportResult;
import io.metersphere.api.dto.share.*;
import io.metersphere.api.exec.generator.JSONSchemaGenerator;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ShareInfo;
import io.metersphere.base.domain.User;
import io.metersphere.base.domain.UserExample;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ShareInfoMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.ext.ExtApiScenarioReportMapper;
import io.metersphere.base.mapper.ext.ExtShareInfoMapper;
import io.metersphere.commons.constants.ProjectApplicationType;
import io.metersphere.commons.constants.PropertyConstant;
import io.metersphere.commons.constants.ShareType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
import io.metersphere.i18n.Translator;
import io.metersphere.service.definition.ApiModuleService;
import io.metersphere.service.scenario.ApiScenarioReportService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import static io.metersphere.commons.user.ShareUtil.getTimeMills;
/**
* @author song.tianyang
* @Date 2021/2/7 10:37 上午
@ -45,6 +52,12 @@ public class ShareInfoService extends BaseShareInfoService {
ApiModuleService apiModuleService;
@Resource
private UserMapper userMapper;
@Resource
private ExtApiScenarioReportMapper extApiScenarioReportMapper;
@Resource
private ApiScenarioReportService apiScenarioReportService;
@Resource
private BaseProjectApplicationService baseProjectApplicationService;
public Pager<List<ApiDocumentInfoDTO>> selectApiInfoByParam(ApiDocumentRequest apiDocumentRequest, int goPage, int pageSize) {
this.iniApiDocumentRequest(apiDocumentRequest);
@ -547,4 +560,71 @@ public class ShareInfoService extends BaseShareInfoService {
private boolean isObjectHasKey(JsonNode object, String key) {
return object != null && object.has(key);
}
public void validateExpired(String shareId) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
this.validateExpired(shareInfo);
}
/**
* 不加入事务抛出异常不回滚
* 若在当前类中调用请使用如下方式调用否则该方法的事务注解不生效
* ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
* shareInfoService.validateExpired(shareInfo);
*
* @param shareInfo
*/
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void validateExpired(ShareInfo shareInfo) {
// 有效期根据类型从ProjectApplication中获取
if (shareInfo == null) {
MSException.throwException(Translator.get("connection_expired"));
}
String type = ProjectApplicationType.API_SHARE_REPORT_TIME.toString();
String projectId = "";
ApiScenarioReportResult reportResult = extApiScenarioReportMapper.get(shareInfo.getCustomData());
if (reportResult != null) {
projectId = reportResult.getProjectId();
} else {
// case 集成报告
ApiScenarioReportResult result = apiScenarioReportService.getApiIntegrated(shareInfo.getCustomData());
if (result != null) {
projectId = result.getProjectId();
}
}
if (StringUtils.isBlank(type) || Strings.isBlank(projectId)) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
} else {
ProjectApplication projectApplication = baseProjectApplicationService.getProjectApplication(projectId, type);
if (projectApplication.getTypeValue() == null) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
} else {
String expr = projectApplication.getTypeValue();
long timeMills = getTimeMills(shareInfo.getUpdateTime(), expr);
millisCheck(System.currentTimeMillis(), timeMills, shareInfo.getId());
}
}
}
private void millisCheck(long compareMillis, long millis, String shareInfoId) {
if (compareMillis > millis) {
shareInfoMapper.deleteByPrimaryKey(shareInfoId);
MSException.throwException(Translator.get("connection_expired"));
}
}
public void validate(String shareId, String customData) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
validateExpired(shareInfo);
if (shareInfo == null) {
MSException.throwException("ShareInfo not exist!");
} else {
if (!StringUtils.equals(customData, shareInfo.getCustomData())) {
MSException.throwException("ShareInfo validate failure!");
}
}
}
}

View File

@ -3,12 +3,9 @@ package io.metersphere.service;
import io.metersphere.base.domain.ShareInfo;
import io.metersphere.base.mapper.ShareInfoMapper;
import io.metersphere.base.mapper.ext.BaseShareInfoMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.dto.ShareInfoDTO;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@ -63,47 +60,4 @@ public class BaseShareInfoService {
public ShareInfo get(String id) {
return shareInfoMapper.selectByPrimaryKey(id);
}
public void validate(String shareId, String customData) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
validateExpired(shareInfo);
if (shareInfo == null) {
MSException.throwException("ShareInfo not exist!");
} else {
if (!StringUtils.equals(customData, shareInfo.getCustomData())) {
MSException.throwException("ShareInfo validate failure!");
}
}
}
public void validateExpired(String shareId) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
this.validateExpired(shareInfo);
}
/**
* 不加入事务抛出异常不回滚
* 若在当前类中调用请使用如下方式调用否则该方法的事务注解不生效
* ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
* shareInfoService.validateExpired(shareInfo);
*
* @param shareInfo
*/
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void validateExpired(ShareInfo shareInfo) {
// 有效期根据类型从ProjectApplication中获取
if (shareInfo == null) {
MSException.throwException(Translator.get("connection_expired"));
}
// todo check
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
}
private void millisCheck(long compareMillis, long millis, String shareInfoId) {
if (compareMillis > millis) {
shareInfoMapper.deleteByPrimaryKey(shareInfoId);
MSException.throwException(Translator.get("connection_expired"));
}
}
}

View File

@ -24,7 +24,7 @@ import java.util.List;
public class ShareController {
@Resource
BaseShareInfoService baseShareInfoService;
ShareInfoService shareInfoService;
@Resource
PerformanceReportService performanceReportService;
@Resource
@ -37,20 +37,20 @@ public class ShareController {
@GetMapping("/performance/report/{shareId}/{reportId}")
public ReportDTO getLoadTestReport(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportTestAndProInfo(reportId);
}
@GetMapping("/performance/report/content/report_time/{shareId}/{reportId}")
public ReportTimeInfo getReportTimeInfo(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportTimeInfo(reportId);
}
@GetMapping("/performance/report/get-advanced-config/{shareId}/{reportId}")
public String getAdvancedConfig(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getAdvancedConfiguration(reportId);
}
@ -61,74 +61,74 @@ public class ShareController {
@GetMapping("/performance/report/get-jmx-content/{shareId}/{reportId}")
public LoadTestExportJmx getJmxContent(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getJmxContent(reportId).get(0);
}
@GetMapping("/performance/get-jmx-content/{shareId}/{testId}")
public List<LoadTestExportJmx> getOldJmxContent(@PathVariable String shareId, @PathVariable String testId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceTestService.getJmxContent(testId);
}
@GetMapping("/performance/report/content/testoverview/{shareId}/{reportId}")
public TestOverview getTestOverview(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getTestOverview(reportId);
}
@GetMapping("/performance/report/content/load_chart/{shareId}/{reportId}")
public List<ChartsData> getLoadChartData(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getLoadChartData(reportId);
}
@GetMapping("/performance/report/content/res_chart/{shareId}/{reportId}")
public List<ChartsData> getResponseTimeChartData(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getResponseTimeChartData(reportId);
}
@GetMapping("/performance/report/content/error_chart/{shareId}/{reportId}")
public List<ChartsData> getErrorChartData(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getErrorChartData(reportId);
}
@GetMapping("/performance/report/content/response_code_chart/{shareId}/{reportId}")
public List<ChartsData> getResponseCodeChartData(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getResponseCodeChartData(reportId);
}
@GetMapping("/performance/report/content/{shareId}/{reportKey}/{reportId}")
public List<ChartsData> getReportChart(@PathVariable String shareId, @PathVariable String reportKey, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportChart(reportKey, reportId);
}
@GetMapping("/performance/report/content/{shareId}/{reportId}")
public List<Statistics> getReportContent(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportStatistics(reportId);
}
@GetMapping("/performance/report/content/errors/{shareId}/{reportId}")
public List<Errors> getReportErrors(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportErrors(reportId);
}
@GetMapping("/performance/report/content/errors_top5/{shareId}/{reportId}")
public List<ErrorsTop5> getReportErrorsTop5(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportErrorsTOP5(reportId);
}
@GetMapping("/performance/report/log/resource/{shareId}/{reportId}")
public List<LogDetailDTO> getResourceIds(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceReportService.getReportLogResource(reportId);
}
@ -139,26 +139,26 @@ public class ShareController {
@GetMapping("/performance/report/log/{shareId}/{reportId}/{resourceId}/{goPage}")
public Pager<List<LoadTestReportLog>> logs(@PathVariable String shareId, @PathVariable String reportId, @PathVariable String resourceId, @PathVariable int goPage) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
Page<Object> page = PageHelper.startPage(goPage, 1, true);
return PageUtils.setPageInfo(page, performanceReportService.getReportLogs(reportId, resourceId));
}
@GetMapping("/metric/query/{shareId}/{id}")
public List<MetricData> queryMetric(@PathVariable String shareId, @PathVariable("id") String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return metricService.queryMetric(reportId);
}
@GetMapping("/metric/query/resource/{shareId}/{id}")
public List<Monitor> queryReportResource(@PathVariable String shareId, @PathVariable("id") String reportId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return metricService.queryReportResource(reportId);
}
@GetMapping("/performance/report/get-load-config/{shareId}/{testId}")
public String getLoadConfiguration(@PathVariable String shareId, @PathVariable String testId) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return performanceTestService.getLoadConfiguration(testId);
}

View File

@ -3,7 +3,7 @@ package io.metersphere.plan.controller;
import io.metersphere.plan.dto.TestPlanLoadCaseDTO;
import io.metersphere.plan.request.LoadCaseReportRequest;
import io.metersphere.plan.service.TestPlanLoadCaseService;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.ShareInfoService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -14,25 +14,25 @@ import java.util.List;
public class ShareTestPlanLoadCaseController {
@Resource
BaseShareInfoService baseShareInfoService;
ShareInfoService shareInfoService;
@Resource
TestPlanLoadCaseService testPlanLoadCaseService;
@GetMapping("/list/failure/{shareId}/{planId}")
public List<TestPlanLoadCaseDTO> getLoadFailureCases(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanLoadCaseService.getFailureCases(planId);
}
@GetMapping("/list/all/{shareId}/{planId}")
public List<TestPlanLoadCaseDTO> getLoadAllCases(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanLoadCaseService.getAllCases(planId);
}
@PostMapping("/report/exist/{shareId}")
public Boolean isExistReport(@PathVariable String shareId, @RequestBody LoadCaseReportRequest request) {
baseShareInfoService.validateExpired(shareId);
shareInfoService.validateExpired(shareId);
return testPlanLoadCaseService.isExistReport(request);
}
}

View File

@ -0,0 +1,88 @@
package io.metersphere.service;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.domain.ProjectApplication;
import io.metersphere.base.domain.ShareInfo;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ShareInfoMapper;
import io.metersphere.commons.constants.ProjectApplicationType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import static io.metersphere.commons.user.ShareUtil.getTimeMills;
@Service
public class ShareInfoService {
@Resource
private ShareInfoMapper shareInfoMapper;
@Resource
private BaseProjectApplicationService baseProjectApplicationService;
@Resource
private LoadTestReportMapper loadTestReportMapper;
public void validateExpired(String shareId) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
this.validateExpired(shareInfo);
}
public void validate(String shareId, String customData) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
validateExpired(shareInfo);
if (shareInfo == null) {
MSException.throwException("ShareInfo not exist!");
} else {
if (!StringUtils.equals(customData, shareInfo.getCustomData())) {
MSException.throwException("ShareInfo validate failure!");
}
}
}
/**
* 不加入事务抛出异常不回滚
* 若在当前类中调用请使用如下方式调用否则该方法的事务注解不生效
* ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
* shareInfoService.validateExpired(shareInfo);
*
* @param shareInfo
*/
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void validateExpired(ShareInfo shareInfo) {
// 有效期根据类型从ProjectApplication中获取
if (shareInfo == null) {
MSException.throwException(Translator.get("connection_expired"));
}
String type = ProjectApplicationType.PERFORMANCE_SHARE_REPORT_TIME.toString();
String projectId = "";
LoadTestReportWithBLOBs loadTestReportWithBLOBs = loadTestReportMapper.selectByPrimaryKey(shareInfo.getCustomData());
if (loadTestReportWithBLOBs != null) {
projectId = loadTestReportWithBLOBs.getProjectId();
}
if (StringUtils.isBlank(type) || Strings.isBlank(projectId)) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
} else {
ProjectApplication projectApplication = baseProjectApplicationService.getProjectApplication(projectId, type);
if (projectApplication.getTypeValue() == null) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
} else {
String expr = projectApplication.getTypeValue();
long timeMills = getTimeMills(shareInfo.getUpdateTime(), expr);
millisCheck(System.currentTimeMillis(), timeMills, shareInfo.getId());
}
}
}
private void millisCheck(long compareMillis, long millis, String shareInfoId) {
if (compareMillis > millis) {
shareInfoMapper.deleteByPrimaryKey(shareInfoId);
MSException.throwException(Translator.get("connection_expired"));
}
}
}

View File

@ -1,13 +1,13 @@
package io.metersphere.controller;
import io.metersphere.xpack.track.dto.IssuesDao;
import io.metersphere.dto.TestPlanCaseDTO;
import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
import io.metersphere.plan.service.TestPlanReportService;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.TestPlanTestCaseService;
import io.metersphere.service.BaseShareInfoService;
import io.metersphere.service.IssuesService;
import io.metersphere.service.ShareInfoService;
import io.metersphere.xpack.track.dto.IssuesDao;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -20,7 +20,7 @@ import java.util.List;
public class ShareController {
@Resource
BaseShareInfoService baseShareInfoService;
ShareInfoService shareInfoService;
@Resource
IssuesService issuesService;
@Resource
@ -32,33 +32,33 @@ public class ShareController {
@GetMapping("/issues/plan/get/{shareId}/{planId}")
public List<IssuesDao> getIssuesByPlanoId(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return issuesService.getIssuesByPlanId(planId);
}
@GetMapping("/test/plan/report/{shareId}/{planId}")
public TestPlanSimpleReportDTO getReport(@PathVariable String shareId, @PathVariable String planId) {
baseShareInfoService.validate(shareId, planId);
return testPlanService.getShareReport(baseShareInfoService.get(shareId), planId);
shareInfoService.validate(shareId, planId);
return testPlanService.getShareReport(shareInfoService.get(shareId), planId);
}
@GetMapping("/report/export/{shareId}/{planId}/{lang}")
public void exportHtmlReport(@PathVariable String shareId, @PathVariable String planId,
@PathVariable(required = false) String lang, HttpServletResponse response) throws UnsupportedEncodingException {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
testPlanService.exportPlanReport(planId, lang, response);
}
@PostMapping("/test/plan/case/list/all/{shareId}/{planId}")
public List<TestPlanCaseDTO> getAllCases(@PathVariable String shareId, @PathVariable String planId,
@RequestBody(required = false) List<String> statusList) {
baseShareInfoService.validate(shareId, planId);
shareInfoService.validate(shareId, planId);
return testPlanTestCaseService.getAllCasesByStatusList(planId, statusList);
}
@GetMapping("/test/plan/report/db/{shareId}/{reportId}")
public TestPlanSimpleReportDTO getTestPlanDbReport(@PathVariable String shareId, @PathVariable String reportId) {
baseShareInfoService.validate(shareId, reportId);
return testPlanReportService.getShareDbReport(baseShareInfoService.get(shareId), reportId);
shareInfoService.validate(shareId, reportId);
return testPlanReportService.getShareDbReport(shareInfoService.get(shareId), reportId);
}
}

View File

@ -0,0 +1,117 @@
package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ShareInfoMapper;
import io.metersphere.base.mapper.TestPlanMapper;
import io.metersphere.base.mapper.TestPlanReportContentMapper;
import io.metersphere.base.mapper.TestPlanReportMapper;
import io.metersphere.commons.constants.ProjectApplicationType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import static io.metersphere.commons.user.ShareUtil.getTimeMills;
@Service
public class ShareInfoService {
@Resource
private ShareInfoMapper shareInfoMapper;
@Resource
private BaseProjectApplicationService baseProjectApplicationService;
@Resource
private TestPlanReportContentMapper testPlanReportContentMapper;
@Resource
private TestPlanReportMapper testPlanReportMapper;
@Resource
private TestPlanMapper testPlanMapper;
public void validate(String shareId, String customData) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
validateExpired(shareInfo);
if (shareInfo == null) {
MSException.throwException("ShareInfo not exist!");
} else {
if (!StringUtils.equals(customData, shareInfo.getCustomData())) {
MSException.throwException("ShareInfo validate failure!");
}
}
}
public ShareInfo get(String id) {
return shareInfoMapper.selectByPrimaryKey(id);
}
public void validateExpired(String shareId) {
ShareInfo shareInfo = shareInfoMapper.selectByPrimaryKey(shareId);
this.validateExpired(shareInfo);
}
/**
* 不加入事务抛出异常不回滚
* 若在当前类中调用请使用如下方式调用否则该方法的事务注解不生效
* ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class);
* shareInfoService.validateExpired(shareInfo);
*
* @param shareInfo
*/
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void validateExpired(ShareInfo shareInfo) {
// 有效期根据类型从ProjectApplication中获取
if (shareInfo == null) {
MSException.throwException(Translator.get("connection_expired"));
}
String type = ProjectApplicationType.TRACK_SHARE_REPORT_TIME.toString();
String projectId = "";
TestPlanWithBLOBs testPlan = getTestPlan(shareInfo);
if (testPlan != null) {
projectId = testPlan.getProjectId();
}
if (StringUtils.isBlank(type) || Strings.isBlank(projectId)) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
} else {
ProjectApplication projectApplication = baseProjectApplicationService.getProjectApplication(projectId, type);
if (projectApplication.getTypeValue() == null) {
millisCheck(System.currentTimeMillis() - shareInfo.getUpdateTime(), 1000 * 60 * 60 * 24, shareInfo.getId());
} else {
String expr = projectApplication.getTypeValue();
long timeMills = getTimeMills(shareInfo.getUpdateTime(), expr);
millisCheck(System.currentTimeMillis(), timeMills, shareInfo.getId());
}
}
}
private void millisCheck(long compareMillis, long millis, String shareInfoId) {
if (compareMillis > millis) {
shareInfoMapper.deleteByPrimaryKey(shareInfoId);
MSException.throwException(Translator.get("connection_expired"));
}
}
private TestPlanWithBLOBs getTestPlan(ShareInfo shareInfo) {
TestPlanReportContentExample example = new TestPlanReportContentExample();
example.createCriteria().andTestPlanReportIdEqualTo(shareInfo.getCustomData());
List<TestPlanReportContentWithBLOBs> testPlanReportContents = testPlanReportContentMapper.selectByExampleWithBLOBs(example);
if (!CollectionUtils.isEmpty(testPlanReportContents)) {
TestPlanReportContentWithBLOBs testPlanReportContent = testPlanReportContents.get(0);
if (testPlanReportContent != null) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportContent.getTestPlanReportId());
if (testPlanReport != null) {
return testPlanMapper.selectByPrimaryKey(testPlanReport.getTestPlanId());
}
}
}
return null;
}
}

View File

@ -5,5 +5,5 @@ const BASE_URL = "/project_application/";
export function getProjectApplicationConfig(type) {
let projectId = getCurrentProjectID();
return get(BASE_URL + `get/config/${projectId}/${type}`);
return get(BASE_URL + `get/${projectId}/${type}`);
}

View File

@ -143,35 +143,27 @@ export default {
} else if (this.isDb) {
if (this.isShare) {
//
this.loading = true;
getShareTestPlanReportContent(this.shareId, this.reportId)
this.loading = getShareTestPlanReportContent(this.shareId, this.reportId)
.then((r) => {
this.loading = false;
this.report = r.data;
this.report.config = this.getDefaultConfig(this.report);
});
} else {
this.loading = true;
getTestPlanReportContent(this.reportId)
this.loading = getTestPlanReportContent(this.reportId)
.then((r) => {
this.loading = false;
this.report = r.data;
this.report.config = this.getDefaultConfig(this.report);
});
}
} else if (this.isShare) {
this.loading = true;
getShareTestPlanReport(this.shareId, this.planId)
this.loading = getShareTestPlanReport(this.shareId, this.planId)
.then((r) => {
this.loading = false;
this.report = r.data;
this.report.config = this.getDefaultConfig(this.report);
});
} else {
this.loading = true;
getTestPlanReport(this.planId)
this.loading = getTestPlanReport(this.planId)
.then((r) => {
this.loading = false;
this.report = r.data;
this.report.config = this.getDefaultConfig(this.report);
});