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
b2f0ee8e
Commit
b2f0ee8e
authored
9 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
progress on REST services implementation
parent
7b0b8b2b
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/org/hbp/mip/MIPApplication.java
+38
-10
38 additions, 10 deletions
src/main/java/org/hbp/mip/MIPApplication.java
with
38 additions
and
10 deletions
src/main/java/org/hbp/mip/MIPApplication.java
+
38
−
10
View file @
b2f0ee8e
...
@@ -20,8 +20,6 @@
...
@@ -20,8 +20,6 @@
*/
*/
package
org.hbp.mip
;
package
org.hbp.mip
;
import
org.hbp.mip.mock.ArticleMock
;
import
org.hbp.mip.mock.ModelMock
;
import
org.hbp.mip.model.*
;
import
org.hbp.mip.model.*
;
import
org.hibernate.Session
;
import
org.hibernate.Session
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -82,7 +80,7 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
...
@@ -82,7 +80,7 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
public
List
<
Article
>
getArticles
()
{
public
List
<
Article
>
getArticles
()
{
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
session
.
beginTransaction
();
List
articles
=
session
.
createQuery
(
"from Article"
).
list
();
List
<
Article
>
articles
=
session
.
createQuery
(
"from Article"
).
list
();
session
.
getTransaction
().
commit
();
session
.
getTransaction
().
commit
();
return
articles
;
return
articles
;
}
}
...
@@ -90,13 +88,25 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
...
@@ -90,13 +88,25 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
@RequestMapping
(
value
=
"/articles/{slug}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/articles/{slug}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
public
Article
getArticle
(
@PathVariable
(
"slug"
)
String
slug
)
{
public
Article
getArticle
(
@PathVariable
(
"slug"
)
String
slug
)
{
return
new
ArticleMock
(
1
);
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
org
.
hibernate
.
Query
query
=
session
.
createQuery
(
"from Article where slug= :slug"
);
query
.
setString
(
"slug"
,
slug
);
Article
article
=
(
Article
)
query
.
uniqueResult
();
session
.
getTransaction
().
commit
();
return
article
;
}
}
@RequestMapping
(
value
=
"/datasets/{code}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/datasets/{code}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
public
Dataset
getDatasets
(
@PathVariable
(
"code"
)
String
code
)
{
public
Dataset
getDatasets
(
@PathVariable
(
"code"
)
String
code
)
{
return
null
;
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
org
.
hibernate
.
Query
query
=
session
.
createQuery
(
"from Dataset where code= :code"
);
query
.
setString
(
"code"
,
code
);
Dataset
ds
=
(
Dataset
)
query
.
uniqueResult
();
session
.
getTransaction
().
commit
();
return
ds
;
}
}
@RequestMapping
(
value
=
"/models"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/models"
,
method
=
RequestMethod
.
GET
)
...
@@ -104,7 +114,7 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
...
@@ -104,7 +114,7 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
public
List
<
Model
>
getModels
()
{
public
List
<
Model
>
getModels
()
{
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
session
.
beginTransaction
();
List
models
=
session
.
createQuery
(
"from Model"
).
list
();
List
<
Model
>
models
=
session
.
createQuery
(
"from Model"
).
list
();
session
.
getTransaction
().
commit
();
session
.
getTransaction
().
commit
();
return
models
;
return
models
;
}
}
...
@@ -112,7 +122,13 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
...
@@ -112,7 +122,13 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
@RequestMapping
(
value
=
"/models/{slug}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/models/{slug}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
public
Model
getModel
(
@PathVariable
(
"slug"
)
String
slug
)
{
public
Model
getModel
(
@PathVariable
(
"slug"
)
String
slug
)
{
return
new
ModelMock
(
1
);
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
org
.
hibernate
.
Query
query
=
session
.
createQuery
(
"from Model where slug= :slug"
);
query
.
setString
(
"slug"
,
slug
);
Model
model
=
(
Model
)
query
.
uniqueResult
();
session
.
getTransaction
().
commit
();
return
model
;
}
}
@RequestMapping
(
value
=
"/articles"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/articles"
,
method
=
RequestMethod
.
POST
)
...
@@ -132,13 +148,25 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
...
@@ -132,13 +148,25 @@ public class MIPApplication extends WebSecurityConfigurerAdapter {
@RequestMapping
(
value
=
"/models"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/models"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ResponseBody
public
Model
postModel
(
@RequestBody
Model
model
)
{
public
Model
postModel
(
@RequestBody
Model
model
)
{
return
new
ModelMock
(
1
);
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
model
.
setCreatedAt
(
new
Date
());
model
.
setSlug
(
model
.
getTitle
().
toLowerCase
());
session
.
save
(
model
);
session
.
getTransaction
().
commit
();
return
model
;
}
}
@RequestMapping
(
value
=
"/models/{slug}/copies"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/models/{slug}/copies"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ResponseBody
public
Model
postModelCopies
(
@PathVariable
(
"slug"
)
String
slug
)
{
public
Model
postModelCopies
(
@PathVariable
(
"slug"
)
String
slug
)
{
return
new
ModelMock
(
1
);
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
org
.
hibernate
.
Query
query
=
session
.
createQuery
(
"from Model where slug= :slug"
);
query
.
setString
(
"slug"
,
slug
);
Model
model
=
(
Model
)
query
.
uniqueResult
();
session
.
getTransaction
().
commit
();
return
model
;
}
}
@RequestMapping
(
value
=
"/queries/requests"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/queries/requests"
,
method
=
RequestMethod
.
POST
)
...
...
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