Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
36c55089
Commit
36c55089
authored
Feb 22, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implelemtn get all solutions endpoint group by task id
parent
37e4655a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
11 deletions
+82
-11
CTFApplication.java
service/src/main/java/CTFApplication.java
+3
-0
SolutionsResource.java
service/src/main/java/api/SolutionsResource.java
+53
-0
Solution.java
service/src/main/java/objects/Solution.java
+16
-2
SolutionsRepository.java
service/src/main/java/repositories/SolutionsRepository.java
+10
-9
No files found.
service/src/main/java/CTFApplication.java
View file @
36c55089
import
api.ProxyResource
;
import
api.SolutionsResource
;
import
api.TasksResource
;
import
api.TeamsResource
;
import
com.bazaarvoice.dropwizard.webjars.WebJarBundle
;
...
...
@@ -76,6 +77,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
environment
.
jersey
().
register
(
injector
.
getInstance
(
TeamsResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
TasksResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
ProxyResource
.
class
));
environment
.
jersey
().
register
(
injector
.
getInstance
(
SolutionsResource
.
class
));
//REGISTER AUTH
environment
.
jersey
().
register
(
new
AuthDynamicFeature
(
...
...
@@ -137,6 +139,7 @@ public class CTFApplication extends Application<ApplicationConfiguration> {
bind
(
TasksResource
.
class
).
toInstance
(
new
TasksResource
(
tasksRepository
));
bind
(
ProxyResource
.
class
).
toInstance
(
new
ProxyResource
());
bind
(
SolutionsResource
.
class
).
toInstance
(
new
SolutionsResource
(
solutionsRepository
));
}
});
...
...
service/src/main/java/api/SolutionsResource.java
0 → 100644
View file @
36c55089
package
api
;
import
objects.Solution
;
import
repositories.SolutionsRepository
;
import
javax.inject.Inject
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* Created by gpietrus on 16.02.16.
*/
@Path
(
value
=
"/solutions"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
class
SolutionsResource
{
private
SolutionsRepository
solutionsRepository
;
@Inject
public
SolutionsResource
(
SolutionsRepository
solutionsRepository
)
{
this
.
solutionsRepository
=
solutionsRepository
;
}
@GET
@Path
(
"/all"
)
//todo: refactor mapping
public
Map
<
String
,
List
<
String
>>
getTeamsSolutions
()
{
//todo: general refactor
return
solutionsRepository
.
getAll
()
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
new
Function
<
Solution
,
String
>()
{
@Override
public
String
apply
(
Solution
solution
)
{
return
solution
.
getTaskId
();
}
}))
.
entrySet
()
.
stream
()
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
entry
->
entry
.
getValue
().
stream
()
.
map
(
Solution:
:
getTeamId
)
.
collect
(
Collectors
.
toList
())
));
}
}
service/src/main/java/objects/Solution.java
View file @
36c55089
package
objects
;
import
com.google.common.collect.ImmutableMap
;
import
org.bson.Document
;
import
java.util.Map
;
...
...
@@ -16,9 +17,22 @@ public class Solution {
this
.
taskId
=
taskId
;
}
public
String
getTaskId
()
{
return
taskId
;
}
public
String
getTeamId
()
{
return
teamId
;
}
public
Solution
(
Document
document
)
{
this
.
taskId
=
document
.
get
(
"taskId"
).
toString
();
//todo: refactor mapping
this
.
teamId
=
document
.
get
(
"teamId"
).
toString
();
}
//todo: refactor mapping
public
Map
<
String
,
Object
>
toMap
()
{
return
ImmutableMap
.<
String
,
Object
>
builder
()
public
Map
<
String
,
String
>
toMap
()
{
return
ImmutableMap
.<
String
,
String
>
builder
()
.
put
(
"teamId"
,
teamId
)
.
put
(
"taskId"
,
taskId
)
.
build
();
...
...
service/src/main/java/repositories/SolutionsRepository.java
View file @
36c55089
...
...
@@ -2,9 +2,10 @@ package repositories;
import
database.MongoDBConnector
;
import
objects.Solution
;
import
org.bson.Document
;
import
javax.inject.Inject
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* Created by gpietrus on 20.02.2016.
...
...
@@ -21,15 +22,15 @@ public class SolutionsRepository implements Repository {
//
// }
//
public List<Solution> getAll() {
//
return mongoDBConnector.getCollection("solutions")
//
.stream()
//
.map(Solution::new)
//
.collect(Collectors.toList());
//
}
public
List
<
Solution
>
getAll
()
{
return
mongoDBConnector
.
getCollection
(
"solutions"
)
.
stream
()
.
map
(
Solution:
:
new
)
.
collect
(
Collectors
.
toList
());
}
public
void
add
(
Solution
solution
)
{
mongoDBConnector
.
addDocument
(
"solutions"
,
new
Document
(
solution
.
toMap
()));
public
void
add
(
Solution
solution
)
{
//todo
//
mongoDBConnector.addDocument("solutions", new Document(solution.toMap()));
}
public
void
clean
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment