fix: 取消集成后,解除项目关联

This commit is contained in:
shiziyuan9527 2020-08-18 15:44:41 +08:00
parent ab07bc3de8
commit 7ffb6812cf
7 changed files with 46 additions and 26 deletions

View File

@ -11,4 +11,6 @@ public interface ExtProjectMapper {
List<ProjectDTO> getProjectWithWorkspace(@Param("proRequest") ProjectRequest request); List<ProjectDTO> getProjectWithWorkspace(@Param("proRequest") ProjectRequest request);
List<String> getProjectIdByWorkspaceId(String workspaceId); List<String> getProjectIdByWorkspaceId(String workspaceId);
int removeIssuePlatform(@Param("platform") String platform, @Param("orgId") String orgId);
} }

View File

@ -4,9 +4,9 @@
<select id="getProjectWithWorkspace" resultType="io.metersphere.dto.ProjectDTO"> <select id="getProjectWithWorkspace" resultType="io.metersphere.dto.ProjectDTO">
select p.id, p.workspace_id, p.name, p.description, p.update_time, select p.id, p.workspace_id, p.name, p.description, p.update_time,
p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key p.create_time, w.id as workspaceId, w.name as workspaceName, p.tapd_id, p.jira_key
from project p from project p
join workspace w on p.workspace_id = w.id join workspace w on p.workspace_id = w.id
<where> <where>
<if test="proRequest.name != null and proRequest.name != ''"> <if test="proRequest.name != null and proRequest.name != ''">
and p.name like #{proRequest.name, jdbcType=VARCHAR} and p.name like #{proRequest.name, jdbcType=VARCHAR}
@ -28,4 +28,22 @@
where workspace_id = #{workspaceId} where workspace_id = #{workspaceId}
</select> </select>
<update id="removeIssuePlatform">
update project
<set>
<if test="platform == 'Jira'">
jira_key = null
</if>
<if test="platform == 'Tapd'">
tapd_id = null
</if>
</set>
where project.id in (select id from (select id
from project
where workspace_id in
(select workspace.id
from workspace
where organization_id = #{orgId})) as a)
</update>
</mapper> </mapper>

View File

@ -3,6 +3,7 @@ package io.metersphere.service;
import io.metersphere.base.domain.ServiceIntegration; import io.metersphere.base.domain.ServiceIntegration;
import io.metersphere.base.domain.ServiceIntegrationExample; import io.metersphere.base.domain.ServiceIntegrationExample;
import io.metersphere.base.mapper.ServiceIntegrationMapper; import io.metersphere.base.mapper.ServiceIntegrationMapper;
import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.controller.request.IntegrationRequest; import io.metersphere.controller.request.IntegrationRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -20,6 +21,8 @@ public class IntegrationService {
@Resource @Resource
private ServiceIntegrationMapper serviceIntegrationMapper; private ServiceIntegrationMapper serviceIntegrationMapper;
@Resource
private ExtProjectMapper extProjectMapper;
public ServiceIntegration save(ServiceIntegration service) { public ServiceIntegration save(ServiceIntegration service) {
ServiceIntegrationExample example = new ServiceIntegrationExample(); ServiceIntegrationExample example = new ServiceIntegrationExample();
@ -63,6 +66,8 @@ public class IntegrationService {
.andOrganizationIdEqualTo(orgId) .andOrganizationIdEqualTo(orgId)
.andPlatformEqualTo(platform); .andPlatformEqualTo(platform);
serviceIntegrationMapper.deleteByExample(example); serviceIntegrationMapper.deleteByExample(example);
// 删除项目关联的id/key
extProjectMapper.removeIssuePlatform(platform, orgId);
} }
public List<ServiceIntegration> getAll(String orgId) { public List<ServiceIntegration> getAll(String orgId) {

View File

@ -1,7 +1,7 @@
package io.metersphere.track.controller; package io.metersphere.track.controller;
import io.metersphere.base.domain.Issues; import io.metersphere.base.domain.Issues;
import io.metersphere.service.IssuesService; import io.metersphere.track.service.IssuesService;
import io.metersphere.track.request.testcase.IssuesRequest; import io.metersphere.track.request.testcase.IssuesRequest;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;

View File

@ -1,4 +1,4 @@
package io.metersphere.service; package io.metersphere.track.service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -15,8 +15,9 @@ import io.metersphere.commons.utils.RestTemplateUtils;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.ResultHolder; import io.metersphere.controller.ResultHolder;
import io.metersphere.controller.request.IntegrationRequest; import io.metersphere.controller.request.IntegrationRequest;
import io.metersphere.service.IntegrationService;
import io.metersphere.service.ProjectService;
import io.metersphere.track.request.testcase.IssuesRequest; import io.metersphere.track.request.testcase.IssuesRequest;
import io.metersphere.track.service.TestCaseService;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@ -154,12 +155,6 @@ public class IssuesService {
String tapdId = getTapdProjectId(issuesRequest.getTestCaseId()); String tapdId = getTapdProjectId(issuesRequest.getTestCaseId());
String jiraKey = getJiraProjectKey(issuesRequest.getTestCaseId()); String jiraKey = getJiraProjectKey(issuesRequest.getTestCaseId());
if (tapd || jira) {
if (StringUtils.isBlank(tapdId) && StringUtils.isBlank(jiraKey)) {
MSException.throwException("集成了缺陷管理平台,但未进行项目关联!");
}
}
if (tapd) { if (tapd) {
// 是否关联了项目 // 是否关联了项目
if (StringUtils.isNotBlank(tapdId)) { if (StringUtils.isNotBlank(tapdId)) {
@ -173,7 +168,7 @@ public class IssuesService {
} }
} }
if (!tapd && !jira) { if (StringUtils.isBlank(tapdId) && StringUtils.isBlank(jiraKey)) {
addLocalIssues(issuesRequest); addLocalIssues(issuesRequest);
} }
@ -322,7 +317,7 @@ public class IssuesService {
HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(headers); HttpEntity<MultiValueMap> requestEntity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
//post //post
ResponseEntity<String> responseEntity = null; ResponseEntity<String> responseEntity;
Issues issues = new Issues(); Issues issues = new Issues();
try { try {
responseEntity = restTemplate.exchange(url + "/rest/api/2/issue/" + issuesId, HttpMethod.GET, requestEntity, String.class); responseEntity = restTemplate.exchange(url + "/rest/api/2/issue/" + issuesId, HttpMethod.GET, requestEntity, String.class);
@ -395,7 +390,7 @@ public class IssuesService {
List<Issues> issues = extIssuesMapper.getIssues(caseId, IssuesManagePlatform.Tapd.toString()); List<Issues> issues = extIssuesMapper.getIssues(caseId, IssuesManagePlatform.Tapd.toString());
List<String> issuesIds = issues.stream().map(issue -> issue.getId()).collect(Collectors.toList()); List<String> issuesIds = issues.stream().map(Issues::getId).collect(Collectors.toList());
issuesIds.forEach(issuesId -> { issuesIds.forEach(issuesId -> {
Issues dto = getTapdIssues(tapdId, issuesId); Issues dto = getTapdIssues(tapdId, issuesId);
if (StringUtils.isBlank(dto.getId())) { if (StringUtils.isBlank(dto.getId())) {
@ -437,7 +432,7 @@ public class IssuesService {
List<Issues> issues = extIssuesMapper.getIssues(caseId, IssuesManagePlatform.Jira.toString()); List<Issues> issues = extIssuesMapper.getIssues(caseId, IssuesManagePlatform.Jira.toString());
List<String> issuesIds = issues.stream().map(issue -> issue.getId()).collect(Collectors.toList()); List<String> issuesIds = issues.stream().map(Issues::getId).collect(Collectors.toList());
issuesIds.forEach(issuesId -> { issuesIds.forEach(issuesId -> {
Issues dto = getJiraIssues(headers, url, issuesId); Issues dto = getJiraIssues(headers, url, issuesId);
if (StringUtils.isBlank(dto.getId())) { if (StringUtils.isBlank(dto.getId())) {

View File

@ -1,6 +1,6 @@
<template> <template>
<el-card class="header-title"> <el-card class="header-title" v-loading="result.loading">
<div v-loading="result.loading"> <div>
<div>{{$t('organization.select_defect_platform')}}</div> <div>{{$t('organization.select_defect_platform')}}</div>
<el-radio-group v-model="platform" style="margin-top: 10px" @change="change"> <el-radio-group v-model="platform" style="margin-top: 10px" @change="change">
<el-radio v-for="(item, index) in platforms" :key="index" :label="item.value" size="small"> <el-radio v-for="(item, index) in platforms" :key="index" :label="item.value" size="small">
@ -26,12 +26,12 @@
</div> </div>
<div style="margin-left: 100px"> <div style="margin-left: 100px">
<el-button type="primary" size="small" :disabled="!show" @click="testConnection">{{$t('ldap.test_connect')}} <el-button type="primary" size="mini" :disabled="!show" @click="testConnection">{{$t('ldap.test_connect')}}
</el-button> </el-button>
<el-button v-if="showEdit" size="small" @click="edit">{{$t('commons.edit')}}</el-button> <el-button v-if="showEdit" size="mini" @click="edit">{{$t('commons.edit')}}</el-button>
<el-button type="primary" v-if="showSave" size="small" @click="save('form')">{{$t('commons.save')}}</el-button> <el-button type="primary" v-if="showSave" size="mini" @click="save('form')">{{$t('commons.save')}}</el-button>
<el-button v-if="showCancel" size="small" @click="cancelEdit">取消编辑</el-button> <el-button v-if="showCancel" size="mini" @click="cancelEdit">取消编辑</el-button>
<el-button type="info" size="small" @click="cancelIntegration('form')" :disabled="!show"> <el-button type="info" size="mini" @click="cancelIntegration('form')" :disabled="!show">
取消集成 取消集成
</el-button> </el-button>
</div> </div>
@ -54,7 +54,7 @@
import {getCurrentUser} from "../../../../common/js/utils"; import {getCurrentUser} from "../../../../common/js/utils";
export default { export default {
name: "DefectManagement", name: "IssuesManagement",
data() { data() {
return { return {
form: {}, form: {},
@ -195,7 +195,7 @@
}); });
}, },
testConnection() { testConnection() {
this.$get("issues/auth/" + this.platform, () => { this.result = this.$get("issues/auth/" + this.platform, () => {
this.$success("验证通过!"); this.$success("验证通过!");
}); });
} }

View File

@ -10,7 +10,7 @@
<script> <script>
import DefectManagement from "./DefectManagement"; import DefectManagement from "./IssuesManagement";
export default { export default {
name: "ServiceIntegration", name: "ServiceIntegration",