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
10138179
Commit
10138179
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
groups api is working
parent
1c6d584f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/eu/hbp/mip/controllers/GroupsApi.java
+29
-7
29 additions, 7 deletions
src/main/java/eu/hbp/mip/controllers/GroupsApi.java
with
29 additions
and
7 deletions
src/main/java/eu/hbp/mip/controllers/GroupsApi.java
+
29
−
7
View file @
10138179
...
...
@@ -5,13 +5,14 @@
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.
Variable
;
import
eu.hbp.mip.model.
Group
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponses
;
import
eu.hbp.mip.model.Group
;
import
org.apache.log4j.Logger
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -33,6 +34,8 @@ public class GroupsApi {
private
static
final
String
VARIABLES_FILE
=
"data/variables.json"
;
private
static
String
groups
;
@ApiOperation
(
value
=
"Get the root group (containing all subgroups)"
,
response
=
Group
.
class
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Success"
)
})
...
...
@@ -40,14 +43,33 @@ public class GroupsApi {
public
ResponseEntity
<
Object
>
getTheRootGroup
()
{
LOGGER
.
info
(
"Get root group and its whole sub-groups tree"
);
InputStream
is
=
Variable
.
class
.
getClassLoader
().
getResourceAsStream
(
VARIABLES_FILE
);
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
loadGroups
();
Object
hierarchy
=
new
Gson
().
fromJson
(
new
JsonReader
(
br
),
Object
.
class
);
return
ResponseEntity
.
ok
(
new
Gson
().
fromJson
(
groups
,
Object
.
class
));
}
private
static
void
loadGroups
()
{
if
(
groups
==
null
)
{
InputStream
is
=
VariablesApi
.
class
.
getClassLoader
().
getResourceAsStream
(
VARIABLES_FILE
);
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
BufferedReader
br
=
new
BufferedReader
(
isr
);
return
ResponseEntity
.
ok
(
hierarchy
);
JsonObject
root
=
new
Gson
().
fromJson
(
new
JsonReader
(
br
),
JsonObject
.
class
);
removeVariablesRecursive
(
root
);
groups
=
new
Gson
().
toJson
(
root
);
}
}
private
static
void
removeVariablesRecursive
(
JsonObject
element
)
{
if
(
element
.
has
(
"groups"
)){
for
(
JsonElement
child
:
element
.
getAsJsonArray
(
"groups"
))
{
removeVariablesRecursive
(
child
.
getAsJsonObject
());
}
}
if
(
element
.
has
(
"variables"
))
{
element
.
remove
(
"variables"
);
}
}
}
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