Skip to content

Commit

Permalink
use legacy entities endpoint to get objectids (#318)
Browse files Browse the repository at this point in the history
* use legacy entities endpoint to get analysis files

* better naming
  • Loading branch information
jaserud authored Aug 18, 2021
1 parent 8b3519b commit f18bce0
Showing 1 changed file with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import bio.overture.score.client.metadata.Entity;
import bio.overture.score.client.metadata.EntityNotFoundException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists;
import lombok.Getter;
Expand Down Expand Up @@ -83,15 +81,15 @@ public Entity findEntity(@NonNull String objectId) throws EntityNotFoundExceptio
}

public List<Entity> findEntities(String... fields) throws EntityNotFoundException {
return readAll("/" + (fields.length > 0 ? "?" + resolveFields(fields) : ""));
return readAllEntities("/" + (fields.length > 0 ? "?" + resolveFields(fields) : ""));
}

public List<Entity> findEntitiesByGnosId(@NonNull String gnosId) throws EntityNotFoundException {
return findEntitiesByGnosId(gnosId, new String[] {});
}

public List<Entity> findEntitiesByGnosId(@NonNull String gnosId, String... fields) throws EntityNotFoundException {
return readAll("?gnosId=" + gnosId + (fields.length > 0 ? "&" + resolveFields(fields) : ""));
return readAllEntities("?gnosId=" + gnosId + (fields.length > 0 ? "&" + resolveFields(fields) : ""));
}

@SneakyThrows
Expand All @@ -104,7 +102,7 @@ private Entity read(@NonNull String path) {
}

@SneakyThrows
private List<Entity> readAll(@NonNull String path) {
private List<Entity> readAllEntities(@NonNull String path) {
val results = Lists.<Entity>newArrayList();
boolean last = false;
int pageNumber = 0;
Expand Down Expand Up @@ -133,15 +131,14 @@ private List<Entity> readAll(@NonNull String path) {

@SneakyThrows
public List<String> getObjectIdsByAnalysisId(@NonNull String programId, @NonNull String analysisId) {
val url = new URL(serverUrl + "/studies/" + programId + "/analysis/" + analysisId + "/files");
val path = "?gnosId=" + analysisId + "&projectCode=" + programId;

log.debug("Fetching analysis files from url '{}'", url);
log.debug("Fetching analysis files via entities endpoint with path '{}'", path);

return stream(MAPPER.readValue(url, ArrayNode.class).spliterator(), false).
peek(r -> log.debug("Got result {}", r)).
map(x -> x.path("objectId")).
map(JsonNode::textValue).
collect(toImmutableList());
return readAllEntities(path).stream()
.peek(r -> log.debug("Got result {}", r))
.map(Entity::getId)
.collect(toImmutableList());
}

@SneakyThrows
Expand All @@ -152,5 +149,4 @@ private URL resolveEntitiesUrl(String path) {
private static String resolveFields(String[] fields) {
return Stream.of(fields).map(f -> "fields=" + f).collect(joining("&"));
}

}

0 comments on commit f18bce0

Please sign in to comment.