From 2a3756833800d7fe0aa53491750c0100d0d84a2e Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 14 Sep 2021 19:28:03 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=8F=92=E4=BB=B6=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0xpack=E6=8F=92=E4=BB=B6=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PluginController.java | 3 +- .../controller/request/PluginDTO.java | 9 +++++ .../io/metersphere/service/PluginService.java | 37 ++++++++++++++++--- .../automation/scenario/EditApiScenario.vue | 16 +++++++- .../scenario/maximize/MaximizeScenario.vue | 16 ++++++-- .../settings/plugin/PluginConfig.vue | 8 +++- frontend/src/common/js/utils.js | 15 ++++---- 7 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/controller/request/PluginDTO.java diff --git a/backend/src/main/java/io/metersphere/controller/PluginController.java b/backend/src/main/java/io/metersphere/controller/PluginController.java index f223ba0a13..9d1a9a504c 100644 --- a/backend/src/main/java/io/metersphere/controller/PluginController.java +++ b/backend/src/main/java/io/metersphere/controller/PluginController.java @@ -2,6 +2,7 @@ package io.metersphere.controller; import io.metersphere.base.domain.Plugin; import io.metersphere.commons.exception.MSException; +import io.metersphere.controller.request.PluginDTO; import io.metersphere.controller.request.PluginRequest; import io.metersphere.service.PluginService; import org.springframework.web.bind.annotation.*; @@ -26,7 +27,7 @@ public class PluginController { } @GetMapping("/list") - public List list() { + public List list() { return pluginService.list(); } diff --git a/backend/src/main/java/io/metersphere/controller/request/PluginDTO.java b/backend/src/main/java/io/metersphere/controller/request/PluginDTO.java new file mode 100644 index 0000000000..ea5e84d580 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/PluginDTO.java @@ -0,0 +1,9 @@ +package io.metersphere.controller.request; + +import io.metersphere.base.domain.Plugin; +import lombok.Data; + +@Data +public class PluginDTO extends Plugin { + private Boolean license; +} diff --git a/backend/src/main/java/io/metersphere/service/PluginService.java b/backend/src/main/java/io/metersphere/service/PluginService.java index 46e66d818b..55818626ea 100644 --- a/backend/src/main/java/io/metersphere/service/PluginService.java +++ b/backend/src/main/java/io/metersphere/service/PluginService.java @@ -8,11 +8,11 @@ import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.controller.request.PluginDTO; import io.metersphere.controller.request.PluginRequest; import io.metersphere.controller.request.PluginResourceDTO; import io.metersphere.plugin.core.ui.PluginResource; import io.metersphere.service.utils.CommonUtil; -import io.metersphere.service.utils.MsClassLoader; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -32,8 +32,6 @@ import java.util.stream.Collectors; public class PluginService { @Resource private PluginMapper pluginMapper; - @Resource - private MsClassLoader classLoader; public String editPlugin(MultipartFile file) { String id = UUID.randomUUID().toString(); @@ -79,6 +77,15 @@ public class PluginService { }); } + private boolean isXpack(Class aClass, Object instance) { + try { + Object verify = aClass.getDeclaredMethod("xpack").invoke(instance); + return (Boolean) verify; + } catch (Exception e) { + return false; + } + } + private List getMethod(String path, String fileName) { List resources = new LinkedList<>(); try { @@ -143,10 +150,30 @@ public class PluginService { } } - public List list() { + public List list() { PluginExample example = new PluginExample(); List plugins = pluginMapper.selectByExample(example); - return plugins; + Map pluginMap = new HashMap<>(); + List lists = new LinkedList<>(); + // 校验插件是否是企业版 + plugins.forEach(item -> { + PluginDTO dto = new PluginDTO(); + BeanUtils.copyBean(dto, item); + if (!pluginMap.containsKey(item.getPluginId())) { + try { + Class clazz = Class.forName(item.getExecEntry()); + Object instance = clazz.newInstance(); + dto.setLicense(this.isXpack(Class.forName(item.getExecEntry()), instance)); + } catch (Exception e) { + LogUtil.error(e.getMessage()); + } + } else { + dto.setLicense(pluginMap.get(item.getPluginId())); + } + lists.add(dto); + pluginMap.put(item.getPluginId(), dto.getLicense()); + }); + return lists; } public Plugin get(String scriptId) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 9677172c4f..206c9b1dcc 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -332,7 +332,7 @@ import { strMapToObj, handleCtrlSEvent, getCurrentProjectID, - handleCtrlREvent + handleCtrlREvent, hasLicense } from "@/common/js/utils"; import "@/common/css/material-icons.css" import OutsideClick from "@/common/js/outside-click"; @@ -529,8 +529,20 @@ export default { }, getPlugins() { let url = "/plugin/list"; + this.plugins = []; this.$get(url, response => { - this.plugins = response.data; + let data = response.data; + if (data) { + data.forEach(item => { + if (item.license) { + if (hasLicense()) { + this.plugins.push(item); + } + } else { + this.plugins.push(item); + } + }) + } }); }, stop() { diff --git a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue index bcd7881737..6e79afb365 100644 --- a/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/maximize/MaximizeScenario.vue @@ -150,7 +150,7 @@ import {API_STATUS, PRIORITY} from "../../../definition/model/JsonData"; import {parseEnvironment} from "../../../definition/model/EnvironmentModel"; import {ELEMENT_TYPE, STEP} from "../Setting"; -import {getCurrentProjectID, getUUID, strMapToObj} from "@/common/js/utils"; +import {getCurrentProjectID, getUUID, hasLicense, strMapToObj} from "@/common/js/utils"; import "@/common/css/material-icons.css" import OutsideClick from "@/common/js/outside-click"; import {handleCtrlSEvent} from "../../../../../../common/js/utils"; @@ -293,8 +293,16 @@ export default { this.addComponent(item.name, item) } } - if (this.operatingElements && this.operatingElements.includes(item.jmeterClazz)) { - this.buttonData.push(plugin); + if (item.license) { + if (hasLicense()) { + if (this.operatingElements && this.operatingElements.includes(item.jmeterClazz)) { + this.buttonData.push(plugin); + } + } + } else { + if (this.operatingElements && this.operatingElements.includes(item.jmeterClazz)) { + this.buttonData.push(plugin); + } } }); } @@ -704,7 +712,7 @@ export default { this.$refs['currentScenario'].validate((valid) => { if (valid) { this.setParameter(); - saveScenario(this.path, this.currentScenario, this.scenarioDefinition, this,(response) => { + saveScenario(this.path, this.currentScenario, this.scenarioDefinition, this, (response) => { this.$success(this.$t('commons.save_success')); this.path = "/api/automation/update"; if (response.data) { diff --git a/frontend/src/business/components/settings/plugin/PluginConfig.vue b/frontend/src/business/components/settings/plugin/PluginConfig.vue index 763b9a1ddc..5e193ff564 100644 --- a/frontend/src/business/components/settings/plugin/PluginConfig.vue +++ b/frontend/src/business/components/settings/plugin/PluginConfig.vue @@ -30,6 +30,12 @@ {{ scope.row.updateTime | timestampFormatDate }} + + +