From 7b87c272603f318c826d9338ac5faaf997f91810 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 19 Jan 2022 16:26:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A6=85=E9=81=93=E5=BD=B1=E5=93=8D?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=B2=A1=E6=9C=89=E5=90=8C=E6=AD=A5=20--bug?= =?UTF-8?q?=3D1009624=20--user=3D=E9=99=88=E5=BB=BA=E6=98=9F=20=E3=80=90?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA=E3=80=91=E7=A6=85=E9=81=93?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=9A=84=E7=89=88=E6=9C=AC=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E8=BF=87=E6=9D=A5=20https://www.tapd.cn/5504?= =?UTF-8?q?9933/s/10944277?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/issue/ZentaoPlatform.java | 32 ++++--------------- .../track/issue/client/ZentaoClient.java | 18 +++++++++++ .../track/issue/client/ZentaoGetClient.java | 2 ++ .../issue/client/ZentaoPathInfoClient.java | 2 ++ .../issue/domain/zentao/AddIssueResponse.java | 6 +--- .../zentao/GetCreateMetaDataResponse.java | 21 ++++++++++++ .../issue/domain/zentao/GetIssueResponse.java | 6 +--- .../domain/zentao/GetSessionResponse.java | 6 +--- .../track/issue/domain/zentao/RequestUrl.java | 1 + .../issue/domain/zentao/ZentaoBuild.java | 7 ++++ .../issue/domain/zentao/ZentaoResponse.java | 12 +++++++ 11 files changed, 73 insertions(+), 40 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetCreateMetaDataResponse.java create mode 100644 backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoResponse.java 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 869a6e695c..8810478dd4 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -338,32 +338,14 @@ public class ZentaoPlatform extends AbstractIssuePlatform { } public List getBuilds() { - String session = zentaoClient.login();; - HttpHeaders httpHeaders = new HttpHeaders(); - HttpEntity> requestEntity = new HttpEntity<>(httpHeaders); - RestTemplate restTemplate = new RestTemplate(); - String buildGet = zentaoClient.requestUrl.getBuildsGet(); - ResponseEntity responseEntity = restTemplate.exchange(buildGet + session, - HttpMethod.GET, requestEntity, String.class, getProjectId(projectId)); - String body = responseEntity.getBody(); - JSONObject obj = JSONObject.parseObject(body); - - LogUtil.info("zentao builds" + obj); - - JSONObject data = obj.getJSONObject("data"); - Map maps = data.getInnerMap(); - - List list = new ArrayList<>(); - for (Map.Entry map : maps.entrySet()) { - ZentaoBuild build = new ZentaoBuild(); - String id = map.getKey(); - if (StringUtils.isNotBlank(id)) { - build.setId(map.getKey()); - build.setName((String) map.getValue()); - list.add(build); + Map builds = zentaoClient.getBuilds(getProjectId(projectId)); + List res = new ArrayList<>(); + builds.forEach((k, v) -> { + if (StringUtils.isNotBlank(k)) { + res.add(new ZentaoBuild(k, v)); } - } - return list; + }); + return res; } private String uploadFile(FileSystemResource resource) { 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 0ff1c9aa1e..31c1f402b9 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 @@ -16,6 +16,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import java.util.Map; + public abstract class ZentaoClient extends BaseClient { protected String ENDPOINT; @@ -128,6 +130,22 @@ public abstract class ZentaoClient extends BaseClient { return JSONObject.parseObject(getIssueResponse.getData()); } + public GetCreateMetaDataResponse.MetaData getCreateMetaData(String productID) { + String sessionId = login(); + ResponseEntity response = restTemplate.exchange(requestUrl.getCreateMetaData(), + HttpMethod.GET, null, String.class, productID, sessionId); + GetCreateMetaDataResponse getCreateMetaDataResponse = (GetCreateMetaDataResponse) getResultForObject(GetCreateMetaDataResponse.class, response); + return JSONObject.parseObject(getCreateMetaDataResponse.getData(), GetCreateMetaDataResponse.MetaData.class); + } + + public JSONObject getCustomFields(String productID) { + return getCreateMetaData(productID).getCustomFields(); + } + + public Map getBuilds(String productID) { + return getCreateMetaData(productID).getBuilds(); + } + public JSONArray getBugsByProjectId(String projectId, int pageNum, int pageSize) { String sessionId = login(); ResponseEntity response = restTemplate.exchange(requestUrl.getBugList(), diff --git a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoGetClient.java b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoGetClient.java index d7d0579a79..ccaf693d44 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoGetClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoGetClient.java @@ -16,6 +16,7 @@ public class ZentaoGetClient extends ZentaoClient { private static final String USER_GET="&module=user&methodName=getList&t=json&zentaosid="; private static final String BUILDS_GET="&module=build&methodName=getProductBuildPairs&productID={0}&zentaosid="; private static final String FILE_UPLOAD="&module=file&methodName=saveUpload&t=json&zentaosid="; + private static final String CREATE_META_DATA="?m=bug&f=create&productID={0}&t=json&zentaosid={1}"; private static final String REPLACE_IMG_URL=""; private static final Pattern IMG_PATTERN = Pattern.compile("m=file&f=read&fileID=(.*?)\"/>"); // 注意 recTotal={1}&recPerPage={2}&pageID={3} 顺序不能调换,有点恶心 @@ -41,6 +42,7 @@ public class ZentaoGetClient extends ZentaoClient { request.setBugUpdate(getUrl(BUG_UPDATE)); request.setBugDelete(getNotSuperModelUrl(BUG_DELETE)); request.setBugList(getNotSuperModelUrl(BUG_LIST_URL)); + request.setCreateMetaData(getNotSuperModelUrl(CREATE_META_DATA)); requestUrl = request; } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java index 90c3e8d88b..69b4797211 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java @@ -16,6 +16,7 @@ public class ZentaoPathInfoClient extends ZentaoClient { private static final String STORY_GET = "/api-getModel-story-getProductStories-productID={key}?zentaosid="; private static final String USER_GET = "/api-getModel-user-getList?zentaosid="; private static final String BUILDS_GET = "/api-getModel-build-getProductBuildPairs-productID={projectId}?zentaosid="; + private static final String CREATE_META_DATA="/bug-create-{0}.json"; private static final String FILE_UPLOAD = "/api-getModel-file-saveUpload.json?zentaosid="; private static final String REPLACE_IMG_URL = ""; private static final Pattern IMG_PATTERN = Pattern.compile("file-read-(.*?)\"/>"); @@ -42,6 +43,7 @@ public class ZentaoPathInfoClient extends ZentaoClient { request.setBugUpdate(getUrl(BUG_UPDATE)); request.setBugDelete(getUrl(BUG_DELETE)); request.setBugList(getUrl(BUG_LIST_URL)); + request.setCreateMetaData(getUrl(CREATE_META_DATA)); requestUrl = request; } diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/AddIssueResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/AddIssueResponse.java index 8597260026..5d7855f03f 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/AddIssueResponse.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/AddIssueResponse.java @@ -5,11 +5,7 @@ import lombok.Setter; @Getter @Setter -public class AddIssueResponse { - private String status; - private String md5; - private String data; - +public class AddIssueResponse extends ZentaoResponse { @Getter @Setter public static class Issue { diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetCreateMetaDataResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetCreateMetaDataResponse.java new file mode 100644 index 0000000000..47b1d596e7 --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetCreateMetaDataResponse.java @@ -0,0 +1,21 @@ +package io.metersphere.track.issue.domain.zentao; + +import com.alibaba.fastjson.JSONObject; +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; + +@Getter +@Setter +public class GetCreateMetaDataResponse extends ZentaoResponse { + + @Getter + @Setter + public static class MetaData { + private String title; + private JSONObject users; + private JSONObject customFields; + private Map builds; + } +} diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetIssueResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetIssueResponse.java index 9bac16cd89..3f1b7916cd 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetIssueResponse.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetIssueResponse.java @@ -5,11 +5,7 @@ import lombok.Setter; @Getter @Setter -public class GetIssueResponse { - private String status; - private String md5; - private String data; - +public class GetIssueResponse extends ZentaoResponse { @Getter @Setter public static class Issue { diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetSessionResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetSessionResponse.java index 0212c4edfa..abd7194673 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetSessionResponse.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/GetSessionResponse.java @@ -5,11 +5,7 @@ import lombok.Setter; @Getter @Setter -public class GetSessionResponse { - private String status; - private String data; -// private String md5; - +public class GetSessionResponse extends ZentaoResponse { @Getter @Setter public static class Session { diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/RequestUrl.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/RequestUrl.java index 850cdba221..4124fb02a3 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/RequestUrl.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/RequestUrl.java @@ -11,6 +11,7 @@ public class RequestUrl { private String login; private String sessionGet; private String bugCreate; + private String createMetaData; private String bugUpdate; private String bugList; private String bugDelete; diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoBuild.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoBuild.java index 642651162c..2f7d8a36e5 100644 --- a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoBuild.java +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoBuild.java @@ -6,4 +6,11 @@ import lombok.Data; public class ZentaoBuild { private String id; private String name; + + public ZentaoBuild(String id, String name) { + this.id = id; + this.name = name; + } + + public ZentaoBuild() {} } diff --git a/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoResponse.java b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoResponse.java new file mode 100644 index 0000000000..3381b86449 --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/issue/domain/zentao/ZentaoResponse.java @@ -0,0 +1,12 @@ +package io.metersphere.track.issue.domain.zentao; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ZentaoResponse { + private String status; + private String md5; + private String data; +}