From a11cfd6945902dec8a8c52e38448cc76f94d64be Mon Sep 17 00:00:00 2001 From: Pim van Nierop Date: Mon, 11 Oct 2021 14:36:17 +0200 Subject: [PATCH] REVERT ME: Remove the need for session service dependency. Pending PR https://github.com/cBioPortal/session-service/pull/45 --- pom.xml | 12 +-- portal/pom.xml | 4 + utils/pom.xml | 16 ++++ .../cbioportal/utils/removeme/Session.java | 90 +++++++++++++++++++ web/pom.xml | 18 ++-- .../web/SessionServiceController.java | 4 +- .../web/config/CustomObjectMapper.java | 2 +- .../web/parameter/CustomDataSession.java | 3 +- .../web/parameter/CustomGeneList.java | 3 +- .../web/parameter/PageSettings.java | 3 +- .../web/parameter/VirtualStudy.java | 3 +- .../web/studyview/CustomDataController.java | 7 +- .../web/util/CustomDataFilterApplier.java | 4 +- .../util/SessionServiceRequestHandler.java | 6 +- 14 files changed, 146 insertions(+), 29 deletions(-) create mode 100644 utils/src/main/java/org/cbioportal/utils/removeme/Session.java diff --git a/pom.xml b/pom.xml index bdfb71d72b1..26f0afa43e7 100644 --- a/pom.xml +++ b/pom.xml @@ -361,12 +361,12 @@ simple-java-bitly 1.1 - - com.github.cbioportal - session-service - model - v0.5.0 - + + + + + + com.googlecode.json-simple json-simple diff --git a/portal/pom.xml b/portal/pom.xml index 13abe9f1296..3645e1361f1 100644 --- a/portal/pom.xml +++ b/portal/pom.xml @@ -93,6 +93,10 @@ com.fasterxml.jackson.datatype jackson-datatype-jdk8 + + org.mongodb + bson + diff --git a/utils/pom.xml b/utils/pom.xml index 3ec17c20268..c76773eb18a 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -38,11 +38,27 @@ spring-boot-starter-test test + + org.springframework.boot + spring-boot-starter-validation + org.junit.vintage junit-vintage-engine test + + com.fasterxml.jackson.core + jackson-annotations + + + org.mongodb + bson + + + org.springframework.data + spring-data-commons + \ No newline at end of file diff --git a/utils/src/main/java/org/cbioportal/utils/removeme/Session.java b/utils/src/main/java/org/cbioportal/utils/removeme/Session.java new file mode 100644 index 00000000000..6cfb277654e --- /dev/null +++ b/utils/src/main/java/org/cbioportal/utils/removeme/Session.java @@ -0,0 +1,90 @@ +package org.cbioportal.utils.removeme; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonView; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import org.bson.Document; +import org.springframework.data.annotation.Id; +import org.springframework.util.DigestUtils; + +// TODO this class was taken from session service. The session service dependency had to be dropped +// since it forced cbioportal into autoconfiguration of mongoDB connections. +// When session service is updated reinstate the correct session service dependency. + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Session { + + public enum SessionType { + main_session, + virtual_study, + group, + comparison_session, + settings, + custom_data, + genomic_chart, + custom_gene_list + } + + @Id + private String id; + @NotNull + private String checksum; + @NotNull + private Object data; + @NotNull + @Size(min=3, message="source has a minimum length of 3") + private String source; + @NotNull + private SessionType type; + + + @JsonView(Session.Views.IdOnly.class) + public String getId() { + return id; + } + + public String getChecksum() { + return checksum; + } + + public void setData(Object data) { + if(data instanceof String) { + this.data = Document.parse((String)data); + } else { + this.data = data; + } + this.checksum = DigestUtils.md5DigestAsHex(this.data.toString().getBytes()); + } + + @JsonView(Session.Views.Full.class) + public Object getData() { + return data; + } + + public void setType(SessionType type) { + this.type = type; + } + + @JsonView(org.cbioportal.utils.removeme.Session.Views.Full.class) + public SessionType getType() { + return type; + } + + public void setSource(String source) { + this.source = source; + } + + @JsonView(Session.Views.Full.class) + public String getSource() { + return source; + } + + public static final class Views { + // show only id + public interface IdOnly {} + + // show all data + public interface Full extends Session.Views.IdOnly {} + } +} diff --git a/web/pom.xml b/web/pom.xml index 7f211b5408d..49a4222eb48 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -36,6 +36,10 @@ org.cbioportal model + + org.cbioportal + utils + org.cbioportal service @@ -54,14 +58,14 @@ commons-validator commons-validator + + + + + - com.github.cbioportal - session-service - model - - - com.googlecode.json-simple - json-simple + org.springframework.boot + spring-boot-starter-data-mongodb org.mongodb diff --git a/web/src/main/java/org/cbioportal/web/SessionServiceController.java b/web/src/main/java/org/cbioportal/web/SessionServiceController.java index 49e39d0ff5a..ff8732cc14f 100644 --- a/web/src/main/java/org/cbioportal/web/SessionServiceController.java +++ b/web/src/main/java/org/cbioportal/web/SessionServiceController.java @@ -11,8 +11,8 @@ import org.apache.commons.logging.LogFactory; import org.cbioportal.web.parameter.*; import org.cbioportal.web.util.SessionServiceRequestHandler; -import org.cbioportal.session_service.domain.Session; -import org.cbioportal.session_service.domain.SessionType; +import org.cbioportal.utils.removeme.Session; +import org.cbioportal.utils.removeme.Session.SessionType; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; diff --git a/web/src/main/java/org/cbioportal/web/config/CustomObjectMapper.java b/web/src/main/java/org/cbioportal/web/config/CustomObjectMapper.java index 58206b8a3fe..8056afa1952 100644 --- a/web/src/main/java/org/cbioportal/web/config/CustomObjectMapper.java +++ b/web/src/main/java/org/cbioportal/web/config/CustomObjectMapper.java @@ -63,7 +63,7 @@ import org.cbioportal.model.Sample; import org.cbioportal.model.SampleList; import org.cbioportal.model.TypeOfCancer; -import org.cbioportal.session_service.domain.Session; +import org.cbioportal.utils.removeme.Session; import org.cbioportal.web.CustomAttributeWithData; import org.cbioportal.web.mixin.CancerStudyMixin; import org.cbioportal.web.mixin.ClinicalAttributeCountMixin; diff --git a/web/src/main/java/org/cbioportal/web/parameter/CustomDataSession.java b/web/src/main/java/org/cbioportal/web/parameter/CustomDataSession.java index 54a0bf0a237..66f136b96b5 100644 --- a/web/src/main/java/org/cbioportal/web/parameter/CustomDataSession.java +++ b/web/src/main/java/org/cbioportal/web/parameter/CustomDataSession.java @@ -4,8 +4,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.cbioportal.session_service.domain.Session; -import org.cbioportal.session_service.domain.SessionType; +import org.cbioportal.utils.removeme.Session; import org.cbioportal.web.CustomAttributeWithData; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/web/src/main/java/org/cbioportal/web/parameter/CustomGeneList.java b/web/src/main/java/org/cbioportal/web/parameter/CustomGeneList.java index 101a401ca73..fbb9f2c9fe7 100644 --- a/web/src/main/java/org/cbioportal/web/parameter/CustomGeneList.java +++ b/web/src/main/java/org/cbioportal/web/parameter/CustomGeneList.java @@ -5,8 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.cbioportal.session_service.domain.Session; -import org.cbioportal.session_service.domain.SessionType; +import org.cbioportal.utils.removeme.Session; import java.io.IOException; diff --git a/web/src/main/java/org/cbioportal/web/parameter/PageSettings.java b/web/src/main/java/org/cbioportal/web/parameter/PageSettings.java index df577eb88fb..91944309eb1 100644 --- a/web/src/main/java/org/cbioportal/web/parameter/PageSettings.java +++ b/web/src/main/java/org/cbioportal/web/parameter/PageSettings.java @@ -4,8 +4,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.cbioportal.session_service.domain.Session; -import org.cbioportal.session_service.domain.SessionType; +import org.cbioportal.utils.removeme.Session; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/web/src/main/java/org/cbioportal/web/parameter/VirtualStudy.java b/web/src/main/java/org/cbioportal/web/parameter/VirtualStudy.java index 58367283390..923a98d68a2 100644 --- a/web/src/main/java/org/cbioportal/web/parameter/VirtualStudy.java +++ b/web/src/main/java/org/cbioportal/web/parameter/VirtualStudy.java @@ -4,12 +4,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.cbioportal.session_service.domain.Session; -import org.cbioportal.session_service.domain.SessionType; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.ObjectMapper; +import org.cbioportal.utils.removeme.Session; @JsonIgnoreProperties(ignoreUnknown = true) public class VirtualStudy extends Session { diff --git a/web/src/main/java/org/cbioportal/web/studyview/CustomDataController.java b/web/src/main/java/org/cbioportal/web/studyview/CustomDataController.java index 90891a75f23..dc2712255c6 100644 --- a/web/src/main/java/org/cbioportal/web/studyview/CustomDataController.java +++ b/web/src/main/java/org/cbioportal/web/studyview/CustomDataController.java @@ -1,5 +1,8 @@ package org.cbioportal.web.studyview; +import static org.cbioportal.utils.removeme.Session.*; + + import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -14,7 +17,6 @@ import org.cbioportal.model.ClinicalDataCountItem; import org.cbioportal.model.Patient; import org.cbioportal.service.PatientService; -import org.cbioportal.session_service.domain.SessionType; import org.cbioportal.web.config.annotation.InternalApi; import org.cbioportal.web.parameter.ClinicalDataCountFilter; import org.cbioportal.web.parameter.ClinicalDataFilter; @@ -83,7 +85,8 @@ public ResponseEntity> fetchCustomDataCounts( List> postFutures = attributes.stream().map(clinicalDataFilter -> { return CompletableFuture.supplyAsync(() -> { try { - return (CustomDataSession) sessionServiceRequestHandler.getSession(SessionType.custom_data, + return (CustomDataSession) sessionServiceRequestHandler.getSession( + SessionType.custom_data, clinicalDataFilter.getAttributeId()); } catch (Exception e) { return null; diff --git a/web/src/main/java/org/cbioportal/web/util/CustomDataFilterApplier.java b/web/src/main/java/org/cbioportal/web/util/CustomDataFilterApplier.java index ff3ab72a65f..26eadaa490f 100644 --- a/web/src/main/java/org/cbioportal/web/util/CustomDataFilterApplier.java +++ b/web/src/main/java/org/cbioportal/web/util/CustomDataFilterApplier.java @@ -1,5 +1,8 @@ package org.cbioportal.web.util; +import static org.cbioportal.utils.removeme.Session.*; + + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -11,7 +14,6 @@ import org.apache.commons.collections.map.MultiKeyMap; import org.cbioportal.service.ClinicalDataService; import org.cbioportal.service.PatientService; -import org.cbioportal.session_service.domain.SessionType; import org.cbioportal.web.parameter.ClinicalDataFilter; import org.cbioportal.web.parameter.CustomDataSession; import org.cbioportal.web.parameter.SampleIdentifier; diff --git a/web/src/main/java/org/cbioportal/web/util/SessionServiceRequestHandler.java b/web/src/main/java/org/cbioportal/web/util/SessionServiceRequestHandler.java index 8985c316ca9..e6a4d5e48a0 100644 --- a/web/src/main/java/org/cbioportal/web/util/SessionServiceRequestHandler.java +++ b/web/src/main/java/org/cbioportal/web/util/SessionServiceRequestHandler.java @@ -1,11 +1,13 @@ package org.cbioportal.web.util; +import static org.cbioportal.utils.removeme.Session.*; + + import java.nio.charset.Charset; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.cbioportal.session_service.domain.Session; -import org.cbioportal.session_service.domain.SessionType; +import org.cbioportal.utils.removeme.*; import org.cbioportal.web.parameter.CustomDataSession; import org.cbioportal.web.parameter.CustomGeneList; import org.cbioportal.web.parameter.PageSettings;