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
34ac118f
Commit
34ac118f
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
refactoring : try to reduce NPath complexity
parent
e691bd4f
No related branches found
Branches containing commit
Tags
2.6.8
Tags containing commit
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/ModelsApi.java
+50
-44
50 additions, 44 deletions
src/main/java/eu/hbp/mip/controllers/ModelsApi.java
with
50 additions
and
44 deletions
src/main/java/eu/hbp/mip/controllers/ModelsApi.java
+
50
−
44
View file @
34ac118f
...
...
@@ -118,72 +118,78 @@ public class ModelsApi {
model
.
setValid
(
false
);
}
// Ensure the title is unique
boolean
titleExists
=
true
;
for
(
int
i
=
1
;
titleExists
;
i
++)
ensureTitleUniqueness
(
model
);
ensureSlugUniqueness
(
model
);
Map
<
String
,
String
>
map
=
new
HashMap
<>(
model
.
getConfig
().
getTitle
());
map
.
put
(
"text"
,
model
.
getTitle
());
model
.
getConfig
().
setTitle
(
map
);
saveVariables
(
model
.
getQuery
().
getVariables
());
saveVariables
(
model
.
getQuery
().
getCovariables
());
saveVariables
(
model
.
getQuery
().
getGrouping
());
configRepository
.
save
(
model
.
getConfig
());
queryRepository
.
save
(
model
.
getQuery
());
datasetRepository
.
save
(
model
.
getDataset
());
modelRepository
.
save
(
model
);
LOGGER
.
info
(
"Model saved (also saved model.config and model.query)"
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
model
);
}
private
void
saveVariables
(
@RequestBody
@ApiParam
(
value
=
"Model to create"
,
required
=
true
)
List
<
Variable
>
variables
)
{
for
(
Variable
var
:
variables
)
{
String
title
=
model
.
getTitle
();
titleExists
=
modelRepository
.
countByTitle
(
title
)
>
0
;
if
(
titleExists
)
variableRepository
.
save
(
var
);
}
}
private
void
ensureSlugUniqueness
(
@RequestBody
@ApiParam
(
value
=
"Model to create"
,
required
=
true
)
Model
model
)
{
String
slug
=
createSlug
(
model
.
getTitle
());
boolean
slugExists
=
true
;
for
(
int
i
=
1
;
slugExists
;
i
++)
{
slugExists
=
modelRepository
.
exists
(
slug
);
if
(
slugExists
)
{
if
(
i
>
1
)
{
title
=
title
.
substring
(
0
,
title
.
length
()-
4
);
slug
=
slug
.
substring
(
0
,
slug
.
length
()-
2
);
}
model
.
setTitle
(
title
+
"
("
+
i
+
")"
)
;
slug
+
=
"
-"
+
i
;
}
model
.
setSlug
(
slug
);
}
}
// Create slug from
title
private
String
createSlug
(
@RequestBody
@ApiParam
(
value
=
"Model to create"
,
required
=
true
)
String
title
)
{
String
slug
;
try
{
slug
=
new
Slugify
().
slugify
(
model
.
getT
itle
()
);
slug
=
new
Slugify
().
slugify
(
t
itle
);
}
catch
(
IOException
e
)
{
slug
=
""
;
// Should never happen
LOGGER
.
trace
(
e
);
}
return
slug
;
}
// Ensure slug is unique
boolean
slug
Exists
=
true
;
for
(
int
i
=
1
;
slug
Exists
;
i
++)
private
void
ensureTitleUniqueness
(
@RequestBody
@ApiParam
(
value
=
"Model to create"
,
required
=
true
)
Model
model
)
{
boolean
title
Exists
=
true
;
for
(
int
i
=
1
;
title
Exists
;
i
++)
{
slugExists
=
modelRepository
.
exists
(
slug
);
if
(
slugExists
)
String
title
=
model
.
getTitle
();
titleExists
=
modelRepository
.
countByTitle
(
title
)
>
0
;
if
(
titleExists
)
{
if
(
i
>
1
)
{
slug
=
slug
.
substring
(
0
,
slug
.
length
()-
2
);
title
=
title
.
substring
(
0
,
title
.
length
()-
4
);
}
slug
+
=
"
-"
+
i
;
model
.
setTitle
(
title
+
"
("
+
i
+
")"
)
;
}
model
.
setSlug
(
slug
);
}
Map
<
String
,
String
>
map
=
new
HashMap
<>(
model
.
getConfig
().
getTitle
());
map
.
put
(
"text"
,
model
.
getTitle
());
model
.
getConfig
().
setTitle
(
map
);
for
(
Variable
var
:
model
.
getQuery
().
getVariables
())
{
variableRepository
.
save
(
var
);
}
for
(
Variable
var
:
model
.
getQuery
().
getCovariables
())
{
variableRepository
.
save
(
var
);
}
for
(
Variable
var
:
model
.
getQuery
().
getGrouping
())
{
variableRepository
.
save
(
var
);
}
configRepository
.
save
(
model
.
getConfig
());
queryRepository
.
save
(
model
.
getQuery
());
datasetRepository
.
save
(
model
.
getDataset
());
modelRepository
.
save
(
model
);
LOGGER
.
info
(
"Model saved (also saved model.config and model.query)"
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
model
);
}
@ApiOperation
(
value
=
"Get a model"
,
response
=
Model
.
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