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
4c300516
Commit
4c300516
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
refactoring in progress : return all variables from JSON
parent
3007ddc5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/hbp/mip/configuration/PersistenceConfiguration.java
+3
-0
3 additions, 0 deletions
...va/eu/hbp/mip/configuration/PersistenceConfiguration.java
src/main/java/eu/hbp/mip/controllers/VariablesApi.java
+28
-1
28 additions, 1 deletion
src/main/java/eu/hbp/mip/controllers/VariablesApi.java
with
31 additions
and
1 deletion
src/main/java/eu/hbp/mip/configuration/PersistenceConfiguration.java
+
3
−
0
View file @
4c300516
...
...
@@ -25,6 +25,9 @@ public class PersistenceConfiguration {
@Autowired
DataSource
dataSource
;
@Autowired
DataSource
variablesDatasource
;
@Bean
@DependsOn
(
"flyway"
)
public
LocalContainerEntityManagerFactoryBean
entityManagerFactory
()
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/eu/hbp/mip/controllers/VariablesApi.java
+
28
−
1
View file @
4c300516
...
...
@@ -6,6 +6,8 @@ package eu.hbp.mip.controllers;
import
com.google.gson.Gson
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.stream.JsonReader
;
import
eu.hbp.mip.model.Value
;
import
eu.hbp.mip.model.Variable
;
...
...
@@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import
java.io.BufferedReader
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.LinkedList
;
import
java.util.List
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
...
...
@@ -30,6 +33,8 @@ public class VariablesApi {
private
static
final
String
VARIABLES_FILE
=
"data/variables.json"
;
private
static
LinkedList
<
Variable
>
variables
;
@ApiOperation
(
value
=
"Get variables"
,
response
=
Variable
.
class
,
responseContainer
=
"List"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Success"
)
})
...
...
@@ -44,7 +49,29 @@ public class VariablesApi {
)
{
LOGGER
.
info
(
"Get variables"
);
return
ResponseEntity
.
ok
(
null
);
// TODO : findall
InputStream
is
=
Variable
.
class
.
getClassLoader
().
getResourceAsStream
(
VARIABLES_FILE
);
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
JsonObject
root
=
new
Gson
().
fromJson
(
new
JsonReader
(
br
),
JsonObject
.
class
);
variables
=
new
LinkedList
<>();
extractVariablesRecursive
(
root
);
return
ResponseEntity
.
ok
(
variables
);
}
private
static
void
extractVariablesRecursive
(
JsonObject
element
)
{
if
(
element
.
has
(
"groups"
)){
for
(
JsonElement
child
:
element
.
getAsJsonArray
(
"groups"
))
{
extractVariablesRecursive
(
child
.
getAsJsonObject
());
}
}
if
(
element
.
has
(
"variables"
)){
for
(
JsonElement
var
:
element
.
getAsJsonArray
(
"variables"
)){
variables
.
add
(
new
Gson
().
fromJson
(
var
,
Variable
.
class
));
}
}
}
@ApiOperation
(
value
=
"Get a variable"
,
response
=
Variable
.
class
)
...
...
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