Skip to content
Snippets Groups Projects
Commit afec2b06 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

mesh id with space caused exception to be thrown

parent 0e87bbaa
No related branches found
No related tags found
2 merge requests!541version 12.1.3 into master,!527Resolve "Unexpected error if MESH term is invalid"
...@@ -109,6 +109,9 @@ public class MeSHParser extends CachableInterface implements IExternalService { ...@@ -109,6 +109,9 @@ public class MeSHParser extends CachableInterface implements IExternalService {
if (meshID == null || meshID.getResource() == null) { if (meshID == null || meshID.getResource() == null) {
throw new InvalidArgumentException("mesh cannot be null "); throw new InvalidArgumentException("mesh cannot be null ");
} }
if (meshID.getResource().indexOf(" ") >= 0) {
return null;
}
MeSH mesh = null; MeSH mesh = null;
// look for Mesh in the cache // look for Mesh in the cache
...@@ -321,7 +324,7 @@ public class MeSHParser extends CachableInterface implements IExternalService { ...@@ -321,7 +324,7 @@ public class MeSHParser extends CachableInterface implements IExternalService {
ArrayList<?> hitsList = (ArrayList<?>) hits.get("hits"); ArrayList<?> hitsList = (ArrayList<?>) hits.get("hits");
for (Object object : hitsList) { for (Object object : hitsList) {
StringMap<?> hit = (StringMap<?>) object; StringMap<?> hit = (StringMap<?>) object;
String id = (String) hit.get("_id"); String id = (String) hit.get("_id");
result.add(new MiriamData(MiriamType.MESH_2012, id)); result.add(new MiriamData(MiriamType.MESH_2012, id));
} }
return result; return result;
......
...@@ -118,6 +118,18 @@ public class MeSHParserTest extends AnnotationTestFunctions { ...@@ -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 @Test
public void testGetInvalidMesh() throws Exception { public void testGetInvalidMesh() throws Exception {
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment