Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
portal-backend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HBP Medical Informatics Platform
portal-backend
Commits
02dbfaf7
Commit
02dbfaf7
authored
7 years ago
by
Ludovic Claude
Browse files
Options
Downloads
Patches
Plain Diff
Use ApplicationStartupEvent to connect to Woken and fill the local db
parent
80161c39
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/hbp/mip/StartupTasks.java
+43
-0
43 additions, 0 deletions
src/main/java/eu/hbp/mip/StartupTasks.java
src/main/java/eu/hbp/mip/controllers/DatasetsApi.java
+2
-27
2 additions, 27 deletions
src/main/java/eu/hbp/mip/controllers/DatasetsApi.java
with
45 additions
and
27 deletions
src/main/java/eu/hbp/mip/StartupTasks.java
0 → 100644
+
43
−
0
View file @
02dbfaf7
package
eu.hbp.mip
;
import
eu.hbp.mip.controllers.DatasetsApi
;
import
eu.hbp.mip.model.Variable
;
import
eu.hbp.mip.repositories.VariableRepository
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.stereotype.Component
;
@Component
public
class
StartupTasks
implements
ApplicationListener
<
ApplicationReadyEvent
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
StartupTasks
.
class
);
@Autowired
private
VariableRepository
variableRepository
;
@Autowired
private
DatasetsApi
datasetsApi
;
@Override
public
void
onApplicationEvent
(
ApplicationReadyEvent
event
)
{
// Pre-fill the local variable repository with the list of datasets, interpreted here as variables
// (a bit like a categorical variable can be split into a set of variables (a.k.a one hot encoding in Data science) )
try
{
for
(
ch
.
chuv
.
lren
.
woken
.
messages
.
datasets
.
Dataset
dataset:
datasetsApi
.
fetchDatasets
())
{
final
String
code
=
dataset
.
dataset
().
code
();
Variable
v
=
variableRepository
.
findOne
(
code
);
if
(
v
==
null
)
{
v
=
new
Variable
(
code
);
variableRepository
.
save
(
v
);
}
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"Cannot initialise the variable repository. Is the connection to Woken working?"
,
e
);
}
LOGGER
.
info
(
"MIP Portal backend is ready!"
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/eu/hbp/mip/controllers/DatasetsApi.java
+
2
−
27
View file @
02dbfaf7
...
...
@@ -7,17 +7,13 @@ package eu.hbp.mip.controllers;
import
ch.chuv.lren.woken.messages.datasets.DatasetsQuery
;
import
ch.chuv.lren.woken.messages.datasets.DatasetsResponse
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonObject
;
import
eu.hbp.mip.akka.WokenClientController
;
import
eu.hbp.mip.model.Dataset
;
import
eu.hbp.mip.model.Variable
;
import
eu.hbp.mip.repositories.VariableRepository
;
import
io.swagger.annotations.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -25,10 +21,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.RestController
;
import
scala.Option
;
import
javax.annotation.PostConstruct
;
import
java.util.Set
;
import
java.util.stream.Stream
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
...
...
@@ -39,24 +32,6 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
public
class
DatasetsApi
extends
WokenClientController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DatasetsApi
.
class
);
private
static
final
Gson
gson
=
new
Gson
();
@Autowired
private
VariableRepository
variableRepository
;
@PostConstruct
public
void
init
()
throws
Exception
{
// Pre-fill the local variable repository with the list of datasets, interpreted here as variables
// (a bit like a categorical variable can be split into a set of variables (a.k.a one hot encoding in Data science) )
for
(
ch
.
chuv
.
lren
.
woken
.
messages
.
datasets
.
Dataset
dataset:
fetchDatasets
())
{
final
String
code
=
dataset
.
dataset
().
code
();
Variable
v
=
variableRepository
.
findOne
(
code
);
if
(
v
==
null
)
{
v
=
new
Variable
(
code
);
variableRepository
.
save
(
v
);
}
}
}
@ApiOperation
(
value
=
"Get dataset list"
,
response
=
Dataset
.
class
,
responseContainer
=
"List"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
)
...
...
@@ -66,7 +41,7 @@ public class DatasetsApi extends WokenClientController {
try
{
JsonArray
datasets
=
new
JsonArray
();
Stream
<
JsonObject
>
values
=
fetchDatasets
().
stream
().
map
(
d
->
{
fetchDatasets
().
stream
().
map
(
d
->
{
JsonObject
jsObject
=
new
JsonObject
();
jsObject
.
addProperty
(
"code"
,
d
.
dataset
().
code
());
jsObject
.
addProperty
(
"label"
,
d
.
label
());
...
...
@@ -83,7 +58,7 @@ public class DatasetsApi extends WokenClientController {
}
p
rivate
Set
<
ch
.
chuv
.
lren
.
woken
.
messages
.
datasets
.
Dataset
>
fetchDatasets
()
throws
Exception
{
p
ublic
Set
<
ch
.
chuv
.
lren
.
woken
.
messages
.
datasets
.
Dataset
>
fetchDatasets
()
throws
Exception
{
DatasetsResponse
result
=
askWoken
(
new
DatasetsQuery
(
Option
.
empty
()),
30
);
return
scala
.
collection
.
JavaConversions
.
setAsJavaSet
(
result
.
datasets
());
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment