From baa6a831a277c3cf8b64a6e02f2b371dc19267e8 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 1 Nov 2021 14:47:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BC=BA=E9=99=B7=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/issue/AbstractIssuePlatform.java | 38 +++++++++++++++++++ .../metersphere/track/issue/JiraPlatform.java | 38 +------------------ .../metersphere/track/issue/TapdPlatform.java | 26 +++++++------ .../track/issue/ZentaoPlatform.java | 20 +++++----- .../track/issue/client/ZentaoClient.java | 4 +- .../domain/tapd/TapdGetIssueResponse.java | 13 ++++--- backend/src/main/java/io/metersphere/xpack | 2 +- 7 files changed, 74 insertions(+), 67 deletions(-) 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 d446a1168c..a0e988bffa 100644 --- a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java @@ -1,5 +1,7 @@ package io.metersphere.track.issue; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.IssuesMapper; import io.metersphere.base.mapper.ProjectMapper; @@ -344,4 +346,40 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { } }); } + + + protected String syncIssueCustomField(String customFieldsStr, JSONObject issue) { + List customFields = CustomFieldService.getCustomFields(customFieldsStr); + customFields.forEach(item -> { + String fieldName = item.getCustomData(); + Object value = issue.get(fieldName); + if (value != null) { + if (value instanceof JSONObject) { + if (!fieldName.equals("assignee") && !fieldName.equals("reporter")) { // 获取不到账号名 + item.setValue(((JSONObject)value).getString("id")); + } + } else { + if (StringUtils.isNotBlank(item.getType()) && + StringUtils.equalsAny(item.getType(), "multipleSelect", "checkbox", "multipleMember")) { + List values = new ArrayList<>(); + if (item.getValue() != null) { + JSONArray attrs = (JSONArray) item.getValue(); + attrs.forEach(attr -> { + if (attr instanceof JSONObject) { + values.add(((JSONObject)attr).getString("id")); + } else { + values.add((String) attr); + } + }); + } + item.setValue(values); + } else { + item.setValue(value); + } + } + } + }); + return JSONObject.toJSONString(customFields); + } + } 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 df9254d3f8..1dadfe652d 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -106,43 +106,7 @@ public class JiraPlatform extends AbstractIssuePlatform { item.setDescription(description); item.setPlatformStatus(status); item.setPlatform(IssuesManagePlatform.Jira.toString()); - item.setCustomFields(parseIssueCustomField(customFieldsStr, jiraIssue)); - } - - public String parseIssueCustomField(String customFieldsStr, JiraIssue jiraIssue) { - List customFields = CustomFieldService.getCustomFields(customFieldsStr); - JSONObject fields = jiraIssue.getFields(); - - customFields.forEach(item -> { - String fieldName = item.getCustomData(); - Object value = fields.get(fieldName); - if (value != null) { - if (value instanceof JSONObject) { - if (!fieldName.equals("assignee") && !fieldName.equals("reporter")) { // 获取不到账号名 - item.setValue(((JSONObject)value).getString("id")); - } - } else { - if (StringUtils.isNotBlank(item.getType()) && - StringUtils.equalsAny(item.getType(), "multipleSelect", "checkbox", "multipleMember")) { - List values = new ArrayList<>(); - if (item.getValue() != null) { - JSONArray attrs = (JSONArray) item.getValue(); - attrs.forEach(attr -> { - if (attr instanceof JSONObject) { - values.add(((JSONObject)attr).getString("id")); - } else { - values.add((String) attr); - } - }); - } - item.setValue(values); - } else { - item.setValue(value); - } - } - } - }); - return JSONObject.toJSONString(customFields); + item.setCustomFields(syncIssueCustomField(customFieldsStr, jiraIssue.getFields())); } private String getStatus(JSONObject fields) { 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 0d4bed5de7..6021f3768e 100644 --- a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java @@ -3,7 +3,10 @@ package io.metersphere.track.issue; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import io.metersphere.base.domain.*; +import io.metersphere.base.domain.IssuesDao; +import io.metersphere.base.domain.IssuesWithBLOBs; +import io.metersphere.base.domain.Project; +import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; @@ -206,8 +209,6 @@ public class TapdPlatform extends AbstractIssuePlatform { .map(IssuesDao::getPlatformId) .collect(Collectors.toList()); - LogUtil.info("ids: " + ids); - if (CollectionUtils.isEmpty(ids)) { return; } @@ -218,21 +219,24 @@ public class TapdPlatform extends AbstractIssuePlatform { while (count == limit) { TapdGetIssueResponse result = tapdClient.getIssueForPageByIds(project.getTapdId(), pageNum, limit, ids); - List data = result.getData(); - count = data.size(); + List datas = result.getData(); + count = datas.size(); pageNum++; - data.forEach(issue -> { - TapdBug bug = issue.getBug(); + datas.forEach(issue -> { + JSONObject bug = issue.getJSONObject("Bug"); + String id = idMap.get(bug.getString("id")); IssuesDao issuesDao = new IssuesDao(); BeanUtils.copyBean(issuesDao, bug); - issuesDao.setId(idMap.get(issuesDao.getId())); - issuesDao.setPlatformStatus(statusMap.get(bug.getStatus())); + issuesDao.setId(id); + issuesDao.setPlatformStatus(statusMap.get(bug.getString("status"))); issuesDao.setDescription(htmlDesc2MsDesc(issuesDao.getDescription())); + IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(id); + issuesDao.setCustomFields(syncIssueCustomField(issuesWithBLOBs.getCustomFields(), bug)); issuesMapper.updateByPrimaryKeySelective(issuesDao); - ids.remove(issue.getBug().getId()); + ids.remove(bug.getString("id")); }); } - // 查不到的就置为删除 + // 查不到的设置为删除 ids.forEach((id) -> { if (StringUtils.isNotBlank(idMap.get(id))) { IssuesDao issuesDao = new IssuesDao(); 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 7e50a0560b..4f6d859768 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -9,13 +9,11 @@ import io.metersphere.commons.constants.IssuesManagePlatform; 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; import io.metersphere.track.issue.domain.zentao.AddIssueResponse; -import io.metersphere.track.issue.domain.zentao.GetIssueResponse; import io.metersphere.track.issue.domain.zentao.ZentaoBuild; import io.metersphere.track.issue.domain.zentao.ZentaoConfig; import io.metersphere.track.request.testcase.IssuesRequest; @@ -148,9 +146,9 @@ public class ZentaoPlatform extends AbstractIssuePlatform { return list; } - public IssuesDao getZentaoIssues(String bugId) { - GetIssueResponse.Issue bug = zentaoClient.getBugById(bugId); - String description = bug.getSteps(); + public IssuesDao getZentaoIssues(IssuesDao issue) { + JSONObject bug = zentaoClient.getBugById(issue.getPlatformId()); + String description = bug.getString("steps"); String steps = description; try { steps = zentao2MsDescription(description); @@ -158,14 +156,16 @@ public class ZentaoPlatform extends AbstractIssuePlatform { LogUtil.error(e.getMessage(), e); } IssuesDao issues = new IssuesDao(); - issues.setPlatformStatus(bug.getStatus()); - if (StringUtils.equals(bug.getDeleted(),"1")) { + issues.setPlatformStatus(bug.getString("status")); + if (StringUtils.equals(bug.getString("deleted"),"1")) { issues.setPlatformStatus(IssuesStatus.DELETE.toString()); issuesMapper.updateByPrimaryKeySelective(issues); } - issues.setTitle(bug.getTitle()); + issues.setTitle(bug.getString("title")); issues.setDescription(steps); - issues.setReporter(bug.getOpenedBy()); + issues.setReporter(bug.getString("openedBy")); + IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(issue.getId()); + issuesWithBLOBs.setCustomFields(syncIssueCustomField(issuesWithBLOBs.getCustomFields(), bug)); return issues; } @@ -329,7 +329,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { public void syncIssues(Project project, List issues) { issues.forEach(item -> { setConfig(); - IssuesDao issuesDao = getZentaoIssues(item.getPlatformId()); + IssuesDao issuesDao = getZentaoIssues(item); issuesDao.setId(item.getId()); issuesMapper.updateByPrimaryKeySelective(issuesDao); }); 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 3ed951714a..e4d46a72a5 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 @@ -106,13 +106,13 @@ public abstract class ZentaoClient extends BaseClient { } } - public GetIssueResponse.Issue getBugById(String id) { + public JSONObject getBugById(String id) { String sessionId = login(); String bugGet = requestUrl.getBugGet(); ResponseEntity response = restTemplate.exchange(bugGet, HttpMethod.GET, null, String.class, id, sessionId); GetIssueResponse getIssueResponse = (GetIssueResponse) getResultForObject(GetIssueResponse.class, response); - return JSONObject.parseObject(getIssueResponse.getData(), GetIssueResponse.Issue.class); + return JSONObject.parseObject(getIssueResponse.getData()); } protected String getBaseUrl() { 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 13efdf773e..aaf8b38f33 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 @@ -1,5 +1,6 @@ package io.metersphere.track.issue.domain.tapd; +import com.alibaba.fastjson.JSONObject; import lombok.Getter; import lombok.Setter; @@ -10,12 +11,12 @@ import java.util.List; public class TapdGetIssueResponse { private int status; - private List data; + private List data; private String info; - @Getter - @Setter - public static class Data { - private TapdBug bug; - } +// @Getter +// @Setter +// public static class Data { +// private TapdBug bug; +// } } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 62c43d8713..f0f7c9894e 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 62c43d871336e35eb9faad05a1c81150d9d329af +Subproject commit f0f7c9894e04b050a2edd24f1b71bb4ddc2c1f59