Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use legacy entities endpoint to get objectids #318

Merged
merged 2 commits into from
Aug 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("&"));
}

}