From afec2b06d7d13a5ea4e2898cfd4d1987cdeafbb6 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 14 Dec 2018 11:53:02 +0100 Subject: [PATCH] mesh id with space caused exception to be thrown --- .../mapviewer/annotation/services/MeSHParser.java | 5 ++++- .../annotation/services/MeSHParserTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java index 84d2a47962..e7882624e9 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/MeSHParser.java @@ -109,6 +109,9 @@ public class MeSHParser extends CachableInterface implements IExternalService { if (meshID == null || meshID.getResource() == null) { throw new InvalidArgumentException("mesh cannot be null "); } + if (meshID.getResource().indexOf(" ") >= 0) { + return null; + } MeSH mesh = null; // look for Mesh in the cache @@ -321,7 +324,7 @@ public class MeSHParser extends CachableInterface implements IExternalService { ArrayList<?> hitsList = (ArrayList<?>) hits.get("hits"); for (Object object : hitsList) { StringMap<?> hit = (StringMap<?>) object; - String id = (String) hit.get("_id"); + String id = (String) hit.get("_id"); result.add(new MiriamData(MiriamType.MESH_2012, id)); } return result; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/MeSHParserTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/MeSHParserTest.java index 8fb197d385..720bc0ebfc 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/MeSHParserTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/MeSHParserTest.java @@ -118,6 +118,18 @@ public class MeSHParserTest extends AnnotationTestFunctions { } } + @Test + public void testIsValidWithSpace() throws Exception { + try { + MiriamData meshID = new MiriamData(MiriamType.MESH_2012, "some disease"); + assertFalse(meshParser.isValidMeshId(meshID)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testGetInvalidMesh() throws Exception { try { -- GitLab