Skip to content

Commit

Permalink
Merge pull request #31 from TheJacksonLaboratory/bugfix/queries
Browse files Browse the repository at this point in the history
Bugfix/queries
  • Loading branch information
iimpulse authored Sep 25, 2024
2 parents f6a71da + 3e3c3f9 commit 8923412
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion oan-etl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jax.oan</groupId>
<artifactId>ontology-annotation-network</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
</parent>

<artifactId>oan-etl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion oan-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jax.oan</groupId>
<artifactId>ontology-annotation-network</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
</parent>

<artifactId>oan-model</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion oan-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jax.oan</groupId>
<artifactId>ontology-annotation-network</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
</parent>

<artifactId>oan-rest</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion oan-rest/src/main/java/org/jax/oan/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@OpenAPIDefinition(
info = @Info(
title = "ontology-annotation-network",
version = "1.0.7",
version = "1.0.9",
description = "A restful service for access to the ontology annotation network.",
contact = @Contact(name = "Michael Gargano", email = "[email protected]")
), servers = {@Server(url = "https://ontology.jax.org/api/network", description = "Production Server URL")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jax.oan.exception.OntologyAnnotationNetworkRuntimeException;
import org.jax.oan.service.DiseaseService;
import org.jax.oan.service.SearchService;
import org.jax.oan.utils.QueryCleaner;
import org.monarchinitiative.phenol.base.PhenolRuntimeException;
import org.monarchinitiative.phenol.ontology.data.TermId;

Expand Down Expand Up @@ -46,9 +47,9 @@ public HttpResponse<?> searchEntity(@Schema(minLength = 1, maxLength = 20, type
@QueryValue(value = "limit", defaultValue = "10") int limit) {

if (entity.equalsIgnoreCase("GENE")){
return HttpResponse.ok(this.searchService.searchGene(q.toUpperCase(), page, limit));
return HttpResponse.ok(this.searchService.searchGene(QueryCleaner.clean(q.toUpperCase()), page, limit));
} else if (entity.equalsIgnoreCase("DISEASE")){
return HttpResponse.ok(this.searchService.searchDisease(q.toUpperCase(), page, limit));
return HttpResponse.ok(this.searchService.searchDisease(QueryCleaner.clean(q.toUpperCase()), page, limit));
} else {
return HttpResponse.badRequest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public Optional<Disease> findDiseaseById(TermId termId){
}
return Optional.empty();
}
catch (Exception e){
return Optional.empty();
}
}

/**
Expand All @@ -57,6 +60,9 @@ public Collection<Disease> findDiseases(String query) {
diseases.add(disease);
}
}
catch (Exception e){
return Collections.emptyList();
}
return diseases.stream().sorted(Comparator.comparing((Disease d) -> !d.getName().toLowerCase()
.startsWith(query.toLowerCase()))).toList();
}
Expand All @@ -76,6 +82,9 @@ public Collection<Gene> findGenesByDisease(TermId termId) {
genes.add(gene);
}
}
catch (Exception e){
return Collections.emptyList();
}
return genes;
}

Expand All @@ -97,6 +106,9 @@ public Collection<PhenotypeExtended> findPhenotypesByDisease(TermId termId){
phenotypes.add(phenotype);
}
}
catch (Exception e){
return Collections.emptyList();
}
return phenotypes;
}

Expand Down Expand Up @@ -130,6 +142,9 @@ public Collection<MedicalActionTargetExtended> findMedicalActionsByDisease(TermI
actions.add(new MedicalActionTargetExtended(TermId.of(m.get("id").asString()), m.get("name").asString(), relations, targets ));
}
}
catch (Exception e){
return Collections.emptyList();
}
return actions;
}
}
15 changes: 10 additions & 5 deletions oan-rest/src/main/java/org/jax/oan/repository/GeneRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import org.neo4j.driver.Transaction;
import org.neo4j.driver.Value;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.*;

import static org.neo4j.driver.Values.parameters;

Expand Down Expand Up @@ -41,7 +38,10 @@ public Collection<Gene> findGenes(String query){
Gene gene = new Gene(TermId.of(value.get("id").asString()), value.get("name").asString());
genes.add(gene);
}
}
}
catch (Exception e){
return Collections.emptyList();
}
return genes.stream().sorted(Comparator.comparing((Gene g) -> !g.getName().toLowerCase()
.startsWith(query.toLowerCase()))).toList();
}
Expand All @@ -60,6 +60,8 @@ public Collection<Phenotype> findPhenotypesByGene(TermId termId){
Phenotype phenotype = new Phenotype(TermId.of(value.get("id").asString()), value.get("name").asString());
phenotypes.add(phenotype);
}
} catch (Exception e){
return Collections.emptyList();
}
return phenotypes;
}
Expand All @@ -80,6 +82,9 @@ public Collection<Disease> findDiseasesByGene(TermId termId) {
diseases.add(disease);
}
}
catch (Exception e){
return Collections.emptyList();
}
return diseases;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public Collection<Disease> findDiseasesByTerm(TermId termId){
diseases.add(disease);
}
}
catch (Exception e){
return Collections.emptyList();
}
return diseases;
}

Expand All @@ -56,6 +59,9 @@ public Collection<Gene> findGenesByTerm(TermId termId) {
genes.add(gene);
}
}
catch (Exception e){
return Collections.emptyList();
}
return genes;
}

Expand All @@ -75,6 +81,9 @@ public Collection<Assay> findAssaysByTerm(TermId termId){
assays.add(assay);
}
}
catch (Exception e){
return Collections.emptyList();
}
return assays;
}

Expand All @@ -101,6 +110,9 @@ public Collection<MedicalActionSourceExtended> findMedicalActionsByTerm(TermId t
medicalActions.add(new MedicalActionSourceExtended(TermId.of(subject.get("id").asString()), subject.get("name").asString(), relations, sources));
}
}
catch (Exception e){
return Collections.emptyList();
}
return medicalActions;
}
}
13 changes: 13 additions & 0 deletions oan-rest/src/main/java/org/jax/oan/utils/QueryCleaner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.jax.oan.utils;

public class QueryCleaner {

/**
* This method cleans the query string from any special characters
* @param query the query string
* @return the cleaned query string
*/
public static String clean(String query) {
return query.replaceAll("[^a-zA-Z0-9\\-:\\s]", "");
}
}
16 changes: 16 additions & 0 deletions oan-rest/src/test/java/org/jax/oan/utils/QueryCleanerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jax.oan.utils;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class QueryCleanerTest {

@Test
void clean() {
String query = "HP:0000001";
String badQuery = "HP:0000001!)";
assertEquals("HP:0000001", QueryCleaner.clean(query));
assertEquals("HP:0000001", QueryCleaner.clean(badQuery));
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.jax.oan</groupId>
<artifactId>ontology-annotation-network</artifactId>
<packaging>pom</packaging>
<version>1.0.8</version>
<version>1.0.9</version>

<name>ontology-annotation-network</name>
<url>https://github.com/TheJacksonLaboratory/ontology-annotation-network</url>
Expand Down

0 comments on commit 8923412

Please sign in to comment.