refactor(测试跟踪): 缺陷管理同步Jira平台附件的优化
--story=1008034 --user=宋昌昌 【Bug转需求】[缺陷管理]-github#9580-jira集成,缺陷模版使用 jira 缺陷模版,字段没有同步全 https://www.tapd.cn/55049933/s/1206944
This commit is contained in:
parent
85eb119237
commit
4bb3714773
|
@ -862,32 +862,51 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
}
|
||||
|
||||
public void syncJiraIssueAttachments(IssuesWithBLOBs issue, JiraIssue jiraIssue) {
|
||||
List<String> jiraAttachmentsName = new ArrayList<String>();
|
||||
AttachmentRequest request = new AttachmentRequest();
|
||||
request.setBelongType(AttachmentType.ISSUE.type());
|
||||
request.setBelongId(issue.getId());
|
||||
attachmentService.deleteAttachment(request);
|
||||
List<FileAttachmentMetadata> allMsAttachments = attachmentService.listMetadata(request);
|
||||
List<String> msAttachmentsName = allMsAttachments.stream().map(FileAttachmentMetadata::getName).collect(Collectors.toList());
|
||||
JSONArray attachments = jiraIssue.getFields().getJSONArray("attachment");
|
||||
if (CollectionUtils.isEmpty(attachments)) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < attachments.size(); i++) {
|
||||
JSONObject attachment = attachments.getJSONObject(i);
|
||||
String filename = attachment.getString("filename");
|
||||
if ((issue.getDescription() == null || !issue.getDescription().contains(filename))
|
||||
&& (issue.getCustomFields() == null || !issue.getCustomFields().contains(filename))) {
|
||||
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);
|
||||
// 同步Jira中新的附件
|
||||
if (CollectionUtils.isNotEmpty(attachments)) {
|
||||
for (int i = 0; i < attachments.size(); i++) {
|
||||
JSONObject attachment = attachments.getJSONObject(i);
|
||||
String filename = attachment.getString("filename");
|
||||
jiraAttachmentsName.add(filename);
|
||||
if ((issue.getDescription() == null || !issue.getDescription().contains(filename))
|
||||
&& (issue.getCustomFields() == null || !issue.getCustomFields().contains(filename))
|
||||
&& !msAttachmentsName.contains(filename)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除Jira中不存在的附件
|
||||
if (CollectionUtils.isNotEmpty(allMsAttachments)) {
|
||||
List<FileAttachmentMetadata> deleteMsAttachments = allMsAttachments.stream()
|
||||
.filter(msAttachment -> !jiraAttachmentsName.contains(msAttachment.getName())).collect(Collectors.toList());
|
||||
deleteMsAttachments.forEach(fileAttachmentMetadata -> {
|
||||
List<String> ids = List.of(fileAttachmentMetadata.getId());
|
||||
AttachmentModuleRelationExample example = new AttachmentModuleRelationExample();
|
||||
example.createCriteria().andAttachmentIdIn(ids).andRelationTypeEqualTo(AttachmentType.ISSUE.type());
|
||||
// 删除MS附件及关联数据
|
||||
fileService.deleteAttachment(ids);
|
||||
fileService.deleteFileAttachmentByIds(ids);
|
||||
attachmentModuleRelationMapper.deleteByExample(example);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void syncJiraRichTextAttachment(IssuesUpdateRequest request) {
|
||||
|
|
Loading…
Reference in New Issue