Skip to content

Commit

Permalink
[incubator-kie-issues#733] Remove JavaScript language option from Scr…
Browse files Browse the repository at this point in the history
…ipt Editor in BPMN Editor
  • Loading branch information
pefernan committed Dec 24, 2024
1 parent c59b389 commit a64edf0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,20 @@ 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";
static final String TITLE_DROOLS = "DROOLS";
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,
TITLE_JAVA,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ private static List<MonacoEditorLanguage> 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);
Expand All @@ -140,7 +139,6 @@ private static List<MonacoEditorLanguage> 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);
Expand All @@ -159,6 +157,7 @@ protected void onChange() {
true);
value.setScript(view.getValue());
value.setLanguage(view.getLanguageId());

notifyChange(oldValue,
value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ 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));
}

@Test
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));
Expand All @@ -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));
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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<ExtensionAttributeValue> extensions) {
Expand Down

0 comments on commit a64edf0

Please sign in to comment.