Skip to content

Commit

Permalink
Get an initial prototype working! 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
cbioportal import user committed Nov 2, 2024
1 parent 7b20055 commit c74cad9
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -20,44 +19,4 @@ public List<SummaryServer> getServers() {
public void setServers(List<SummaryServer> servers) {
this.servers = servers;
}

public static class SummaryServer {

private String name;
private String baseUrl;
private List<String> studyIds = new ArrayList<>();
private List<String> supportedEndpoints = new ArrayList<>();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getBaseUrl() {
return baseUrl;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public List<String> getStudyIds() {
return studyIds;
}

public void setStudyIds(List<String> studyIds) {
this.studyIds = studyIds;
}

public List<String> getSupportedEndpoints() {
return supportedEndpoints;
}

public void setSupportedEndpoints(List<String> supportedEndpoints) {
this.supportedEndpoints = supportedEndpoints;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.apache.http.client.utils.URIBuilder;
import org.cbioportal.model.ClinicalAttribute;
import org.cbioportal.model.ClinicalDataBin;
import org.cbioportal.model.ClinicalDataCountItem;
import org.cbioportal.web.config.CustomObjectMapper;
import org.cbioportal.web.parameter.*;
import org.cbioportal.persistence.summary.SummaryApiConfig.SummaryServer;

import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand All @@ -25,12 +25,10 @@ public class SummaryApiImpl implements SummaryApi {

private final SummaryServer summaryServer;
private final ObjectMapper jsonMapper;
private final ObjectMapper yamlMapper;

public SummaryApiImpl(SummaryServer summaryServer) {
this.summaryServer = summaryServer;
jsonMapper = new ObjectMapper(new JsonFactory());
yamlMapper = new ObjectMapper(new YAMLFactory());
jsonMapper = new CustomObjectMapper();
}

@Override
Expand Down Expand Up @@ -69,7 +67,7 @@ public CompletableFuture<List<ClinicalAttribute>> fetchClinicalAttributes(List<S
@Override
public CompletableFuture<List<ClinicalDataCountItem>> fetchClinicalDataCounts(ClinicalDataCountFilter filter) {
return POST(
"/clinical-data-counts",
"/clinical-data-counts/fetch",
Map.of(),
filter,
new TypeReference<List<ClinicalDataCountItem>>() {}
Expand All @@ -82,7 +80,7 @@ public CompletableFuture<List<ClinicalDataBin>> fetchClinicalDataBinCounts(Clini
Map.entry("dataBinMethod", dataBinMethod.toString())
);
return POST(
"/clinical-data-bin-counts",
"/clinical-data-bin-counts/fetch",
params,
filter,
new TypeReference<List<ClinicalDataBin>>() {}
Expand Down Expand Up @@ -110,18 +108,23 @@ private <T> CompletableFuture<T> POST(
String payload = jsonMapper.writeValueAsString(data);

// Build the HttpClient/HttpRequest objects
HttpClient client = HttpClient.newHttpClient();
HttpClient client = HttpClient.newHttpClient(); // TODO dispose after use?
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.timeout(Duration.ofSeconds(10))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(payload))
.build();

// Send the request asynchronously and try to serialize it into the provided response type
System.out.println("POST " + uri);
System.out.println("Request body: " + payload);
return client.sendAsync(request, BodyHandlers.ofString())
.thenApply(resp -> {
try {
return jsonMapper.readValue(resp.body(), responseType);
String body = resp.body();
System.out.println("Response body: " + body);
return jsonMapper.readValue(body, responseType);
} catch (Exception e) {
throw new RuntimeException("Could not parse response JSON from " + endpoint, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.cbioportal.persistence.summary;


import java.util.ArrayList;
import java.util.List;

public class SummaryServer {

private String name;
private String baseUrl;
private List<String> studyIds = new ArrayList<>();
private List<String> supportedEndpoints = new ArrayList<>();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getBaseUrl() {
return baseUrl;
}

public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}

public List<String> getStudyIds() {
return studyIds;
}

public void setStudyIds(List<String> studyIds) {
this.studyIds = studyIds;
}

public List<String> getSupportedEndpoints() {
return supportedEndpoints;
}

public void setSupportedEndpoints(List<String> supportedEndpoints) {
this.supportedEndpoints = supportedEndpoints;
}
}
28 changes: 16 additions & 12 deletions src/main/java/org/cbioportal/web/GenePanelDataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -82,20 +83,23 @@ public ResponseEntity<List<GenePanelData>> fetchGenePanelDataInMultipleMolecular
@Valid @RequestAttribute(required = false, value = "interceptedGenePanelDataMultipleStudyFilter") GenePanelDataMultipleStudyFilter interceptedGenePanelDataMultipleStudyFilter,
@Parameter(required = true, description = "Gene panel data filter object")
@RequestBody(required = false) GenePanelDataMultipleStudyFilter genePanelDataMultipleStudyFilter) {

List<GenePanelData> genePanelDataList;
if(CollectionUtils.isEmpty(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds())) {
List<MolecularProfileCaseIdentifier> molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers()
.stream()
.map(sampleMolecularIdentifier -> {
MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier();
profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId());
profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId());
return profileCaseIdentifier;
})
.collect(Collectors.toList());

genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers);
// Not sure what this does-- stub out for now
genePanelDataList = new ArrayList<>();

// List<MolecularProfileCaseIdentifier> molecularProfileSampleIdentifiers = interceptedGenePanelDataMultipleStudyFilter.getSampleMolecularIdentifiers()
// .stream()
// .map(sampleMolecularIdentifier -> {
// MolecularProfileCaseIdentifier profileCaseIdentifier = new MolecularProfileCaseIdentifier();
// profileCaseIdentifier.setMolecularProfileId(sampleMolecularIdentifier.getMolecularProfileId());
// profileCaseIdentifier.setCaseId(sampleMolecularIdentifier.getSampleId());
// return profileCaseIdentifier;
// })
// .collect(Collectors.toList());
//
// genePanelDataList = genePanelService.fetchGenePanelDataInMultipleMolecularProfiles(molecularProfileSampleIdentifiers);
} else {
genePanelDataList = genePanelService.fetchGenePanelDataByMolecularProfileIds(new HashSet<>(interceptedGenePanelDataMultipleStudyFilter.getMolecularProfileIds()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class GenePanelDataMultipleStudyFilter implements Serializable {

@Size(min = 1, max = PagingConstants.MAX_PAGE_SIZE)
private List<SampleMolecularIdentifier> sampleMolecularIdentifiers;
@Size(min = 1, max = PagingConstants.MAX_PAGE_SIZE)
@Size(min = 0, max = PagingConstants.MAX_PAGE_SIZE)
private List<String> molecularProfileIds;

@AssertTrue
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/summary-api.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
summary.servers[0].name=Enclave Proxy
summary.servers[0].base-url=http://localhost:8088
summary.servers[0].base-url=http://host.docker.internal:8088
summary.servers[0].study-ids[0]=enclave_2024
summary.servers[0].supported-endpoints[0]=/clinical-attributes/fetch
summary.servers[0].supported-endpoints[1]=/clinical-data-counts/fetch
Expand Down

0 comments on commit c74cad9

Please sign in to comment.