Skip to content

Commit

Permalink
Merge pull request #51 from EliotRagueneau/master
Browse files Browse the repository at this point in the history
Use OLS4
  • Loading branch information
ypriverol authored Oct 6, 2023
2 parents f2b574e + a210c84 commit d123103
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 198 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.22.RELEASE</version>
<version>5.3.29</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.2.22.RELEASE</version>
<version>5.3.29</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import uk.ac.ebi.pride.utilities.ols.web.service.model.Identifier;
import uk.ac.ebi.pride.utilities.ols.web.service.model.Term;

import java.util.concurrent.ConcurrentHashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

@Service
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @author olgavrou
*/
public class FieldList {
public class FieldList implements Joinable {

private String iri;
private String label;
Expand All @@ -13,12 +13,12 @@ public class FieldList {
private String ontologyPrefix;
private String description;
private String type;
private String synonyms;
private String synonym;
private String score;
private String ontologyIri;
private String isDefiningOntology;

private FieldList(String iri, String label, String shortForm, String oboId, String ontologyName, String ontologyPrefix, String description, String type, String synonyms, String score, String ontologyIri, String isDefiningOntology) {
private FieldList(String iri, String label, String shortForm, String oboId, String ontologyName, String ontologyPrefix, String description, String type, String synonym, String score, String ontologyIri, String isDefiningOntology) {
this.iri = iri;
this.label = label;
this.shortForm = shortForm;
Expand All @@ -27,7 +27,7 @@ private FieldList(String iri, String label, String shortForm, String oboId, Stri
this.ontologyPrefix = ontologyPrefix;
this.description = description;
this.type = type;
this.synonyms = synonyms;
this.synonym = synonym;
this.score = score;
this.ontologyIri = ontologyIri;
this.isDefiningOntology = isDefiningOntology;
Expand Down Expand Up @@ -65,8 +65,8 @@ private String getType() {
return type;
}

private String getSynonyms() {
return synonyms;
private String getSynonym() {
return synonym;
}

private String getScore() {
Expand All @@ -77,41 +77,16 @@ private String getOntologyIri() {
return ontologyIri;
}

private String getIsDefiningOntology() {return isDefiningOntology;}
private String getIsDefiningOntology() {
return isDefiningOntology;
}


@Override
public String toString() {
StringBuilder fieldList = new StringBuilder("fieldList=");

if (getIri() != null)
fieldList.append(getIri()).append(",");
if (getLabel() != null)
fieldList.append(getLabel()).append(",");
if (getShortForm() != null)
fieldList.append(getShortForm()).append(",");
if (getOboId() != null)
fieldList.append(getOboId()).append(",");
if (getOntologyName() != null)
fieldList.append(getOntologyName()).append(",");
if (getOntologyPrefix() != null)
fieldList.append(getOntologyPrefix()).append(",");
if (getDescription() != null)
fieldList.append(getDescription()).append(",");
if (getType() != null)
fieldList.append(getType()).append(",");
if (getSynonyms() != null)
fieldList.append(getSynonyms()).append(",");
if (getScore() != null)
fieldList.append(getScore()).append(",");
if (getOntologyIri() != null)
fieldList.append(getOntologyIri()).append(",");
if (getIsDefiningOntology() != null){
fieldList.append(getIsDefiningOntology()).append(",");
}

return fieldList.toString();
return "fieldList=" + this.join();
}

public static class FieldListBuilder {

private String iri;
Expand All @@ -122,17 +97,18 @@ public static class FieldListBuilder {
private String ontologyPrefix;
private String description;
private String type;
private String synonyms;
private String synonym;
private String score;
private String ontologyIri;
private String isDefiningOntology;

public FieldListBuilder() {
}

public FieldList build(){
return new FieldList(iri, label, shortForm, oboId, ontologyName, ontologyPrefix, description, type, synonyms, score, ontologyIri, isDefiningOntology);
public FieldList build() {
return new FieldList(iri, label, shortForm, oboId, ontologyName, ontologyPrefix, description, type, synonym, score, ontologyIri, isDefiningOntology);
}

public FieldListBuilder setIri() {
this.iri = "iri";
return this;
Expand Down Expand Up @@ -174,7 +150,7 @@ public FieldListBuilder setType() {
}

public FieldListBuilder setSynonyms() {
this.synonyms = "synonyms";
this.synonym = "synonym";
return this;
}

Expand All @@ -188,7 +164,7 @@ public FieldListBuilder setOntologyIri() {
return this;
}

public FieldListBuilder setIsDefiningOntology(){
public FieldListBuilder setIsDefiningOntology() {
this.isDefiningOntology = "is_defining_ontology";
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uk.ac.ebi.pride.utilities.ols.web.service.model;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

public interface Joinable {

default String access(Field field) {
try {
field.setAccessible(true);
return (String) field.get(this);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
default String join() {
return Arrays.stream(getClass().getDeclaredFields())
.map(this::access)
.filter(Objects::nonNull)
.collect(Collectors.joining(","));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @author olgavrou
*/
public class QueryFields {
public class QueryFields implements Joinable {

private String label;
private String synonym;
Expand Down Expand Up @@ -61,26 +61,7 @@ private String getLogicalDescription() {

@Override
public String toString() {
StringBuilder queryFields = new StringBuilder("queryFields=");

if (getIri() != null)
queryFields.append(getIri()).append(",");
if (getLabel() != null)
queryFields.append(getLabel()).append(",");
if (getShortForm() != null)
queryFields.append(getShortForm()).append(",");
if (getOboId() != null)
queryFields.append(getOboId()).append(",");
if (getDescription() != null)
queryFields.append(getDescription()).append(",");
if (getAnnotations() != null)
queryFields.append(getAnnotations()).append(",");
if (getSynonym() != null)
queryFields.append(getSynonym()).append(",");
if (getLogicalDescription() != null)
queryFields.append(getLogicalDescription()).append(",");

return queryFields.toString();
return "queryFields=" + this.join();
}
public static class QueryFieldBuilder {

Expand All @@ -96,7 +77,7 @@ public static class QueryFieldBuilder {
public QueryFieldBuilder() {
}

public QueryFields build(){
public QueryFields build() {
return new QueryFields(iri, label, shortForm, oboId, description, annotations, synonym, logicalDescription);
}
public QueryFieldBuilder setIri() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
* SearchResult contains summary term information after the query to the ols service.
*
Expand All @@ -18,13 +20,13 @@ public class SearchResult implements ITerm {
private Identifier iri;

@JsonProperty("short_form")
private Identifier shortName;
private Identifier[] shortName;

@JsonProperty("obo_id")
private Identifier oboId;
private Identifier[] oboId;

@JsonProperty("label")
private String name;
private String[] name;

@JsonProperty("description")
private String[] description;
Expand Down Expand Up @@ -53,6 +55,41 @@ public class SearchResult implements ITerm {
@JsonProperty("obo_definition_citation")
private OboDefinitionCitation[] oboDefinitionCitation;

public Term toTerm() {
if (this.name == null) return null;
if (!this.obsolete) {
return new Term(
this.getIri(),
this.getName(),
this.getDescription(),
this.getShortName(),
this.getOboId(),
this.getOntologyName(),
this.getScore(),
this.getOntologyIri(),
this.getIsDefiningOntology(),
this.getOboDefinitionCitation(),
this.getAnnotation());
} else {
return new ObsoleteTerm(
this.getIri(),
this.getName(),
this.getDescription(),
this.getShortName(),
this.getOboId(),
this.getOntologyName(),
this.getScore(),
this.getOntologyIri(),
this.getIsDefiningOntology(),
this.getOboDefinitionCitation(),
this.getAnnotation(),
this.isObsolete(),
this.getTermReplacedBy()
);
}
}


public String getId() {
return id;
}
Expand All @@ -70,26 +107,26 @@ public void setIri(String iri) {
}

public Identifier getShortName() {
return shortName;
return first(shortName);
}

public void setShortName(String shortName) {
this.shortName = new Identifier(shortName, Identifier.IdentifierType.OWL);
public void setShortName(List<String> shortName) {
this.shortName = shortName.stream().map(s -> new Identifier(s, Identifier.IdentifierType.OWL)).toArray(Identifier[]::new);
}

public Identifier getOboId() {
return oboId;
return first(oboId);
}

public void setOboId(String oboId) {
this.oboId = new Identifier(oboId, Identifier.IdentifierType.OBO);
public void setOboId(List<String> oboId) {
this.oboId = oboId.stream().map(s -> new Identifier(s, Identifier.IdentifierType.OBO)).toArray(Identifier[]::new);
}

public String getName() {
return name;
return first(name);
}

public void setName(String name) {
public void setName(String[] name) {
this.name = name;
}

Expand Down Expand Up @@ -165,7 +202,12 @@ public void setOboDefinitionCitation(OboDefinitionCitation[] oboDefinitionCitati
this.oboDefinitionCitation = oboDefinitionCitation;
}

public Identifier getGlobalId(){
return (oboId != null)?oboId:shortName;
public Identifier getGlobalId() {
return getOboId() != null ? getOboId() : getShortName();
}

private static <T> T first(T[] array) {
return array != null && array.length >= 1 ? array[0] : null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ public void setSynonyms(String[] synonyms) {
this.synonyms = synonyms;
}

/**
* Support synonym/synonyms name which differ between the different ensdoints
* @param synonym
*/
@JsonProperty("synonym")
public void setSynonym(String[] synonym) {
this.synonyms = synonym;
}

public String getOntologyName() {
return ontologyName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class Constants {
public static final int TERM_PAGE_SIZE = 1000;
public static final String REFERENCE_SEPARATOR = ":";
public static final String OLS_PROTOCOL = "https";
public static final String OLS_SERVER = "www.ebi.ac.uk/ols/";
public static final String OLS_SERVER = "www.ebi.ac.uk/ols4/";
public static final String OLS_SERVER_DEV = "wwwdev.ebi.ac.uk/ols/";
}
Loading

0 comments on commit d123103

Please sign in to comment.