Skip to content

Commit

Permalink
computed last loaded time for subset of ontologies in #91
Browse files Browse the repository at this point in the history
  • Loading branch information
giraygi committed Nov 18, 2024
1 parent a8bd1ea commit 6246cd3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
<version>4.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.13.0</version>
<scope>compile</scope>
</dependency>

<!-- Logging -->
<!-- <dependency>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class V2StatisticsController {
@Operation(description = "Get Whole System Statistics. Components in all ontologies are taken into consideration")
@RequestMapping(path = "/stats", produces = {MediaType.APPLICATION_JSON_VALUE, MediaTypes.HAL_JSON_VALUE}, method = RequestMethod.GET)
public HttpEntity<V2Statistics> getStatistics() throws ResourceNotFoundException, IOException {
return new ResponseEntity<>( computeStats("*:*"), HttpStatus.OK);
return new ResponseEntity<>( computeStats("*:*", null), HttpStatus.OK);
}

@Operation(description = "Get Schema and Classification based Statistics. Possible schema keys and possible classification values of particular keys can be inquired with /api/ontologies/schemakeys and /api/ontologies/schemavalues methods respectively.")
Expand All @@ -53,6 +53,7 @@ public HttpEntity<V2Statistics> getStatistics(
@RequestParam(value = "lang", defaultValue = "en") String lang) throws ResourceNotFoundException, IOException{

ontologyIds = ontologyRepository.filterOntologyIDs(schemas,classifications,ontologyIds,exclusive,filterOption,lang);
String lastLoaded = ontologyRepository.getLastLoaded(ontologyIds,lang).toString();
StringBuilder sb = new StringBuilder();
String queryString = "none";
if(ontologyIds != null){
Expand All @@ -61,7 +62,7 @@ public HttpEntity<V2Statistics> getStatistics(
}
queryString = sb.toString().substring(0,sb.toString().lastIndexOf(" OR "));
}
return new ResponseEntity<>( computeStats(queryString), HttpStatus.OK);
return new ResponseEntity<>( computeStats(queryString, lastLoaded), HttpStatus.OK);
}
@Operation(description = "Get Composite Schema based Statistics. All schemas with their respective classifications under the classifications variable will be computed.")
@RequestMapping(path = "/allstatsbyschema", produces = {MediaType.APPLICATION_JSON_VALUE, MediaTypes.HAL_JSON_VALUE}, method = RequestMethod.GET)
Expand All @@ -82,11 +83,11 @@ HttpEntity<MultiKeyMap> getStatisticsBySchema(
return new ResponseEntity<>( summaries, HttpStatus.OK);
}

private V2Statistics computeStats(String queryString) throws IOException {
private V2Statistics computeStats(String queryString, String lastLoaded) throws IOException {

Map<String,Object> coreStatus = solrClient.getCoreStatus();
Map<String,Object> indexStatus = (Map<String,Object>) coreStatus.get("index");
String lastModified = (String) indexStatus.get("lastModified");
String lastModified = lastLoaded == null ? (String) indexStatus.get("lastModified") : lastLoaded;

SolrQuery query = new SolrQuery();
query.setQuery(queryString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import uk.ac.ebi.spot.ols.repository.transforms.RemoveLiteralDatatypesTransform;
import uk.ac.ebi.spot.ols.repository.v2.helpers.V2DynamicFilterParser;
import uk.ac.ebi.spot.ols.repository.v2.helpers.V2SearchFieldsParser;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.io.IOException;

Expand Down Expand Up @@ -103,6 +106,19 @@ public Set<V2Entity> getOntologies(String lang){
return entities;
}

public LocalDateTime getLastLoaded(Collection<String> ontologies,String lang){
LocalDateTime lastLoaded = LocalDateTime.MIN;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS");
for (V2Entity entity : getOntologies(lang)){
if (ontologies.contains(entity.any().get("ontologyId").toString())){
LocalDateTime dateTime = LocalDateTime.parse(entity.any().get("loaded").toString(), formatter);
if (dateTime.isAfter(lastLoaded))
lastLoaded = dateTime;
}
}
return lastLoaded;
}

public Collection<String> filterOntologyIDs(Collection<String> schemas, Collection<String> classifications, Collection<String> ontologies, boolean exclusiveFilter, FilterOption filterOption, String lang){
if (schemas != null)
schemas.remove("");
Expand Down

0 comments on commit 6246cd3

Please sign in to comment.