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

some drugs didn't have mechanism target defined

parent 8dbb8ec0
No related branches found
No related tags found
2 merge requests!541version 12.1.3 into master,!516Resolve "Searching for some drugs results in an internal server error"
......@@ -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);
}
}
}
}
......
......@@ -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);
......
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