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 16, 2024
1 parent f043915 commit a9310e7
Showing 1 changed file with 55 additions and 0 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,15 @@ private static Pattern initDMPSampleIDPattern() {
return Pattern.compile("(P-[0-9]{7,})-T[0-9]{2,}-(\\w{3,})");
}

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

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

private String getDecryptedId(String sampleID) {
String requestUrl = constructMpathDecryptionUrl(sampleID);
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 = responseEntity.getBody().toString();
return decryptedId;
}

private String constructMpathDecryptionUrl(String sampleId) {
return mpathDecryptionUrl + sampleId;
}

private String getRedirectURL(String sampleID) {
String redirectURL = "redirect:" + sampleViewURL;
String studyID = getCancerStudy(sampleID);
Expand Down Expand Up @@ -141,6 +185,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 a9310e7

Please sign in to comment.