Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 api inconsistencies #712

Merged
merged 15 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.spot.ols.repository.Validation;
import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient;
import uk.ac.ebi.spot.ols.repository.solr.OlsSolrClient;
import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform;
import uk.ac.ebi.spot.ols.repository.transforms.RemoveLiteralDatatypesTransform;
Expand Down Expand Up @@ -92,8 +91,10 @@ public void search(
String[] fields = {"label_s", "synonym_s", "short_form_s", "obo_id_s", "iri_s", "annotations_trimmed"};
solrQuery.setQuery(
"((" +
createUnionQuery(query.toLowerCase(), SolrFieldMapper.mapFieldsList(List.of(fields)).toArray(new String[0]), true)
+ ") AND (isDefiningOntology:\"true\"^100 OR isDefiningOntology:false^0))"
createUnionQuery(query.toLowerCase(), SolrFieldMapper.mapFieldsList(List.of(fields))
.toArray(new String[0]), true)
+ ") AND ("+ IS_DEFINING_ONTOLOGY.getText() + ":\"true\"^100 OR " +
IS_DEFINING_ONTOLOGY.getText() + ":false^0))"
);

} else {
Expand All @@ -106,13 +107,14 @@ public void search(
solrQuery.set("qf", String.join(" ", SolrFieldMapper.mapFieldsList(List.of(fields))));

solrQuery.set("bq",
"isDefiningOntology:\"true\"^100 " +
IS_DEFINING_ONTOLOGY.getText() + ":\"true\"^100 " +
"lowercase_label:\"" + query.toLowerCase() + "\"^5 " +
"lowercase_synonym:\"" + query.toLowerCase() + "\"^3");
}
} else {
if (exact) {
String[] fields = SolrFieldMapper.mapFieldsList(queryFields.stream().map(queryField -> queryField + "_s").collect(Collectors.toList())).toArray(new String[0]);
String[] fields = SolrFieldMapper.mapFieldsList(queryFields.stream().map(queryField -> queryField + "_s")
.collect(Collectors.toList())).toArray(new String[0]);
solrQuery.setQuery(createUnionQuery(query.toLowerCase(), fields, true));
} else {

Expand Down Expand Up @@ -140,7 +142,7 @@ public void search(
}

if (isLocal) {
solrQuery.addFilterQuery("imported:false");
solrQuery.addFilterQuery(IMPORTED.getText() + ":false");
}

if (isLeaf) {
Expand Down Expand Up @@ -207,7 +209,7 @@ public void search(
"ontologyIri",
"ontologyPreferredPrefix",
"type",
"isDefiningOntology",
IS_DEFINING_ONTOLOGY.getText(),
IS_OBSOLETE.getText());
/*
* Fix: End
Expand Down Expand Up @@ -259,8 +261,9 @@ public void search(
if (fieldList.contains("description")) outDoc.put("description", JsonHelper.getStrings(json, "definition"));
if (fieldList.contains("short_form")) outDoc.put("short_form", JsonHelper.getString(json, "shortForm"));
if (fieldList.contains("obo_id")) outDoc.put("obo_id", JsonHelper.getString(json, "curie"));
if (fieldList.contains("is_defining_ontology")) outDoc.put("is_defining_ontology",
JsonHelper.getString(json, "isDefiningOntology") != null && JsonHelper.getString(json, "isDefiningOntology").equals("true"));
if (fieldList.contains(IS_DEFINING_ONTOLOGY.getOls3Text())) outDoc.put(IS_DEFINING_ONTOLOGY.getOls3Text(),
JsonHelper.getString(json, IS_DEFINING_ONTOLOGY.getText()) != null &&
JsonHelper.getString(json, IS_DEFINING_ONTOLOGY.getText()).equals("true"));
if (fieldList.contains("type")) {
outDoc.put("type", JsonHelper.getType(json, "type"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.spot.ols.repository.Validation;
import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient;
import uk.ac.ebi.spot.ols.repository.solr.OlsSolrClient;
import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform;
import uk.ac.ebi.spot.ols.repository.transforms.RemoveLiteralDatatypesTransform;
Expand Down Expand Up @@ -72,7 +71,9 @@ public void select(
solrQuery.setQuery(query);
solrQuery.set("defType", "edismax");
solrQuery.set("qf", "label whitespace_edge_label synonym whitespace_edge_synonym shortForm whitespace_edge_shortForm curie iri");
solrQuery.set("bq", "type:ontology^10.0 isDefiningOntology:true^100.0 str_label:\"" + queryLc + "\"^1000 edge_label:\"" + queryLc + "\"^500 str_synonym:\"" + queryLc + "\" edge_synonym:\"" + queryLc + "\"^100");
solrQuery.set("bq", "type:ontology^10.0 " +
IS_DEFINING_ONTOLOGY.getText() +":true^100.0 str_label:\"" + queryLc + "\"^1000 edge_label:\"" +
queryLc + "\"^500 str_synonym:\"" + queryLc + "\" edge_synonym:\"" + queryLc + "\"^100");
solrQuery.set("wt", "json");

solrQuery.setFields("_json", "id");
Expand All @@ -94,7 +95,7 @@ public void select(
}

if (isLocal) {
solrQuery.addFilterQuery("isDefiningOntology:true");
solrQuery.addFilterQuery(IS_DEFINING_ONTOLOGY.getText() + ":true");
}

if (childrenOf != null) {
Expand Down Expand Up @@ -163,8 +164,9 @@ public void select(
if (fieldList.contains("description")) outDoc.put("description", JsonHelper.getStrings(json, "definition"));
if (fieldList.contains("short_form")) outDoc.put("short_form", JsonHelper.getString(json, "shortForm"));
if (fieldList.contains("obo_id")) outDoc.put("obo_id", JsonHelper.getString(json, "curie"));
if (fieldList.contains("is_defining_ontology")) outDoc.put("is_defining_ontology",
JsonHelper.getString(json, "isDefiningOntology") != null && JsonHelper.getString(json, "isDefiningOntology").equals("true"));
if (fieldList.contains(IS_DEFINING_ONTOLOGY.getOls3Text())) outDoc.put(IS_DEFINING_ONTOLOGY.getOls3Text(),
JsonHelper.getString(json, IS_DEFINING_ONTOLOGY.getText()) != null &&
JsonHelper.getString(json, IS_DEFINING_ONTOLOGY.getText()).equals("true"));
if (fieldList.contains("type")) {
outDoc.put("type", JsonHelper.getType(json, "type"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ public HttpEntity<V2Entity> getIndividual(
}


// The instances of classes are individuals. So, the /instances endpoint is part of the Class controller.
//
@RequestMapping(path = "/ontologies/{onto}/classes/{class}/instances", produces = {MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.GET)
public HttpEntity<V2PagedResponse<V2Entity>> getClassInstances(
@RequestMapping(path = "/ontologies/{onto}/classes/{class}/individuals", produces = {MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.GET)
public HttpEntity<V2PagedResponse<V2Entity>> getClassIndividuals(
@PageableDefault(size = 20, page = 0) Pageable pageable,
@PathVariable("onto") String ontologyId,
@PathVariable("class") String classIri,
Expand All @@ -115,7 +113,7 @@ public HttpEntity<V2PagedResponse<V2Entity>> getClassInstances(

return new ResponseEntity<>(
new V2PagedResponse<>(
individualRepository.getInstancesOfClass(ontologyId, classIri, pageable, lang)
individualRepository.getIndividualsOfClass(ontologyId, classIri, pageable, lang)
),
HttpStatus.OK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static String getString(JsonObject json, String key) {
return objectToString(json.get(key));
}

public static boolean getBoolean(JsonObject json, String key) {
return json.getAsJsonPrimitive(key).getAsBoolean();
}

public static String objectToString(JsonElement value) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
import static uk.ac.ebi.ols.shared.DefinedFields.*;

public class V1AncestorsJsTreeBuilder {

Expand Down Expand Up @@ -90,8 +91,8 @@ private void createJsTreeEntries(List<Map<String,Object>> jstree, JsonObject ent
boolean opened = (!selected);


boolean hasDirectChildren = Objects.equals(JsonHelper.getString(entity, "hasDirectChildren"), "true");
boolean hasHierarchicalChildren = Objects.equals(JsonHelper.getString(entity, "hasHierarchicalChildren"), "true");
boolean hasDirectChildren = Objects.equals(JsonHelper.getString(entity, HAS_DIRECT_CHILDREN.getText()), "true");
boolean hasHierarchicalChildren = Objects.equals(JsonHelper.getString(entity, HAS_DIRECT_CHILDREN.getText()), "true");

// only nodes that aren't already opened are marked as having children, (iff they actually have children!)
boolean children = (!opened) && (hasDirectChildren || hasHierarchicalChildren);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.nio.charset.StandardCharsets;
import java.util.*;
import static uk.ac.ebi.ols.shared.DefinedFields.*;

public class V1ChildrenJsTreeBuilder {

Expand Down Expand Up @@ -34,7 +35,7 @@ List<Map<String,Object>> buildJsTree() {
jstreeEntry.put("text", JsonHelper.getString(child.getAsJsonObject(), "label"));
jstreeEntry.put("state", Map.of("opened", false));
jstreeEntry.put("children",
JsonHelper.getString(child.getAsJsonObject(), "hasDirectChildren").equals("true")
JsonHelper.getString(child.getAsJsonObject(), HAS_DIRECT_CHILDREN.getText()).equals("true")
|| JsonHelper.getString(child.getAsJsonObject(), "hasHierarchicalChildren").equals("true")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.ac.ebi.spot.ols.repository.solr.OlsFacetedResultsPage;
import uk.ac.ebi.spot.ols.repository.v1.mappers.V1IndividualMapper;
import uk.ac.ebi.spot.ols.repository.v1.mappers.V1TermMapper;
import static uk.ac.ebi.ols.shared.DefinedFields.*;

//@RepositoryRestResource(collectionResourceRel = "individuals", exported = false)
@Component
Expand Down Expand Up @@ -116,7 +117,7 @@ public OlsFacetedResultsPage<V1Individual> findAllByIsDefiningOntology(String la

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("individual"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);

OlsFacetedResultsPage<JsonElement> entities = solrClient.searchSolrPaginated(query, pageable);

Expand Down Expand Up @@ -145,7 +146,7 @@ public OlsFacetedResultsPage<V1Individual> findAllByIriAndIsDefiningOntology(Str

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("individual"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter("iri", List.of(iri), SearchType.WHOLE_FIELD);

OlsFacetedResultsPage<JsonElement> entities = solrClient.searchSolrPaginated(query, pageable);
Expand Down Expand Up @@ -176,7 +177,7 @@ public OlsFacetedResultsPage<V1Individual> findAllByShortFormAndIsDefiningOntolo

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("individual"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter("shortForm", List.of(shortForm), SearchType.WHOLE_FIELD);

OlsFacetedResultsPage<JsonElement> entities = solrClient.searchSolrPaginated(query, pageable);
Expand Down Expand Up @@ -204,7 +205,7 @@ public OlsFacetedResultsPage<V1Individual> findAllByOboIdAndIsDefiningOntology(S

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("individual"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter("oboId", List.of(oboId), SearchType.WHOLE_FIELD);

OlsFacetedResultsPage<JsonElement> entities = solrClient.searchSolrPaginated(query, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public Page<V1Property> getRoots(String ontologyId, boolean obsolete, String lan
OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("property"), SearchType.WHOLE_FIELD);
query.addFilter("ontologyId", List.of(ontologyId), SearchType.WHOLE_FIELD);
query.addFilter("hasDirectParent", List.of("false"), SearchType.WHOLE_FIELD);
query.addFilter("hasHierarchicalParent", List.of("false"), SearchType.WHOLE_FIELD);
query.addFilter(HAS_DIRECT_PARENTS.getText(), List.of("false"), SearchType.WHOLE_FIELD);
query.addFilter(HAS_HIERARCHICAL_PARENTS.getText(), List.of("false"), SearchType.WHOLE_FIELD);

if(!obsolete)
query.addFilter(IS_OBSOLETE.getText(), List.of("false"), SearchType.WHOLE_FIELD);
Expand All @@ -119,7 +119,7 @@ public Page<V1Property> findAllByIsDefiningOntology(String lang, Pageable pageab

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("property"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
.map(result -> V1PropertyMapper.mapProperty(result, lang));
Expand All @@ -141,7 +141,7 @@ public Page<V1Property> findAllByIriAndIsDefiningOntology(String iri, String lan
OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("property"), SearchType.WHOLE_FIELD);
query.addFilter("iri", List.of(iri), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
.map(result -> V1PropertyMapper.mapProperty(result, lang));
Expand All @@ -163,7 +163,7 @@ public Page<V1Property> findAllByShortFormAndIsDefiningOntology(String shortForm
OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("property"), SearchType.WHOLE_FIELD);
query.addFilter("shortForm", List.of(shortForm), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
.map(result -> V1PropertyMapper.mapProperty(result, lang));
Expand All @@ -186,7 +186,7 @@ public Page<V1Property> findAllByOboIdAndIsDefiningOntology(String oboId, String
OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("property"), SearchType.WHOLE_FIELD);
query.addFilter("oboId", List.of(oboId), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
.map(result -> V1PropertyMapper.mapProperty(result, lang));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public Page<V1Term> getRoots(String ontologyId, boolean obsolete, String lang, P
OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("class"), SearchType.WHOLE_FIELD);
query.addFilter("ontologyId", List.of(ontologyId), SearchType.WHOLE_FIELD);
query.addFilter("hasDirectParent", List.of("false"), SearchType.WHOLE_FIELD);
query.addFilter("hasHierarchicalParent", List.of("false"), SearchType.WHOLE_FIELD);
query.addFilter(HAS_DIRECT_PARENTS.getText(), List.of("false"), SearchType.WHOLE_FIELD);
query.addFilter(HAS_HIERARCHICAL_PARENTS.getText(), List.of("false"), SearchType.WHOLE_FIELD);

if (!obsolete)
query.addFilter(IS_OBSOLETE.getText(), List.of("false"), SearchType.WHOLE_FIELD);
Expand Down Expand Up @@ -215,7 +215,7 @@ public Page<V1Term> findAllByIsDefiningOntology(String lang, Pageable pageable)

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("class"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
.map(result -> V1TermMapper.mapTerm(result, lang));
Expand All @@ -236,7 +236,7 @@ public Page<V1Term> findAllByIriAndIsDefiningOntology(String iri, String lang, P

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("class"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter("iri", List.of(iri), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
Expand All @@ -257,7 +257,7 @@ public Page<V1Term> findAllByShortFormAndIsDefiningOntology(String shortForm, St

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("class"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter("shortForm", List.of(shortForm), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
Expand All @@ -279,7 +279,7 @@ public Page<V1Term> findAllByOboIdAndIsDefiningOntology(String oboId, String lan

OlsSolrQuery query = new OlsSolrQuery();
query.addFilter("type", List.of("class"), SearchType.WHOLE_FIELD);
query.addFilter("isDefiningOntology", List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter(IS_DEFINING_ONTOLOGY.getText(), List.of("true"), SearchType.WHOLE_FIELD);
query.addFilter("curie", List.of(oboId), SearchType.WHOLE_FIELD);

return solrClient.searchSolrPaginated(query, pageable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import java.util.Objects;

import static uk.ac.ebi.ols.shared.DefinedFields.*;

public class V1PropertyMapper {

public static V1Property mapProperty(JsonElement json, String lang) {
Expand All @@ -34,12 +36,12 @@ public static V1Property mapProperty(JsonElement json, String lang) {
property.shortForm = JsonHelper.getString(localizedJson, "shortForm");
property.oboId = property.shortForm.replace("_", ":");

property.hasChildren = Boolean.parseBoolean(JsonHelper.getString(localizedJson, "hasDirectChildren"))
|| Boolean.parseBoolean(JsonHelper.getString(localizedJson, "hasHierarchicalChildren"));
property.hasChildren = Boolean.parseBoolean(JsonHelper.getString(localizedJson, HAS_DIRECT_CHILDREN.getText()))
|| Boolean.parseBoolean(JsonHelper.getString(localizedJson, HAS_DIRECT_CHILDREN.getText()));

property.isRoot = !(
Boolean.parseBoolean(JsonHelper.getString(localizedJson, "hasDirectParent")) ||
Boolean.parseBoolean(JsonHelper.getString(localizedJson, "hasHierarchicalParent"))
JsonHelper.getBoolean(localizedJson, HAS_DIRECT_PARENTS.getText()) ||
JsonHelper.getBoolean(localizedJson, HAS_HIERARCHICAL_PARENTS.getText())
);

return property;
Expand Down
Loading
Loading