Commit 67b94844 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

invalid pubmed id could break clicking on elements or listing publications

parent 4c18ff64
......@@ -4,6 +4,8 @@ minerva (12.2.1) stable; urgency=medium
* Bug fix: removing active plugin didn't switch plugin tab to the next loaded
plugin (#757)
* Bug fix: closed submap will not be reopened after page refresh (#763)
* Bug fix: invalid pubmed identifier could break clicking on element
containing it (#764, #765, #769)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 1 Apr 2019 17:00:00 +0200
......
......@@ -19,6 +19,7 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
......@@ -116,11 +117,15 @@ public abstract class BaseRestImpl {
}
}
if (MiriamType.PUBMED.equals(annotation.getDataType())) {
try {
Article article = pubmedParser.getPubmedArticleById(annotation.getResource());
result.put("article", article);
} catch (PubmedSearchException e) {
logger.error("Problem with accessing info about pubmed", e);
if (NumberUtils.isDigits(annotation.getResource())) {
try {
Article article = pubmedParser.getPubmedArticleById(annotation.getResource());
result.put("article", article);
} catch (PubmedSearchException e) {
logger.error("Problem with accessing info about pubmed", e);
}
} else {
logger.error("Invalid pubmed identifier: " + annotation.getResource());
}
}
result.put("type", annotation.getDataType().name());
......
......@@ -20,10 +20,10 @@ import lcsb.mapviewer.model.map.MiriamType;
public class BaseRestImplTest extends RestTestFunctions {
Logger logger = Logger.getLogger(BaseRestImplTest.class);
@Autowired
MiriamConnector mc;
@Autowired
PubmedParser pubmedParser;
......@@ -44,7 +44,7 @@ public class BaseRestImplTest extends RestTestFunctions {
String presentationXml2 = controller.mathMLToPresentationML(content);
assertEquals(presentationXml, presentationXml2);
}
@Test
public void testMathMLToPresentationMLCalledTwiceShouldntHaveXmlNode() throws Exception {
BaseRestImpl controller = Mockito.mock(BaseRestImpl.class, CALLS_REAL_METHODS);
......@@ -52,16 +52,31 @@ public class BaseRestImplTest extends RestTestFunctions {
String presentationXml = controller.mathMLToPresentationML(content);
assertFalse(presentationXml.startsWith("<?xml"));
}
@Test
public void testCreateAnnotationWithWhitespace() throws Exception {
BaseRestImpl controller = Mockito.mock(BaseRestImpl.class, CALLS_REAL_METHODS);
controller.setMiriamConnector(mc);
controller.setPubmedParser(pubmedParser);
Map<String, Object> response = controller.createAnnotation(new MiriamData(MiriamType.PUBMED,"28255955 "));
Map<String, Object> response = controller.createAnnotation(new MiriamData(MiriamType.PUBMED, "28255955 "));
assertNotNull(response);
}
@Test
public void testCreateAnnotationWithNonNumericValues() throws Exception {
BaseRestImpl controller = Mockito.mock(BaseRestImpl.class, CALLS_REAL_METHODS);
controller.setMiriamConnector(mc);
controller.setPubmedParser(pubmedParser);
Map<String, Object> response = controller.createAnnotation(new MiriamData(MiriamType.PUBMED, "28255955PG"));
assertNotNull(response);
}
@Test
public void testCreateAnnotationWithEmptyValue() throws Exception {
BaseRestImpl controller = Mockito.mock(BaseRestImpl.class, CALLS_REAL_METHODS);
controller.setMiriamConnector(mc);
controller.setPubmedParser(pubmedParser);
Map<String, Object> response = controller.createAnnotation(new MiriamData(MiriamType.PUBMED, ""));
assertNotNull(response);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment