Skip to content

Commit

Permalink
Add DefinedFields page on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
haideriqbal committed Jan 14, 2025
1 parent 17017ee commit febfef3
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public OpenAPI customOpenApi(ServletContext context) {
.addServersItem(new Server().url(serverUrl))
.info(new Info()
.title("OLS Service")
.description("REST API for OLS")
.description("REST API for OLS. Please see <a href='/defined-response-fields' target='_blank'>this page</a> for defined response field in OLS.")
.version("3.0")
.termsOfService("https://www.ebi.ac.uk/about/terms-of-use/")
.license(new License()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package uk.ac.ebi.spot.ols.controller.api.v2;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.ac.ebi.ols.shared.DefinedFields;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
public class V2DefinedFieldsController {

@GetMapping("/api/v2/defined-fields")
public List<DefinedFieldDto> getDefinedFields() {
return Stream.of(DefinedFields.values())
.map(field -> new DefinedFieldDto(
field.getText(),
field.getOls3Text(),
field.getDescription(),
field.getType()
))
.collect(Collectors.toList());
}

// DTO class for serialization
static class DefinedFieldDto {
private String ols4FieldName;
private String ols3FieldName;
private String description;
private String dataType;

public DefinedFieldDto(String ols4FieldName, String ols3FieldName, String description, String dataType) {
this.ols4FieldName = ols4FieldName;
this.ols3FieldName = ols3FieldName;
this.description = description;
this.dataType = dataType;
}

public String getOls4FieldName() {
return ols4FieldName;
}

public String getOls3FieldName() {
return ols3FieldName;
}

public String getDescription() {
return description;
}

public String getDataType() {
return dataType;
}
}
}
2 changes: 2 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import About from "./pages/About";
import Downloads from "./pages/Downloads";
import Error from "./pages/Error";
import Help from "./pages/Help";
import DefinedResponseFields from "./pages/DefinedResponseFields";
import OLS3Help from "./pages/OLS3Help";
import Home from "./pages/home/Home";
import OntologiesPage from "./pages/ontologies/OntologiesPage";
Expand Down Expand Up @@ -85,6 +86,7 @@ class App extends React.Component {
/>

<Route path={`/help`} element={<Help />} />
<Route path={`/defined-response-fields`} element={<DefinedResponseFields />} />
<Route path={`/ols3help`} element={<OLS3Help />} />
<Route path={`/about`} element={<About />} />
<Route path={`/downloads`} element={<Downloads />} />
Expand Down
51 changes: 51 additions & 0 deletions frontend/src/pages/DefinedResponseFields.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Fragment, useEffect, useState } from "react";
import Header from "../components/Header";

interface DefinedField {
ols4FieldName: string;
ols3FieldName: string;
description: string;
dataType: string;
}

export default function StaticDocs() {
document.title = "OLS Documentation";

const [fields, setFields] = useState<DefinedField[]>([]);

useEffect(() => {
fetch('/api/v2/defined-fields')
.then((response) => response.json())
.then((data) => setFields(data))
.catch((error) => console.error('Error fetching defined fields:', error));
}, []);

return (
<Fragment>
<Header section="static-docs" />
<main className="container mx-auto px-4 my-8">
<div className="text-2xl font-bold my-6">Defined Response Fields in OLS</div>
<table className="table-auto w-full border-collapse border border-gray-300">
<thead>
<tr className="bg-gray-100">
<th className="border border-gray-300 px-4 py-2">OLS4 Field Name</th>
<th className="border border-gray-300 px-4 py-2">OLS3 Field Name</th>
<th className="border border-gray-300 px-4 py-2">Description</th>
<th className="border border-gray-300 px-4 py-2">Data Type</th>
</tr>
</thead>
<tbody>
{fields.map((field, index) => (
<tr key={index}>
<td className="border border-gray-300 px-4 py-2">{field.ols4FieldName}</td>
<td className="border border-gray-300 px-4 py-2">{field.ols3FieldName}</td>
<td className="border border-gray-300 px-4 py-2">{field.description}</td>
<td className="border border-gray-300 px-4 py-2">{field.dataType}</td>
</tr>
))}
</tbody>
</table>
</main>
</Fragment>
);
}
64 changes: 35 additions & 29 deletions ols-shared/src/main/java/uk/ac/ebi/ols/shared/DefinedFields.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
package uk.ac.ebi.ols.shared;

public enum DefinedFields {
APPEARS_IN("appearsIn", "", "The list of ontologies in which the current entity is used."),
APPEARS_IN("appearsIn", "", "The list of ontologies in which the current entity is used.", "array"),
BASE_URI("baseUri", "baseUris",
"The beginning of URIs that OLS assumes to belong to an ontology."),
DEFINED_BY("definedBy", "", "A list of ontologies which defines this term"),
DEFINITION("definition", "description","The definition of this entity."),
"The beginning of URIs that OLS assumes to belong to an ontology.", "array"),
DEFINED_BY("definedBy", "", "A list of ontologies which defines this term", "array"),
DEFINITION("definition", "description","The definition of this entity.", "string"),
DIRECT_ANCESTOR("directAncestor", "",
"A list of all direct parents by subclass- and hierarchical relations for this entity."),
DIRECT_PARENT("directParent", "","A list of the direct parents of this entity."),
EXPORTS_TO("exportsTo", "", "Lists the prefixes of ontologies that imports this ontology."),
"A list of all direct parents by subclass- and hierarchical relations for this entity.", "array"),
DIRECT_PARENT("directParent", "","A list of the direct parents of this entity.", "array"),
EXPORTS_TO("exportsTo", "", "Lists the prefixes of ontologies that imports this ontology.", "array"),
HAS_DIRECT_CHILDREN("hasDirectChildren", "has_children",
"Whether this class has direct children or not."),
"Whether this class has direct children or not.", "boolean"),
HAS_DIRECT_PARENTS("hasDirectParents", "",
"Indicates whether this class has direct parents or not."),
"Indicates whether this class has direct parents or not.", "boolean"),
HAS_HIERARCHICAL_CHILDREN("hasHierarchicalChildren", "",
"Whether this class has hierarchical children or not."),
"Whether this class has hierarchical children or not.", "boolean"),
HAS_HIERARCHICAL_PARENTS("hasHierarchicalParents", "",
"Whether this class has hierarchical parents or not."),
HAS_INDIVIDUALS("hasIndividuals", "", ""),
"Whether this class has hierarchical parents or not.", "boolean"),
HAS_INDIVIDUALS("hasIndividuals", "", "Whether individuals exists or not.", "boolean"),
HAS_LOCAL_DEFINITION("hasLocalDefinition", "",
"True if term is definined within this ontology."),
"True if term is definined within this ontology.", "boolean"),
HIERARCHICAL_ANCESTOR("hierarchicalAncestor","","The list of ancestors of this entity via " +
"subclass relationships and hierarchical properties such as part_of(BFO:0000050) relations."),
"subclass relationships and hierarchical properties such as part_of(BFO:0000050) relations.", "array"),
HIERARCHICAL_PARENT("hierarchicalParent","" ,"The list of parents of this entity via " +
"subclass relationships and hierarchical properties such as part_of(BFO:0000050) relations."),
"subclass relationships and hierarchical properties such as part_of(BFO:0000050) relations.", "array"),
IMPORTED("imported", "",
"Whether this entity is imported or not."),
"Whether this entity is imported or not.", "boolean"),
IMPORTS_FROM("importsFrom", "",
"Lists the prefixes of the ontologies the current ontology imports from."),
"Lists the prefixes of the ontologies the current ontology imports from.", "array"),
IS_DEFINING_ONTOLOGY("isDefiningOntology",
"is_defining_ontology","Whether this entity is defined in this ontology or not."),
"is_defining_ontology","Whether this entity is defined in this ontology or not.", "boolean"),
IS_OBSOLETE("isObsolete", "isObsolete",
"Set to true if this entity is obsolete, otherwise is set to false."),
"Set to true if this entity is obsolete, otherwise is set to false.", "boolean"),
IS_PREFERRED_ROOT("isPreferredRoot", "is_preferred_root",
"Set to true if this entity is a preferred root or not."),
LABEL("label", "", "The name or names of this entity."),
LANGUAGE("language", "", "The language or languages this ontology is available in."),
NUM_DESCENDANTS ("numDescendants", "", "Number of descendants of this entity."),
"Set to true if this entity is a preferred root or not.", "boolean"),
LABEL("label", "", "The name or names of this entity.", "string"),
LANGUAGE("language", "", "The language or languages this ontology is available in.", "array"),
NUM_DESCENDANTS ("numDescendants", "", "Number of descendants of this entity.", "integer"),
NUM_HIERARCHICAL_DESCENDANTS ("numHierarchicalDescendants", "",
"Number of hierarchical descendants of this entity."),
"Number of hierarchical descendants of this entity.", "integer"),
PREFERRED_ROOT("preferredRoot", "",
"A list of entities that serve as roots for this ontology."),
"A list of entities that serve as roots for this ontology.", "array"),
RELATED_FROM("relatedFrom","", "The list of classes in which this class is used as part of its definition. " +
"I.e. 'liver disease' (EFO:0001421) has a relatedFrom relation with 'serum albumin measurement' (EFO:0004535) because " +
"'serum albumin measurement' is a subclass of 'is about some liver disease'."),
"'serum albumin measurement' is a subclass of 'is about some liver disease'.", "array"),
RELATED_TO("relatedTo","", "The list of classes that are used in axioms in the filler position" +
" in defining this class. It only considers classes in the filler position, not classes expressions in the filler position." +
"I.e. 'liver disease' (EFO:0001421) has a relatedTo relation with 'liver' (UBERON:0002107) because " +
"'liver disease' is a subclass of 'has_disease_location some liver'."),
SYNONYM("synonym", "", "The list of names that are synonyms of this entity.");
"'liver disease' is a subclass of 'has_disease_location some liver'.", "array"),
SYNONYM("synonym", "", "The list of names that are synonyms of this entity.", "array"),;

private final String text;
private final String ols3Text;
private final String description;
private final String type;

DefinedFields(String text, String ols3Text, String description) {
DefinedFields(String text, String ols3Text, String description, String type) {
this.text = text;
this.ols3Text = ols3Text;
this.description = description;
this.type = type;
}

public String getText() {
Expand All @@ -68,4 +70,8 @@ public String getText() {
public String getOls3Text() {
return ols3Text;
}

public String getDescription() { return description; }

public String getType() { return type; }
}

0 comments on commit febfef3

Please sign in to comment.