Skip to content

Commit

Permalink
Publish virtual study by modifying it instead of making copy
Browse files Browse the repository at this point in the history
Also get rid of undocumented endpoint
  • Loading branch information
forus committed Jul 9, 2024
1 parent 5e5ba92 commit b8ee5e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 53 deletions.
8 changes: 2 additions & 6 deletions docs/Create-And-Publish-Virtual-Study.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ curl \
-H 'X-PUBLISHER-API-KEY: <session.endpoint.publisher-api-key>' \
-v 'http://<cbioportal_host>/api/public_virtual_studies/<virtual_study_id>'
```
This call publishes a *copy* of the virtual study under a different ID.
The new ID hash will be printed by the command.
The published virtual study will appear under the `Public Virtual Studies` section (next to the `My Virtual Studies` section) on the landing page for all users of cBioPortal.

While publishing, you can specify the PubMed ID (`pmid`) and `typeOfCancerId` of the virtual study using the following command:
Expand All @@ -58,7 +56,5 @@ Here is the command to un-publish a virtual study:
curl \
-X DELETE \
-H 'X-PUBLISHER-API-KEY: <session.endpoint.publisher-api-key>' \
-v 'http://<cbioportal_host>/api/public_virtual_studies/<published_virtual_study_id>'
```

*Note*: You have to use the ID of the *published* virtual study, not the one it was copied from during the publishing process.
-v 'http://<cbioportal_host>/api/public_virtual_studies/<virtual_study_id>'
```
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ public void softRemoveVirtualStudy(String id) {
VirtualStudy virtualStudy = getVirtualStudyById(id);
VirtualStudyData data = virtualStudy.getData();
data.setUsers(Collections.emptySet());
updateVirtualStudy(virtualStudy);
}

/**
* Updates virtual study
* @param virtualStudy - virtual study to update
*/
public void updateVirtualStudy(VirtualStudy virtualStudy) {
new RestTemplate()
.put(sessionServiceURL + "/virtual_study/" + id,
new HttpEntity<>(data, getHttpHeaders()));
.put(sessionServiceURL + "/virtual_study/" + virtualStudy.getId(),
new HttpEntity<>(virtualStudy.getData(), getHttpHeaders()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -58,33 +57,17 @@ public ResponseEntity<List<VirtualStudy>> getPublicVirtualStudies() {
return new ResponseEntity<>(virtualStudies, HttpStatus.OK);
}

@PostMapping
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = VirtualStudy.class)))
public ResponseEntity<VirtualStudy> publishVirtualStudyData(
@RequestBody VirtualStudyData virtualStudyData,
@RequestHeader(value = "X-PUBLISHER-API-KEY") String providedPublisherApiKey,
@RequestParam(required = false) String typeOfCancerId,
@RequestParam(required = false) String pmid
) {
ensureProvidedPublisherApiKeyCorrect(providedPublisherApiKey);
VirtualStudyData virtualStudyDataToPublish = makeCopyForPublishing(virtualStudyData);
updateStudyMetadataFieldsIfSpecified(virtualStudyDataToPublish, typeOfCancerId, pmid);
VirtualStudy virtualStudy = sessionServiceRequestHandler.createVirtualStudy(virtualStudyDataToPublish);

return new ResponseEntity<>(virtualStudy, HttpStatus.OK);
}

@PostMapping("/{id}")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = VirtualStudy.class)))
public ResponseEntity<VirtualStudy> publishVirtualStudy(
public ResponseEntity<Void> publishVirtualStudy(
@PathVariable String id,
@RequestHeader(value = "X-PUBLISHER-API-KEY") String providedPublisherApiKey,
@RequestParam(required = false) String typeOfCancerId,
@RequestParam(required = false) String pmid
) {
ensureProvidedPublisherApiKeyCorrect(providedPublisherApiKey);
VirtualStudy virtualStudy = sessionServiceRequestHandler.getVirtualStudyById(id);
return publishVirtualStudyData(virtualStudy.getData(), providedPublisherApiKey, typeOfCancerId, pmid);
publishVirtualStudy(id, typeOfCancerId, pmid);
return ResponseEntity.ok().build();
}

@DeleteMapping("/{id}")
Expand All @@ -98,6 +81,14 @@ public ResponseEntity<Void> retractVirtualStudy(
return ResponseEntity.ok().build();
}

private void publishVirtualStudy(String id, String typeOfCancerId, String pmid) {
VirtualStudy virtualStudyDataToPublish = sessionServiceRequestHandler.getVirtualStudyById(id);
VirtualStudyData virtualStudyData = virtualStudyDataToPublish.getData();
updateStudyMetadataFieldsIfSpecified(virtualStudyData, typeOfCancerId, pmid);
virtualStudyData.setUsers(Set.of(ALL_USERS));
sessionServiceRequestHandler.updateVirtualStudy(virtualStudyDataToPublish);
}

private void ensureProvidedPublisherApiKeyCorrect(String providedPublisherApiKey) {
if (requiredPublisherApiKey.isBlank()
|| !requiredPublisherApiKey.equals(providedPublisherApiKey)) {
Expand All @@ -120,15 +111,4 @@ private void updateStudyMetadataFieldsIfSpecified(VirtualStudyData virtualStudyD
}
}

private VirtualStudyData makeCopyForPublishing(VirtualStudyData virtualStudyData) {
VirtualStudyData virtualStudyDataToPublish = new VirtualStudyData();
virtualStudyDataToPublish.setName(virtualStudyData.getName());
virtualStudyDataToPublish.setDescription(virtualStudyData.getDescription());
virtualStudyDataToPublish.setStudies(virtualStudyData.getStudies());
virtualStudyDataToPublish.setStudyViewFilter(virtualStudyData.getStudyViewFilter());
virtualStudyDataToPublish.setTypeOfCancerId(virtualStudyData.getTypeOfCancerId());
virtualStudyDataToPublish.setPmid(virtualStudyData.getPmid());
virtualStudyDataToPublish.setUsers(Set.of(ALL_USERS));
return virtualStudyDataToPublish;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public class PublicVirtualStudiesIntegrationTest extends ContainerConfig {
static final ParameterizedTypeReference<List<VirtualStudy>> typeRef = new ParameterizedTypeReference<>() {
};

static String createdVsId;
static String publishedVsId;
static String virtualStudyId;

static final VirtualStudyData virtualStudyDataToSave = createTestVsData();

Expand Down Expand Up @@ -107,35 +106,32 @@ public void test2CreateVirtualStudy() {
assertThat(response2.getStatusCode().is2xxSuccessful()).isTrue();
VirtualStudy savedVs = response2.getBody();
assertThat(savedVs).isNotNull().hasFieldOrProperty("id").isNotNull();
createdVsId = savedVs.getId();
virtualStudyId = savedVs.getId();
}

@Test
public void test3PublishVirtualStudy() {
String url = CBIO_URL + "/api/public_virtual_studies/" + createdVsId + "?typeOfCancerId=acc&pmid=12345";
ResponseEntity<VirtualStudy> response3 = restTemplate.exchange(
String url = CBIO_URL + "/api/public_virtual_studies/" + virtualStudyId + "?typeOfCancerId=acc&pmid=12345";
ResponseEntity<Void> response3 = restTemplate.exchange(
url,
HttpMethod.POST,
null,
VirtualStudy.class);
Void.class);
assertThat(response3.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);

response3 = restTemplate.exchange(
url,
HttpMethod.POST,
new HttpEntity<>(null, invalidKeyContainingHeaders),
VirtualStudy.class);
Void.class);
assertThat(response3.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);

response3 = restTemplate.exchange(
url,
HttpMethod.POST,
new HttpEntity<>(null, validKeyContainingHeaders),
VirtualStudy.class);
Void.class);
assertThat(response3.getStatusCode().is2xxSuccessful()).isTrue();
VirtualStudy publishedVs = response3.getBody();
assertThat(publishedVs).isNotNull();
publishedVsId = publishedVs.getId();
}

@Test
Expand Down Expand Up @@ -163,21 +159,21 @@ public void test4ListJustPublishedStudy() {
@Test
public void test5UnpublishVirtualStudy() {
ResponseEntity<Object> response5 = restTemplate.exchange(
CBIO_URL + "/api/public_virtual_studies/" + publishedVsId,
CBIO_URL + "/api/public_virtual_studies/" + virtualStudyId,
HttpMethod.DELETE,
null,
Object.class);
assertThat(response5.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);

response5 = restTemplate.exchange(
CBIO_URL + "/api/public_virtual_studies/" + publishedVsId,
CBIO_URL + "/api/public_virtual_studies/" + virtualStudyId,
HttpMethod.DELETE,
new HttpEntity<>(null, invalidKeyContainingHeaders),
Object.class);
assertThat(response5.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);

response5 = restTemplate.exchange(
CBIO_URL + "/api/public_virtual_studies/" + publishedVsId,
CBIO_URL + "/api/public_virtual_studies/" + virtualStudyId,
HttpMethod.DELETE,
new HttpEntity<>(null, validKeyContainingHeaders),
Object.class);
Expand Down

0 comments on commit b8ee5e9

Please sign in to comment.