From a64edf002da2b346dfa1ea86bc5c49a69510bcc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pere=20Fern=C3=A1ndez?= Date: Tue, 24 Dec 2024 16:41:33 +0100 Subject: [PATCH] [incubator-kie-issues#733] Remove JavaScript language option from Script Editor in BPMN Editor --- .../monaco_editor/MonacoEditorLanguage.java | 11 ----- .../ScriptTypeFieldEditorPresenter.java | 3 +- .../MonacoEditorLanguageTest.java | 13 ------ .../ScriptTypeFieldEditorPresenterTest.java | 4 -- .../tostunner/properties/Scripts.java | 42 +++++-------------- 5 files changed, 12 insertions(+), 61 deletions(-) diff --git a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguage.java b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguage.java index 181155edee3..a58cb93aef3 100644 --- a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguage.java +++ b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguage.java @@ -24,8 +24,6 @@ public class MonacoEditorLanguage { static final String LANG_JAVA = "java"; static final String TITLE_JAVA = "Java"; - static final String LANG_JAVASCRIPT = "javascript"; - static final String TITLE_JAVASCRIPT = "JavaScript"; static final String LANG_MVEL = "mvel"; static final String TITLE_MVEL = "MVEL"; static final String LANG_DROOLS = "drools"; @@ -33,9 +31,6 @@ public class MonacoEditorLanguage { static final String LANG_FEEL = "feel"; static final String TITLE_FEEL = "FEEL"; static final String JAVA_MODULE = "vs/basic-languages/java/java"; - static final String JAVASCRIPT_MODULE = "vs/basic-languages/javascript/javascript"; - static final String TYPESCRIPT_MODULE = "vs/basic-languages/typescript/typescript"; - static final String TYPESCRIPT_MODE_MODULE = "vs/language/typescript/tsMode"; public static MonacoEditorLanguage JAVA = new MonacoEditorLanguage(LANG_JAVA, @@ -43,12 +38,6 @@ public class MonacoEditorLanguage { LANG_JAVA, new String[]{JAVA_MODULE}); - public static MonacoEditorLanguage JAVA_SCRIPT = - new MonacoEditorLanguage(LANG_JAVASCRIPT, - TITLE_JAVASCRIPT, - LANG_JAVASCRIPT, - new String[]{JAVASCRIPT_MODULE, TYPESCRIPT_MODULE, TYPESCRIPT_MODE_MODULE}); - // Let's assume use of Java syntax for MVEL. public static MonacoEditorLanguage MVEL = new MonacoEditorLanguage(LANG_MVEL, diff --git a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenter.java b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenter.java index 2c9b089fced..8adbf5763c1 100644 --- a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenter.java +++ b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/main/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenter.java @@ -131,7 +131,6 @@ private static List getLanguages(ScriptTypeMode mode) { if (mode == ACTION_SCRIPT) { languages = new ArrayList<>(3); languages.add(MonacoEditorLanguage.JAVA); - languages.add(MonacoEditorLanguage.JAVA_SCRIPT); languages.add(MonacoEditorLanguage.MVEL); } else if (mode == COMPLETION_CONDITION) { languages = new ArrayList<>(2); @@ -140,7 +139,6 @@ private static List getLanguages(ScriptTypeMode mode) { } else if (mode == FLOW_CONDITION) { languages = new ArrayList<>(5); languages.add(MonacoEditorLanguage.JAVA); - languages.add(MonacoEditorLanguage.JAVA_SCRIPT); languages.add(MonacoEditorLanguage.MVEL); languages.add(MonacoEditorLanguage.DROOLS); languages.add(MonacoEditorLanguage.FEEL); @@ -159,6 +157,7 @@ protected void onChange() { true); value.setScript(view.getValue()); value.setLanguage(view.getLanguageId()); + notifyChange(oldValue, value); } diff --git a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguageTest.java b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguageTest.java index b55683be56d..2cc71ed206c 100644 --- a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguageTest.java +++ b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/components/monaco_editor/MonacoEditorLanguageTest.java @@ -52,19 +52,6 @@ public void testJavaOptions() { assertEquals(MonacoEditorLanguage.LANG_JAVA, language.buildOptions().getLanguage()); } - @Test - public void testJavaScriptOptions() { - MonacoEditorLanguage language = MonacoEditorLanguage.JAVA_SCRIPT; - assertEquals(MonacoEditorLanguage.LANG_JAVASCRIPT, language.getId()); - assertEquals(MonacoEditorLanguage.TITLE_JAVASCRIPT, language.getTitle()); - assertEquals(MonacoEditorLanguage.LANG_JAVASCRIPT, language.getLanguageCode()); - assertEquals(3, language.getModules().length); - assertEquals(MonacoEditorLanguage.JAVASCRIPT_MODULE, language.getModules()[0]); - assertEquals(MonacoEditorLanguage.TYPESCRIPT_MODULE, language.getModules()[1]); - assertEquals(MonacoEditorLanguage.TYPESCRIPT_MODE_MODULE, language.getModules()[2]); - assertEquals(MonacoEditorLanguage.LANG_JAVASCRIPT, language.buildOptions().getLanguage()); - } - @Test public void testMVELOptions() { MonacoEditorLanguage language = MonacoEditorLanguage.MVEL; diff --git a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenterTest.java b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenterTest.java index 118a26d6fa6..11ce084e64e 100644 --- a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenterTest.java +++ b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-client/src/test/java/org/kie/workbench/common/stunner/bpmn/client/forms/fields/scriptEditor/ScriptTypeFieldEditorPresenterTest.java @@ -82,7 +82,6 @@ public void testSetCompletionConditionMode() { verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.MVEL)); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.DROOLS)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.JAVA)); - verify(view, never()).addLanguage(eq(MonacoEditorLanguage.JAVA_SCRIPT)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.FEEL)); } @@ -90,7 +89,6 @@ public void testSetCompletionConditionMode() { public void testSetFlowConditionMode() { editor.setMode(ScriptTypeMode.FLOW_CONDITION); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.JAVA)); - verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.JAVA_SCRIPT)); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.MVEL)); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.DROOLS)); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.FEEL)); @@ -100,7 +98,6 @@ public void testSetFlowConditionMode() { public void testSetActionScriptMode() { editor.setMode(ScriptTypeMode.ACTION_SCRIPT); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.JAVA)); - verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.JAVA_SCRIPT)); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.MVEL)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.DROOLS)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.FEEL)); @@ -111,7 +108,6 @@ public void testSetDroolsConditionScriptMode() { editor.setMode(ScriptTypeMode.DROOLS_CONDITION); verify(view, times(1)).addLanguage(eq(MonacoEditorLanguage.DROOLS)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.JAVA)); - verify(view, never()).addLanguage(eq(MonacoEditorLanguage.JAVA_SCRIPT)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.MVEL)); verify(view, never()).addLanguage(eq(MonacoEditorLanguage.FEEL)); } diff --git a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-marshalling/src/main/java/org/kie/workbench/common/stunner/bpmn/client/marshall/converters/tostunner/properties/Scripts.java b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-marshalling/src/main/java/org/kie/workbench/common/stunner/bpmn/client/marshall/converters/tostunner/properties/Scripts.java index 19b554571f1..a597f07a426 100644 --- a/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-marshalling/src/main/java/org/kie/workbench/common/stunner/bpmn/client/marshall/converters/tostunner/properties/Scripts.java +++ b/packages/stunner-editors/kie-wb-common-stunner/kie-wb-common-stunner-sets/kie-wb-common-stunner-bpmn/kie-wb-common-stunner-bpmn-marshalling/src/main/java/org/kie/workbench/common/stunner/bpmn/client/marshall/converters/tostunner/properties/Scripts.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.bpmn2.Bpmn2Factory; import org.eclipse.bpmn2.ExtensionAttributeValue; @@ -42,17 +43,12 @@ import static org.jboss.drools.DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT; import static org.jboss.drools.DroolsPackage.Literals.DOCUMENT_ROOT__ON_EXIT_SCRIPT; import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.fromstunner.Factories.droolsFactory; -import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.tostunner.properties.Scripts.LANGUAGE.DROOLS; -import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.tostunner.properties.Scripts.LANGUAGE.FEEL; import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.tostunner.properties.Scripts.LANGUAGE.JAVA; -import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.tostunner.properties.Scripts.LANGUAGE.JAVASCRIPT; -import static org.kie.workbench.common.stunner.bpmn.client.marshall.converters.tostunner.properties.Scripts.LANGUAGE.MVEL; public class Scripts { public enum LANGUAGE { JAVA("java", "http://www.java.com/java"), - JAVASCRIPT("javascript", "http://www.javascript.com/javascript"), MVEL("mvel", "http://www.mvel.org/2.0"), DROOLS("drools", "http://www.jboss.org/drools/rule"), FEEL("feel", "http://www.omg.org/spec/FEEL/20140401"); @@ -116,19 +112,11 @@ public static String scriptLanguageToUri(String language, String defaultValue) { return defaultValue; } - if (JAVA.language().equals(language)) { - return JAVA.format(); - } else if (MVEL.language().equals(language)) { - return MVEL.format(); - } else if (JAVASCRIPT.language().equals(language)) { - return JAVASCRIPT.format(); - } else if (DROOLS.language().equals(language)) { - return DROOLS.format(); - } else if (FEEL.language().equals(language)) { - return FEEL.format(); - } else { - return defaultValue; - } + return Stream.of(LANGUAGE.values()) + .filter(lang -> lang.language().equals(language)) + .findFirst() + .map(LANGUAGE::format) + .orElse(defaultValue); } public static String scriptLanguageFromUri(String format) { @@ -140,19 +128,11 @@ public static String scriptLanguageFromUri(String format, String defaultValue) { return defaultValue; } - if (JAVA.format().equals(format)) { - return JAVA.language(); - } else if (MVEL.format().equals(format)) { - return MVEL.language(); - } else if (JAVASCRIPT.format().equals(format)) { - return JAVASCRIPT.language(); - } else if (DROOLS.format().equals(format)) { - return DROOLS.language(); - } else if (FEEL.format().equals(format)) { - return FEEL.language(); - } else { - return defaultValue; - } + return Stream.of(LANGUAGE.values()) + .filter(lang -> lang.format().equals(format)) + .findFirst() + .map(LANGUAGE::language) + .orElse(defaultValue); } public static ScriptTypeListValue onExit(List extensions) {