From e4fede9b8ec097f0dce69a0d86377fecf20faf94 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 11 Oct 2022 09:44:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E7=BC=BA=E9=99=B7xpack=E7=9B=B8=E5=85=B3=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/commons/utils/DateUtils.java | 4 + .../controller/XpackIssueController.java | 19 ++ .../xpack/track/dto}/AttachmentSyncType.java | 2 +- .../AzureDevopsWorkItemsBatchResponse.java | 4 +- .../xpack/track}/dto/DemandDTO.java | 2 +- .../xpack/track/dto}/EditTestCaseRequest.java | 2 +- .../xpack/track}/dto/IssueTemplateDao.java | 3 +- .../xpack/track}/dto/IssuesDao.java | 4 +- .../xpack/track/dto}/JiraIssue.java | 2 +- .../track/dto}/JiraIssueListResponse.java | 2 +- .../xpack/track}/dto/PlatformStatusDTO.java | 2 +- .../xpack/track/dto}/PlatformUser.java | 2 +- .../xpack/track/dto/TapdBaseResponse.java | 11 + .../track/dto}/TapdGetIssueResponse.java | 7 +- .../track/dto/request}/IssuesRequest.java | 2 +- .../dto/request}/IssuesUpdateRequest.java | 4 +- .../xpack/track}/issue/IssuesPlatform.java | 21 +- .../track/service/XpackIssueService.java | 6 + .../ext/ExtCustomFieldTemplateMapper.xml | 2 +- .../base/mapper/ext/ExtIssuesMapper.java | 3 +- .../base/mapper/ext/ExtIssuesMapper.xml | 18 +- .../controller/IssuesController.java | 12 +- .../controller/ShareController.java | 2 +- .../controller/TestCaseController.java | 1 + .../java/io/metersphere/dto/TestCaseDTO.java | 1 + .../dto/TestCaseReportMetricDTO.java | 1 + .../io/metersphere/dto/TestPlanCaseDTO.java | 1 + .../plan/dto/TestPlanSimpleReportDTO.java | 1 + .../plan/service/TestPlanReportService.java | 5 +- .../plan/service/TestPlanService.java | 1 + .../plan/service/TestPlanTestCaseService.java | 1 + .../service/AttachmentService.java | 6 +- .../service/CustomFieldIssuesService.java | 6 +- .../io/metersphere/service/IssuesService.java | 152 ++++++----- .../metersphere/service/TestCaseService.java | 26 +- .../service/issue/XpackIssueService.java | 8 - .../issue/client/JiraAbstractClient.java | 12 +- .../service/issue/client/TapdClient.java | 15 +- .../service/issue/client/ZentaoClient.java | 6 +- .../domain/tapd/AddTapdIssueResponse.java | 2 + .../issue/platform/AbstractIssuePlatform.java | 44 +-- .../service/issue/platform/IssueFactory.java | 21 +- .../service/issue/platform/JiraPlatform.java | 254 ++++++++++-------- .../issue/platform/LocalAbstractPlatform.java | 6 +- .../service/issue/platform/LocalPlatform.java | 10 +- .../service/issue/platform/TapdPlatform.java | 36 ++- .../issue/platform/ZentaoPlatform.java | 41 ++- .../TrackCustomFieldTemplateService.java | 2 +- .../project/TrackIssueTemplateService.java | 2 +- .../remote/setting/IntegrationService.java | 16 -- .../wapper/IssueProxyResourceService.java | 2 +- 51 files changed, 451 insertions(+), 364 deletions(-) create mode 100644 framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/controller/XpackIssueController.java rename {test-track/backend/src/main/java/io/metersphere/constants => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/AttachmentSyncType.java (90%) rename {test-track/backend/src/main/java/io/metersphere/service/issue/domain/azure => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/AzureDevopsWorkItemsBatchResponse.java (89%) rename {test-track/backend/src/main/java/io/metersphere => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track}/dto/DemandDTO.java (86%) rename {test-track/backend/src/main/java/io/metersphere/request/testcase => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/EditTestCaseRequest.java (98%) rename {test-track/backend/src/main/java/io/metersphere => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track}/dto/IssueTemplateDao.java (70%) rename {test-track/backend/src/main/java/io/metersphere => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track}/dto/IssuesDao.java (87%) rename {test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/JiraIssue.java (83%) rename {test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/JiraIssueListResponse.java (84%) rename {test-track/backend/src/main/java/io/metersphere => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track}/dto/PlatformStatusDTO.java (79%) rename {test-track/backend/src/main/java/io/metersphere/service/issue/domain => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/PlatformUser.java (78%) create mode 100644 framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdBaseResponse.java rename {test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto}/TapdGetIssueResponse.java (50%) rename {test-track/backend/src/main/java/io/metersphere/request/testcase => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request}/IssuesRequest.java (97%) rename {test-track/backend/src/main/java/io/metersphere/request/testcase => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request}/IssuesUpdateRequest.java (93%) rename {test-track/backend/src/main/java/io/metersphere/service => framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track}/issue/IssuesPlatform.java (85%) create mode 100644 framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/service/XpackIssueService.java delete mode 100644 test-track/backend/src/main/java/io/metersphere/service/issue/XpackIssueService.java delete mode 100644 test-track/backend/src/main/java/io/metersphere/service/remote/setting/IntegrationService.java diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java index 00851442d3..645ed0908f 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/DateUtils.java @@ -119,6 +119,10 @@ public class DateUtils { return dateSum(now, countDays).getTime() / 1000 * 1000; } + public static Long getTimestamp(String dateString) throws Exception { + return getDate(dateString).getTime(); + } + /** * 获取当天的起始时间Date * diff --git a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/controller/XpackIssueController.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/controller/XpackIssueController.java new file mode 100644 index 0000000000..ba2458f934 --- /dev/null +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/controller/XpackIssueController.java @@ -0,0 +1,19 @@ +package io.metersphere.xpack.track.controller; + +import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.xpack.track.service.XpackIssueService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/xpack/issue") +public class XpackIssueController { + + @GetMapping("/sync/{projectId}") + public boolean getPlatformIssue(@PathVariable String projectId) { + XpackIssueService xpackIssueService = CommonBeanFactory.getBean(XpackIssueService.class); + return xpackIssueService.syncThirdPartyIssues(projectId); + } +} diff --git a/test-track/backend/src/main/java/io/metersphere/constants/AttachmentSyncType.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/AttachmentSyncType.java similarity index 90% rename from test-track/backend/src/main/java/io/metersphere/constants/AttachmentSyncType.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/AttachmentSyncType.java index 86cd198db7..ea348cb2aa 100644 --- a/test-track/backend/src/main/java/io/metersphere/constants/AttachmentSyncType.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/AttachmentSyncType.java @@ -1,4 +1,4 @@ -package io.metersphere.constants; +package io.metersphere.xpack.track.dto; /** * @author songcc diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/azure/AzureDevopsWorkItemsBatchResponse.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/AzureDevopsWorkItemsBatchResponse.java similarity index 89% rename from test-track/backend/src/main/java/io/metersphere/service/issue/domain/azure/AzureDevopsWorkItemsBatchResponse.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/AzureDevopsWorkItemsBatchResponse.java index 262a4c0643..aa6e160b35 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/azure/AzureDevopsWorkItemsBatchResponse.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/AzureDevopsWorkItemsBatchResponse.java @@ -1,4 +1,4 @@ -package io.metersphere.service.issue.domain.azure; +package io.metersphere.xpack.track.dto; import lombok.Getter; import lombok.Setter; @@ -16,7 +16,7 @@ public class AzureDevopsWorkItemsBatchResponse { @Getter @Setter - public class Value { + public static class Value { private int id; private int rev; private Map fields; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/DemandDTO.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/DemandDTO.java similarity index 86% rename from test-track/backend/src/main/java/io/metersphere/dto/DemandDTO.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/DemandDTO.java index 6439f73af9..419ed61f07 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/DemandDTO.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/DemandDTO.java @@ -1,4 +1,4 @@ -package io.metersphere.dto; +package io.metersphere.xpack.track.dto; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/request/testcase/EditTestCaseRequest.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/EditTestCaseRequest.java similarity index 98% rename from test-track/backend/src/main/java/io/metersphere/request/testcase/EditTestCaseRequest.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/EditTestCaseRequest.java index 579dd8db28..ad90ae79ea 100644 --- a/test-track/backend/src/main/java/io/metersphere/request/testcase/EditTestCaseRequest.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/EditTestCaseRequest.java @@ -1,4 +1,4 @@ -package io.metersphere.request.testcase; +package io.metersphere.xpack.track.dto; import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.dto.CustomFieldResourceDTO; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/IssueTemplateDao.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/IssueTemplateDao.java similarity index 70% rename from test-track/backend/src/main/java/io/metersphere/dto/IssueTemplateDao.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/IssueTemplateDao.java index 8d0a6afded..e468d0c91f 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/IssueTemplateDao.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/IssueTemplateDao.java @@ -1,6 +1,7 @@ -package io.metersphere.dto; +package io.metersphere.xpack.track.dto; import io.metersphere.base.domain.IssueTemplate; +import io.metersphere.dto.CustomFieldDao; import lombok.Data; import java.util.List; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/IssuesDao.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/IssuesDao.java similarity index 87% rename from test-track/backend/src/main/java/io/metersphere/dto/IssuesDao.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/IssuesDao.java index 8fa6ef43df..926cf095f1 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/IssuesDao.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/IssuesDao.java @@ -1,6 +1,8 @@ -package io.metersphere.dto; +package io.metersphere.xpack.track.dto; import io.metersphere.base.domain.IssuesWithBLOBs; +import io.metersphere.dto.CustomFieldDao; +import io.metersphere.dto.CustomFieldItemDTO; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira/JiraIssue.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/JiraIssue.java similarity index 83% rename from test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira/JiraIssue.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/JiraIssue.java index 82e0171570..3c0ef6b96b 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira/JiraIssue.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/JiraIssue.java @@ -1,4 +1,4 @@ -package io.metersphere.service.issue.domain.jira; +package io.metersphere.xpack.track.dto; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira/JiraIssueListResponse.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/JiraIssueListResponse.java similarity index 84% rename from test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira/JiraIssueListResponse.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/JiraIssueListResponse.java index 57c5a7ef58..bc69d90f67 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/jira/JiraIssueListResponse.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/JiraIssueListResponse.java @@ -1,4 +1,4 @@ -package io.metersphere.service.issue.domain.jira; +package io.metersphere.xpack.track.dto; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/PlatformStatusDTO.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/PlatformStatusDTO.java similarity index 79% rename from test-track/backend/src/main/java/io/metersphere/dto/PlatformStatusDTO.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/PlatformStatusDTO.java index 1598a7de14..de3b29b4bc 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/PlatformStatusDTO.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/PlatformStatusDTO.java @@ -1,4 +1,4 @@ -package io.metersphere.dto; +package io.metersphere.xpack.track.dto; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/PlatformUser.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/PlatformUser.java similarity index 78% rename from test-track/backend/src/main/java/io/metersphere/service/issue/domain/PlatformUser.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/PlatformUser.java index f5803cf4b6..83e99b3375 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/PlatformUser.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/PlatformUser.java @@ -1,4 +1,4 @@ -package io.metersphere.service.issue.domain; +package io.metersphere.xpack.track.dto; import lombok.Data; diff --git a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdBaseResponse.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdBaseResponse.java new file mode 100644 index 0000000000..c1d5ea69b0 --- /dev/null +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdBaseResponse.java @@ -0,0 +1,11 @@ +package io.metersphere.xpack.track.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class TapdBaseResponse { + private int status; + private String info; +} diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/TapdGetIssueResponse.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdGetIssueResponse.java similarity index 50% rename from test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/TapdGetIssueResponse.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdGetIssueResponse.java index 703a6e36f1..f03b48918c 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/TapdGetIssueResponse.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/TapdGetIssueResponse.java @@ -1,4 +1,4 @@ -package io.metersphere.service.issue.domain.tapd; +package io.metersphere.xpack.track.dto; import lombok.Getter; import lombok.Setter; @@ -8,9 +8,6 @@ import java.util.Map; @Getter @Setter -public class TapdGetIssueResponse { - - private int status; +public class TapdGetIssueResponse extends TapdBaseResponse { private List data; - private String info; } diff --git a/test-track/backend/src/main/java/io/metersphere/request/testcase/IssuesRequest.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request/IssuesRequest.java similarity index 97% rename from test-track/backend/src/main/java/io/metersphere/request/testcase/IssuesRequest.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request/IssuesRequest.java index 91e476ff8b..8928468edc 100644 --- a/test-track/backend/src/main/java/io/metersphere/request/testcase/IssuesRequest.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request/IssuesRequest.java @@ -1,4 +1,4 @@ -package io.metersphere.request.testcase; +package io.metersphere.xpack.track.dto.request; import io.metersphere.request.BaseQueryRequest; import lombok.Getter; diff --git a/test-track/backend/src/main/java/io/metersphere/request/testcase/IssuesUpdateRequest.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request/IssuesUpdateRequest.java similarity index 93% rename from test-track/backend/src/main/java/io/metersphere/request/testcase/IssuesUpdateRequest.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request/IssuesUpdateRequest.java index 29b8ce79f1..3305104518 100644 --- a/test-track/backend/src/main/java/io/metersphere/request/testcase/IssuesUpdateRequest.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/dto/request/IssuesUpdateRequest.java @@ -1,11 +1,11 @@ -package io.metersphere.request.testcase; +package io.metersphere.xpack.track.dto.request; import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.IssuesWithBLOBs; import io.metersphere.dto.CustomFieldItemDTO; import io.metersphere.dto.CustomFieldResourceDTO; -import io.metersphere.dto.PlatformStatusDTO; +import io.metersphere.xpack.track.dto.PlatformStatusDTO; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/IssuesPlatform.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/issue/IssuesPlatform.java similarity index 85% rename from test-track/backend/src/main/java/io/metersphere/service/issue/IssuesPlatform.java rename to framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/issue/IssuesPlatform.java index 2010323d89..7c5df2a39f 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/IssuesPlatform.java +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/issue/IssuesPlatform.java @@ -1,16 +1,11 @@ -package io.metersphere.service.issue; +package io.metersphere.xpack.track.issue; import io.metersphere.base.domain.IssuesWithBLOBs; import io.metersphere.base.domain.Project; -import io.metersphere.constants.AttachmentSyncType; -import io.metersphere.dto.IssueTemplateDao; -import io.metersphere.dto.IssuesDao; import io.metersphere.dto.UserDTO; -import io.metersphere.dto.DemandDTO; -import io.metersphere.service.issue.domain.PlatformUser; -import io.metersphere.request.testcase.EditTestCaseRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.*; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import org.springframework.http.ResponseEntity; import java.io.File; @@ -123,4 +118,12 @@ public interface IssuesPlatform { * @param syncType 同步操作类型: UPLOAD, DELETE */ void syncIssuesAttachment(IssuesUpdateRequest issuesRequest, File file, AttachmentSyncType syncType); + + + /** + * 获取第三方平台的状态集合 + * @param issueKey + * @return + */ + List getTransitions(String issueKey); } diff --git a/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/service/XpackIssueService.java b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/service/XpackIssueService.java new file mode 100644 index 0000000000..bb03d66a59 --- /dev/null +++ b/framework/sdk-parent/xpack-interface/src/main/java/io/metersphere/xpack/track/service/XpackIssueService.java @@ -0,0 +1,6 @@ +package io.metersphere.xpack.track.service; + +public interface XpackIssueService { + + boolean syncThirdPartyIssues(String projectId); +} diff --git a/project-management/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml b/project-management/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml index 7549155c5b..a2fe89266f 100644 --- a/project-management/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml +++ b/project-management/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml @@ -33,7 +33,7 @@ from custom_field_template cft inner join custom_field cf on cft.field_id = cf.id - + where cft.template_id = #{templateId} diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.java index 4ba75f94be..cf555af1af 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.java +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.java @@ -5,7 +5,8 @@ import io.metersphere.dto.*; import io.metersphere.plan.dto.PlanReportIssueDTO; import io.metersphere.request.testcase.IssuesCountRequest; -import io.metersphere.request.testcase.IssuesRequest; +import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.track.dto.request.IssuesRequest; import org.apache.ibatis.annotations.Param; import java.util.List; diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml index 181af3e5d4..96a553b245 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml @@ -8,7 +8,7 @@ and (resource_id = #{resourceId} or ref_id = #{resourceId}) - select issues.* from issues inner join test_case_issues @@ -17,7 +17,7 @@ - select issues.id, issues.title , issues.num , test_case_issues.resource_id, test_case_issues.ref_id, test_case_issues.ref_type from issues inner join test_case_issues @@ -49,7 +49,7 @@ issues.lastmodify - select @@ -67,7 +67,7 @@ - select from issues @@ -100,7 +100,7 @@ where i.creator = #{request.creator} group by statusValue; - select issues.id, issues.num, issues.title, issues.project_id, issues.create_time, issues.update_time, issues.description, issues.status, issues.platform, issues.custom_fields,test_case_issues.resource_id,issues.platform_status, issues.lastmodify @@ -111,7 +111,7 @@ group by issues.id - select id,platform, platform_id from issues where project_id = #{projectId} and platform = #{platform} and (platform_status != 'delete' or platform_status is null); @@ -132,7 +132,7 @@ where project_id = #{projectId} limit #{offset},#{pageSize} - select from issues @@ -150,13 +150,13 @@ join custom_field cf on cf.id = cfi.field_id where cfi.resource_id = #{issueId} - select * from issues where project_id = #{projectId} and platform_id in #{value} - select cfi.field_id as fieldId, cf.type fieldType, cft.custom_data, diff --git a/test-track/backend/src/main/java/io/metersphere/controller/IssuesController.java b/test-track/backend/src/main/java/io/metersphere/controller/IssuesController.java index 9602031173..660d4cfb8f 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/IssuesController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/IssuesController.java @@ -4,7 +4,6 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.Issues; import io.metersphere.base.domain.IssuesWithBLOBs; -import io.metersphere.base.domain.Project; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogModule; @@ -14,7 +13,7 @@ import io.metersphere.commons.utils.Pager; import io.metersphere.dto.*; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.notice.annotation.SendNotice; -import io.metersphere.service.issue.domain.PlatformUser; +import io.metersphere.xpack.track.dto.*; import io.metersphere.service.issue.domain.jira.JiraIssueType; import io.metersphere.service.issue.domain.zentao.ZentaoBuild; @@ -22,8 +21,8 @@ import io.metersphere.request.issues.JiraIssueTypeRequest; import io.metersphere.request.issues.PlatformIssueTypeRequest; import io.metersphere.request.testcase.AuthUserIssueRequest; import io.metersphere.request.testcase.IssuesCountRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.IssuesService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; @@ -185,9 +184,4 @@ public class IssuesController { public List getPlatformTransitions(@RequestBody PlatformIssueTypeRequest request) { return issuesService.getPlatformTransitions(request); } - - @PostMapping("/check/third/project") - public void checkThirdProjectExist(@RequestBody Project project) { - issuesService.checkThirdProjectExist(project); - } } diff --git a/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java b/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java index 1583261bce..a412ec707d 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/ShareController.java @@ -1,6 +1,6 @@ package io.metersphere.controller; -import io.metersphere.dto.IssuesDao; +import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.dto.TestPlanCaseDTO; import io.metersphere.plan.dto.TestPlanSimpleReportDTO; import io.metersphere.plan.service.TestPlanReportService; diff --git a/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java b/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java index cfc3ca979a..cae5b02ac1 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/TestCaseController.java @@ -24,6 +24,7 @@ import io.metersphere.service.BaseCheckPermissionService; import io.metersphere.service.FileService; import io.metersphere.service.TestCaseService; import io.metersphere.service.wapper.CheckPermissionService; +import io.metersphere.xpack.track.dto.EditTestCaseRequest; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.http.HttpHeaders; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/TestCaseDTO.java b/test-track/backend/src/main/java/io/metersphere/dto/TestCaseDTO.java index 1876000efe..b118c07084 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/TestCaseDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/dto/TestCaseDTO.java @@ -1,6 +1,7 @@ package io.metersphere.dto; import io.metersphere.base.domain.TestCaseWithBLOBs; +import io.metersphere.xpack.track.dto.IssuesDao; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/TestCaseReportMetricDTO.java b/test-track/backend/src/main/java/io/metersphere/dto/TestCaseReportMetricDTO.java index 452140ef3b..80cc74ed8d 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/TestCaseReportMetricDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/dto/TestCaseReportMetricDTO.java @@ -1,5 +1,6 @@ package io.metersphere.dto; +import io.metersphere.xpack.track.dto.IssuesDao; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/dto/TestPlanCaseDTO.java b/test-track/backend/src/main/java/io/metersphere/dto/TestPlanCaseDTO.java index 4d004c925e..5388f4f017 100644 --- a/test-track/backend/src/main/java/io/metersphere/dto/TestPlanCaseDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/dto/TestPlanCaseDTO.java @@ -1,6 +1,7 @@ package io.metersphere.dto; import io.metersphere.base.domain.TestCaseWithBLOBs; +import io.metersphere.xpack.track.dto.IssuesDao; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java index c74b268e01..3e66a828ab 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanSimpleReportDTO.java @@ -3,6 +3,7 @@ package io.metersphere.plan.dto; import io.metersphere.base.domain.TestPlanReportContent; import io.metersphere.dto.*; +import io.metersphere.xpack.track.dto.IssuesDao; import lombok.Getter; import lombok.Setter; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index d306ec8a94..cae2c6d845 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -25,6 +25,7 @@ import io.metersphere.plan.utils.TestPlanRequestUtil; import io.metersphere.plan.utils.TestPlanStatusCalculator; import io.metersphere.request.report.QueryTestPlanReportRequest; import io.metersphere.service.ServiceUtils; +import io.metersphere.xpack.track.dto.IssuesDao; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -72,7 +73,7 @@ public class TestPlanReportService { private TestPlanPrincipalMapper testPlanPrincipalMapper; @Resource ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; -// @Resource + // @Resource // private PerformanceTestService performanceTestService; @Resource private PlanApiDefinitionExecResultService planApiDefinitionExecResultService; @@ -1022,7 +1023,7 @@ public class TestPlanReportService { TestPlanEnvInfoDTO testPlanEnvInfo = planTestPlanScenarioCaseService.generateEnvironmentInfo(testPlanReport); BeanUtils.copyBean(testPlanReportDTO, testPlanEnvInfo); } catch (Exception e) { - LogUtil.error(e); + LogUtil.error(e); } } diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 20586ae482..923112f622 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -41,6 +41,7 @@ import io.metersphere.plan.utils.TestPlanRequestUtil; import io.metersphere.request.ScheduleRequest; import io.metersphere.service.*; import io.metersphere.utils.LoggerUtil; +import io.metersphere.xpack.track.dto.IssuesDao; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java index c2e3417c93..32f50c7017 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java @@ -42,6 +42,7 @@ import io.metersphere.service.ServiceUtils; import io.metersphere.dto.*; import io.metersphere.request.testcase.TrackCount; import io.metersphere.request.testreview.SaveCommentRequest; +import io.metersphere.xpack.track.dto.IssuesDao; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; diff --git a/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java b/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java index 09ca15e3b8..7b56910762 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/AttachmentService.java @@ -8,14 +8,14 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.SessionUtils; -import io.metersphere.constants.AttachmentSyncType; +import io.metersphere.xpack.track.dto.AttachmentSyncType; import io.metersphere.constants.AttachmentType; import io.metersphere.i18n.Translator; import io.metersphere.metadata.service.FileMetadataService; import io.metersphere.metadata.utils.MetadataUtils; import io.metersphere.request.attachment.AttachmentRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.issue.platform.IssueFactory; import io.metersphere.xmind.utils.FileUtil; import org.apache.commons.collections.CollectionUtils; diff --git a/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java index 5da8f92787..3d9c25fe90 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/CustomFieldIssuesService.java @@ -43,10 +43,6 @@ public class CustomFieldIssuesService extends CustomFieldResourceService { super.batchEditFields(TABLE_NAME, resourceId, fields); } -// public void batchEditFields(HashMap> customFieldMap) { -// super.batchEditFields(TABLE_NAME, customFieldMap); -// } - public int updateByPrimaryKeySelective(CustomFieldResourceDTO field) { return super.updateByPrimaryKeySelective(TABLE_NAME, field); } @@ -71,7 +67,7 @@ public class CustomFieldIssuesService extends CustomFieldResourceService { return super.getByResourceId(TABLE_NAME, resourceId); } - public void batchEditFields(HashMap> customFieldMap) { + public void batchEditFields(Map> customFieldMap) { if (customFieldMap == null || customFieldMap.size() == 0) { return; } diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index 2370e8edf9..b28e6d5d9f 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -1,5 +1,7 @@ package io.metersphere.service; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtIssuesMapper; @@ -9,11 +11,12 @@ import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; -import io.metersphere.constants.AttachmentSyncType; +import io.metersphere.plan.service.TestPlanTestCaseService; +import io.metersphere.xpack.track.dto.AttachmentSyncType; import io.metersphere.constants.AttachmentType; import io.metersphere.constants.SystemCustomField; import io.metersphere.dto.CustomFieldDao; -import io.metersphere.dto.IssueTemplateDao; +import io.metersphere.xpack.track.dto.IssueTemplateDao; import io.metersphere.i18n.Translator; import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.vo.DetailColumn; @@ -30,19 +33,21 @@ import io.metersphere.request.issues.JiraIssueTypeRequest; import io.metersphere.request.issues.PlatformIssueTypeRequest; import io.metersphere.request.testcase.AuthUserIssueRequest; import io.metersphere.request.testcase.IssuesCountRequest; -import io.metersphere.service.issue.domain.PlatformUser; +import io.metersphere.xpack.track.dto.PlatformUser; import io.metersphere.service.issue.domain.jira.JiraIssueType; import io.metersphere.service.issue.domain.zentao.ZentaoBuild; import io.metersphere.request.attachment.AttachmentRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.DemandDTO; +import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.issue.platform.*; import io.metersphere.service.remote.project.TrackCustomFieldTemplateService; import io.metersphere.service.remote.project.TrackIssueTemplateService; -import io.metersphere.service.remote.setting.IntegrationService; import io.metersphere.service.wapper.TrackProjectService; +import io.metersphere.xpack.track.dto.PlatformStatusDTO; +import io.metersphere.xpack.track.issue.IssuesPlatform; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -66,7 +71,7 @@ import java.util.stream.Collectors; public class IssuesService { @Resource - private IntegrationService integrationService; + private BaseIntegrationService baseIntegrationService; @Resource private TrackProjectService trackProjectService; @Resource @@ -90,12 +95,13 @@ public class IssuesService { private TrackIssueTemplateService trackIssueTemplateService; @Resource private TestCaseIssueService testCaseIssueService; -// @Resource -// private TestPlanTestCaseService testPlanTestCaseService; + @Lazy + @Resource + private TestPlanTestCaseService testPlanTestCaseService; @Resource private IssueFollowMapper issueFollowMapper; -// @Resource -// private TestPlanTestCaseMapper testPlanTestCaseMapper; + @Resource + private TestPlanTestCaseMapper testPlanTestCaseMapper; @Resource private CustomFieldIssuesService customFieldIssuesService; @Resource @@ -118,15 +124,15 @@ public class IssuesService { public void testAuth(String workspaceId, String platform) { IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(workspaceId); - AbstractIssuePlatform abstractPlatform = IssueFactory.createPlatform(platform, issuesRequest); + IssuesPlatform abstractPlatform = IssueFactory.createPlatform(platform, issuesRequest); abstractPlatform.testAuth(); } public IssuesWithBLOBs addIssues(IssuesUpdateRequest issuesRequest, List files) { - List platformList = getAddPlatforms(issuesRequest); + List platformList = getAddPlatforms(issuesRequest); IssuesWithBLOBs issues = null; - for (AbstractIssuePlatform platform : platformList) { + for (IssuesPlatform platform : platformList) { issues = platform.addIssue(issuesRequest); } if (issuesRequest.getIsPlanEdit()) { @@ -203,7 +209,7 @@ public class IssuesService { } public IssuesWithBLOBs updateIssues(IssuesUpdateRequest issuesRequest) { - List platformList = getUpdatePlatforms(issuesRequest); + List platformList = getUpdatePlatforms(issuesRequest); platformList.forEach(platform -> { platform.updateIssue(issuesRequest); }); @@ -227,7 +233,7 @@ public class IssuesService { } } - public List getAddPlatforms(IssuesUpdateRequest updateRequest) { + public List getAddPlatforms(IssuesUpdateRequest updateRequest) { List platforms = new ArrayList<>(); // 缺陷管理关联 platforms.add(getPlatform(updateRequest.getProjectId())); @@ -240,7 +246,7 @@ public class IssuesService { return IssueFactory.createPlatforms(platforms, issuesRequest); } - public List getUpdatePlatforms(IssuesUpdateRequest updateRequest) { + public List getUpdatePlatforms(IssuesUpdateRequest updateRequest) { String id = updateRequest.getId(); IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(id); String platform = issuesWithBLOBs.getPlatform(); @@ -338,7 +344,7 @@ public class IssuesService { IntegrationRequest request = new IntegrationRequest(); request.setPlatform(platform); request.setWorkspaceId(workspaceId); - ServiceIntegration integration = integrationService.get(request); + ServiceIntegration integration = baseIntegrationService.get(request); return StringUtils.isNotBlank(integration.getId()); } @@ -350,12 +356,12 @@ public class IssuesService { } public List getTapdProjectUsers(IssuesRequest request) { - AbstractIssuePlatform platform = IssueFactory.createPlatform(IssuesManagePlatform.Tapd.name(), request); + IssuesPlatform platform = IssueFactory.createPlatform(IssuesManagePlatform.Tapd.name(), request); return platform.getPlatformUser(); } public List getZentaoUsers(IssuesRequest request) { - AbstractIssuePlatform platform = IssueFactory.createPlatform(IssuesManagePlatform.Zentao.name(), request); + IssuesPlatform platform = IssueFactory.createPlatform(IssuesManagePlatform.Zentao.name(), request); return platform.getPlatformUser(); } @@ -387,7 +393,7 @@ public class IssuesService { updateRequest.setResourceId(request.getCaseResourceId()); updateRequest.setProjectId(request.getProjectId()); updateRequest.setWorkspaceId(request.getWorkspaceId()); - List platformList = getUpdatePlatforms(updateRequest); + List platformList = getUpdatePlatforms(updateRequest); platformList.forEach(platform -> { platform.removeIssueParentLink(updateRequest); }); @@ -395,10 +401,10 @@ public class IssuesService { extIssuesMapper.deleteIssues(id, caseResourceId); TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); testPlanTestCaseExample.createCriteria().andCaseIdEqualTo(caseResourceId); -// List list = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample); -// list.forEach(item -> { -// testCaseIssueService.updateIssuesCount(item.getId()); -// }); + List list = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample); + list.forEach(item -> { + testCaseIssueService.updateIssuesCount(item.getId()); + }); } } @@ -410,7 +416,7 @@ public class IssuesService { Project project = baseProjectService.getProjectById(projectId); IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(project.getWorkspaceId()); - AbstractIssuePlatform platform = IssueFactory.createPlatform(issuesWithBLOBs.getPlatform(), issuesRequest); + IssuesPlatform platform = IssueFactory.createPlatform(issuesWithBLOBs.getPlatform(), issuesRequest); platform.deleteIssue(id); // 删除缺陷对应的附件 AttachmentRequest request = new AttachmentRequest(); @@ -570,7 +576,7 @@ public class IssuesService { return issueMap; } - public Map getPlatformMap(IssuesRequest request) { + public Map getPlatformMap(IssuesRequest request) { Project project = baseProjectService.getProjectById(request.getProjectId()); List platforms = getPlatforms(project); platforms.add(IssuesManagePlatform.Local.toString()); @@ -589,18 +595,18 @@ public class IssuesService { } public void issuesCount() { -// LogUtil.info("测试计划-测试用例同步缺陷信息开始"); -// int pageSize = 100; -// int pages = 1; -// for (int i = 0; i < pages; i++) { -// Page> page = PageHelper.startPage(i, pageSize, true); -// List list = testPlanTestCaseService.listAll(); -// pages = page.getPages();// 替换成真实的值 -// list.forEach(l -> { -// testCaseIssueService.updateIssuesCount(l.getCaseId()); -// }); -// } -// LogUtil.info("测试计划-测试用例同步缺陷信息结束"); + LogUtil.info("测试计划-测试用例同步缺陷信息开始"); + int pageSize = 100; + int pages = 1; + for (int i = 0; i < pages; i++) { + Page> page = PageHelper.startPage(i, pageSize, true); + List list = testPlanTestCaseService.listAll(); + pages = page.getPages();// 替换成真实的值 + list.forEach(l -> { + testCaseIssueService.updateIssuesCount(l.getCaseId()); + }); + } + LogUtil.info("测试计划-测试用例同步缺陷信息结束"); } public boolean checkSync(String projectId) { @@ -649,7 +655,7 @@ public class IssuesService { String defaultCustomFields = getDefaultCustomFields(projectId); issuesRequest.setDefaultCustomFields(defaultCustomFields); } - AbstractIssuePlatform platform = IssueFactory.createPlatform(project.getPlatform(), issuesRequest); + IssuesPlatform platform = IssueFactory.createPlatform(project.getPlatform(), issuesRequest); syncThirdPartyIssues(platform::syncIssues, project, issues); } catch (Exception e) { throw e; @@ -706,7 +712,7 @@ public class IssuesService { request.setWorkspaceId(orgId); request.setPlatform(platform); - ServiceIntegration integration = integrationService.get(request); + ServiceIntegration integration = baseIntegrationService.get(request); return integration.getConfiguration(); } @@ -737,7 +743,7 @@ public class IssuesService { public void userAuth(AuthUserIssueRequest authUserIssueRequest) { IssuesRequest issuesRequest = new IssuesRequest(); issuesRequest.setWorkspaceId(authUserIssueRequest.getWorkspaceId()); - AbstractIssuePlatform abstractPlatform = IssueFactory.createPlatform(authUserIssueRequest.getPlatform(), issuesRequest); + IssuesPlatform abstractPlatform = IssueFactory.createPlatform(authUserIssueRequest.getPlatform(), issuesRequest); abstractPlatform.userAuth(authUserIssueRequest); } @@ -877,6 +883,7 @@ public class IssuesService { } public List getIssuesByPlatformIds(List platformIds, String projectId) { + if (CollectionUtils.isEmpty(platformIds)) return new ArrayList<>(); IssuesExample example = new IssuesExample(); example.createCriteria() @@ -885,6 +892,30 @@ public class IssuesService { return issuesMapper.selectByExampleWithBLOBs(example); } + public List getPlatformIssueByIds(List platformIds, String projectId) { + // todo 是否保留 + List issues = extIssuesMapper.getPlatformIssueByIds(platformIds, projectId); + if (CollectionUtils.isEmpty(issues)) { + return issues; + } + List issueIds = issues.stream().map(IssuesDao::getId).collect(Collectors.toList()); + List issuesList = extIssuesMapper.getIssueCustomFields(issueIds); + Map> map = new HashMap<>(); + issuesList.forEach(f -> { + CustomFieldItemDTO dto = new CustomFieldItemDTO(); + dto.setId(f.getFieldId()); + dto.setName(f.getFieldName()); + dto.setType(f.getFieldType()); + dto.setValue(f.getFieldValue()); + dto.setCustomData(f.getCustomData()); + List list = Optional.ofNullable(map.get(f.getId())).orElse(new ArrayList<>()); + map.put(f.getId(), list); + list.add(dto); + }); + issues.forEach(i -> i.setCustomFieldList(map.getOrDefault(i.getId(), new ArrayList<>()))); + return issues; + } + public IssueTemplateDao getThirdPartTemplate(String projectId) { if (StringUtils.isNotBlank(projectId)) { @@ -918,7 +949,7 @@ public class IssuesService { IssuesRequest issueRequest = new IssuesRequest(); issueRequest.setWorkspaceId(workspaceId); issueRequest.setProjectId(projectId); - AbstractIssuePlatform platform = IssueFactory.createPlatform(project.getPlatform(), issueRequest); + IssuesPlatform platform = IssueFactory.createPlatform(project.getPlatform(), issueRequest); return platform.getDemandList(projectId); } @@ -938,12 +969,12 @@ public class IssuesService { } IssuesRequest issuesRequest = getDefaultIssueRequest(request.getProjectId(), request.getWorkspaceId()); - Map platformMap = IssueFactory.createPlatformsForMap(platforms, issuesRequest); + Map platformMap = IssueFactory.createPlatformsForMap(platforms, issuesRequest); try { if (platformMap.size() > 1) { MSException.throwException(Translator.get("project_reference_multiple_plateform")); } - Optional platformOptional = platformMap.values().stream().findFirst(); + Optional platformOptional = platformMap.values().stream().findFirst(); if (platformOptional.isPresent()) { platformStatusDTOS = platformOptional.get().getTransitions(request.getPlatformKey()); } @@ -968,32 +999,7 @@ public class IssuesService { issueFileMapper.deleteByExample(example); } - public void checkThirdProjectExist(Project project) { - IssuesRequest issuesRequest = new IssuesRequest(); - if (StringUtils.isBlank(project.getId())) { - MSException.throwException("project ID cannot be empty"); - } - issuesRequest.setProjectId(project.getId()); - issuesRequest.setWorkspaceId(project.getWorkspaceId()); - if (StringUtils.equalsIgnoreCase(project.getPlatform(), IssuesManagePlatform.Tapd.name())) { - TapdPlatform tapd = new TapdPlatform(issuesRequest); - this.doCheckThirdProjectExist(tapd, project.getTapdId()); - } else if (StringUtils.equalsIgnoreCase(project.getPlatform(), IssuesManagePlatform.Jira.name())) { - JiraPlatform jira = new JiraPlatform(issuesRequest); - this.doCheckThirdProjectExist(jira, project.getJiraKey()); - } else if (StringUtils.equalsIgnoreCase(project.getPlatform(), IssuesManagePlatform.Zentao.name())) { - ZentaoPlatform zentao = new ZentaoPlatform(issuesRequest); - this.doCheckThirdProjectExist(zentao, project.getZentaoId()); - } - } - - private void doCheckThirdProjectExist(AbstractIssuePlatform platform, String relateId) { - if (StringUtils.isBlank(relateId)) { - MSException.throwException(Translator.get("issue_project_not_exist")); - } - Boolean exist = platform.checkProjectExist(relateId); - if (BooleanUtils.isFalse(exist)) { - MSException.throwException(Translator.get("issue_project_not_exist")); - } + public boolean isThirdPartTemplate(Project project) { + return project.getThirdPartTemplate() != null && project.getThirdPartTemplate() && project.getPlatform().equals(IssuesManagePlatform.Jira.name()); } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 4bac5edd0d..455be5919e 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -36,8 +36,6 @@ import io.metersphere.request.ResetOrderRequest; import io.metersphere.request.attachment.AttachmentRequest; import io.metersphere.request.member.QueryMemberRequest; import io.metersphere.request.testcase.*; -import io.metersphere.service.issue.XpackIssueService; -import io.metersphere.service.issue.platform.AbstractIssuePlatform; import io.metersphere.service.issue.platform.IssueFactory; import io.metersphere.service.remote.api.RelevanceApiCaseService; import io.metersphere.service.remote.performance.RelevanceLoadCaseService; @@ -46,6 +44,10 @@ import io.metersphere.service.wapper.TrackProjectService; import io.metersphere.xmind.XmindCaseParser; import io.metersphere.xmind.pojo.TestCaseXmindData; import io.metersphere.xmind.utils.XmindExportUtil; +import io.metersphere.xpack.track.dto.EditTestCaseRequest; +import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.issue.IssuesPlatform; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.ListUtils; @@ -56,7 +58,6 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.jetbrains.annotations.NotNull; import org.mybatis.spring.SqlSessionUtils; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -259,7 +260,7 @@ public class TestCaseService { Project project = baseProjectService.getProjectById(request.getProjectId()); if (StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) { updateRequest.setWorkspaceId(project.getWorkspaceId()); - List platformList = getAddPlatforms(updateRequest); + List platformList = getAddPlatforms(updateRequest); platformList.forEach(platform -> { platform.updateDemandHyperLink(request, project, type); }); @@ -293,7 +294,7 @@ public class TestCaseService { } } - private List getAddPlatforms(IssuesRequest request) { + private List getAddPlatforms(IssuesRequest request) { List platforms = new ArrayList<>(); // 缺陷管理关联 platforms.add(issuesService.getPlatform(request.getProjectId())); @@ -417,10 +418,19 @@ public class TestCaseService { * @param testCase */ public void updateThirdPartyIssuesLink(EditTestCaseRequest testCase) { - XpackIssueService issueService = CommonBeanFactory.getBean(XpackIssueService.class); - if (issueService != null) { - issueService.updateThirdPartyIssuesLink(testCase); + if (StringUtils.isBlank(testCase.getProjectId())) { + return; } + Project project = baseProjectService.getProjectById(testCase.getProjectId()); + IssuesRequest issuesRequest = new IssuesRequest(); + if (!issuesService.isThirdPartTemplate(project)) { + issuesRequest.setDefaultCustomFields(issuesService.getDefaultCustomFields(testCase.getProjectId())); + } + issuesRequest.setProjectId(testCase.getProjectId()); + issuesRequest.setWorkspaceId(project.getWorkspaceId()); + IssueFactory.createPlatform(issuesService.getPlatform(testCase.getProjectId()), issuesRequest) + .updateDemandIssueLink(testCase, project); + } /** diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/XpackIssueService.java b/test-track/backend/src/main/java/io/metersphere/service/issue/XpackIssueService.java deleted file mode 100644 index a6eb5e5099..0000000000 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/XpackIssueService.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.metersphere.service.issue; - -import io.metersphere.request.testcase.EditTestCaseRequest; - -public interface XpackIssueService { - - void updateThirdPartyIssuesLink(EditTestCaseRequest testCase); -} diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/client/JiraAbstractClient.java b/test-track/backend/src/main/java/io/metersphere/service/issue/client/JiraAbstractClient.java index ea8e1cc6a3..42b55a98ee 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/client/JiraAbstractClient.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/client/JiraAbstractClient.java @@ -5,6 +5,8 @@ import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; import io.metersphere.i18n.Translator; import io.metersphere.service.issue.domain.jira.*; +import io.metersphere.xpack.track.dto.JiraIssue; +import io.metersphere.xpack.track.dto.JiraIssueListResponse; import org.apache.commons.lang3.StringUtils; import org.springframework.core.io.FileSystemResource; import org.springframework.http.*; @@ -45,7 +47,7 @@ public abstract class JiraAbstractClient extends BaseClient { MSException.throwException(e.getMessage()); } try { - fields = ((JiraCreateMetadataResponse) getResultForObject(JiraCreateMetadataResponse.class, response)) + fields = ((JiraCreateMetadataResponse) getResultForObject(JiraCreateMetadataResponse.class, response)) .getProjects().get(0).getIssuetypes().get(0).getFields(); } catch (Exception e) { MSException.throwException(Translator.get("issue_jira_info_error")); @@ -138,7 +140,7 @@ public abstract class JiraAbstractClient extends BaseClient { headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity requestEntity = new HttpEntity<>(body, headers); try { - restTemplate.exchange(getBaseUrl() + "/issue/" + id, HttpMethod.PUT, requestEntity, String.class); + restTemplate.exchange(getBaseUrl() + "/issue/" + id, HttpMethod.PUT, requestEntity, String.class); } catch (Exception e) { LogUtil.error(e.getMessage(), e); MSException.throwException(e.getMessage()); @@ -242,11 +244,11 @@ public abstract class JiraAbstractClient extends BaseClient { PASSWD = config.getPassword(); } - public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType) { + public JiraIssueListResponse getProjectIssues(Integer startAt, Integer maxResults, String projectKey, String issueType) { return getProjectIssues(startAt, maxResults, projectKey, issueType, null); } - public JiraIssueListResponse getProjectIssues(int startAt, int maxResults, String projectKey, String issueType, String fields) { + public JiraIssueListResponse getProjectIssues(Integer startAt, Integer maxResults, String projectKey, String issueType, String fields) { ResponseEntity responseEntity; String url = getBaseUrl() + "/search?startAt={1}&maxResults={2}&jql=project={3}+AND+issuetype={4}"; if (StringUtils.isNotBlank(fields)) { @@ -264,7 +266,7 @@ public abstract class JiraAbstractClient extends BaseClient { return responseEntity.getBody(); } - public JiraIssueListResponse getProjectIssuesAttachment(int startAt, int maxResults, String projectKey, String issueType) { + public JiraIssueListResponse getProjectIssuesAttachment(Integer startAt, Integer maxResults, String projectKey, String issueType) { return getProjectIssues(startAt, maxResults, projectKey, issueType, "attachment"); } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/client/TapdClient.java b/test-track/backend/src/main/java/io/metersphere/service/issue/client/TapdClient.java index 1a7adcdaa3..e453d4c9ed 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/client/TapdClient.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/client/TapdClient.java @@ -6,7 +6,8 @@ import io.metersphere.commons.utils.LogUtil; import io.metersphere.service.issue.domain.tapd.AddTapdIssueResponse; import io.metersphere.service.issue.domain.tapd.TapdBug; import io.metersphere.service.issue.domain.tapd.TapdConfig; -import io.metersphere.service.issue.domain.tapd.TapdGetIssueResponse; +import io.metersphere.xpack.track.dto.TapdBaseResponse; +import io.metersphere.xpack.track.dto.TapdGetIssueResponse; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -29,8 +30,8 @@ public class TapdClient extends BaseClient { protected String PASSWD; - public TapdGetIssueResponse getIssueForPage(String projectId, int pageNum, int limit) { - return getIssueForPageByIds(projectId, pageNum, limit, null); + public TapdGetIssueResponse getIssueForPage(String projectId, Integer pageNum, Integer limit) { + return getIssueForPageByIds(projectId, pageNum, limit, null); } public Map getStatusMap(String projectId) { @@ -42,10 +43,8 @@ public class TapdClient extends BaseClient { MSException.throwException("请检查配置信息是否填写正确!"); LogUtil.error(e); } - String resultForObject = (String) getResultForObject(String.class, response); - Map jsonObject = JSON.parseMap(resultForObject); - String data = jsonObject.get("data").toString(); - return JSON.parseObject(data, Map.class); + Map resultForObject = (Map) getResultForObject(Map.class, response); + return (Map) resultForObject.get("data"); } public List getPlatformUser(String projectId) { @@ -126,7 +125,7 @@ public class TapdClient extends BaseClient { public boolean checkProjectExist(String relateId) { String url = getBaseUrl() + "/roles?workspace_id={1}"; ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getAuthHttpEntity(), String.class, relateId); - TapdGetIssueResponse res = (TapdGetIssueResponse) getResultForObject(TapdGetIssueResponse.class, response); + TapdBaseResponse res = (TapdBaseResponse) getResultForObject(TapdBaseResponse.class, response); return res == null || res.getStatus() != 404; } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/client/ZentaoClient.java b/test-track/backend/src/main/java/io/metersphere/service/issue/client/ZentaoClient.java index b3511d17bd..c61a19107c 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/client/ZentaoClient.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/client/ZentaoClient.java @@ -152,12 +152,12 @@ public abstract class ZentaoClient extends BaseClient { return (Map) JSON.parseMap(response.getBody()).get("data"); } - public Map getBugsByProjectId(String projectId, int pageNum, int pageSize) { + public Map getBugsByProjectId(String projectId, Integer pageNum, Integer pageSize) { String sessionId = login(); ResponseEntity response = restTemplate.exchange(requestUrl.getBugList(), HttpMethod.GET, null, String.class, projectId, 9999999, pageSize, pageNum, sessionId); try { - return (Map) JSON.parseMap(response.getBody()).get("data"); + return JSON.parseMap(JSON.parseMap(response.getBody()).get("data").toString()); } catch (Exception e) { LogUtil.error(e); MSException.throwException("请检查配置信息是否填写正确!"); @@ -222,7 +222,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/test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/AddTapdIssueResponse.java b/test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/AddTapdIssueResponse.java index 8a122f4906..a5737cbaab 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/AddTapdIssueResponse.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/domain/tapd/AddTapdIssueResponse.java @@ -1,5 +1,6 @@ package io.metersphere.service.issue.domain.tapd; +import com.fasterxml.jackson.annotation.JsonAlias; import lombok.Getter; import lombok.Setter; @@ -14,6 +15,7 @@ public class AddTapdIssueResponse { @Getter @Setter public static class Data { + @JsonAlias("Bug") private TapdBug bug; } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java index c3a5ef7292..a42990d75f 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/AbstractIssuePlatform.java @@ -11,21 +11,19 @@ import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.dto.CustomFieldItemDTO; -import io.metersphere.dto.IssueTemplateDao; -import io.metersphere.dto.PlatformStatusDTO; +import io.metersphere.xpack.track.dto.IssueTemplateDao; +import io.metersphere.xpack.track.dto.PlatformStatusDTO; import io.metersphere.dto.UserDTO; import io.metersphere.request.IntegrationRequest; -import io.metersphere.request.testcase.EditTestCaseRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.EditTestCaseRequest; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.*; -import io.metersphere.service.issue.IssuesPlatform; +import io.metersphere.xpack.track.issue.IssuesPlatform; import io.metersphere.service.issue.domain.ProjectIssueConfig; -import io.metersphere.service.remote.setting.IntegrationService; import io.metersphere.service.wapper.TrackProjectService; import io.metersphere.service.wapper.UserService; import org.apache.commons.lang3.StringUtils; -import org.json.JSONObject; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.safety.Safelist; @@ -44,7 +42,7 @@ import java.util.stream.Collectors; public abstract class AbstractIssuePlatform implements IssuesPlatform { - protected IntegrationService integrationService; + protected BaseIntegrationService baseIntegrationService; protected TestCaseIssueService testCaseIssueService; protected TestCaseIssuesMapper testCaseIssuesMapper; protected TrackProjectService trackProjectService; @@ -82,7 +80,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { } public AbstractIssuePlatform() { - this.integrationService = CommonBeanFactory.getBean(IntegrationService.class); + this.baseIntegrationService = CommonBeanFactory.getBean(BaseIntegrationService.class); this.testCaseIssuesMapper = CommonBeanFactory.getBean(TestCaseIssuesMapper.class); this.trackProjectService = CommonBeanFactory.getBean(TrackProjectService.class); this.testCaseService = CommonBeanFactory.getBean(TestCaseService.class); @@ -100,6 +98,11 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { this.baseProjectService = CommonBeanFactory.getBean(BaseProjectService.class); } + // xpack 反射调用 + public String getProjectId() { + return projectId; + } + protected String getPlatformConfig(String platform) { IntegrationRequest request = new IntegrationRequest(); if (StringUtils.isBlank(workspaceId)) { @@ -108,7 +111,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { request.setWorkspaceId(workspaceId); request.setPlatform(platform); - ServiceIntegration integration = integrationService.get(request); + ServiceIntegration integration = baseIntegrationService.get(request); return integration.getConfiguration(); } @@ -395,26 +398,27 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { protected Object getSyncJsonParamValue(Object value) { Map valObj = ((Map) value); - String accountId = valObj.get("accountId").toString(); + String accountId = Optional.ofNullable(valObj.get("accountId")).orElse("").toString(); Map child = (Map) valObj.get("child"); if (child != null) {// 级联框 List values = new ArrayList<>(); - if (StringUtils.isNotBlank(valObj.get("id").toString())) { - values.add(valObj.get("id").toString()); + String id = Optional.ofNullable(valObj.get("id")).orElse("").toString(); + if (StringUtils.isNotBlank(id)) { + values.add(valObj.get("id")); } - if (StringUtils.isNotBlank(child.get("id").toString())) { - values.add(child.get("id").toString()); + if (StringUtils.isNotBlank(id)) { + values.add(child.get("id")); } return values; } else if (StringUtils.isNotBlank(accountId) && isThirdPartTemplate) { // 用户选择框 return accountId; } else { - String id = valObj.get("id").toString(); + String id = Optional.ofNullable(valObj.get("id")).orElse("").toString(); if (StringUtils.isNotBlank(id)) { - return valObj.get("id").toString(); + return valObj.get("id"); } else { - return valObj.get("key").toString(); + return valObj.get("key"); } } } @@ -434,7 +438,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { if (value instanceof Map) { item.setValue(getSyncJsonParamValue(value)); if (StringUtils.equals(fieldName, "assignee")) { - item.setValue(((JSONObject) value).get("displayName")); + item.setValue(((Map) value).get("displayName")); } else { item.setValue(getSyncJsonParamValue(value)); } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/IssueFactory.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/IssueFactory.java index d5184f338d..f8517e7389 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/IssueFactory.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/IssueFactory.java @@ -2,7 +2,8 @@ package io.metersphere.service.issue.platform; import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.request.testcase.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.issue.IssuesPlatform; import org.apache.commons.lang3.StringUtils; import java.lang.reflect.Constructor; @@ -12,7 +13,7 @@ import java.util.List; import java.util.Map; public class IssueFactory { - public static AbstractIssuePlatform createPlatform(String platform, IssuesRequest addIssueRequest) { + public static IssuesPlatform createPlatform(String platform, IssuesRequest addIssueRequest) { if (StringUtils.equals(IssuesManagePlatform.Tapd.toString(), platform)) { return new TapdPlatform(addIssueRequest); } else if (StringUtils.equals(IssuesManagePlatform.Jira.toString(), platform)) { @@ -22,9 +23,9 @@ public class IssueFactory { } else if (StringUtils.equals(IssuesManagePlatform.AzureDevops.toString(), platform)) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { - Class clazz = loader.loadClass("io.metersphere.xpack.issue.azuredevops.AzureDevopsPlatform"); + Class clazz = loader.loadClass("io.metersphere.xpack.track.issue.platform.AzureDevopsPlatform"); Constructor cons = clazz.getDeclaredConstructor(new Class[] { IssuesRequest.class }); - AbstractIssuePlatform azureDevopsPlatform = (AbstractIssuePlatform) cons.newInstance(addIssueRequest); + IssuesPlatform azureDevopsPlatform = (IssuesPlatform) cons.newInstance(addIssueRequest); return azureDevopsPlatform; } catch (Throwable e) { LogUtil.error(e); @@ -35,10 +36,10 @@ public class IssueFactory { return null; } - public static List createPlatforms(List types, IssuesRequest addIssueRequest) { - List platforms = new ArrayList<>(); + public static List createPlatforms(List types, IssuesRequest addIssueRequest) { + List platforms = new ArrayList<>(); types.forEach(type -> { - AbstractIssuePlatform abstractIssuePlatform = createPlatform(type, addIssueRequest); + IssuesPlatform abstractIssuePlatform = createPlatform(type, addIssueRequest); if (abstractIssuePlatform != null) { platforms.add(abstractIssuePlatform); } @@ -46,10 +47,10 @@ public class IssueFactory { return platforms; } - public static Map createPlatformsForMap(List types, IssuesRequest addIssueRequest) { - Map platformMap = new HashMap<>(); + public static Map createPlatformsForMap(List types, IssuesRequest addIssueRequest) { + Map platformMap = new HashMap<>(); types.forEach(type -> { - AbstractIssuePlatform abstractIssuePlatform = createPlatform(type, addIssueRequest); + IssuesPlatform abstractIssuePlatform = createPlatform(type, addIssueRequest); if (abstractIssuePlatform != null) { platformMap.put(type, abstractIssuePlatform); } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java index c4cba07c52..51646b63a7 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/JiraPlatform.java @@ -6,20 +6,20 @@ import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.constants.AttachmentSyncType; +import io.metersphere.xpack.track.dto.AttachmentSyncType; import io.metersphere.constants.AttachmentType; import io.metersphere.dto.*; import io.metersphere.request.attachment.AttachmentRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.*; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.issue.client.JiraClientV2; -import io.metersphere.service.issue.domain.PlatformUser; import io.metersphere.service.IssuesService; import io.metersphere.service.issue.domain.ProjectIssueConfig; import io.metersphere.service.issue.domain.jira.*; -import net.minidev.json.JSONObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang3.ObjectUtils; @@ -50,6 +50,11 @@ public class JiraPlatform extends AbstractIssuePlatform { setConfig(); } + // xpack 反射调用 + public JiraClientV2 getJiraClientV2() { + return jiraClientV2; + } + @Override public List getIssue(IssuesRequest issuesRequest) { issuesRequest.setPlatform(key); @@ -62,47 +67,61 @@ public class JiraPlatform extends AbstractIssuePlatform { return issues; } + public IssuesWithBLOBs getUpdateIssue(JiraIssue jiraIssue) { + return getUpdateIssue(null, jiraIssue); + } + public IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, JiraIssue jiraIssue) { - if (issue == null) { - issue = new IssuesWithBLOBs(); - issue.setCustomFields(defaultCustomFields); - } else { - mergeCustomField(issue, defaultCustomFields); - } - - Map fields = jiraIssue.getFields(); - String status = getStatus(fields); - - Map fileContentMap = getContextMap((List) fields.get("attachment")); - - // 先转换下desc的图片 - String description = dealWithDescription(fields.get("description").toString(), fileContentMap); - fields.put("description", description); - CustomFieldItemDTO descItem = null; - List customFieldItems = syncIssueCustomFieldList(issue.getCustomFields(), jiraIssue.getFields()); - - // 其他自定义里有富文本框的也转换下图片 - for (CustomFieldItemDTO item : customFieldItems) { - if (StringUtils.equals("description", item.getId())) { - // desc转过了,跳过 - descItem = item; + try { + if (issue == null) { + issue = new IssuesWithBLOBs(); + issue.setCustomFields(defaultCustomFields); } else { - if (StringUtils.equals(CustomFieldType.RICH_TEXT.getValue(), item.getType())) { - item.setValue(dealWithDescription((String) item.getValue(), fileContentMap)); + mergeCustomField(issue, defaultCustomFields); + } + + Map fields = jiraIssue.getFields(); + String status = getStatus(fields); + + Map fileContentMap = getContextMap((List) fields.get("attachment")); + + // 先转换下desc的图片 + String description = dealWithDescription(Optional.ofNullable(fields.get("description")).orElse("").toString(), fileContentMap); + fields.put("description", description); + CustomFieldItemDTO descItem = null; + List customFieldItems = syncIssueCustomFieldList(issue.getCustomFields(), jiraIssue.getFields()); + + // 其他自定义里有富文本框的也转换下图片 + for (CustomFieldItemDTO item : customFieldItems) { + if (StringUtils.equals("description", item.getId())) { + // desc转过了,跳过 + descItem = item; + } else { + if (StringUtils.equals(CustomFieldType.RICH_TEXT.getValue(), item.getType())) { + item.setValue(dealWithDescription((String) item.getValue(), fileContentMap)); + } } } - } - JSONObject assignee = (JSONObject) fields.get("assignee"); - issue.setTitle(fields.get("summary").toString()); - issue.setCreateTime((Long) fields.get("created")); - issue.setUpdateTime((Long) fields.get("updated")); - issue.setLastmodify(assignee == null ? "" : assignee.get("displayName").toString()); - issue.setDescription(description); - issue.setPlatformStatus(status); - issue.setPlatform(key); - issue.setCustomFields(JSON.toJSONString(customFieldItems)); - return issue; + Map assignee = (Map) fields.get("assignee"); + issue.setTitle(fields.get("summary").toString()); + issue.setLastmodify(assignee == null ? "" : assignee.get("displayName").toString()); + issue.setDescription(description); + issue.setPlatformStatus(status); + issue.setPlatform(key); + issue.setCustomFields(JSON.toJSONString(customFieldItems)); + try { + issue.setCreateTime(DateUtils.getTimestamp((String) fields.get("created"))); + issue.setUpdateTime(DateUtils.getTimestamp((String) fields.get("updated"))); + } catch (Exception e) { + LogUtil.error(e); + } + return issue; + } catch (Exception e) { + LogUtil.error(e); + MSException.throwException(e); + return null; + } } private String dealWithDescription(String description, Map fileContentMap) { @@ -207,11 +226,7 @@ public class JiraPlatform extends AbstractIssuePlatform { } public List getIssueTypes(String jiraKey) { - try { - return jiraClientV2.getIssueType(jiraKey); - } catch (Exception e) { - return null; - } + return jiraClientV2.getIssueType(jiraKey); } @Override @@ -220,8 +235,8 @@ public class JiraPlatform extends AbstractIssuePlatform { setUserConfig(); Project project = getProject(); - JSONObject addJiraIssueParam = buildUpdateParam(issuesRequest, getIssueType(project.getIssueConfig()), project.getJiraKey()); - JiraAddIssueResponse result = jiraClientV2.addIssue(JSONObject.toJSONString(addJiraIssueParam)); + Map addJiraIssueParam = buildUpdateParam(issuesRequest, getIssueType(project.getIssueConfig()), project.getJiraKey()); + JiraAddIssueResponse result = jiraClientV2.addIssue(JSON.toJSONString(addJiraIssueParam)); JiraIssue issues = jiraClientV2.getIssues(result.getId()); // 上传富文本中的图片作为附件 @@ -259,7 +274,7 @@ public class JiraPlatform extends AbstractIssuePlatform { } public Project getProject() { - return super.getProject(this.projectId, Project::getJiraKey); + return super.getProject(this.projectId, Project::getJiraKey); } private List getImageFiles(IssuesUpdateRequest issuesRequest) { @@ -284,7 +299,7 @@ public class JiraPlatform extends AbstractIssuePlatform { * 参数比较特殊,需要特别处理 * @param fields */ - private void setSpecialParam(JSONObject fields) { + private void setSpecialParam(Map fields) { Project project = getProject(); try { Map createMetadata = jiraClientV2.getCreateMetadata(project.getJiraKey(), getIssueType(project.getIssueConfig())); @@ -310,9 +325,9 @@ public class JiraPlatform extends AbstractIssuePlatform { } if (isUserKey) { if (schema.getType() != null && schema.getType().endsWith("user")) { - Map field = (Map) fields.get(key); + Map field = (Map) fields.get(key); // 如果不是用户ID,则是用户的key,参数调整为key - JSONObject newField = new JSONObject(); + Map newField = new LinkedHashMap<>(); newField.put("name", field.get("id").toString()); fields.put(key, newField); } @@ -329,10 +344,10 @@ public class JiraPlatform extends AbstractIssuePlatform { } } - private JSONObject buildUpdateParam(IssuesUpdateRequest issuesRequest, String issuetypeStr, String jiraKey) { + private Map buildUpdateParam(IssuesUpdateRequest issuesRequest, String issuetypeStr, String jiraKey) { issuesRequest.setPlatform(key); - JSONObject fields = new JSONObject(); - JSONObject project = new JSONObject(); + Map fields = new LinkedHashMap<>(); + Map project = new LinkedHashMap<>(); String desc = ""; // 附件描述信息处理 @@ -344,11 +359,11 @@ public class JiraPlatform extends AbstractIssuePlatform { fields.put("project", project); project.put("key", jiraKey); - JSONObject issuetype = new JSONObject(); + Map issuetype = new LinkedHashMap<>(); issuetype.put("id", issuetypeStr); fields.put("issuetype", issuetype); - JSONObject addJiraIssueParam = new JSONObject(); + Map addJiraIssueParam = new LinkedHashMap(); addJiraIssueParam.put("fields", fields); if (issuesRequest.isThirdPartPlatform()) { @@ -411,7 +426,7 @@ public class JiraPlatform extends AbstractIssuePlatform { return result; } - private void parseCustomFiled(IssuesUpdateRequest issuesRequest, JSONObject fields) { + private void parseCustomFiled(IssuesUpdateRequest issuesRequest, Map fields) { List customFields = issuesRequest.getRequestFields(); customFields.forEach(item -> { @@ -424,7 +439,7 @@ public class JiraPlatform extends AbstractIssuePlatform { if (StringUtils.equalsAnyIgnoreCase(name, "PML", "PMLinkTest", "PMLink")) { fields.put(fieldName, item.getValue()); } else { - JSONObject param = new JSONObject(); + Map param = new LinkedHashMap<>(); if (fieldName.equals("assignee") || fieldName.equals("reporter")) { if (issuesRequest.isThirdPartPlatform()) { param.put("id", item.getValue()); @@ -441,7 +456,7 @@ public class JiraPlatform extends AbstractIssuePlatform { if (item.getValue() != null) { List values = JSON.parseArray((String) item.getValue()); values.forEach(v -> { - JSONObject param = new JSONObject(); + Map param = new LinkedHashMap<>(); param.put("id", v); attrs.add(param); }); @@ -449,7 +464,7 @@ public class JiraPlatform extends AbstractIssuePlatform { fields.put(fieldName, attrs); } else if (StringUtils.equalsAny(item.getType(), "cascadingSelect")) { if (item.getValue() != null) { - JSONObject attr = new JSONObject(); + Map attr = new LinkedHashMap<>(); if (item.getValue() instanceof List) { List values = JSON.parseArray((String) item.getValue()); if (CollectionUtils.isNotEmpty(values)) { @@ -457,7 +472,7 @@ public class JiraPlatform extends AbstractIssuePlatform { attr.put("id", values.get(0)); } if (values.size() > 1) { - JSONObject param = new JSONObject(); + Map param = new LinkedHashMap<>(); param.put("id", values.get(1)); attr.put("child", param); } @@ -486,8 +501,8 @@ public class JiraPlatform extends AbstractIssuePlatform { public void updateIssue(IssuesUpdateRequest request) { setUserConfig(); Project project = getProject(); - JSONObject param = buildUpdateParam(request, getIssueType(project.getIssueConfig()), project.getJiraKey()); - jiraClientV2.updateIssue(request.getPlatformId(), JSONObject.toJSONString(param)); + Map param = buildUpdateParam(request, getIssueType(project.getIssueConfig()), project.getJiraKey()); + jiraClientV2.updateIssue(request.getPlatformId(), JSON.toJSONString(param)); // 同步Jira富文本有关的附件 syncJiraRichTextAttachment(request); @@ -535,10 +550,7 @@ public class JiraPlatform extends AbstractIssuePlatform { super.isThirdPartTemplate = isThirdPartTemplate(); HashMap> customFieldMap = new HashMap<>(); - IssuesService issuesService = CommonBeanFactory.getBean(IssuesService.class); - if (project.getThirdPartTemplate()) { - super.defaultCustomFields = issuesService.getCustomFieldsValuesString(getThirdPartTemplate().getCustomFields()); - } + prepareSync(project); issues.forEach(item -> { try { @@ -564,6 +576,13 @@ public class JiraPlatform extends AbstractIssuePlatform { customFieldIssuesService.batchEditFields(customFieldMap); } + public void prepareSync(Project project) { + IssuesService issuesService = CommonBeanFactory.getBean(IssuesService.class); + if (project.getThirdPartTemplate()) { + super.defaultCustomFields = issuesService.getCustomFieldsValuesString(getThirdPartTemplate().getCustomFields()); + } + } + @Override public String getProjectId(String projectId) { return getProjectId(projectId, Project::getJiraKey); @@ -676,7 +695,7 @@ public class JiraPlatform extends AbstractIssuePlatform { public String getStoryType(String configStr) { ProjectIssueConfig projectConfig = super.getProjectConfig(configStr); String jiraStoryType = projectConfig.getJiraStoryTypeId(); - if (StringUtils.isBlank(jiraStoryType)) { + if (StringUtils.isBlank(jiraStoryType)) { MSException.throwException("请在项目中配置 Jira 需求类型!"); } return jiraStoryType; @@ -761,13 +780,13 @@ public class JiraPlatform extends AbstractIssuePlatform { Object defaultValue = item.getDefaultValue(); if (defaultValue != null) { Object msDefaultValue; - if (defaultValue instanceof JSONObject) { - msDefaultValue = ((JSONObject) defaultValue).get("id"); + if (defaultValue instanceof Map) { + msDefaultValue = ((Map) defaultValue).get("id"); } else if (defaultValue instanceof List) { List defaultList = new ArrayList(); ((List) defaultValue).forEach(i -> { - if (i instanceof JSONObject) { - JSONObject obj = (JSONObject) i; + if (i instanceof Map) { + Map obj = (Map) i; defaultList.add(obj.get("id")); } else { defaultList.add(i); @@ -801,7 +820,7 @@ public class JiraPlatform extends AbstractIssuePlatform { if (allowedValues != null) { List options = new ArrayList<>(); allowedValues.forEach(val -> { - JSONObject jsonObject = new JSONObject(); + Map jsonObject = new LinkedHashMap(); jsonObject.put("value", val.getId()); if (StringUtils.isNotBlank(val.getName())) { jsonObject.put("text", val.getName()); @@ -823,7 +842,7 @@ public class JiraPlatform extends AbstractIssuePlatform { List userOptions = jiraClientV2.getAssignableUser(projectKey); List options = new ArrayList(); userOptions.forEach(val -> { - JSONObject jsonObject = new JSONObject(); + Map jsonObject = new LinkedHashMap<>(); if (StringUtils.isNotBlank(val.getAccountId())) { jsonObject.put("value", val.getAccountId()); } else { @@ -877,50 +896,55 @@ public class JiraPlatform extends AbstractIssuePlatform { } public void syncJiraIssueAttachments(IssuesWithBLOBs issue, JiraIssue jiraIssue) { - List jiraAttachmentsName = new ArrayList(); - AttachmentRequest request = new AttachmentRequest(); - request.setBelongType(AttachmentType.ISSUE.type()); - request.setBelongId(issue.getId()); - List allMsAttachments = attachmentService.listMetadata(request); - List msAttachmentsName = allMsAttachments.stream().map(FileAttachmentMetadata::getName).collect(Collectors.toList()); - List attachments = (List) jiraIssue.getFields().get("attachment"); - // 同步Jira中新的附件 - if (CollectionUtils.isNotEmpty(attachments)) { - for (int i = 0; i < attachments.size(); i++) { - Map attachment = (Map) attachments.get(i); - String filename = attachment.get("filename").toString(); - 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.get("content").toString()); - FileAttachmentMetadata fileAttachmentMetadata = attachmentService.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); + try { + List jiraAttachmentsName = new ArrayList(); + AttachmentRequest request = new AttachmentRequest(); + request.setBelongType(AttachmentType.ISSUE.type()); + request.setBelongId(issue.getId()); + List allMsAttachments = attachmentService.listMetadata(request); + List msAttachmentsName = allMsAttachments.stream().map(FileAttachmentMetadata::getName).collect(Collectors.toList()); + List attachments = (List) jiraIssue.getFields().get("attachment"); + // 同步Jira中新的附件 + if (CollectionUtils.isNotEmpty(attachments)) { + for (int i = 0; i < attachments.size(); i++) { + Map attachment = (Map) attachments.get(i); + String filename = attachment.get("filename").toString(); + 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.get("content").toString()); + FileAttachmentMetadata fileAttachmentMetadata = attachmentService.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 deleteMsAttachments = allMsAttachments.stream() - .filter(msAttachment -> !jiraAttachmentsName.contains(msAttachment.getName())).collect(Collectors.toList()); - deleteMsAttachments.forEach(fileAttachmentMetadata -> { - List ids = List.of(fileAttachmentMetadata.getId()); - AttachmentModuleRelationExample example = new AttachmentModuleRelationExample(); - example.createCriteria().andAttachmentIdIn(ids).andRelationTypeEqualTo(AttachmentType.ISSUE.type()); - // 删除MS附件及关联数据 - attachmentService.deleteAttachmentByIds(ids); - attachmentService.deleteFileAttachmentByIds(ids); - attachmentModuleRelationMapper.deleteByExample(example); - }); + // 删除Jira中不存在的附件 + if (CollectionUtils.isNotEmpty(allMsAttachments)) { + List deleteMsAttachments = allMsAttachments.stream() + .filter(msAttachment -> !jiraAttachmentsName.contains(msAttachment.getName())).collect(Collectors.toList()); + deleteMsAttachments.forEach(fileAttachmentMetadata -> { + List ids = List.of(fileAttachmentMetadata.getId()); + AttachmentModuleRelationExample example = new AttachmentModuleRelationExample(); + example.createCriteria().andAttachmentIdIn(ids).andRelationTypeEqualTo(AttachmentType.ISSUE.type()); + // 删除MS附件及关联数据 + attachmentService.deleteAttachmentByIds(ids); + attachmentService.deleteFileAttachmentByIds(ids); + attachmentModuleRelationMapper.deleteByExample(example); + }); + } + } catch (Exception e) { + LogUtil.error(e); + MSException.throwException(e); } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalAbstractPlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalAbstractPlatform.java index 2e4c483c3c..b53110a367 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalAbstractPlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalAbstractPlatform.java @@ -1,10 +1,10 @@ package io.metersphere.service.issue.platform; import io.metersphere.base.domain.Project; -import io.metersphere.dto.IssuesDao; +import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.dto.UserDTO; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.service.issue.domain.PlatformUser; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.PlatformUser; import java.util.List; diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalPlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalPlatform.java index 2a58b3c392..b28603f343 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalPlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/LocalPlatform.java @@ -8,12 +8,12 @@ import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.SessionUtils; -import io.metersphere.constants.AttachmentSyncType; +import io.metersphere.xpack.track.dto.AttachmentSyncType; import io.metersphere.dto.CustomFieldItemDTO; -import io.metersphere.dto.DemandDTO; -import io.metersphere.dto.IssuesDao; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.DemandDTO; +import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.request.testcase.TestCaseBatchRequest; import org.apache.commons.lang3.StringUtils; diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/TapdPlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/TapdPlatform.java index 5fa56cbf2d..2cb7c8bba8 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/TapdPlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/TapdPlatform.java @@ -5,21 +5,16 @@ import io.metersphere.base.domain.Project; import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.BeanUtils; -import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.commons.utils.JSON; -import io.metersphere.commons.utils.SessionUtils; -import io.metersphere.constants.AttachmentSyncType; +import io.metersphere.commons.utils.*; +import io.metersphere.xpack.track.dto.*; import io.metersphere.dto.*; import io.metersphere.i18n.Translator; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.SystemParameterService; import io.metersphere.service.issue.client.TapdClient; -import io.metersphere.service.issue.domain.PlatformUser; import io.metersphere.service.issue.domain.tapd.TapdBug; import io.metersphere.service.issue.domain.tapd.TapdConfig; -import io.metersphere.service.issue.domain.tapd.TapdGetIssueResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.util.LinkedMultiValueMap; @@ -40,6 +35,11 @@ public class TapdPlatform extends AbstractIssuePlatform { setConfig(); } + // xpack 反射调用 + public TapdClient getTapdClient() { + return tapdClient; + } + @Override public List getIssue(IssuesRequest issuesRequest) { issuesRequest.setPlatform(key); @@ -211,7 +211,7 @@ public class TapdPlatform extends AbstractIssuePlatform { Map bug = (Map) issue.get("Bug"); String platformId = bug.get("id").toString(); String id = idMap.get(platformId); - IssuesWithBLOBs updateIssue = getUpdateIssue(issuesMapper.selectByPrimaryKey(id), bug, statusMap); + IssuesWithBLOBs updateIssue = getUpdateIssue(issuesMapper.selectByPrimaryKey(id), bug); updateIssue.setId(id); updateIssue.setCustomFields(syncIssueCustomField(updateIssue.getCustomFields(), bug)); customFieldMap.put(id, baseCustomFieldService.getCustomFieldResourceDTO(updateIssue.getCustomFields())); @@ -232,7 +232,7 @@ public class TapdPlatform extends AbstractIssuePlatform { customFieldIssuesService.batchEditFields(customFieldMap); } - protected IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, Map bug, Map statusMap) { + public IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, Map bug) { if (issue == null) { issue = new IssuesWithBLOBs(); issue.setCustomFields(defaultCustomFields); @@ -244,6 +244,10 @@ public class TapdPlatform extends AbstractIssuePlatform { return issue; } + public IssuesWithBLOBs getUpdateIssue(Map bug) { + return getUpdateIssue(null, bug); + } + private void parseIssue(IssuesWithBLOBs issue, Map bug) { TapdBug bugObj = JSON.parseObject(JSON.toJSONString(bug), TapdBug.class); BeanUtils.copyBean(issue, bugObj); @@ -251,11 +255,15 @@ public class TapdPlatform extends AbstractIssuePlatform { issue.setDescription(htmlDesc2MsDesc(issue.getDescription())); issue.setCustomFields(syncIssueCustomField(issue.getCustomFields(), bug)); issue.setPlatform(key); - issue.setCreateTime((Long) bug.get("created")); - issue.setUpdateTime((Long) bug.get("modified")); + try { + issue.setCreateTime(DateUtils.getTimestamp((String) bug.get("created"))); + issue.setUpdateTime(DateUtils.getTimestamp((String) bug.get("modified"))); + } catch (Exception e) { + LogUtil.error(e); + } } - protected IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, Map bug, List customField) { + public IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, Map bug, List customField) { if (issue == null) { issue = new IssuesWithBLOBs(); issue.setCustomFields(defaultCustomFields); diff --git a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/ZentaoPlatform.java b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/ZentaoPlatform.java index 26acd7c98f..218bdf1946 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/issue/platform/ZentaoPlatform.java +++ b/test-track/backend/src/main/java/io/metersphere/service/issue/platform/ZentaoPlatform.java @@ -7,20 +7,23 @@ import io.metersphere.commons.constants.ZentaoIssuePlatformStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.constants.AttachmentSyncType; +import io.metersphere.xpack.track.dto.AttachmentSyncType; import io.metersphere.constants.AttachmentType; import io.metersphere.dto.*; import io.metersphere.request.attachment.AttachmentRequest; -import io.metersphere.request.testcase.IssuesRequest; -import io.metersphere.request.testcase.IssuesUpdateRequest; +import io.metersphere.xpack.track.dto.DemandDTO; +import io.metersphere.xpack.track.dto.IssuesDao; +import io.metersphere.xpack.track.dto.request.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesUpdateRequest; import io.metersphere.service.issue.client.ZentaoClient; import io.metersphere.service.issue.client.ZentaoGetClient; -import io.metersphere.service.issue.domain.PlatformUser; +import io.metersphere.xpack.track.dto.PlatformUser; import io.metersphere.service.issue.domain.zentao.AddIssueResponse; import io.metersphere.service.issue.domain.zentao.GetIssueResponse; import io.metersphere.service.issue.domain.zentao.ZentaoBuild; import io.metersphere.service.issue.domain.zentao.ZentaoConfig; +import io.metersphere.xpack.track.dto.PlatformStatusDTO; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.util.Strings; @@ -50,6 +53,10 @@ public class ZentaoPlatform extends AbstractIssuePlatform { "bmp", "jpg", "png", "tif", "gif", "jpeg" }; + // xpack 反射调用 + public ZentaoClient getZentaoClient() { + return zentaoClient; + } public ZentaoPlatform(IssuesRequest issuesRequest) { super(issuesRequest); @@ -77,12 +84,12 @@ public class ZentaoPlatform extends AbstractIssuePlatform { return issues; } - public IssuesDao getZentaoAssignedAndBuilds(IssuesDao issue){ + public IssuesDao getZentaoAssignedAndBuilds(IssuesDao issue) { Map zentaoIssue = (Map) zentaoClient.getBugById(issue.getPlatformId()); String assignedTo = zentaoIssue.get("assignedTo").toString(); String openedBuild = zentaoIssue.get("openedBuild").toString(); - ListzentaoBuilds = new ArrayList<>(); - if(Strings.isNotBlank(openedBuild)){ + List zentaoBuilds = new ArrayList<>(); + if (Strings.isNotBlank(openedBuild)) { zentaoBuilds = Arrays.asList(openedBuild.split(",")); } issue.setZentaoAssigned(assignedTo); @@ -146,13 +153,19 @@ public class ZentaoPlatform extends AbstractIssuePlatform { return list; } + public IssuesWithBLOBs getUpdateIssues(Map bug) { + return getUpdateIssues(null, bug); + } + /** * 更新缺陷数据 + * * @param issue 待更新缺陷数据 - * @param bug 平台缺陷数据 + * @param bug 平台缺陷数据 * @return */ public IssuesWithBLOBs getUpdateIssues(IssuesWithBLOBs issue, Map bug) { + GetIssueResponse.Issue bugObj = JSON.parseObject(JSON.toJSONString(bug), GetIssueResponse.Issue.class); String description = bugObj.getSteps(); String steps = description; @@ -168,7 +181,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { mergeCustomField(issue, defaultCustomFields); } issue.setPlatformStatus(bugObj.getStatus()); - if (StringUtils.equals(bugObj.getDeleted(),"1")) { + if (StringUtils.equals(bugObj.getDeleted(), "1")) { issue.setPlatformStatus(IssuesStatus.DELETE.toString()); issuesMapper.updateByPrimaryKeySelective(issue); } @@ -181,7 +194,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { String lastEditedDate = bug.get("lastEditedDate").toString(); if (StringUtils.isNotBlank(openedDate) && !openedDate.startsWith("0000-00-00")) issue.setCreateTime((Long) bug.get("openedDate")); - if (StringUtils.isNotBlank(lastEditedDate) && !lastEditedDate.startsWith("0000-00-00")) + if (StringUtils.isNotBlank(lastEditedDate) && !lastEditedDate.startsWith("0000-00-00")) issue.setUpdateTime((Long) bug.get("lastEditedDate")); } catch (Exception e) { LogUtil.error("update zentao time" + e.getMessage()); @@ -362,9 +375,9 @@ public class ZentaoPlatform extends AbstractIssuePlatform { @Override public List getPlatformUser() { - String session = zentaoClient.login();; + String session = zentaoClient.login(); HttpHeaders httpHeaders = new HttpHeaders(); - HttpEntity> requestEntity = new HttpEntity<>(httpHeaders); + HttpEntity> requestEntity = new HttpEntity<>(httpHeaders); RestTemplate restTemplate = new RestTemplate(); String getUser = zentaoClient.requestUrl.getUserGet(); ResponseEntity responseEntity = restTemplate.exchange(getUser + session, @@ -374,7 +387,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { LogUtil.info("zentao user " + obj); - List data = (List) obj.get("data"); + List data = JSON.parseArray(obj.get("data").toString()); List users = new ArrayList<>(); for (int i = 0; i < data.size(); i++) { @@ -483,7 +496,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { } private String zentao2MsDescription(String ztDescription) { - String imgRegex =""; + String imgRegex = ""; Pattern pattern = Pattern.compile(imgRegex); Matcher matcher = pattern.matcher(ztDescription); while (matcher.find()) { diff --git a/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackCustomFieldTemplateService.java b/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackCustomFieldTemplateService.java index a8617a61ea..aac44621e0 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackCustomFieldTemplateService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackCustomFieldTemplateService.java @@ -11,6 +11,6 @@ public class TrackCustomFieldTemplateService extends TrackProjectSettingService private static final String BASE_UEL = "/custom/field/template"; public List getCustomFieldByTemplateId(String templateId) { - return microService.getForDataArray(serviceName, BASE_UEL + templateId, CustomFieldDao.class); + return microService.getForDataArray(serviceName, BASE_UEL + "/list/" + templateId, CustomFieldDao.class); } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackIssueTemplateService.java b/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackIssueTemplateService.java index 1bfd714e81..20006f6e40 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackIssueTemplateService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/remote/project/TrackIssueTemplateService.java @@ -1,6 +1,6 @@ package io.metersphere.service.remote.project; -import io.metersphere.dto.IssueTemplateDao; +import io.metersphere.xpack.track.dto.IssueTemplateDao; import org.springframework.stereotype.Service; @Service diff --git a/test-track/backend/src/main/java/io/metersphere/service/remote/setting/IntegrationService.java b/test-track/backend/src/main/java/io/metersphere/service/remote/setting/IntegrationService.java deleted file mode 100644 index da479bffa8..0000000000 --- a/test-track/backend/src/main/java/io/metersphere/service/remote/setting/IntegrationService.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.metersphere.service.remote.setting; - -import io.metersphere.base.domain.ServiceIntegration; -import io.metersphere.request.IntegrationRequest; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional(rollbackFor = Exception.class) -public class IntegrationService extends SettingService { - - public ServiceIntegration get(IntegrationRequest request) { - return microService.postForData(serviceName, "/service/integration/type", request, - ServiceIntegration.class); - } -} diff --git a/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java b/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java index 0f325876aa..4da35d0a32 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java @@ -3,7 +3,7 @@ package io.metersphere.service.wapper; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.i18n.Translator; -import io.metersphere.request.testcase.IssuesRequest; +import io.metersphere.xpack.track.dto.request.IssuesRequest; import io.metersphere.service.issue.platform.IssueFactory; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod;