From ae9ec42f0173b5dfb951c0e7fcd3e700b286fc2d Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 23 Aug 2022 19:54:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86=E5=90=8C=E6=AD=A5=E7=A6=85?= =?UTF-8?q?=E9=81=93=E9=99=84=E4=BB=B6=E5=8F=8A=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016148,1016146 --user=宋昌昌 【测试跟踪】ms关联禅道。创建缺陷,上传图片 / 图片附件失败 https://www.tapd.cn/55049933/s/1231808 --- .../metersphere/track/issue/ZentaoPlatform.java | 16 +++++++++++----- .../track/issue/client/ZentaoClient.java | 2 +- .../track/issue/client/ZentaoPathInfoClient.java | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) 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 6b7c6d111b..47b8696624 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -430,8 +430,8 @@ public class ZentaoPlatform extends AbstractIssuePlatform { RestTemplate restTemplate = new RestTemplate(); try { String fileUpload = zentaoClient.requestUrl.getFileUpload(); - ResponseEntity responseEntity = restTemplate.exchange(fileUpload + session, - HttpMethod.POST, requestEntity, String.class); + ResponseEntity responseEntity = restTemplate.exchange(fileUpload, HttpMethod.POST, requestEntity, + String.class, "bug", null, session); String body = responseEntity.getBody(); JSONObject obj = JSONObject.parseObject(body); JSONObject data = obj.getJSONObject("data"); @@ -579,8 +579,14 @@ public class ZentaoPlatform extends AbstractIssuePlatform { List allMsAttachments = attachmentService.listMetadata(request); List msAttachmentsName = allMsAttachments.stream().map(FileAttachmentMetadata::getName).collect(Collectors.toList()); JSONObject bugInfo = zentaoClient.getBugById(issue.getPlatformId()); - JSONObject zenFiles = bugInfo.getJSONObject("files"); - // 同步Jira中新的附件 + Object files = bugInfo.get("files"); + JSONObject zenFiles; + if (files instanceof JSONArray && ((JSONArray) files).size() == 0) { + zenFiles = null; + } else { + zenFiles = (JSONObject) files; + } + // 同步禅道中新的附件 if (zenFiles != null) { for (String fileId : zenFiles.keySet()) { JSONObject fileInfo = zenFiles.getJSONObject(fileId); @@ -602,7 +608,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { } } - // 删除Jira中不存在的附件 + // 删除禅道中不存在的附件 if (CollectionUtils.isNotEmpty(allMsAttachments)) { List deleteMsAttachments = allMsAttachments.stream() .filter(msAttachment -> !znetaoAttachmentsName.contains(msAttachment.getName())).collect(Collectors.toList()); 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 8d02ffa00d..2e52b8f4c4 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 @@ -226,7 +226,7 @@ public abstract class ZentaoClient extends BaseClient { HttpEntity> requestEntity = new HttpEntity<>(paramMap, authHeader); try { - restTemplate.exchange(requestUrl.getFileUpload(), HttpMethod.POST, requestEntity, + restTemplate.exchange(requestUrl.getFileUpload(), HttpMethod.POST, requestEntity, String.class, objectType, objectId, sessionId); } catch (Exception e) { LogUtil.info("upload zentao attachment error"); 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 a0305c7b83..bb224155bf 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 @@ -17,7 +17,7 @@ public class ZentaoPathInfoClient extends ZentaoClient { private static final String USER_GET = "/api-getModel-user-getList?zentaosid="; private static final String BUILDS_GET = "/api-getModel-build-getProductBuildPairs-productID={0}?zentaosid={1}"; private static final String CREATE_META_DATA="/bug-create-{0}.json?zentaosid={1}"; - private static final String FILE_UPLOAD = "/api-getModel-file-saveUpload-{1}-{2}.json?zentaosid={3}"; + private static final String FILE_UPLOAD = "/api-getModel-file-saveUpload-objectType={1},objectID={2}?zentaosid={3}"; private static final String FILE_DELETE = "/file-delete-{1}-.yes.json?zentaosid={2}"; private static final String FILE_DOWNLOAD="/file-download-{1}-.click.json?zentaosid={2}"; private static final String REPLACE_IMG_URL = ""; @@ -48,7 +48,7 @@ public class ZentaoPathInfoClient extends ZentaoClient { request.setCreateMetaData(getUrl(CREATE_META_DATA)); request.setProductGet(getUrl(PRODUCT_GET)); request.setFileDelete(getUrl(FILE_DELETE)); - request.setFileDelete(getUrl(FILE_DOWNLOAD)); + request.setFileDownload(getUrl(FILE_DOWNLOAD)); requestUrl = request; }