fix(测试跟踪): 非sass版同步缺陷附件报错

--bug=1015126 --user=陈建星 【测试跟踪】本地安装的 jira,往 ms 同步缺陷报错了 https://www.tapd.cn/55049933/s/1206687
This commit is contained in:
chenjianxing 2022-07-21 18:13:22 +08:00 committed by f2c-ci-robot[bot]
parent 9e6b15381b
commit b196791b7e
3 changed files with 17 additions and 14 deletions

View File

@ -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);

View File

@ -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> 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);
}
}
}
}

View File

@ -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<byte[]> 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();
}