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
0ade7af7
Commit
0ade7af7
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
refactoring experimentApi to use Spring Data
parent
9de044a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/hbp/mip/controllers/ExperimentApi.java
+20
-39
20 additions, 39 deletions
src/main/java/org/hbp/mip/controllers/ExperimentApi.java
src/main/java/org/hbp/mip/repositories/ExperimentRepository.java
+3
-0
3 additions, 0 deletions
...n/java/org/hbp/mip/repositories/ExperimentRepository.java
with
23 additions
and
39 deletions
src/main/java/org/hbp/mip/controllers/ExperimentApi.java
+
20
−
39
View file @
0ade7af7
package
org.hbp.mip.controllers
;
import
com.google.common.collect.Iterables
;
import
com.google.gson.*
;
import
io.swagger.annotations.*
;
import
org.apache.log4j.Logger
;
...
...
@@ -21,6 +22,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.util.Iterator
;
import
java.util.UUID
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
...
...
@@ -209,53 +211,32 @@ public class ExperimentApi {
int
maxResultCount
,
String
modelSlug
)
{
/*List<Experiment> experiments = new LinkedList<>();
User
user
=
mipApplication
.
getUser
();
Iterable
<
Experiment
>
experiments
=
null
;
try {
Query hibernateQuery;
String baseQuery = "from Experiment as e WHERE ";
baseQuery += mine ? "e.createdBy = :user" : "(e.createdBy = :user OR e.shared is true)";
if (modelSlug == null || "".equals(modelSlug)) {
hibernateQuery = session.createQuery(baseQuery);
} else {
baseQuery += " AND e.model.slug = :slug";
hibernateQuery = session.createQuery(baseQuery);
hibernateQuery.setParameter("slug", modelSlug);
}
hibernateQuery.setParameter("user", user);
if (maxResultCount > 0)
hibernateQuery.setMaxResults(maxResultCount);
for (Object experiment: hibernateQuery.list()) {
if (experiment instanceof Experiment) { // should definitely be true
Experiment experiment1 = (Experiment) experiment;
// remove some fields because it is costly and not useful to send them over the network
experiment1.setResult(null);
experiment1.setAlgorithms(null);
experiment1.setValidations(null);
experiments.add(experiment1);
}
Iterable
<
Experiment
>
myExperiments
=
experimentRepository
.
findByUser
(
user
);
if
(!
mine
)
{
Iterable
<
Experiment
>
sharedExperiments
=
experimentRepository
.
findShared
(
true
);
experiments
=
Iterables
.
concat
(
myExperiments
,
sharedExperiments
);
}
}
} catch (Exception e) {
// 404 here probably
LOGGER.trace(e);
throw e;
} finally {
if(session.getTransaction() != null)
if
(
modelSlug
!=
null
&&
!
""
.
equals
(
modelSlug
))
{
for
(
Iterator
<
Experiment
>
i
=
myExperiments
.
iterator
();
i
.
hasNext
();
)
{
session.getTransaction().rollback();
Experiment
e
=
i
.
next
();
e
.
setResult
(
null
);
e
.
setAlgorithms
(
null
);
e
.
setValidations
(
null
);
if
(!
e
.
getModel
().
getSlug
().
equals
(
modelSlug
))
{
i
.
remove
();
}
}
}
return new ResponseEntity<>(gson.toJson(experiments), HttpStatus.OK);
*/
return
new
ResponseEntity
<>(
gson
.
toJson
(
experiments
),
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
""
,
HttpStatus
.
OK
);
}
private
ResponseEntity
<
String
>
doMarkExperimentAsShared
(
String
uuid
,
boolean
shared
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/hbp/mip/repositories/ExperimentRepository.java
+
3
−
0
View file @
0ade7af7
package
org.hbp.mip.repositories
;
import
org.hbp.mip.model.Experiment
;
import
org.hbp.mip.model.User
;
import
org.springframework.data.repository.CrudRepository
;
import
java.util.UUID
;
...
...
@@ -10,4 +11,6 @@ import java.util.UUID;
*/
public
interface
ExperimentRepository
extends
CrudRepository
<
Experiment
,
UUID
>
{
Iterable
<
Experiment
>
findByUser
(
User
user
);
Iterable
<
Experiment
>
findShared
(
Boolean
shared
);
}
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