From b196791b7ed936e75b87e1463a463c0264149d9d Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 21 Jul 2022 18:13:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E9=9D=9Esass=E7=89=88=E5=90=8C=E6=AD=A5=E7=BC=BA=E9=99=B7?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015126 --user=陈建星 【测试跟踪】本地安装的 jira,往 ms 同步缺陷报错了 https://www.tapd.cn/55049933/s/1206687 --- .../io/metersphere/service/FileService.java | 2 +- .../metersphere/track/issue/JiraPlatform.java | 24 +++++++++++-------- .../issue/client/JiraAbstractClient.java | 5 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/FileService.java b/backend/src/main/java/io/metersphere/service/FileService.java index 007213083a..b5ead89244 100644 --- a/backend/src/main/java/io/metersphere/service/FileService.java +++ b/backend/src/main/java/io/metersphere/service/FileService.java @@ -140,7 +140,7 @@ public class FileService { String uploadPath = FileUtils.ATTACHMENT_DIR + "/" + attachmentType + "/" + belongId; File parentFile = new File(uploadPath); if (!parentFile.exists()) { - parentFile.mkdir(); + parentFile.mkdirs(); } try (OutputStream os = new FileOutputStream(uploadPath + "/" + attachmentName)){ InputStream in = new ByteArrayInputStream(bytes); 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 6c8695d8a2..703a77b0bb 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -527,14 +527,15 @@ public class JiraPlatform extends AbstractIssuePlatform { issues.forEach(item -> { try { - getUpdateIssue(item, jiraClientV2.getIssues(item.getPlatformId())); + JiraIssue jiraIssue = jiraClientV2.getIssues(item.getPlatformId()); + getUpdateIssue(item, jiraIssue); String customFields = item.getCustomFields(); // 把自定义字段存入新表 List customFieldResource = customFieldService.getCustomFieldResource(customFields); customFieldMap.put(item.getId(), customFieldResource); issuesMapper.updateByPrimaryKeySelective(item); // 同步第三方平台附件 - syncJiraIssueAttachments(item, jiraClientV2.getIssues(item.getPlatformId())); + syncJiraIssueAttachments(item, jiraIssue); } catch (HttpClientErrorException e) { if (e.getRawStatusCode() == 404) { // 标记成删除 @@ -874,14 +875,17 @@ public class JiraPlatform extends AbstractIssuePlatform { String filename = attachment.getString("filename"); if ((issue.getDescription() == null || !issue.getDescription().contains(filename)) && (issue.getCustomFields() == null || !issue.getCustomFields().contains(filename))) { - String id = attachment.getString("id"); - byte[] content = jiraClientV2.getAttachmentContent(id); - FileAttachmentMetadata fileAttachmentMetadata = fileService.saveAttachmentByBytes(content, AttachmentType.ISSUE.type(), issue.getId(), filename); - AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation(); - attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId()); - attachmentModuleRelation.setRelationId(issue.getId()); - attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type()); - attachmentModuleRelationMapper.insert(attachmentModuleRelation); + try { + byte[] content = jiraClientV2.getAttachmentContent(attachment.getString("content")); + FileAttachmentMetadata fileAttachmentMetadata = fileService.saveAttachmentByBytes(content, AttachmentType.ISSUE.type(), issue.getId(), filename); + AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation(); + attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId()); + attachmentModuleRelation.setRelationId(issue.getId()); + attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type()); + attachmentModuleRelationMapper.insert(attachmentModuleRelation); + } catch (Exception e) { + LogUtil.error(e); + } } } } 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 2145a96618..1edab73d82 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 @@ -257,11 +257,10 @@ public abstract class JiraAbstractClient extends BaseClient { return (JiraIssueListResponse)getResultForObject(JiraIssueListResponse.class, responseEntity); } - public byte[] getAttachmentContent(String contentId) { + public byte[] getAttachmentContent(String url) { ResponseEntity responseEntity; - String url = getBaseUrl() + "/attachment/content/{1}"; responseEntity = restTemplate.exchange(url, - HttpMethod.GET, getAuthHttpEntity(), byte[].class, contentId); + HttpMethod.GET, getAuthHttpEntity(), byte[].class); return responseEntity.getBody(); }