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
322f305c
Commit
322f305c
authored
Mar 21, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move add method to repository
parent
e13e8aa7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
42 deletions
+16
-42
RegisterTeamsCommand.java
...honers/krakyournet/ctf/commands/RegisterTeamsCommand.java
+1
-1
Repository.java
.../telephoners/krakyournet/ctf/repositories/Repository.java
+15
-5
SolutionsRepository.java
...ers/krakyournet/ctf/repositories/SolutionsRepository.java
+0
-6
TasksRepository.java
...phoners/krakyournet/ctf/repositories/TasksRepository.java
+0
-5
TeamsRepository.java
...phoners/krakyournet/ctf/repositories/TeamsRepository.java
+0
-13
UsersRepository.java
...phoners/krakyournet/ctf/repositories/UsersRepository.java
+0
-12
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/commands/RegisterTeamsCommand.java
View file @
322f305c
...
@@ -20,7 +20,7 @@ public class RegisterTeamsCommand extends ConfiguredCommand<ApplicationConfigura
...
@@ -20,7 +20,7 @@ public class RegisterTeamsCommand extends ConfiguredCommand<ApplicationConfigura
super
(
COMMAND_NAME
,
COMMAND_DESCRIPTION
);
super
(
COMMAND_NAME
,
COMMAND_DESCRIPTION
);
}
}
private
void
initializeTasks
(
ApplicationConfiguration
applicationConfiguration
,
Injector
injector
)
private
void
initializeTasks
(
ApplicationConfiguration
applicationConfiguration
,
Injector
injector
)
throws
ClassNotFoundException
{
{
TeamsRepository
teamsRepository
=
injector
.
getInstance
(
TeamsRepository
.
class
);
TeamsRepository
teamsRepository
=
injector
.
getInstance
(
TeamsRepository
.
class
);
UsersRepository
usersRepository
=
injector
.
getInstance
(
UsersRepository
.
class
);
UsersRepository
usersRepository
=
injector
.
getInstance
(
UsersRepository
.
class
);
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/Repository.java
View file @
322f305c
...
@@ -4,10 +4,10 @@ import org.mongodb.morphia.Datastore;
...
@@ -4,10 +4,10 @@ import org.mongodb.morphia.Datastore;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.util.List
;
import
java.util.List
;
public
abstract
class
Repository
<
T
>
{
public
abstract
class
Repository
<
T
>
{
protected
Datastore
datastore
;
protected
Datastore
datastore
;
@Inject
@Inject
...
@@ -21,10 +21,20 @@ public abstract class Repository<T> {
...
@@ -21,10 +21,20 @@ public abstract class Repository<T> {
}
}
abstract
List
<
T
>
getAll
();
abstract
List
<
T
>
getAll
();
abstract
void
add
(
T
t
);
//todo: the same for add
public
void
add
(
T
item
)
{
datastore
.
save
(
item
);
}
Class
getRepositoryType
()
throws
ClassNotFoundException
{
return
Class
.
forName
((((
ParameterizedType
)
this
.
getClass
().
getGenericSuperclass
())
.
getActualTypeArguments
()[
0
]).
getTypeName
());
}
public
void
clean
()
throws
ClassNotFoundException
public
void
clean
()
throws
ClassNotFoundException
{
{
Type
type
=
((
ParameterizedType
)
this
.
getClass
().
getGenericSuperclass
()).
getActualTypeArguments
()[
0
];
datastore
.
getCollection
(
getRepositoryType
()).
drop
();
datastore
.
getCollection
(
Class
.
forName
(
type
.
getTypeName
())).
drop
();
}
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/SolutionsRepository.java
View file @
322f305c
...
@@ -30,12 +30,6 @@ public class SolutionsRepository extends Repository<Solution>
...
@@ -30,12 +30,6 @@ public class SolutionsRepository extends Repository<Solution>
return
datastore
.
createQuery
(
Solution
.
class
).
asList
();
return
datastore
.
createQuery
(
Solution
.
class
).
asList
();
}
}
public
void
add
(
Solution
solution
)
{
//todo
datastore
.
save
(
solution
);
//todo: error handling?
//todo: do not add if already exists
}
public
List
<
Solution
>
getByTeam
(
Team
team
)
public
List
<
Solution
>
getByTeam
(
Team
team
)
{
{
//todo: merge with upper
//todo: merge with upper
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/TasksRepository.java
View file @
322f305c
...
@@ -58,11 +58,6 @@ public class TasksRepository extends Repository<Task>
...
@@ -58,11 +58,6 @@ public class TasksRepository extends Repository<Task>
return
datastore
.
createQuery
(
Task
.
class
).
asList
();
return
datastore
.
createQuery
(
Task
.
class
).
asList
();
}
}
public
void
add
(
Task
task
)
{
datastore
.
save
(
task
);
}
//todo: refactor?
//todo: refactor?
public
Map
<
List
<
String
>,
Integer
>
getUserFlagsHashes
(
String
username
)
public
Map
<
List
<
String
>,
Integer
>
getUserFlagsHashes
(
String
username
)
{
{
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/TeamsRepository.java
View file @
322f305c
...
@@ -47,17 +47,4 @@ public class TeamsRepository extends Repository<Team>
...
@@ -47,17 +47,4 @@ public class TeamsRepository extends Repository<Team>
{
{
return
datastore
.
createQuery
(
Team
.
class
).
asList
();
return
datastore
.
createQuery
(
Team
.
class
).
asList
();
}
}
//todo: move to interface
//todo: use default as interface-implemented methods
public
void
add
(
Team
team
)
{
datastore
.
save
(
team
);
}
//todo: move clean to upper class?
public
void
clean
()
{
datastore
.
getCollection
(
Team
.
class
).
drop
();
}
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/UsersRepository.java
View file @
322f305c
...
@@ -3,7 +3,6 @@ package com.telephoners.krakyournet.ctf.repositories;
...
@@ -3,7 +3,6 @@ package com.telephoners.krakyournet.ctf.repositories;
import
com.google.inject.Inject
;
import
com.google.inject.Inject
;
import
com.google.inject.Singleton
;
import
com.google.inject.Singleton
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.User
;
import
com.telephoners.krakyournet.ctf.beans.tasks.Task
;
import
io.dropwizard.auth.basic.BasicCredentials
;
import
io.dropwizard.auth.basic.BasicCredentials
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.binary.Hex
;
import
org.mongodb.morphia.Datastore
;
import
org.mongodb.morphia.Datastore
;
...
@@ -28,17 +27,6 @@ public class UsersRepository extends Repository<User>
...
@@ -28,17 +27,6 @@ public class UsersRepository extends Repository<User>
}
}
}
}
public
void
add
(
User
user
)
{
datastore
.
save
(
user
);
}
@Override
public
void
clean
()
{
datastore
.
getCollection
(
User
.
class
).
drop
();
}
public
User
getUserByName
(
String
username
)
public
User
getUserByName
(
String
username
)
{
{
return
datastore
.
createQuery
(
User
.
class
)
return
datastore
.
createQuery
(
User
.
class
)
...
...
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