diff --git a/components/bpmn-q/modeler-component/editor/EditorConstants.js b/components/bpmn-q/modeler-component/editor/EditorConstants.js index 72d79187..756be04f 100644 --- a/components/bpmn-q/modeler-component/editor/EditorConstants.js +++ b/components/bpmn-q/modeler-component/editor/EditorConstants.js @@ -1,3 +1,13 @@ +// names of the supported plugins +export const pluginNames = { + QUANTME: "quantme", + OPENTOSCA: "opentosca", + PLANQK: "planqk", + QHANA: "qhana", + PATTERN: "pattern", + DATAFLOW: "dataflow", +}; + // supported options to handle a transformed workflow export const transformedWorkflowHandlers = { NEW_TAB: "Open in new Tab", diff --git a/components/bpmn-q/modeler-component/editor/plugin/PluginHandler.js b/components/bpmn-q/modeler-component/editor/plugin/PluginHandler.js index 326eabef..b40be846 100644 --- a/components/bpmn-q/modeler-component/editor/plugin/PluginHandler.js +++ b/components/bpmn-q/modeler-component/editor/plugin/PluginHandler.js @@ -7,6 +7,7 @@ import OpenTOSCAPlugin from "../../extensions/opentosca/OpenTOSCAPlugin"; import { getAllConfigs } from "./PluginConfigHandler"; import GeneralTab from "../config/GeneralTab"; import GitHubTab from "../../extensions/quantme/configTabs/GitHubTab"; +import { pluginNames } from "../EditorConstants"; /** * Handler for plugins of the modeler. Controls active plugins and the properties they define. Central access point to @@ -18,7 +19,7 @@ import GitHubTab from "../../extensions/quantme/configTabs/GitHubTab"; const PLUGINS = [ { plugin: QuantMEPlugin, - dependencies: ["DataFlowPlugin"], + dependencies: [pluginNames.OPENTOSCA], }, { plugin: DataFlowPlugin, @@ -34,7 +35,7 @@ const PLUGINS = [ }, { plugin: PatternPlugin, - dependencies: [], + dependencies: [pluginNames.QUANTME], }, { plugin: OpenTOSCAPlugin, @@ -53,6 +54,7 @@ export function getActivePlugins() { const loadPlugin = (plugin) => { if (!activePlugins.includes(plugin.plugin)) { + activePlugins.push(plugin.plugin); for (const dependency of plugin.dependencies) { const dependencyPlugin = PLUGINS.find( (p) => p.plugin.name === dependency @@ -61,11 +63,9 @@ export function getActivePlugins() { dependencyPlugin && !activePlugins.includes(dependencyPlugin.plugin) ) { - activePlugins.push(dependencyPlugin.plugin); loadPlugin(dependencyPlugin); } } - activePlugins.push(plugin.plugin); } }; @@ -86,17 +86,17 @@ export function getActivePlugins() { export function checkEnabledStatus(pluginName) { switch (pluginName) { - case "dataflow": + case pluginNames.DATAFLOW: return process.env.ENABLE_DATA_FLOW_PLUGIN !== "false"; - case "planqk": + case pluginNames.PLANQK: return process.env.ENABLE_PLANQK_PLUGIN !== "false"; - case "qhana": + case pluginNames.QHANA: return process.env.ENABLE_QHANA_PLUGIN !== "false"; - case "quantme": + case pluginNames.QUANTME: return process.env.ENABLE_QUANTME_PLUGIN !== "false"; - case "pattern": + case pluginNames.PATTERN: return process.env.ENABLE_PATTERN_PLUGIN !== "false"; - case "opentosca": + case pluginNames.OPENTOSCA: return process.env.ENABLE_OPENTOSCA_PLUGIN !== "false"; } } diff --git a/components/bpmn-q/modeler-component/extensions/opentosca/framework-config/config-manager.js b/components/bpmn-q/modeler-component/extensions/opentosca/framework-config/config-manager.js index 0e11761f..54708ccb 100644 --- a/components/bpmn-q/modeler-component/extensions/opentosca/framework-config/config-manager.js +++ b/components/bpmn-q/modeler-component/extensions/opentosca/framework-config/config-manager.js @@ -11,6 +11,7 @@ import defaultConfig from "./config"; import { getPluginConfig } from "../../../editor/plugin/PluginConfigHandler"; +import { pluginNames } from "../../../editor/EditorConstants"; let config = {}; @@ -22,7 +23,7 @@ let config = {}; export function getOpenTOSCAEndpoint() { if (config.opentoscaEndpoint === undefined) { setOpenTOSCAEndpoint( - getPluginConfig("opentosca").opentoscaEndpoint || + getPluginConfig(pluginNames.OPENTOSCA).opentoscaEndpoint || defaultConfig.opentoscaEndpoint ); } @@ -48,7 +49,7 @@ export function setOpenTOSCAEndpoint(opentoscaEndpoint) { export function getWineryEndpoint() { if (config.wineryEndpoint === undefined) { setWineryEndpoint( - getPluginConfig("opentosca").wineryEndpoint || + getPluginConfig(pluginNames.OPENTOSCA).wineryEndpoint || defaultConfig.wineryEndpoint ); } diff --git a/components/bpmn-q/test/tests/editor/plugin.spec.js b/components/bpmn-q/test/tests/editor/plugin.spec.js index 9351ac28..3ec3b32a 100644 --- a/components/bpmn-q/test/tests/editor/plugin.spec.js +++ b/components/bpmn-q/test/tests/editor/plugin.spec.js @@ -10,6 +10,7 @@ import { getPluginConfig, setPluginConfig, } from "../../../modeler-component/editor/plugin/PluginConfigHandler"; +import { pluginNames } from "../../../modeler-component/editor/EditorConstants"; describe("Test plugins", function () { describe("Test PluginHandler", function () { @@ -23,39 +24,77 @@ describe("Test plugins", function () { it("Should find 4 active plugins", function () { setPluginConfig([ - { name: "dataflow" }, - { name: "quantme" }, - { name: "opentosca" }, - { name: "planqk" }, + { name: pluginNames.DATAFLOW }, + { name: pluginNames.QUANTME }, + { name: pluginNames.OPENTOSCA }, + { name: pluginNames.PLANQK }, ]); const plugins = getActivePlugins(); expect(plugins.length).to.equal(4); - expect(plugins[0].name).to.equal("dataflow"); - expect(plugins[1].name).to.equal("quantme"); - expect(plugins[2].name).to.equal("opentosca"); - expect(plugins[3].name).to.equal("planqk"); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.DATAFLOW) + .length + ).to.equal(1); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.OPENTOSCA) + .length + ).to.equal(1); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.QUANTME).length + ).to.equal(1); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.PLANQK).length + ).to.equal(1); + }); + + it("Should find 4 active plugins due to dependencies", function () { + setPluginConfig([ + { name: pluginNames.DATAFLOW }, + { name: pluginNames.QUANTME }, + { name: pluginNames.PLANQK }, + ]); + + const plugins = getActivePlugins(); + + expect(plugins.length).to.equal(4); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.DATAFLOW) + .length + ).to.equal(1); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.QUANTME).length + ).to.equal(1); + expect( + plugins.filter((plugin) => plugin.name === pluginNames.PLANQK).length + ).to.equal(1); + + // should be found due to dependency of quantme plugin + expect( + plugins.filter((plugin) => plugin.name === pluginNames.OPENTOSCA) + .length + ).to.equal(1); }); }); describe("Test getter for plugin attributes", function () { it("Should get correct plugin entries for active plugins", function () { setPluginConfig([ - { name: "dataflow" }, - { name: "quantme" }, - { name: "opentosca" }, - { name: "planqk" }, + { name: pluginNames.DATAFLOW }, + { name: pluginNames.QUANTME }, + { name: pluginNames.OPENTOSCA }, + { name: pluginNames.PLANQK }, ]); const modules = getAdditionalModules(); const extensions = getModdleExtension(); expect(modules.length).to.equal(4); - expect(extensions["dataflow"]).to.not.be.undefined; - expect(extensions["quantme"]).to.not.be.undefined; - expect(extensions["opentosca"]).to.not.be.undefined; - expect(extensions["planqk"]).to.not.be.undefined; + expect(extensions[pluginNames.DATAFLOW]).to.not.be.undefined; + expect(extensions[pluginNames.QUANTME]).to.not.be.undefined; + expect(extensions[pluginNames.OPENTOSCA]).to.not.be.undefined; + expect(extensions[pluginNames.PLANQK]).to.not.be.undefined; }); }); }); diff --git a/components/bpmn-q/test/tests/quantme/quantme-transformation.spec.js b/components/bpmn-q/test/tests/quantme/quantme-transformation.spec.js index 33ade903..9895f129 100644 --- a/components/bpmn-q/test/tests/quantme/quantme-transformation.spec.js +++ b/components/bpmn-q/test/tests/quantme/quantme-transformation.spec.js @@ -18,13 +18,16 @@ const { const config = require("../../../modeler-component/extensions/quantme/framework-config/config-manager"); const camundaConfig = require("../../../modeler-component/editor/config/EditorConfigManager"); const chai = require("chai"); +const { + pluginNames, +} = require("../../../modeler-component/editor/EditorConstants"); describe("Test the QuantMETransformator of the QuantME extension.", function () { describe("Transformation of QuantME extensions", function () { it("should create a valid native workflow model after two transformations", async function () { setPluginConfig([ - { name: "dataflow" }, + { name: pluginNames.DATAFLOW }, { - name: "quantme", + name: pluginNames.QUANTME, config: { githubRepositoryName: "QuantME-UseCases", githubUsername: "UST-QuAntiL", @@ -89,7 +92,10 @@ describe("Test the QuantMETransformator of the QuantME extension.", function () it("should fail due to missing QRMs", async function () { resetQRMs(); // setConfig(); - setPluginConfig([{ name: "dataflow" }, { name: "quantme" }]); + setPluginConfig([ + { name: pluginNames.DATAFLOW }, + { name: pluginNames.QUANTME }, + ]); this.timeout(60000); const result = await startQuantmeReplacementProcess(