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
cbe45073
Commit
cbe45073
authored
9 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
add copy Model
parent
f774ac0f
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
README.md
+0
-1
0 additions, 1 deletion
README.md
src/main/java/org/hbp/mip/controllers/ModelsApi.java
+84
-47
84 additions, 47 deletions
src/main/java/org/hbp/mip/controllers/ModelsApi.java
with
84 additions
and
48 deletions
README.md
+
0
−
1
View file @
cbe45073
...
...
@@ -27,7 +27,6 @@ The API documentation is available at `<BASE URL>/swagger-ui.html`. A JSON versi
## BUGS
*
Copy a model;
*
When updating an article from the 'recent articles' list, bug with 'publish' state;
*
When updating a model the SVG is not updated (SVG updates when opening article editor);
*
Dynamic stats (users, articles, ...);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/hbp/mip/controllers/ModelsApi.java
+
84
−
47
View file @
cbe45073
...
...
@@ -21,6 +21,7 @@ import java.security.Principal;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Random
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
...
...
@@ -144,59 +145,57 @@ public class ModelsApi {
Model
model
=
(
Model
)
query
.
uniqueResult
();
session
.
getTransaction
().
commit
();
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransact
ion
();
query
=
session
.
createQuery
(
"from Query where id= :id"
);
query
.
setLong
(
"id"
,
model
.
getQuery
().
getId
()
);
org
.
hbp
.
mip
.
model
.
Query
q
=
(
org
.
hbp
.
mip
.
model
.
Query
)
query
.
uniqueResult
(
);
session
.
getTransaction
().
commi
t
();
List
<
Variable
>
vars
=
new
LinkedList
<>();
for
(
Variable
var
:
q
.
getVariables
()
)
{
Variable
v
=
new
Variable
();
v
.
setCode
(
var
.
getCode
());
vars
.
add
(
v
);
}
if
(
model
!=
null
)
{
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSess
ion
();
session
.
beginTransaction
(
);
query
=
session
.
createQuery
(
"from Query where id= :id"
);
query
.
setLong
(
"id"
,
model
.
get
Query
().
getId
()
);
org
.
hbp
.
mip
.
model
.
Query
q
=
(
org
.
hbp
.
mip
.
model
.
Query
)
query
.
uniqueResul
t
();
session
.
getTransaction
().
commit
();
List
<
Variable
>
var
s
=
new
LinkedList
<>
()
;
for
(
Variable
var
:
q
.
getVariables
())
{
Variable
v
=
new
Variable
();
v
.
setCode
(
var
.
getCode
());
vars
.
add
(
v
);
}
List
<
Variable
>
covs
=
new
LinkedList
<>();
for
(
Variable
cov
:
q
.
getCovariables
())
{
Variable
v
=
new
Variable
();
v
.
setCode
(
cov
.
getCode
());
covs
.
add
(
v
);
}
List
<
Variable
>
covs
=
new
LinkedList
<>();
for
(
Variable
cov
:
q
.
getCovariables
())
{
Variable
v
=
new
Variable
();
v
.
setCode
(
cov
.
getCode
());
covs
.
add
(
v
);
}
List
<
Variable
>
grps
=
new
LinkedList
<>();
for
(
Variable
grp
:
q
.
getGrouping
())
{
Variable
v
=
new
Variable
();
v
.
setCode
(
grp
.
getCode
());
grps
.
add
(
v
);
}
List
<
Variable
>
grps
=
new
LinkedList
<>();
for
(
Variable
grp
:
q
.
getGrouping
())
{
Variable
v
=
new
Variable
();
v
.
setCode
(
grp
.
getCode
());
grps
.
add
(
v
);
}
List
<
Filter
>
fltrs
=
new
LinkedList
<>();
for
(
Filter
fltr
:
q
.
getFilters
())
{
Filter
f
=
new
Filter
();
f
.
setId
(
fltr
.
getId
());
f
.
setOperator
(
fltr
.
getOperator
());
f
.
setValues
(
fltr
.
getValues
());
f
.
setVariable
(
fltr
.
getVariable
());
fltrs
.
add
(
f
);
}
List
<
Filter
>
fltrs
=
new
LinkedList
<>();
for
(
Filter
fltr
:
q
.
getFilters
())
{
Filter
f
=
new
Filter
();
f
.
setId
(
fltr
.
getId
());
f
.
setOperator
(
fltr
.
getOperator
());
f
.
setValues
(
fltr
.
getValues
());
f
.
setVariable
(
fltr
.
getVariable
());
fltrs
.
add
(
f
);
}
org
.
hbp
.
mip
.
model
.
Query
myQuery
=
new
org
.
hbp
.
mip
.
model
.
Query
();
myQuery
.
setId
(
q
.
getId
());
myQuery
.
setVariables
(
vars
);
myQuery
.
setCovariables
(
covs
);
myQuery
.
setGrouping
(
grps
);
myQuery
.
setFilters
(
fltrs
);
org
.
hbp
.
mip
.
model
.
Query
myQuery
=
new
org
.
hbp
.
mip
.
model
.
Query
();
myQuery
.
setId
(
q
.
getId
());
myQuery
.
setVariables
(
vars
);
myQuery
.
setCovariables
(
covs
);
myQuery
.
setGrouping
(
grps
);
myQuery
.
setFilters
(
fltrs
);
model
.
setQuery
(
myQuery
);
model
.
setQuery
(
myQuery
);
Dataset
ds
=
CSVUtil
.
parseValues
(
DATA_FILE
,
model
.
getQuery
());
model
.
setDataset
(
ds
);
Dataset
ds
=
CSVUtil
.
parseValues
(
DATA_FILE
,
model
.
getQuery
());
model
.
setDataset
(
ds
);
}
return
new
ResponseEntity
<
Model
>(
HttpStatus
.
OK
).
ok
(
model
);
}
...
...
@@ -223,6 +222,44 @@ public class ModelsApi {
return
new
ResponseEntity
<
Void
>(
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"Copy a model"
,
response
=
Model
.
class
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Model copied"
),
@ApiResponse
(
code
=
404
,
message
=
"Not found"
)
})
@RequestMapping
(
value
=
"/{slug}/copies"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Model
>
copyAModel
(
@ApiParam
(
value
=
"slug"
,
required
=
true
)
@PathVariable
(
"slug"
)
String
slug
,
@RequestBody
@ApiParam
(
value
=
"Model to update"
,
required
=
true
)
Model
model
,
Principal
principal
)
throws
NotFoundException
{
// Get current user
User
user
=
MIPApplication
.
getUser
(
principal
);
// Set slug
String
originalSlug
=
model
.
getSlug
();
String
copySlug
;
do
{
copySlug
=
originalSlug
+
" copy_"
+
randomStr
(
20
);
}
while
(
getAModel
(
copySlug
)
==
null
);
model
.
setSlug
(
copySlug
);
// Save model into DB
Session
session
=
HibernateUtil
.
getSessionFactory
().
getCurrentSession
();
session
.
beginTransaction
();
session
.
save
(
model
);
session
.
getTransaction
().
commit
();
return
new
ResponseEntity
<
Model
>(
HttpStatus
.
OK
).
ok
(
model
);
}
private
String
randomStr
(
int
length
)
{
char
[]
chars
=
"abcdefghijklmnopqrstuvwxyz0123456789"
.
toCharArray
();
StringBuilder
sb
=
new
StringBuilder
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
char
c
=
chars
[
random
.
nextInt
(
chars
.
length
)];
sb
.
append
(
c
);
}
return
sb
.
toString
();
}
@ApiOperation
(
value
=
"Delete a model"
,
response
=
Void
.
class
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Model deleted"
)
})
...
...
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