Skip to content

Commit 037f6f5

Browse files
authored
Merge pull request #78 from EMResearch/session-service
added session-service SUT
2 parents 645d784 + 86a1839 commit 037f6f5

File tree

36 files changed

+3096
-0
lines changed

36 files changed

+3096
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,6 @@ dotnet_3/em/embedded/rest/ScsDriver/generated-tests/
269269
/jdk_17_maven/em/embedded/grpc/signal-registration/target/
270270
/jdk_17_maven/em/external/grpc/signal-registration/target/
271271
/jdk_17_maven/em/external/web/spring-petclinic/target/
272+
/jdk_8_maven/cs/rest/original/session-service/target/
273+
/jdk_8_maven/em/embedded/rest/session-service/target/
274+
/jdk_8_maven/em/external/rest/session-service/target/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ More details (e.g., #LOCs and used databases) on these APIs can be found [in thi
7272

7373
### REST: Java/Kotlin
7474

75+
* Session Service (not-known license), [jdk_8_maven/cs/rest/original/session-service](jdk_8_maven/cs/rest/original/session-service), from [https://github.com/cBioPortal/session-service](https://github.com/cBioPortal/session-service)
76+
7577
* Bibliothek (MIT), [jdk_17_gradle/cs/rest/bibliothek](jdk_17_gradle/cs/rest/bibliothek), from [https://github.com/PaperMC/bibliothek](https://github.com/PaperMC/bibliothek)
7678

7779
* Reservations API (not-known license), [jdk_11_gradle/cs/rest/reservations-api](jdk_11_gradle/cs/rest/reservations-api), from [https://github.com/cyrilgavala/reservations-api](https://github.com/cyrilgavala/reservations-api)

jdk_8_maven/cs/rest/original/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<module>catwatch</module>
2020
<module>languagetool</module>
2121
<module>restcountries</module>
22+
<module>session-service</module>
2223
</modules>
2324

2425

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2019 The Hyve B.V.
3+
# This code is licensed under the GNU Affero General Public License (AGPL),
4+
# version 3, or (at your option) any later version.
5+
#
6+
7+
FROM maven:3-eclipse-temurin-11 as build
8+
COPY $PWD /session-service
9+
WORKDIR /session-service
10+
RUN mvn package -DskipTests -Dpackaging.type=jar
11+
12+
FROM eclipse-temurin:11
13+
# copy over target/session_service-x.y.z.jar ignore *-model.jar, that jar is
14+
# used by cbioportal/cbioportal to import the models
15+
COPY --from=build /session-service/target/*[0-9].jar /app.war
16+
CMD java ${JAVA_OPTS} -jar /app.war
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: SERVER_PORT=${PORT} java $JAVA_OPTS -Dspring.data.mongodb.uri=${MONGODB_URI} -jar target/*[0-9].jar
Lines changed: 334 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
2+
3+
# session-service
4+
5+
RESTful API to cBioPortal/cbioportal sessions in MongoDB.
6+
7+
Session information is stored in JSON, so this API generalizes to any JSON objects.
8+
9+
10+
## Run with Docker
11+
```
12+
docker-compose up
13+
```
14+
You can also run it in detached mode with:
15+
```
16+
docker-compose up -d
17+
```
18+
In that case, to stop it one runs:
19+
```
20+
docker-compose down
21+
```
22+
If you want to rebuild the session service image after having made changes in
23+
development:
24+
```
25+
docker-compose up --build
26+
```
27+
Check http://localhost:8080/info to confirm session service is running. It
28+
should show a version number.
29+
30+
Test whether a session can be created like this:
31+
32+
```
33+
curl -H "Content-Type: application/json" --user user:pass -X POST http://localhost:8080/api/sessions/test_portal/main_session --data '{"title": "my main portal session", "description": "this is an example"}'
34+
```
35+
36+
The mongo database port is not exposed by default. One can connect to the
37+
mongo database like this:
38+
```
39+
docker exec -it session-service_db_1 mongo mongodb://localhost:27017
40+
```
41+
42+
43+
44+
## Run without docker
45+
### Requirements
46+
47+
JDK 1.7 or later: http://www.oracle.com/technetwork/java/javase/downloads/index.html
48+
49+
Maven 3.0+: http://maven.apache.org/download.cgi
50+
51+
MongoDB: https://docs.mongodb.org/manual/
52+
53+
### Installation and setup
54+
55+
Create database 'session_service' using the 'mongo' shell interface to MongoDB:
56+
57+
```
58+
$ mongo
59+
60+
> use session_service
61+
```
62+
Clone repository, compile, run tests, and start server:
63+
```
64+
$ git clone https://github.com/cBioPortal/session-service.git
65+
66+
$ cd session-service
67+
68+
session-service$ mvn package -Dpackaging.type=jar && java -Dspring.data.mongodb.uri=mongodb://localhost:27017/session-service -jar target/session_service-0.1.0.jar
69+
```
70+
To generate war file with a configuration file:
71+
72+
```
73+
$ cd session-service
74+
75+
session-service$ mkdir src/main/resources/
76+
77+
session-service$ cp /path/to/myapp.config src/main/resources/
78+
79+
session-service$ mvn package
80+
```
81+
82+
An example properties file:
83+
84+
```
85+
spring.data.mongodb.database=session_service
86+
spring.data.mongodb.host=localhost
87+
spring.data.mongodb.port=27017
88+
```
89+
90+
To have a context root that is not "/", add to the properties file:
91+
92+
```
93+
server.contextPath=/session_service
94+
server.port=8080 # change this if u want to use a different port
95+
```
96+
97+
One can use session-service with or without basic authentication. It's
98+
disabled by default. To enable basic authentication set:
99+
100+
```
101+
security.basic.enabled=true
102+
spring.security.user.name=user
103+
spring.security.user.password=pass
104+
```
105+
106+
By default the server runs on port 8080. This can be overridden by setting the
107+
process's SERVER_PORT environment variable.
108+
109+
```
110+
session-service$ export set SERVER_PORT=8090; mvn package -Dpackaging.type=jar && java -Dspring.data.mongodb.uri=mongodb://localhost:27017/session-service -jar target/session_service-0.1.0.jar
111+
```
112+
113+
## Sentry support
114+
115+
Sentry is already included as a dependency of this project, one can add the following this [Sentry official documentation](https://docs.sentry.io/platforms/java/guides/spring-boot/configuration/#setting-the-dsn) to enable sentry.
116+
For example, for Run without docker, add the following when starting the server:
117+
```
118+
-Dsentry.dsn=https://examplePublicKey@o0.ingest.sentry.io/0
119+
```
120+
And example command for Run with docker also included in the docker-compoase.yaml file, please refer that command to enable sentry.
121+
122+
## API
123+
124+
Swagger documentation will be found here: http://[url]:[port]/swagger-ui.html e.g. http://localhost:8090/swagger-ui.html
125+
126+
If basic auth is enabled note that one should pass the username password to access these endpoints e.g. with curl:
127+
128+
```
129+
curl --user user:pass
130+
```
131+
132+
### Create
133+
134+
### Valid Type
135+
136+
| Type | Description |
137+
|---|---|
138+
| main_session | represent result's page query |
139+
| virtual_study | represent a subset for samples saved from study summary page |
140+
| group | similar to virtual study except its used in comparison page |
141+
| comparison_session | represent comparison page query |
142+
| settings | represent cbio page settings. page type is identified by a field `page` in it |
143+
| custom_data | holds study-view page custom charts data |
144+
| genomic_chart | represents genomic chart added by user in study-view page |
145+
| custom_gene_list | represents custom gene list added by user in query page |
146+
147+
#### POST http://localhost:8080/api/sessions/{source}/{type}/
148+
Creates a session. Returns status 200 and the session id in response body
149+
on success. The session is saved in a collection named {type}. Both
150+
source and type are saved in the session document. If a session with the same source, type,
151+
and data already exists in the database returns the session id of that session
152+
instead of creating a duplicate.
153+
154+
WARNING: This is case sensitive. You should always use the same case
155+
for source and type.
156+
157+
Example body for POST http://localhost:8080/api/sessions/msk_portal/main_session/
158+
```
159+
{"title": "my main portal session", "description": "this is an example"}
160+
```
161+
Example response:
162+
```
163+
{
164+
"id": "57167a52ef86d81afb415aba"
165+
}
166+
```
167+
If no JSON data passed in request body or an invalid type is sent returns 400 status
168+
with something like the following in the body:
169+
```
170+
{
171+
"timestamp": 1461093154793,
172+
"status": 400,
173+
"error": "Bad Request",
174+
"exception": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException",
175+
"message": "valid types are: main_session, virtual_study, group, comparison_session, custom_data, genomic_chart",
176+
"path": "/api/sessions/msk_portal/invalid_type/"
177+
}
178+
```
179+
Sending invalid JSON in the request body returns a 400 status
180+
with something like the following in the body:
181+
```
182+
{
183+
"timestamp": 1461090997119,
184+
"status": 400,
185+
"error": "Bad Request",
186+
"exception": "org.cbioportal.session_service.domain.exception.SessionInvalidException",
187+
"message": "\n{\"portal-session\": blah blah blah}\n ^",
188+
"path": "/api/sessions/msk_portal/main_session/"
189+
}
190+
```
191+
192+
### Read
193+
194+
#### GET http://localhost:8080/api/sessions/{source}/{type}/
195+
Returns all sessions for source and type. Returns "[]" if no sessions.
196+
Example response for GET http://localhost:8080/api/sessions/msk_portal/main_session/
197+
```
198+
[
199+
{
200+
"id": "57167a52ef86d81afb415aba",
201+
"data": {
202+
"title": "my main portal session",
203+
"description": "this is an example"
204+
},
205+
"source": "msk_portal",
206+
"type": "main_session"
207+
},
208+
{
209+
"id": "57167c69ef86fdfcec850342",
210+
"data": {
211+
"title": "my main portal session",
212+
"description": "this is another example"
213+
},
214+
"source": "msk_portal",
215+
"type": "main_session"
216+
}
217+
]
218+
```
219+
220+
#### GET http://localhost:8080/api/sessions/{source}/{type}/{id}
221+
Returns single session given source, type, and id.
222+
Example response for GET http://localhost:8080/api/sessions/msk_portal/main_session/57167a52ef86d81afb415aba
223+
```
224+
{
225+
"id": "57167a52ef86d81afb415aba",
226+
"data": {
227+
"title": "my main portal session",
228+
"description": "this is an example"
229+
},
230+
"source": "msk_portal",
231+
"type": "main_session"
232+
}
233+
```
234+
If no session is found returns status 404 with a request body like this:
235+
```
236+
{
237+
"timestamp": 1462379207301,
238+
"status": 404,
239+
"error": "Not Found",
240+
"exception": "org.cbioportal.session_service.service.exception.SessionNotFoundException",
241+
"message": "Session not found",
242+
"path": "/api/sessions/msk_portal/main_session/test"
243+
}
244+
```
245+
WARNING: This is case sensitive.
246+
GET http://localhost:8080/api/sessions/MSK_portal/main_session/57167a52ef86d81afb415aba
247+
and
248+
GET http://localhost:8080/api/sessions/msk_portal/Main_Session/57167a52ef86d81afb415aba
249+
are NOT equivalent.
250+
251+
#### GET http://localhost:8080/api/sessions/{source}/{type}/query?field={field}&value={value}
252+
Returns all sessions matching a query for source and type. Returns
253+
200 status on success.
254+
Example response for GET http://localhost:8080/api/sessions/msk_portal/main_session/query?field=data.title&value=my%20main%20portal%20session
255+
```
256+
[
257+
{
258+
"id": "57167c69ef86fdfcec850342",
259+
"data": {
260+
"title": "my main portal session",
261+
"description": "this is another example"
262+
},
263+
"source": "msk_portal",
264+
"type": "main_session"
265+
}
266+
]
267+
```
268+
269+
### Update
270+
271+
#### PUT http://localhost:8080/api/sessions/{source}/{type}/{id}
272+
Updates a session given the source, type, and id. Returns status 200
273+
on success with empty request body.
274+
Example body for PUT http://localhost:8080/api/sessions/msk_portal/main_session/57167a52ef86d81afb415aba
275+
```
276+
{
277+
"title": "my UPDATED main portal session",
278+
"description": "this is an example"
279+
}
280+
```
281+
If no JSON data passed in request body returns status 400 with a request
282+
body like this:
283+
```
284+
{
285+
"timestamp": 1461092375741,
286+
"status": 400,
287+
"error": "Bad Request",
288+
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
289+
"message": "Required request body is missing: public void org.cbioportal.session_service.web.SessionServiceController.updateSession(java.lang.String,java.lang.String,java.lang.String,java.lang.String)",
290+
"path": "/api/sessions/msk_portal/main_session/57167a52ef86d81afb415aba"
291+
}
292+
```
293+
If an invalid id is passed returns status 404 with a request body like this:
294+
```
295+
{
296+
"timestamp": 1462379078498,
297+
"status": 404,
298+
"error": "Not Found",
299+
"exception": "org.cbioportal.session_service.service.exception.SessionNotFoundException",
300+
"message": "Session not found",
301+
"path": "/api/sessions/msk_portal/main_session/test"
302+
}
303+
```
304+
Sending invalid JSON in the request body returns a 400 status
305+
with something like the following in the body:
306+
```
307+
{
308+
"timestamp": 1461092440979,
309+
"status": 400,
310+
"error": "Bad Request",
311+
"exception": "org.cbioportal.session_service.domain.exception.SessionInvalidException",
312+
"message": "\n{\n \"title\": \"my UPDATED main portal session\",\n \"description\": blah blah blah\n}\n ^",
313+
"path": "/api/sessions/msk_portal/main_session/57167a52ef86d81afb415aba"
314+
}
315+
```
316+
317+
### Delete
318+
319+
#### DELETE http://localhost:8080/api/sessions/{source}/{type}/{id}
320+
Deletes a session with source, type, and id.
321+
Returns 200 status on success with empty request body.
322+
Example URL for DELETE http://localhost:8080/api/sessions/msk_portal/main_session/57167c69ef86fdfcec850342
323+
324+
If an invalid id is passed returns status 404 with a request body like this:
325+
```
326+
{
327+
"timestamp": 1462379146105,
328+
"status": 404,
329+
"error": "Not Found",
330+
"exception": "org.cbioportal.session_service.service.exception.SessionNotFoundException",
331+
"message": "Session not found",
332+
"path": "/api/sessions/msk_portal/main_session/test"
333+
}
334+
```

0 commit comments

Comments
 (0)