Commit 90ea66c5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when ctdbase provides invalid mesh data don't crash

parent 095fafa4
......@@ -127,8 +127,12 @@ public class ChemicalRestImpl extends BaseRestImpl {
try {
MeSH mesh = meSHParser.getMeSH(chemical.getChemicalId());
description = mesh.getDescription();
synonyms = mesh.getSynonyms();
if (mesh != null) {
description = mesh.getDescription();
synonyms = mesh.getSynonyms();
} else {
logger.warn("Mesh used by chemical is invalid: " + chemical.getChemicalId());
}
} catch (AnnotatorException e) {
logger.error("Problem with accessing mesh database", e);
}
......
......@@ -21,13 +21,18 @@ import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.search.db.DbSearchCriteria;
import lcsb.mapviewer.services.search.db.chemical.IChemicalService;
public class ChemicalRestImplTest extends RestTestFunctions {
Logger logger = Logger.getLogger(ChemicalRestImplTest.class);
@Autowired
@Autowired
private ChemicalRestImpl _drugRestImpl;
private ChemicalRestImpl _drugRestImpl;
@Autowired
private IChemicalService chemicalService;
@AfterClass
public static void tearDownAfterClass() throws Exception {
......@@ -41,18 +46,30 @@ public class ChemicalRestImplTest extends RestTestFunctions {
public void tearDown() throws Exception {
}
@Test
public void testPrepareChemical() throws Exception {
try {
Chemical chemical = new Chemical();
chemical.setChemicalId(new MiriamData(MiriamType.MESH_2012, "D010300"));
Map<String, Object> result = _drugRestImpl.prepareChemical(chemical, _drugRestImpl.createChemicalColumnSet(""), new ArrayList<>());
assertNotNull(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testPrepareChemical() throws Exception {
try {
Chemical chemical = new Chemical();
chemical.setChemicalId(new MiriamData(MiriamType.MESH_2012, "D010300"));
Map<String, Object> result = _drugRestImpl.prepareChemical(chemical, _drugRestImpl.createChemicalColumnSet(""), new ArrayList<>());
assertNotNull(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testPrepareChemicalWithProblematicMesh() throws Exception {
try {
Chemical chemical = chemicalService.getByName("Tetrachlorodibenzodioxin", new DbSearchCriteria().disease(new MiriamData(MiriamType.MESH_2012, "D010300")));
Map<String, Object> result = _drugRestImpl.prepareChemical(chemical, _drugRestImpl.createChemicalColumnSet(""), new ArrayList<>());
assertNotNull(result);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
protected ChemicalRestImpl createMockChemicalRest(String string) throws Exception {
Model model = super.getModelForFile(string, true);
......
Supports Markdown
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