Merge pull request #8005 from metersphere/pr@dev@refactor_同步缺陷项目ID未填提示

refactor: 同步缺陷项目ID未填提示
This commit is contained in:
jianxing 2021-11-23 16:21:46 +08:00 committed by GitHub
commit 6e5e805de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 51 deletions

View File

@ -37,6 +37,7 @@ import javax.net.ssl.SSLContext;
import java.io.File; import java.io.File;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -135,6 +136,19 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
*/ */
public abstract String getProjectId(String projectId); public abstract String getProjectId(String projectId);
public String getProjectId(String projectId, Function<Project, String> getProjectKeyFuc) {
Project project;
if (StringUtils.isNotBlank(projectId)) {
project = projectService.getProjectById(projectId);
} else {
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
project = projectService.getProjectById(testCase.getProjectId());
}
String projectKey = getProjectKeyFuc.apply(project);
if (StringUtils.isBlank(projectKey)) MSException.throwException("请在项目设置配置 " + key + "项目ID");
return projectKey;
}
protected boolean isIntegratedPlatform(String workspaceId, String platform) { protected boolean isIntegratedPlatform(String workspaceId, String platform) {
IntegrationRequest request = new IntegrationRequest(); IntegrationRequest request = new IntegrationRequest();
request.setPlatform(platform); request.setPlatform(platform);

View File

@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.IssuesDao; import io.metersphere.base.domain.IssuesDao;
import io.metersphere.base.domain.IssuesWithBLOBs; import io.metersphere.base.domain.IssuesWithBLOBs;
import io.metersphere.base.domain.Project; import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesManagePlatform;
import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.constants.IssuesStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
@ -34,19 +33,18 @@ import java.util.UUID;
public class JiraPlatform extends AbstractIssuePlatform { public class JiraPlatform extends AbstractIssuePlatform {
protected String key = IssuesManagePlatform.Jira.toString();
protected JiraClientV2 jiraClientV2; protected JiraClientV2 jiraClientV2;
public JiraPlatform(IssuesRequest issuesRequest) { public JiraPlatform(IssuesRequest issuesRequest) {
super(issuesRequest); super(issuesRequest);
jiraClientV2 = new JiraClientV2(); jiraClientV2 = new JiraClientV2();
setConfig(); setConfig();
this.key = IssuesManagePlatform.Jira.name();
} }
@Override @Override
public List<IssuesDao> getIssue(IssuesRequest issuesRequest) { public List<IssuesDao> getIssue(IssuesRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Jira.toString()); issuesRequest.setPlatform(key);
List<IssuesDao> issues; List<IssuesDao> issues;
if (StringUtils.isNotBlank(issuesRequest.getProjectId())) { if (StringUtils.isNotBlank(issuesRequest.getProjectId())) {
issues = extIssuesMapper.getIssues(issuesRequest); issues = extIssuesMapper.getIssues(issuesRequest);
@ -81,7 +79,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
issue.setLastmodify(assignee == null ? "" : assignee.getString("displayName")); issue.setLastmodify(assignee == null ? "" : assignee.getString("displayName"));
issue.setDescription(description); issue.setDescription(description);
issue.setPlatformStatus(status); issue.setPlatformStatus(status);
issue.setPlatform(IssuesManagePlatform.Jira.toString()); issue.setPlatform(key);
issue.setCustomFields(syncIssueCustomField(issue.getCustomFields(), jiraIssue.getFields())); issue.setCustomFields(syncIssueCustomField(issue.getCustomFields(), jiraIssue.getFields()));
return issue; return issue;
} }
@ -112,7 +110,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setName(summary); demandDTO.setName(summary);
demandDTO.setId(issueKey); demandDTO.setId(issueKey);
demandDTO.setPlatform(IssuesManagePlatform.Jira.name()); demandDTO.setPlatform(key);
list.add(demandDTO); list.add(demandDTO);
} }
startAt += maxResults; startAt += maxResults;
@ -170,7 +168,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
private JSONObject buildUpdateParam(IssuesUpdateRequest issuesRequest, String issuetypeStr) { private JSONObject buildUpdateParam(IssuesUpdateRequest issuesRequest, String issuetypeStr) {
issuesRequest.setPlatform(IssuesManagePlatform.Jira.toString()); issuesRequest.setPlatform(key);
String jiraKey = validateJiraKey(issuesRequest.getProjectId()); String jiraKey = validateJiraKey(issuesRequest.getProjectId());
@ -288,16 +286,11 @@ public class JiraPlatform extends AbstractIssuePlatform {
@Override @Override
public String getProjectId(String projectId) { public String getProjectId(String projectId) {
if (StringUtils.isNotBlank(projectId)) { return getProjectId(projectId, Project::getJiraKey);
return projectService.getProjectById(projectId).getJiraKey();
}
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
Project project = projectService.getProjectById(testCase.getProjectId());
return project.getJiraKey();
} }
public JiraConfig getConfig() { public JiraConfig getConfig() {
return getConfig(IssuesManagePlatform.Jira.toString(), JiraConfig.class); return getConfig(key, JiraConfig.class);
} }
public JiraConfig setConfig() { public JiraConfig setConfig() {

View File

@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.IssuesDao; import io.metersphere.base.domain.IssuesDao;
import io.metersphere.base.domain.IssuesWithBLOBs; import io.metersphere.base.domain.IssuesWithBLOBs;
import io.metersphere.base.domain.Project; import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesManagePlatform;
import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.constants.IssuesStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
@ -35,19 +34,18 @@ import java.util.stream.Collectors;
public class TapdPlatform extends AbstractIssuePlatform { public class TapdPlatform extends AbstractIssuePlatform {
protected String key = IssuesManagePlatform.Tapd.toString();
protected TapdClient tapdClient; protected TapdClient tapdClient;
public TapdPlatform(IssuesRequest issueRequest) { public TapdPlatform(IssuesRequest issueRequest) {
super(issueRequest); super(issueRequest);
tapdClient = new TapdClient(); tapdClient = new TapdClient();
setConfig(); setConfig();
this.key = IssuesManagePlatform.Tapd.name();
} }
@Override @Override
public List<IssuesDao> getIssue(IssuesRequest issuesRequest) { public List<IssuesDao> getIssue(IssuesRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Tapd.toString()); issuesRequest.setPlatform(key);
List<IssuesDao> issues; List<IssuesDao> issues;
if (StringUtils.isNotBlank(issuesRequest.getProjectId())) { if (StringUtils.isNotBlank(issuesRequest.getProjectId())) {
issues = extIssuesMapper.getIssues(issuesRequest); issues = extIssuesMapper.getIssues(issuesRequest);
@ -64,7 +62,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
for (int i = 0; i < demands.size(); i++) { for (int i = 0; i < demands.size(); i++) {
JSONObject o = demands.getJSONObject(i); JSONObject o = demands.getJSONObject(i);
DemandDTO demand = o.getObject("Story", DemandDTO.class); DemandDTO demand = o.getObject("Story", DemandDTO.class);
demand.setPlatform(IssuesManagePlatform.Tapd.name()); demand.setPlatform(key);
demandList.add(demand); demandList.add(demand);
} }
return demandList; return demandList;
@ -99,7 +97,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
} }
private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) { private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Tapd.toString()); issuesRequest.setPlatform(key);
String tapdId = getProjectId(issuesRequest.getProjectId()); String tapdId = getProjectId(issuesRequest.getProjectId());
@ -228,16 +226,11 @@ public class TapdPlatform extends AbstractIssuePlatform {
@Override @Override
public String getProjectId(String projectId) { public String getProjectId(String projectId) {
if (StringUtils.isNotBlank(projectId)) { return getProjectId(projectId, Project::getTapdId);
return projectService.getProjectById(projectId).getTapdId();
}
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
Project project = projectService.getProjectById(testCase.getProjectId());
return project.getTapdId();
} }
public TapdConfig getConfig() { public TapdConfig getConfig() {
return getConfig(IssuesManagePlatform.Tapd.toString(), TapdConfig.class); return getConfig(key, TapdConfig.class);
} }
public TapdConfig setConfig() { public TapdConfig setConfig() {

View File

@ -37,29 +37,23 @@ import java.util.regex.Pattern;
public class ZentaoPlatform extends AbstractIssuePlatform { public class ZentaoPlatform extends AbstractIssuePlatform {
protected final ZentaoClient zentaoClient; protected final ZentaoClient zentaoClient;
protected String key = IssuesManagePlatform.Zentao.toString();
public ZentaoPlatform(IssuesRequest issuesRequest) { public ZentaoPlatform(IssuesRequest issuesRequest) {
super(issuesRequest); super(issuesRequest);
ZentaoConfig zentaoConfig = getConfig(); ZentaoConfig zentaoConfig = getConfig();
this.workspaceId = issuesRequest.getWorkspaceId(); this.workspaceId = issuesRequest.getWorkspaceId();
this.zentaoClient = ZentaoFactory.getInstance(zentaoConfig.getUrl(), zentaoConfig.getRequest()); this.zentaoClient = ZentaoFactory.getInstance(zentaoConfig.getUrl(), zentaoConfig.getRequest());
this.zentaoClient.setConfig(zentaoConfig); this.zentaoClient.setConfig(zentaoConfig);
this.key = IssuesManagePlatform.Zentao.name();
} }
@Override @Override
public String getProjectId(String projectId) { public String getProjectId(String projectId) {
if (StringUtils.isNotBlank(projectId)) { return getProjectId(projectId, Project::getZentaoId);
return projectService.getProjectById(projectId).getZentaoId();
}
TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId);
Project project = projectService.getProjectById(testCase.getProjectId());
return project.getZentaoId();
} }
@Override @Override
public List<IssuesDao> getIssue(IssuesRequest issuesRequest) { public List<IssuesDao> getIssue(IssuesRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Zentao.toString()); issuesRequest.setPlatform(key);
List<IssuesDao> issues; List<IssuesDao> issues;
if (StringUtils.isNotBlank(issuesRequest.getProjectId())) { if (StringUtils.isNotBlank(issuesRequest.getProjectId())) {
issues = extIssuesMapper.getIssues(issuesRequest); issues = extIssuesMapper.getIssues(issuesRequest);
@ -99,7 +93,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setId(o.getString("id")); demandDTO.setId(o.getString("id"));
demandDTO.setName(o.getString("title")); demandDTO.setName(o.getString("title"));
demandDTO.setPlatform(IssuesManagePlatform.Zentao.name()); demandDTO.setPlatform(key);
list.add(demandDTO); list.add(demandDTO);
} }
} }
@ -114,7 +108,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setId(jsonObject.getString("id")); demandDTO.setId(jsonObject.getString("id"));
demandDTO.setName(jsonObject.getString("title")); demandDTO.setName(jsonObject.getString("title"));
demandDTO.setPlatform(IssuesManagePlatform.Zentao.name()); demandDTO.setPlatform(key);
list.add(demandDTO); list.add(demandDTO);
}); });
} }
@ -170,7 +164,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
IssuesExample issuesExample = new IssuesExample(); IssuesExample issuesExample = new IssuesExample();
issuesExample.createCriteria().andIdEqualTo(id) issuesExample.createCriteria().andIdEqualTo(id)
.andPlatformEqualTo(IssuesManagePlatform.Zentao.toString()); .andPlatformEqualTo(key);
if (issuesMapper.selectByExample(issuesExample).size() <= 0) { if (issuesMapper.selectByExample(issuesExample).size() <= 0) {
// 插入缺陷表 // 插入缺陷表
issues = insertIssues(issuesRequest); issues = insertIssues(issuesRequest);
@ -191,7 +185,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
} }
private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) { private MultiValueMap<String, Object> buildUpdateParam(IssuesUpdateRequest issuesRequest) {
issuesRequest.setPlatform(IssuesManagePlatform.Zentao.toString()); issuesRequest.setPlatform(key);
String projectId = getProjectId(issuesRequest.getProjectId()); String projectId = getProjectId(issuesRequest.getProjectId());
if (StringUtils.isBlank(projectId)) { if (StringUtils.isBlank(projectId)) {
MSException.throwException("未关联禅道项目ID."); MSException.throwException("未关联禅道项目ID.");
@ -246,7 +240,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
} }
public ZentaoConfig getConfig() { public ZentaoConfig getConfig() {
return getConfig(IssuesManagePlatform.Zentao.toString(), ZentaoConfig.class); return getConfig(key, ZentaoConfig.class);
} }
public ZentaoConfig setConfig() { public ZentaoConfig setConfig() {

View File

@ -34,13 +34,6 @@
ref="table" ref="table"
> >
<span v-for="(item) in fields" :key="item.key"> <span v-for="(item) in fields" :key="item.key">
<!-- <ms-table-column
:label="$t('test_track.issue.id')"
prop="id"
:field="item"
:fields-width="fieldsWidth"
v-if="false">
</ms-table-column>-->
<ms-table-column width="1"> <ms-table-column width="1">
</ms-table-column> </ms-table-column>
<ms-table-column <ms-table-column
@ -179,7 +172,7 @@ import {getIssues, syncIssues} from "@/network/Issue";
import { import {
getCustomFieldValue, getCustomFieldValue,
getCustomTableWidth, getCustomTableWidth,
getPageInfo, getTableHeaderWithCustomFields,saveLastTableSortField,getLastTableSortField getPageInfo, getTableHeaderWithCustomFields, getLastTableSortField
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
import MsContainer from "@/business/components/common/components/MsContainer"; import MsContainer from "@/business/components/common/components/MsContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer"; import MsMainContainer from "@/business/components/common/components/MsMainContainer";
@ -253,7 +246,7 @@ export default {
} }
} }
} }
this.$refs.table.reloadTable(); if (this.$refs.table) this.$refs.table.reloadTable();
}); });
this.getIssues(); this.getIssues();
}, },
@ -278,7 +271,7 @@ export default {
}, },
methods: { methods: {
tableDoLayout() { tableDoLayout() {
this.$refs.table.doLayout(); if (this.$refs.table) this.$refs.table.doLayout();
}, },
getCustomFieldValue(row, field) { getCustomFieldValue(row, field) {
return getCustomFieldValue(row, field, this.members); return getCustomFieldValue(row, field, this.members);