From dc017c84c435094a687676bc76a6cfc34438ef40 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 24 Oct 2023 18:24:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=B9=B3=E5=8F=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ProjectApplicationService.java | 40 +++++++++++++------ .../ProjectApplicationControllerTests.java | 8 ++-- .../dml/init_project_application_test.sql | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java index 5778cf6ba6..b33fa93426 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java @@ -2,12 +2,13 @@ package io.metersphere.project.service; import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin; import io.metersphere.plugin.platform.spi.Platform; +import io.metersphere.plugin.sdk.spi.MsPlugin; import io.metersphere.project.domain.FakeErrorExample; import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.dto.ModuleDTO; -import io.metersphere.project.job.CleanUpReportJob; import io.metersphere.project.job.BugSyncJob; +import io.metersphere.project.job.CleanUpReportJob; import io.metersphere.project.mapper.ExtProjectMapper; import io.metersphere.project.mapper.ExtProjectUserRoleMapper; import io.metersphere.project.mapper.FakeErrorMapper; @@ -24,17 +25,18 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.domain.*; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.system.mapper.ExtPluginMapper; import io.metersphere.system.mapper.PluginMapper; import io.metersphere.system.mapper.ServiceIntegrationMapper; import io.metersphere.system.sechedule.ScheduleService; import io.metersphere.system.service.PlatformPluginService; import io.metersphere.system.service.PluginLoadService; +import io.metersphere.system.service.ServiceIntegrationService; import io.metersphere.system.utils.ServiceUtils; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; +import org.pf4j.PluginWrapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,8 +59,6 @@ public class ProjectApplicationService { @Resource private ServiceIntegrationMapper serviceIntegrationMapper; - @Resource - private ExtPluginMapper extPluginMapper; @Resource private PluginMapper pluginMapper; @@ -75,6 +75,9 @@ public class ProjectApplicationService { @Resource private FakeErrorMapper fakeErrorMapper; + @Resource + private ServiceIntegrationService serviceIntegrationService; + /** * 更新配置信息 * @@ -184,15 +187,28 @@ public class ProjectApplicationService { * @return */ public List getPlatformOptions(String organizationId) { - ServiceIntegrationExample example = new ServiceIntegrationExample(); - example.createCriteria().andOrganizationIdEqualTo(organizationId).andEnableEqualTo(true); - List serviceIntegrations = serviceIntegrationMapper.selectByExample(example); + Set orgPluginIds = platformPluginService.getOrgEnabledPlatformPlugins(organizationId) + .stream() + .map(Plugin::getId) + .collect(Collectors.toSet()); + // 查询服务集成中启用并且支持第三方模板的插件 + List plusins = serviceIntegrationService.getServiceIntegrationByOrgId(organizationId) + .stream() + .filter(serviceIntegration -> { + return serviceIntegration.getEnable() // 服务集成开启 + && orgPluginIds.contains(serviceIntegration.getPluginId()); // 该服务集成对应的插件有权限 + }).collect(Collectors.toList()); List options = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(serviceIntegrations)) { - List pluginIds = serviceIntegrations.stream().map(ServiceIntegration::getPluginId).collect(Collectors.toList()); - options = extPluginMapper.selectPluginOptions(pluginIds); - return options; - } + plusins.forEach(serviceIntegration -> { + PluginWrapper pluginWrapper = pluginLoadService.getPluginWrapper(serviceIntegration.getPluginId()); + MsPlugin plugin = (MsPlugin) pluginWrapper.getPlugin(); + if (plugin instanceof AbstractPlatformPlugin) { + OptionDTO optionDTO = new OptionDTO(); + optionDTO.setName(plugin.getName()); + optionDTO.setId(pluginWrapper.getPluginId()); + options.add(optionDTO); + } + }); return options; } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java index cf7d419625..0ad46aa737 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java @@ -63,7 +63,6 @@ public class ProjectApplicationControllerTests extends BaseTest { //测试计划 - 清理报告配置 @Test @Order(1) - @Sql(scripts = {"/dml/init_project_application_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) public void testTestPlanClean() throws Exception { this.testGetTestPlan(); //新增 @@ -358,7 +357,8 @@ public class ProjectApplicationControllerTests extends BaseTest { //用例管理 - 获取平台下拉列表 @Test - @Order(25) + @Order(40) + @Sql(scripts = {"/dml/init_project_application_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) public void testGetPlatform() throws Exception { this.requestGetWithOkAndReturn(GET_PLATFORM_URL + "/100002"); MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_PLATFORM_URL + "/100001"); @@ -439,7 +439,7 @@ public class ProjectApplicationControllerTests extends BaseTest { //缺陷管理 - 获取平台下拉列表 @Test - @Order(31) + @Order(41) public void testGetBugPlatform() throws Exception { this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_URL + "/100002"); MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_URL + "/100001"); @@ -643,7 +643,7 @@ public class ProjectApplicationControllerTests extends BaseTest { configs.put("jiraKey", "Test"); configs.put("jiraIssueTypeId", "10086"); configs.put("jiraStoryTypeId", "10010"); - assertErrorCode(this.requestPost(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs), NOT_FOUND); + assertErrorCode(this.requestPost(CHECK_PROJECT_KEY_URL + "/" + "test", configs), NOT_FOUND); JiraIntegrationConfig integrationConfig = new JiraIntegrationConfig(); integrationConfig.setAddress(String.format("http://%s:%s", mockServerHost, mockServerHostPort)); Map integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig)); diff --git a/backend/services/project-management/src/test/resources/dml/init_project_application_test.sql b/backend/services/project-management/src/test/resources/dml/init_project_application_test.sql index 8dd89f6164..02b0832938 100644 --- a/backend/services/project-management/src/test/resources/dml/init_project_application_test.sql +++ b/backend/services/project-management/src/test/resources/dml/init_project_application_test.sql @@ -1,5 +1,5 @@ -- 模拟数据 -INSERT INTO `service_integration`(`id`, `plugin_id`, `enable`, `configuration`, `organization_id`) VALUES ('1', '952262969139212', b'1', '1111', '100001'); +INSERT INTO `service_integration`(`id`, `plugin_id`, `enable`, `configuration`, `organization_id`) VALUES ('1', 'jira', b'1', '1111', '100002'); -- 模拟用户