From 9e309e1f27a3ca3c10579d6213fc50dacdd73730 Mon Sep 17 00:00:00 2001 From: Cory Nathe Date: Fri, 19 Jan 2024 13:53:03 -0600 Subject: [PATCH 1/4] Fix for getContainerDataTypeExclusions() to handle case when container has already been deleted (#5144) - if we can't get the GUID for a container from the container path, return an empty results set --- .../experiment/api/ExperimentServiceImpl.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java b/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java index e64a820f563..4026b3ea3ee 100644 --- a/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java +++ b/experiment/src/org/labkey/experiment/api/ExperimentServiceImpl.java @@ -8564,7 +8564,7 @@ private void removeDataTypeExclusion(Collection rowIds, DataTypeForExcl new SqlExecutor(getExpSchema()).execute(sql); } - @NotNull private Map[] _getContainerDataTypeExclusions(@Nullable DataTypeForExclusion dataType, @Nullable String excludedContainerIdOrPath, @Nullable Integer dataTypeRowId) + @NotNull private List> _getContainerDataTypeExclusions(@Nullable DataTypeForExclusion dataType, @Nullable String excludedContainerIdOrPath, @Nullable Integer dataTypeRowId) { SQLFragment sql = new SQLFragment("SELECT DataTypeRowId, DataType, ExcludedContainer FROM ") .append(getTinfoDataTypeExclusion()) @@ -8583,8 +8583,13 @@ private void removeDataTypeExclusion(Collection rowIds, DataTypeForExcl if (!GUID.isGUID(excludedContainerIdOrPath)) { Container container = ContainerManager.getForPath(excludedContainerIdOrPath); - if (container != null) - excludedContainerId = container.getId(); + if (container == null) + { + // container not found, it may have been deleted, return empty array instead of making the DB query + return Collections.emptyList(); + } + + excludedContainerId = container.getId(); } sql.append(and); @@ -8600,13 +8605,13 @@ private void removeDataTypeExclusion(Collection rowIds, DataTypeForExcl sql.add(dataTypeRowId); } - return new SqlSelector(getTinfoDataTypeExclusion().getSchema(), sql).getMapArray(); + return Arrays.stream(new SqlSelector(getTinfoDataTypeExclusion().getSchema(), sql).getMapArray()).toList(); } @Override public @NotNull Map> getContainerDataTypeExclusions(@NotNull String excludedContainerId) { - Map[] exclusions = _getContainerDataTypeExclusions(null, excludedContainerId, null); + List> exclusions = _getContainerDataTypeExclusions(null, excludedContainerId, null); Map> typeExclusions = new HashMap<>(); for (Map exclusion : exclusions) @@ -8624,7 +8629,7 @@ private void removeDataTypeExclusion(Collection rowIds, DataTypeForExcl @Override public Set getDataTypeContainerExclusions(@NotNull DataTypeForExclusion dataType, @NotNull Integer dataTypeRowId) { - Map[] exclusions = _getContainerDataTypeExclusions(dataType, null, dataTypeRowId); + List> exclusions = _getContainerDataTypeExclusions(dataType, null, dataTypeRowId); Set excludedProjects = new HashSet<>(); for (Map exclusion : exclusions) excludedProjects.add((String) exclusion.get("ExcludedContainer")); @@ -8635,7 +8640,7 @@ public Set getDataTypeContainerExclusions(@NotNull DataTypeForExclusion private Set _getContainerDataTypeExclusions(DataTypeForExclusion dataType, String excludedContainerId) { Set excludedRowIds = new HashSet<>(); - Map[] exclusions = _getContainerDataTypeExclusions(dataType, excludedContainerId, null); + List> exclusions = _getContainerDataTypeExclusions(dataType, excludedContainerId, null); for (Map exclusion : exclusions) excludedRowIds.add((Integer) exclusion.get("DataTypeRowId")); From 02b5efecd39dd2bbce26bec487a82ecc29396074 Mon Sep 17 00:00:00 2001 From: labkey-matthewb Date: Fri, 19 Jan 2024 12:04:14 -0800 Subject: [PATCH 2/4] update expected behavior of new ObjectMapper().writeValueAsString() (#5146) --- api/src/org/labkey/api/util/JsonUtil.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/src/org/labkey/api/util/JsonUtil.java b/api/src/org/labkey/api/util/JsonUtil.java index 587c1cc2a85..0da6c5993b9 100644 --- a/api/src/org/labkey/api/util/JsonUtil.java +++ b/api/src/org/labkey/api/util/JsonUtil.java @@ -561,7 +561,10 @@ public void testJavascript() throws Exception { // just verifying current behavior: JSONObject escapes /, ObjectMapper does not escape / assertEquals("{\"key<\\/\":\"<\\/script>\"}", new JSONObject(Map.of("key")).toString()); - assertEquals("{\"key\"}", new ObjectMapper().writeValueAsString(Map.of("key"))); + // This is the default ObjectMapper behavior + //assertEquals("{\"key\"}", new ObjectMapper().writeValueAsString(Map.of("key"))); + // This is the "hacked" ObjectMapper behavior see the fix-up code in CoreModule static + assertEquals("{\"key<\\/\":\"<\\/script>\"}", new ObjectMapper().writeValueAsString(Map.of("key"))); // our ObjectMapper should act like JSONObject.toString() assertEquals("{\"key<\\/\":\"<\\/script>\"}", DEFAULT_MAPPER.writeValueAsString(Map.of("key"))); From 7ac77bffce67fbb921c24a3c01ac0277be77b9a4 Mon Sep 17 00:00:00 2001 From: Cory Nathe Date: Mon, 22 Jan 2024 11:55:34 -0600 Subject: [PATCH 3/4] Issue 49447: HTMLDataLoader isHeaderMatch() to catch DOMException for JSoupUtil.convertHtmlToDocument (#5148) --- .../org/labkey/api/reader/HTMLDataLoader.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api/src/org/labkey/api/reader/HTMLDataLoader.java b/api/src/org/labkey/api/reader/HTMLDataLoader.java index a792aa627e7..68538f9285c 100644 --- a/api/src/org/labkey/api/reader/HTMLDataLoader.java +++ b/api/src/org/labkey/api/reader/HTMLDataLoader.java @@ -21,6 +21,7 @@ import org.labkey.api.util.FileType; import org.labkey.api.util.StringUtilsLabKey; import org.labkey.api.util.JSoupUtil; +import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -82,12 +83,19 @@ public boolean isHeaderMatch(@NotNull byte[] header) String s = new String(header, StringUtilsLabKey.DEFAULT_CHARSET); List errors = new ArrayList<>(); - Document doc = JSoupUtil.convertHtmlToDocument(s, true, errors); - if (!errors.isEmpty() || doc == null) - return false; + try + { + Document doc = JSoupUtil.convertHtmlToDocument(s, true, errors); + if (!errors.isEmpty() || doc == null) + return false; - // Look for a html>body>table element - return findTable(doc) != null; + // Look for a html>body>table element + return findTable(doc) != null; + } + catch (DOMException e) + { + return false; + } } }; From 392bf2969ac14723b73e385fe89746bb622363ef Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Mon, 22 Jan 2024 23:19:22 -0500 Subject: [PATCH 4/4] Upgrade to latest GraalJS version (#5153) --- core/build.gradle | 15 +-------------- .../labkey/core/wiki/MarkdownServiceImpl.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index ed2bbf7802a..ea43a91ed67 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -47,20 +47,7 @@ dependencies { BuildUtils.addExternalDependency( project, new ExternalDependency( - "org.graalvm.sdk:graal-sdk:${graalVersion}", - "GraalJS", - "GraalJS", - "https://github.com/graalvm/graaljs", - "Universal Permissive License", - "https://github.com/graalvm/graaljs/blob/master/LICENSE", - "Server-side JavaScript evaluation" - ) - ) - - BuildUtils.addExternalDependency( - project, - new ExternalDependency( - "org.graalvm.js:js:${graalVersion}", + "org.graalvm.polyglot:js-community:${graalVersion}", "GraalJS", "GraalJS", "https://github.com/graalvm/graaljs", diff --git a/core/src/org/labkey/core/wiki/MarkdownServiceImpl.java b/core/src/org/labkey/core/wiki/MarkdownServiceImpl.java index 18f3711bc80..2197c25a495 100644 --- a/core/src/org/labkey/core/wiki/MarkdownServiceImpl.java +++ b/core/src/org/labkey/core/wiki/MarkdownServiceImpl.java @@ -50,9 +50,18 @@ public class MarkdownServiceImpl implements MarkdownService private static class PoolFactory implements KeyedPoolableObjectFactory, MarkdownInvocable> { - public static final String POLYGLOT_ENGINE_WARN_INTERPRETER_ONLY = "polyglot.engine.WarnInterpreterOnly"; + static + { + // Issue 47679 - suppress stdout logging from GraalJS about compilation mode, due to significant difficulties + // in getting the VM configured to use compilation mode + if (System.getProperty(POLYGLOT_ENGINE_WARN_INTERPRETER_ONLY) == null) + { + System.setProperty(POLYGLOT_ENGINE_WARN_INTERPRETER_ONLY, "false"); + } + } + @Override public MarkdownInvocable makeObject(Map options) throws Exception { @@ -61,13 +70,6 @@ public MarkdownInvocable makeObject(Map options) throws Except if (null == svc) throw new ConfigurationException("LabKeyScriptEngineManager service not found."); - // Issue 47679 - suppress stdout logging from Graal about compilation mode, due to significant difficulties - // in getting the VM configured to use compilation mode - if (System.getProperty(POLYGLOT_ENGINE_WARN_INTERPRETER_ONLY) == null) - { - System.setProperty(POLYGLOT_ENGINE_WARN_INTERPRETER_ONLY, "false"); - } - ScriptEngine engine = svc.getEngineByName("graal.js"); if (null == engine) throw new ConfigurationException("Graal.js engine not found");