diff --git a/src/main/java/gov/nih/nci/bento_ri/model/PrivateESDataFetcher.java b/src/main/java/gov/nih/nci/bento_ri/model/PrivateESDataFetcher.java index fcbd0e2..2c4422c 100644 --- a/src/main/java/gov/nih/nci/bento_ri/model/PrivateESDataFetcher.java +++ b/src/main/java/gov/nih/nci/bento_ri/model/PrivateESDataFetcher.java @@ -130,6 +130,9 @@ public RuntimeWiring buildRuntimeWiring() throws IOException { .dataFetcher("numberOfPublications", env -> { return numberOfPublications(); }) + .dataFetcher("numberOfResources", env -> { + return numberOfResources(); + }) .dataFetcher("datasetDetails", env -> { Map args = env.getArguments(); return datasetDetails(args); @@ -748,6 +751,27 @@ private Integer numberOfPublications() throws Exception { return count; } + /** + * Queries Opensearch for the total Resources count + * @return + * @throws Exception + */ + private Integer numberOfResources() throws Exception { + Request homeStatsRequest = new Request("GET", HOME_STATS_END_POINT); + JsonObject homeStatsResult = insEsService.send(homeStatsRequest); + JsonArray hits = homeStatsResult.getAsJsonObject("hits").getAsJsonArray("hits"); + Iterator hitsIter = hits.iterator(); + + if (!hitsIter.hasNext()) { + throw new Exception("Error: no results for homepage stats!"); + } + + JsonObject counts = hitsIter.next().getAsJsonObject().getAsJsonObject("_source"); + int count = counts.get("num_resources").getAsInt(); + + return count; + } + /** * Gets the details for a single Dataset record * diff --git a/src/main/resources/graphql/ins-private-es.graphql b/src/main/resources/graphql/ins-private-es.graphql index 868bafa..6151fb2 100644 --- a/src/main/resources/graphql/ins-private-es.graphql +++ b/src/main/resources/graphql/ins-private-es.graphql @@ -306,6 +306,7 @@ type QueryType { numberOfPrograms: Int numberOfProjects: Int numberOfPublications: Int + numberOfResources: Int stats ( # Facet filters