refactor(测试跟踪): 平台插件构造器添加个人账号信息相关参数

This commit is contained in:
jianxing 2023-08-16 16:25:22 +08:00 committed by jianxing
parent ec0ce49ab4
commit 231d099655
2 changed files with 52 additions and 9 deletions

View File

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

View File

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