From 231d09965561015e26ea5347a904b6ad45e3d353 Mon Sep 17 00:00:00 2001 From: jianxing Date: Wed, 16 Aug 2023 16:25:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E5=B9=B3=E5=8F=B0=E6=8F=92=E4=BB=B6=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E5=99=A8=E6=B7=BB=E5=8A=A0=E4=B8=AA=E4=BA=BA=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9B=B8=E5=85=B3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PlatformPluginService.java | 39 ++++++++++++++----- .../service/PlatformPluginService.java | 22 +++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/system-setting/backend/src/main/java/io/metersphere/service/PlatformPluginService.java b/system-setting/backend/src/main/java/io/metersphere/service/PlatformPluginService.java index 7f35b27083..835547d6c4 100644 --- a/system-setting/backend/src/main/java/io/metersphere/service/PlatformPluginService.java +++ b/system-setting/backend/src/main/java/io/metersphere/service/PlatformPluginService.java @@ -1,25 +1,29 @@ package io.metersphere.service; -import io.metersphere.base.domain.Plugin; import io.metersphere.base.domain.PluginExample; -import io.metersphere.commons.exception.MSException; -import io.metersphere.i18n.Translator; -import io.metersphere.platform.api.Platform; -import io.metersphere.platform.api.PluginMetaInfo; import io.metersphere.base.domain.PluginWithBLOBs; import io.metersphere.base.domain.ServiceIntegration; +import io.metersphere.base.domain.User; import io.metersphere.base.mapper.PluginMapper; +import io.metersphere.base.mapper.UserMapper; import io.metersphere.commons.constants.KafkaTopicConstants; import io.metersphere.commons.constants.PluginScenario; +import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; -import io.metersphere.platform.domain.*; import io.metersphere.dto.PlatformProjectOptionRequest; +import io.metersphere.i18n.Translator; +import io.metersphere.platform.api.Platform; +import io.metersphere.platform.api.PluginMetaInfo; +import io.metersphere.platform.domain.GetOptionRequest; +import io.metersphere.platform.domain.PlatformRequest; +import io.metersphere.platform.domain.SelectOption; import io.metersphere.platform.loader.PlatformPluginManager; import io.metersphere.request.IntegrationRequest; import io.metersphere.utils.PluginManagerUtil; -import org.apache.commons.collections.CollectionUtils; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Lazy; import org.springframework.kafka.core.KafkaTemplate; @@ -28,8 +32,6 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -50,6 +52,8 @@ public class PlatformPluginService { @Resource private BaseIntegrationService baseIntegrationService; @Resource + private UserMapper userMapper; + @Resource private KafkaTemplate kafkaTemplate; @Resource @Lazy @@ -184,6 +188,7 @@ public class PlatformPluginService { PlatformRequest pluginRequest = new PlatformRequest(); pluginRequest.setIntegrationConfig(serviceIntegration.getConfiguration()); + pluginRequest.setUserPlatformInfo(getUserPlatformInfo(workspaceId)); Platform platform = getPluginManager().getPlatformByKey(platformKey, pluginRequest); if (platform == null) { MSException.throwException(Translator.get("platform_plugin_not_exit") + PLUGIN_DOWNLOAD_URL); @@ -191,6 +196,22 @@ public class PlatformPluginService { return platform; } + private String getUserPlatformInfo(String workspaceId) { + try { + String userId = SessionUtils.getUserId(); + if (StringUtils.isBlank(workspaceId) || StringUtils.isBlank(userId)) { + return null; + } + User user = userMapper.selectByPrimaryKey(userId); + if (StringUtils.isNotBlank(user.getPlatformInfo())) { + return JSON.toJSONString(JSON.parseMap(user.getPlatformInfo()).get(workspaceId)); + } + } catch (Exception e) { + LogUtil.error(e); + } + return null; + } + public Map getFrontendMetaDataConfig(PluginWithBLOBs plugin, String configName) { Map metaData = JSON.parseMap(plugin.getFormScript()); Map config = (Map) metaData.get(configName); diff --git a/test-track/backend/src/main/java/io/metersphere/service/PlatformPluginService.java b/test-track/backend/src/main/java/io/metersphere/service/PlatformPluginService.java index b90df284a0..73eb4f8851 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/PlatformPluginService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/PlatformPluginService.java @@ -1,8 +1,11 @@ package io.metersphere.service; +import io.metersphere.base.domain.User; +import io.metersphere.base.mapper.UserMapper; import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.JSON; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.i18n.Translator; import io.metersphere.platform.api.Platform; import io.metersphere.platform.api.PluginMetaInfo; @@ -40,6 +43,8 @@ public class PlatformPluginService { private BaseIntegrationService baseIntegrationService; @Resource private BaseProjectService baseProjectService; + @Resource + private UserMapper userMapper; public static final String PLUGIN_DOWNLOAD_URL = "https://github.com/metersphere/metersphere-platform-plugin"; @@ -96,6 +101,7 @@ public class PlatformPluginService { PlatformRequest pluginRequest = new PlatformRequest(); pluginRequest.setWorkspaceId(workspaceId); pluginRequest.setIntegrationConfig(serviceIntegration.getConfiguration()); + pluginRequest.setUserPlatformInfo(getUserPlatformInfo(workspaceId)); Platform platform = getPluginManager().getPlatformByKey(platformKey, pluginRequest); if (platform == null) { MSException.throwException(Translator.get("platform_plugin_not_exit") + PLUGIN_DOWNLOAD_URL); @@ -103,6 +109,22 @@ public class PlatformPluginService { return platform; } + private String getUserPlatformInfo(String workspaceId) { + try { + String userId = SessionUtils.getUserId(); + if (StringUtils.isBlank(workspaceId) || StringUtils.isBlank(userId)) { + return null; + } + User user = userMapper.selectByPrimaryKey(userId); + if (StringUtils.isNotBlank(user.getPlatformInfo())) { + return JSON.toJSONString(JSON.parseMap(user.getPlatformInfo()).get(workspaceId)); + } + } catch (Exception e) { + LogUtil.error(e); + } + return null; + } + public Platform getPlatform(String platformKey) { return this.getPlatform(platformKey, null); }