diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChEMBLParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChEMBLParser.java index cedc92718ece062d395c9a696998a9fa9f88fdc4..ea67d90cda469760a3f1b0961e3103efd8f65c80 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChEMBLParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChEMBLParser.java @@ -153,6 +153,9 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService { throw new InvalidArgumentException( "Target must be of a type: " + MiriamType.CHEMBL_TARGET + ". But found: " + md.getDataType()); } + if (md.getResource().isEmpty()) { + throw new InvalidArgumentException("Invalid target id" + md); + } try { Target target = new Target(); target.setSource(md); @@ -261,13 +264,13 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService { } /** - * REturns list of targes for given drug. + * Returns list of targets for given drug. * * @param drugId * identifier of a drug for which targets are looked * @throws DrugSearchException * thrown when there are problems with connection to ChEMBL database - * @return list of targes for given drug + * @return list of targets for given drug */ List<Target> getTargetsByDrugId(MiriamData drugId) throws DrugSearchException { if (!MiriamType.CHEMBL_COMPOUND.equals(drugId.getDataType())) { @@ -275,8 +278,8 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService { } List<Target> targets = new ArrayList<>(); try { - - String page = getWebPageContent(TARGET_MECHANISM_BY_DRUG_ID_API_URL + drugId.getResource()); + String url = TARGET_MECHANISM_BY_DRUG_ID_API_URL + drugId.getResource(); + String page = getWebPageContent(url); Document document = getXmlDocumentFromString(page); Node response = getNode("response", document); @@ -287,14 +290,17 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equalsIgnoreCase("mechanism")) { Node chemblTargetIdNode = getNode("target_chembl_id", node); - MiriamData targetMiriam = new MiriamData(MiriamType.CHEMBL_TARGET, chemblTargetIdNode.getTextContent()); + String chemblTargetId = chemblTargetIdNode.getTextContent(); + if (chemblTargetId != null && !chemblTargetId.isEmpty()) { + MiriamData targetMiriam = new MiriamData(MiriamType.CHEMBL_TARGET, chemblTargetId); - Target target = getTargetFromId(targetMiriam); - Node referenceNode = getNode("mechanism_refs", node); + Target target = getTargetFromId(targetMiriam); + Node referenceNode = getNode("mechanism_refs", node); - Set<MiriamData> references = parseReferences(referenceNode); - target.addReferences(references); - targets.add(target); + Set<MiriamData> references = parseReferences(referenceNode); + target.addReferences(references); + targets.add(target); + } } } } diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/drugs/DrugRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/drugs/DrugRestImplTest.java index 89e6026906bae288de75b8592cb26850ce9b6a03..515b299b95cb273d81bc33d98bb9f88d01452c4a 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/drugs/DrugRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/drugs/DrugRestImplTest.java @@ -53,6 +53,19 @@ public class DrugRestImplTest extends RestTestFunctions { throw e; } } + @Test + public void test() throws Exception { + try { + DrugRestImpl drugRestImpl = createMockProjectRest("testFiles/model/sample.xml"); + Map<String, Object> result = drugRestImpl.getDrugsByQuery(token, "sample", "", "Picato").get(0); + assertNotNull(result); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + private DrugRestImpl createMockProjectRest(String string) throws Exception { Model model = super.getModelForFile(string, true);