diff --git a/backend/src/main/java/io/metersphere/dto/UserDTO.java b/backend/src/main/java/io/metersphere/dto/UserDTO.java index 84132de6bf..2d41f6c8c2 100644 --- a/backend/src/main/java/io/metersphere/dto/UserDTO.java +++ b/backend/src/main/java/io/metersphere/dto/UserDTO.java @@ -27,6 +27,8 @@ public class UserDTO extends User { private String jiraAccount; private String jiraPassword; private String tapdUserName; + private String zentaoUserName; + private String zentaoPassword; } } diff --git a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java index 420e7e3417..f5ee923403 100644 --- a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java @@ -188,6 +188,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { issues.setCreateTime(System.currentTimeMillis()); issues.setUpdateTime(System.currentTimeMillis()); issues.setNum(getNextNum(issuesRequest.getProjectId())); + issues.setPlatformStatus(issuesRequest.getPlatformStatus()); issuesMapper.insert(issues); } diff --git a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java index 1c7758e104..b521e78764 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -86,13 +86,9 @@ public class JiraPlatform extends AbstractIssuePlatform { String lastmodify = ""; String status = ""; JSONObject fields = jiraIssue.getFields(); - JSONObject statusObj = (JSONObject) fields.get("status"); - JSONObject assignee = (JSONObject) fields.get("assignee"); - if (statusObj != null) { - JSONObject statusCategory = (JSONObject) statusObj.get("statusCategory"); - status = statusCategory.getString("name"); - } + status = getStatus(fields); + JSONObject assignee = (JSONObject) fields.get("assignee"); String description = fields.getString("description"); Parser parser = Parser.builder().build(); @@ -112,6 +108,15 @@ public class JiraPlatform extends AbstractIssuePlatform { item.setPlatform(IssuesManagePlatform.Jira.toString()); } + private String getStatus(JSONObject fields) { + JSONObject statusObj = (JSONObject) fields.get("status"); + if (statusObj != null) { + JSONObject statusCategory = (JSONObject) statusObj.get("statusCategory"); + return statusCategory.getString("name"); + } + return ""; + } + @Override public List getDemandList(String projectId) { List list = new ArrayList<>(); @@ -227,6 +232,9 @@ public class JiraPlatform extends AbstractIssuePlatform { } }); JiraAddIssueResponse result = jiraClientV2.addIssue(JSONObject.toJSONString(addJiraIssueParam)); + JiraIssue issues = jiraClientV2.getIssues(result.getId()); + String status = getStatus(issues.getFields()); + issuesRequest.setPlatformStatus(status); issuesRequest.setId(result.getKey()); // 用例与第三方缺陷平台中的缺陷关联 diff --git a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java index ee30c6250b..39865112d0 100644 --- a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java @@ -19,6 +19,7 @@ import io.metersphere.dto.UserDTO; import io.metersphere.track.dto.DemandDTO; import io.metersphere.track.issue.client.TapdClient; import io.metersphere.track.issue.domain.PlatformUser; +import io.metersphere.track.issue.domain.tapd.TapdBug; import io.metersphere.track.issue.domain.tapd.TapdConfig; import io.metersphere.track.issue.domain.tapd.TapdGetIssueResponse; import io.metersphere.track.request.testcase.IssuesRequest; @@ -100,13 +101,15 @@ public class TapdPlatform extends AbstractIssuePlatform { usersStr = String.join(";", platformUsers); } - String username = SessionUtils.getUser().getName(); + String reporter = getReporter(); + if (StringUtils.isBlank(reporter)) { + reporter = SessionUtils.getUser().getName(); + } MultiValueMap paramMap = new LinkedMultiValueMap<>(); paramMap.add("title", issuesRequest.getTitle()); paramMap.add("workspace_id", tapdId); paramMap.add("description", issuesRequest.getDescription()); - paramMap.add("reporter", username); paramMap.add("current_owner", usersStr); customFields.forEach(item -> { @@ -114,19 +117,19 @@ public class TapdPlatform extends AbstractIssuePlatform { paramMap.add(item.getCustomData(), item.getValue()); } }); + paramMap.add("reporter", reporter); - ResultHolder result = call(url, HttpMethod.POST, paramMap); + setConfig(); + TapdBug bug = tapdClient.addIssue(paramMap); + Map statusMap = tapdClient.getStatusMap(getProjectId(this.projectId)); + issuesRequest.setPlatformStatus(statusMap.get(bug.getStatus())); - String listJson = JSON.toJSONString(result.getData()); - JSONObject jsonObject = JSONObject.parseObject(listJson); - String issuesId = jsonObject.getObject("Bug", Issues.class).getId(); - - issuesRequest.setId(issuesId); + issuesRequest.setId(bug.getId()); // 用例与第三方缺陷平台中的缺陷关联 handleTestCaseIssues(issuesRequest); // 插入缺陷表 - insertIssues(issuesId, issuesRequest); + insertIssues(bug.getId(), issuesRequest); } @Override @@ -200,7 +203,7 @@ public class TapdPlatform extends AbstractIssuePlatform { count = data.size(); pageNum++; data.forEach(issue -> { - TapdGetIssueResponse.Bug bug = issue.getBug(); + TapdBug bug = issue.getBug(); IssuesDao issuesDao = new IssuesDao(); BeanUtils.copyBean(issuesDao, bug); issuesDao.setPlatformStatus(statusMap.get(bug.getStatus())); @@ -228,19 +231,20 @@ public class TapdPlatform extends AbstractIssuePlatform { } public TapdConfig getConfig() { - TapdConfig tapdConfig = null; String config = getPlatformConfig(IssuesManagePlatform.Tapd.toString()); - if (StringUtils.isNotBlank(config)) { - tapdConfig = JSONObject.parseObject(config, TapdConfig.class); - UserDTO.PlatformInfo userPlatInfo = getUserPlatInfo(this.orgId); - if (userPlatInfo != null && StringUtils.isNotBlank(userPlatInfo.getTapdUserName())) { -// tapdConfig.setAccount(userPlatInfo.getTapdUserName()); - } - } + TapdConfig tapdConfig = JSONObject.parseObject(config, TapdConfig.class); // validateConfig(tapdConfig); return tapdConfig; } + public String getReporter() { + UserDTO.PlatformInfo userPlatInfo = getUserPlatInfo(this.orgId); + if (userPlatInfo != null && StringUtils.isNotBlank(userPlatInfo.getTapdUserName())) { + return userPlatInfo.getTapdUserName(); + } + return null; + } + public TapdConfig setConfig() { TapdConfig config = getConfig(); tapdClient.setConfig(config); diff --git a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java index 2d80074300..9ae57dc5aa 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -13,6 +13,7 @@ import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.CustomFieldItemDTO; +import io.metersphere.dto.UserDTO; import io.metersphere.track.dto.DemandDTO; import io.metersphere.track.issue.client.ZentaoClient; import io.metersphere.track.issue.domain.PlatformUser; @@ -158,18 +159,11 @@ public class ZentaoPlatform extends AbstractIssuePlatform { issuesRequest.setPlatform(IssuesManagePlatform.Zentao.toString()); List customFields = getCustomFields(issuesRequest.getCustomFields()); - setConfig(); - String session = zentaoClient.login(); - + zentaoClient.setConfig(getUserConfig()); String projectId = getProjectId(issuesRequest.getProjectId()); - if (StringUtils.isBlank(projectId)) { MSException.throwException("未关联禅道项目ID."); } - - if (StringUtils.isBlank(session)) { - MSException.throwException("session is null"); - } MultiValueMap paramMap = new LinkedMultiValueMap<>(); paramMap.add("product", projectId); paramMap.add("title", issuesRequest.getTitle()); @@ -203,6 +197,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { } AddIssueResponse.Issue issue = zentaoClient.addIssue(paramMap); + issuesRequest.setPlatformStatus(issue.getStatus()); String id = issue.getId(); if (StringUtils.isNotBlank(id)) { @@ -253,6 +248,22 @@ public class ZentaoPlatform extends AbstractIssuePlatform { return zentaoConfig; } + public ZentaoConfig getUserConfig() { + ZentaoConfig zentaoConfig = null; + String config = getPlatformConfig(IssuesManagePlatform.Zentao.toString()); + if (StringUtils.isNotBlank(config)) { + zentaoConfig = JSONObject.parseObject(config, ZentaoConfig.class); + UserDTO.PlatformInfo userPlatInfo = getUserPlatInfo(this.orgId); + if (userPlatInfo != null && StringUtils.isNotBlank(userPlatInfo.getZentaoUserName()) + && StringUtils.isNotBlank(userPlatInfo.getZentaoPassword())) { + zentaoConfig.setAccount(userPlatInfo.getZentaoUserName()); + zentaoConfig.setPassword(userPlatInfo.getZentaoPassword()); + } + } +// validateConfig(jiraConfig); + return zentaoConfig; + } + @Override public List getPlatformUser() { setConfig(); diff --git a/backend/src/main/java/io/metersphere/track/issue/client/BaseClient.java b/backend/src/main/java/io/metersphere/track/issue/client/BaseClient.java index ab1f438975..42ed052c02 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/BaseClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/BaseClient.java @@ -50,11 +50,11 @@ public abstract class BaseClient { protected String getResult(ResponseEntity response) { int statusCodeValue = response.getStatusCodeValue(); - LogUtil.debug("responseCode: " + statusCodeValue); + LogUtil.info("responseCode: " + statusCodeValue); if(statusCodeValue >= 400){ MSException.throwException(response.getBody()); } - LogUtil.debug("result: " + response.getBody()); + LogUtil.info("result: " + response.getBody()); return response.getBody(); } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java index d317f32915..6262f9a267 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/JiraAbstractClient.java @@ -23,7 +23,7 @@ public abstract class JiraAbstractClient extends BaseClient { protected String PASSWD; public JiraIssue getIssues(String issuesId) { - LogUtil.debug("getIssues: " + issuesId); + LogUtil.info("getIssues: " + issuesId); ResponseEntity responseEntity; responseEntity = restTemplate.exchange(getBaseUrl() + "/issue/" + issuesId, HttpMethod.GET, getAuthHttpEntity(), String.class); return (JiraIssue) getResultForObject(JiraIssue.class, responseEntity); @@ -35,11 +35,17 @@ public abstract class JiraAbstractClient extends BaseClient { } public JiraAddIssueResponse addIssue(String body) { - LogUtil.debug("addIssue: " + body); + LogUtil.info("addIssue: " + body); HttpHeaders headers = getAuthHeader(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity requestEntity = new HttpEntity<>(body, headers); - ResponseEntity response = restTemplate.exchange(getBaseUrl() + "/issue", HttpMethod.POST, requestEntity, String.class); + ResponseEntity response = null; + try { + response = restTemplate.exchange(getBaseUrl() + "/issue", HttpMethod.POST, requestEntity, String.class); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + MSException.throwException(e.getMessage()); + } return (JiraAddIssueResponse) getResultForObject(JiraAddIssueResponse.class, response); } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/TapdClient.java b/backend/src/main/java/io/metersphere/track/issue/client/TapdClient.java index 2e7dd144ce..65fbaafc24 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/TapdClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/TapdClient.java @@ -2,6 +2,9 @@ package io.metersphere.track.issue.client; import com.alibaba.fastjson.JSONObject; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.track.issue.domain.tapd.AddTapdIssueResponse; +import io.metersphere.track.issue.domain.tapd.TapdBug; import io.metersphere.track.issue.domain.tapd.TapdConfig; import io.metersphere.track.issue.domain.tapd.TapdGetIssueResponse; import org.springframework.http.HttpEntity; @@ -53,6 +56,19 @@ public class TapdClient extends BaseClient { return (TapdGetIssueResponse) getResultForObject(TapdGetIssueResponse.class, response); } + public TapdBug addIssue(MultiValueMap paramMap) { + String url = getBaseUrl() + "/bugs"; + HttpEntity> requestEntity = new HttpEntity<>(paramMap, getAuthHeader()); + ResponseEntity response = null; + try { + response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + MSException.throwException(e.getMessage()); + } + return ((AddTapdIssueResponse) getResultForObject(AddTapdIssueResponse.class, response)).getData().getBug(); + } + protected HttpEntity getAuthHttpEntity() { return new HttpEntity<>(getAuthHeader()); } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java index ca9a6ff1cc..f1c42c5507 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java @@ -34,7 +34,6 @@ public class ZentaoClient extends BaseClient { GetUserResponse getUserResponse = (GetUserResponse) getResultForObject(GetUserResponse.class, response); GetUserResponse.User user = getUserResponse.getUser(); if (user == null) { - LogUtil.error("login fail"); LogUtil.error(JSONObject.toJSON(getUserResponse)); // 登录失败,获取的session无效,置空session MSException.throwException("zentao login fail"); diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/tapd/AddTapdIssueResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/tapd/AddTapdIssueResponse.java new file mode 100644 index 0000000000..270160737c --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/issue/domain/tapd/AddTapdIssueResponse.java @@ -0,0 +1,20 @@ +package io.metersphere.track.issue.domain.tapd; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class AddTapdIssueResponse { + + private int status; + private Data data; + private String info; + + @Getter + @Setter + public static class Data { + private TapdBug bug; + } + +} diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdBug.java b/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdBug.java new file mode 100644 index 0000000000..dbde58a4d0 --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdBug.java @@ -0,0 +1,16 @@ +package io.metersphere.track.issue.domain.tapd; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class TapdBug { + private String id; + private String title; + private String description; +// private String priority; +// private String severity; +// private String reporter; + private String status; +} diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdGetIssueResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdGetIssueResponse.java index 0fe05af1fb..13efdf773e 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdGetIssueResponse.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/tapd/TapdGetIssueResponse.java @@ -16,18 +16,6 @@ public class TapdGetIssueResponse { @Getter @Setter public static class Data { - private Bug bug; - } - - @Getter - @Setter - public static class Bug { - private String id; - private String title; - private String description; -// private String priority; -// private String severity; -// private String reporter; - private String status; + private TapdBug bug; } } diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetUserResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetUserResponse.java index 3570f8a7be..94e14ea611 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetUserResponse.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetUserResponse.java @@ -8,6 +8,7 @@ import lombok.Setter; public class GetUserResponse { private String status; private User user; + private String reason; @Getter @Setter diff --git a/frontend/src/business/components/settings/personal/JiraUserInfo.vue b/frontend/src/business/components/settings/personal/JiraUserInfo.vue index 944ca4a100..5028c9d4e8 100644 --- a/frontend/src/business/components/settings/personal/JiraUserInfo.vue +++ b/frontend/src/business/components/settings/personal/JiraUserInfo.vue @@ -1,7 +1,7 @@