Commit 88282e74 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1140-corrupted-drug-db' into 'devel_14.0.x'

when there is problem with deserialization carry on without throwing error

See merge request !1072
parents 2fcf69ec 213fe61b
......@@ -23,8 +23,9 @@ minerva (14.0.9) stable; urgency=medium
* Bug fix: reaction without product in SBGN crashed upload of map
* Bug fix: when SBGN production pointed directly to process instead of
process port upload crashed
* Bug fix: handle properly corrupted cached chembl drug data (#1140)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 3 Feb 2020 15:00:00 +0200
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 25 Feb 2020 15:00:00 +0200
minerva (14.0.8) stable; urgency=medium
* Bug fix: API didn't allow to upload pluins with local url (#1084,
......
......@@ -4,6 +4,7 @@ import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import org.apache.commons.lang3.SerializationException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -319,9 +320,13 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
String query = NAME_PREFIX + name.toLowerCase().trim();
Drug drug = getDrugSerializer().xmlToObject(getCacheNode(query));
if (drug != null) {
return drug;
try {
Drug drug = getDrugSerializer().xmlToObject(getCacheNode(query));
if (drug != null) {
return drug;
}
} catch (SerializationException e) {
logger.error(e, e);
}
try {
......@@ -331,13 +336,13 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
Document document = XmlParser.getXmlDocumentFromString(page);
List<Drug> drugs = extractDrugsFromDocument(document);
if (drugs.size()==0) {
if (drugs.size() == 0) {
accessUrl = DRUG_SYNONYM_API_URL + name;
page = getWebPageContent(accessUrl);
document = XmlParser.getXmlDocumentFromString(page);
drugs = extractDrugsFromDocument(document);
}
if (drugs.size()>1) {
if (drugs.size() > 1) {
logger.warn("More drugs than one found for query: " + query);
}
......
......@@ -7,10 +7,13 @@ import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.*;
import org.apache.commons.lang3.SerializationException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.Node;
......@@ -889,4 +892,22 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
}
}
@Test
public void testFindDrugWhenSerializerFails() throws Exception {
ChEMBLParser parser = Mockito.spy(chemblParser);
when(parser.getDrugSerializer()).then(new Answer<XmlSerializer<Drug>>() {
@Override
public XmlSerializer<Drug> answer(InvocationOnMock invocation) throws Throwable {
@SuppressWarnings("unchecked")
XmlSerializer<Drug> serializer = Mockito.mock(XmlSerializer.class);
when(serializer.xmlToObject(any())).thenThrow(new SerializationException());
return serializer;
}
});
assertNotNull(parser.findDrug("CABOZANTINIB"));
}
}
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