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
8cb1d332
Commit
8cb1d332
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
add new version of request API (without data for now)
parent
19616828
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/RequestsApi.java
+87
-2
87 additions, 2 deletions
src/main/java/eu/hbp/mip/controllers/RequestsApi.java
with
87 additions
and
2 deletions
src/main/java/eu/hbp/mip/controllers/RequestsApi.java
+
87
−
2
View file @
8cb1d332
...
...
@@ -4,16 +4,27 @@
package
eu.hbp.mip.controllers
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
eu.hbp.mip.model.Dataset
;
import
eu.hbp.mip.model.Query
;
import
io.swagger.annotations.*
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
@RestController
...
...
@@ -23,16 +34,90 @@ public class RequestsApi {
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
RequestsApi
.
class
);
@Autowired
@Qualifier
(
"jdbcTemplate"
)
private
JdbcTemplate
jdbcTemplate
;
@ApiOperation
(
value
=
"Post a request"
,
response
=
Dataset
.
class
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Success"
)
})
@RequestMapping
(
method
=
RequestMethod
.
POST
)
@Deprecated
public
ResponseEntity
<
Datase
t
>
postRequests
(
public
ResponseEntity
<
Objec
t
>
postRequests
(
@RequestBody
@ApiParam
(
value
=
"Query to process"
,
required
=
true
)
Query
query
)
{
LOGGER
.
info
(
"Post a request"
);
return
ResponseEntity
.
ok
(
null
);
// TODO: Get data from second datasource
JsonObject
dataset
=
new
JsonObject
();
String
code
=
generateDSCode
(
query
);
Date
date
=
new
Date
();
List
<
String
>
variables
=
new
LinkedList
<>();
List
<
String
>
groupings
=
new
LinkedList
<>();
List
<
String
>
covariables
=
new
LinkedList
<>();
Map
<
String
,
LinkedList
<
Object
>>
data
=
new
HashMap
<>();
Gson
gson
=
new
Gson
();
JsonObject
q
=
gson
.
fromJson
(
gson
.
toJson
(
query
,
Query
.
class
),
JsonObject
.
class
);
JsonArray
queryVars
=
q
.
getAsJsonArray
(
"variables"
);
JsonArray
queryGrps
=
q
.
getAsJsonArray
(
"grouping"
);
JsonArray
queryCoVars
=
q
.
getAsJsonArray
(
"covariables"
);
List
<
String
>
allVars
=
new
LinkedList
<>();
for
(
JsonElement
var
:
queryVars
)
{
String
varCode
=
var
.
getAsJsonObject
().
get
(
"code"
).
getAsString
();
variables
.
add
(
varCode
);
allVars
.
add
(
varCode
);
}
for
(
JsonElement
var
:
queryGrps
)
{
String
varCode
=
var
.
getAsJsonObject
().
get
(
"code"
).
getAsString
();
groupings
.
add
(
varCode
);
allVars
.
add
(
varCode
);
}
for
(
JsonElement
var
:
queryCoVars
)
{
String
varCode
=
var
.
getAsJsonObject
().
get
(
"code"
).
getAsString
();
covariables
.
add
(
varCode
);
allVars
.
add
(
varCode
);
}
for
(
String
varCode
:
allVars
)
{
String
sqlQuery
=
"SELECT "
+
varCode
+
" FROM adni_merge"
;
for
(
Map
resultMap
:
jdbcTemplate
.
queryForList
(
sqlQuery
))
{
resultMap
.
get
(
varCode
);
}
}
dataset
.
addProperty
(
"code"
,
code
);
dataset
.
addProperty
(
"date"
,
date
.
getTime
());
dataset
.
add
(
"variable"
,
gson
.
toJsonTree
(
variables
));
dataset
.
add
(
"grouping"
,
gson
.
toJsonTree
(
groupings
));
dataset
.
add
(
"header"
,
gson
.
toJsonTree
(
covariables
));
dataset
.
add
(
"data"
,
new
Gson
().
toJsonTree
(
data
));
return
ResponseEntity
.
ok
(
new
Gson
().
fromJson
(
dataset
,
Object
.
class
));
}
private
String
generateDSCode
(
Query
query
)
{
String
prefix
=
"DS"
;
String
queryStr
=
Integer
.
toString
(
query
.
hashCode
());
Pattern
p
=
Pattern
.
compile
(
"@(\\w+)"
);
Matcher
m
=
p
.
matcher
(
queryStr
);
String
memId
;
if
(
m
.
find
())
{
memId
=
m
.
group
(
1
);
}
else
{
memId
=
Long
.
toString
(
new
Date
().
getTime
());
// "This should never happen"
}
return
prefix
+
memId
;
}
}
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