Skip to content

Commit

Permalink
add calls for decryption test
Browse files Browse the repository at this point in the history
  • Loading branch information
Avery Wang committed Sep 17, 2024
1 parent f043915 commit c1c8dff
Showing 1 changed file with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@

package org.cbioportal.web;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.cbioportal.service.PatientService;
import org.cbioportal.service.SampleService;
import org.cbioportal.service.exception.PatientNotFoundException;
Expand Down Expand Up @@ -81,6 +92,12 @@ public class MskEntityTranslationController {
@Value("${patient_view.url}")
public void setPatientViewURL(String property) { this.patientViewURL = property; }

@Value("${mpath.decryption_url:}")
private String mpathDecryptionUrl;

@Value("${mpath.token:}")
private String mpathToken;

private static final String ARCHER = "mskarcher";
private static final String RAINDANCE = "mskraindance";
private static final String IMPACT = "mskimpact";
Expand All @@ -90,6 +107,24 @@ private static Pattern initDMPSampleIDPattern() {
return Pattern.compile("(P-[0-9]{7,})-T[0-9]{2,}-(\\w{3,})");
}

@RequestMapping(
value={"/api-legacy/epic/sample/{sampleID}"},
method=RequestMethod.GET
)
public ModelAndView redirectIMPACTSampleForEpic(@PathVariable String sampleID, ModelMap model) {
String decryptedId = getDecryptedId(sampleID);
return new ModelAndView(getRedirectURL(decryptedId), model);
}

@RequestMapping(
value={"/api-legacy/epic/patient/{patientID}"},
method=RequestMethod.GET
)
public ModelAndView redirectIMPACTSampleForEpic(@PathVariable String patientID, ModelMap model) {
String decryptedId = getDecryptedId(patientID);
return new ModelAndView(getPatientRedirectURL(decryptedId), model);
}

@RequestMapping(
value={"/api-legacy/cis/{sampleID}", "/api-legacy/darwin/{sampleID}"},
method=RequestMethod.GET
Expand All @@ -106,17 +141,31 @@ public ModelAndView redirectCRDB(@PathVariable String sampleID, ModelMap model)
return new ModelAndView(getRedirectURL(sampleID), model);
}

// Takes either a patient and/or sample id
private String getDecryptedId(String id) {
String requestUrl = mpathDecryptionUrl + id;
RestTemplate restTemplate = new RestTemplate();
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("x-api-key", mpathToken);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
ResponseEntity<Object> responseEntity = restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, Object.class);
String decryptedId = id;
if (responseEntity.getStatusCode().value() == 200) {
decryptedId = responseEntity.getBody().toString();
}
return decryptedId;
}

private String getRedirectURL(String sampleID) {
String redirectURL = "redirect:" + sampleViewURL;
String studyID = getCancerStudy(sampleID);
if (!checkIfSampleExistsInStudy(studyID, sampleID)) {
if (studyID.equals(ARCHER)) {
String patientID = getPatientID(sampleID);
if (patientID != null) {
redirectURL = "redirect:" + patientViewURL;
redirectURL = redirectURL.replace("STUDY_ID", IMPACT);
redirectURL = redirectURL.replace("CASE_ID", patientID);
return redirectURL;
return getPatientRedirectURL(patientID);
}
// else patientID is null
}
Expand All @@ -131,6 +180,13 @@ private String getRedirectURL(String sampleID) {
return redirectURL;
}

private String getPatientRedirectURL(String patientID) {
String redirectURL = "redirect:" + patientViewURL;
redirectURL = redirectURL.replace("STUDY_ID", IMPACT);
redirectURL = redirectURL.replace("CASE_ID", patientID);
return redirectURL;
}

@RequestMapping(
value={"/api-legacy/cis/{sampleID}/exists", "/api-legacy/darwin/{sampleID}/exists", "/api-legacy/crdb/{sampleID}/exists"},
method=RequestMethod.GET
Expand All @@ -141,6 +197,17 @@ private String getRedirectURL(String sampleID) {
return result;
}

@RequestMapping(
value={"/api-legacy/epic/{sampleID}/exists"},
method=RequestMethod.GET
)
public @ResponseBody HashMap<String, Boolean> existsForEpic(@PathVariable String sampleID, ModelMap model) {
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
String decryptedId = getDecryptedId(sampleID);
result.put("exists", new Boolean(checkIfSampleExists(decryptedId)));
return result;
}

private boolean checkIfPatientExists(String studyID, String sampleID) {
try {
String patientID = getPatientID(sampleID);
Expand Down

0 comments on commit c1c8dff

Please sign in to comment.