fix(系统设置): 上次同类型的平台插件,提示已存在

This commit is contained in:
chenjianxing 2023-02-09 14:06:20 +08:00 committed by jianxing
parent bda4f7d727
commit 0426560d7d
1 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,7 @@
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;
@ -17,6 +19,7 @@ import io.metersphere.dto.PlatformProjectOptionRequest;
import io.metersphere.platform.loader.PlatformPluginManager;
import io.metersphere.request.IntegrationRequest;
import io.metersphere.utils.PluginManagerUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.kafka.core.KafkaTemplate;
@ -73,10 +76,19 @@ public class PlatformPluginService {
public PluginWithBLOBs addPlatformPlugin(MultipartFile file) {
String id = UUID.randomUUID().toString();
PluginManagerUtil.uploadPlugin(id, file);
PluginManagerUtil.loadPlugin(id, getPluginManager(), file);
PluginMetaInfo pluginMetaInfo = getPluginManager().getImplInstance(id, PluginMetaInfo.class);
PluginExample example = new PluginExample();
example.createCriteria().andScriptIdEqualTo(pluginMetaInfo.getKey());
if (pluginMapper.countByExample(example) > 0) {
// 校验插件类型是否存在
unload(id);
MSException.throwException(pluginMetaInfo.getKey() + " plugin is already exist!");
}
PluginManagerUtil.uploadPlugin(id, file);
Map map = JSON.parseMap(pluginMetaInfo.getFrontendMetaData());
map.put("id", id);
map.put("key", pluginMetaInfo.getKey());