Commit aa63ac88 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

move getAll to repository

parent 322f305c
...@@ -23,7 +23,7 @@ public class RegisterTasksCommand extends ConfiguredCommand<ApplicationConfigura ...@@ -23,7 +23,7 @@ public class RegisterTasksCommand extends ConfiguredCommand<ApplicationConfigura
super(COMMAND_NAME, COMMAND_DESCRIPTION); super(COMMAND_NAME, COMMAND_DESCRIPTION);
} }
private void initializeTasks(ApplicationConfiguration applicationConfiguration, Injector injector) throws ClassNotFoundException private void initializeTasks(ApplicationConfiguration applicationConfiguration, Injector injector)
{ {
TasksRepository tasksRepository = injector.getInstance(TasksRepository.class); TasksRepository tasksRepository = injector.getInstance(TasksRepository.class);
......
...@@ -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) throws ClassNotFoundException private void initializeTasks(ApplicationConfiguration applicationConfiguration, Injector injector)
{ {
TeamsRepository teamsRepository = injector.getInstance(TeamsRepository.class); TeamsRepository teamsRepository = injector.getInstance(TeamsRepository.class);
UsersRepository usersRepository = injector.getInstance(UsersRepository.class); UsersRepository usersRepository = injector.getInstance(UsersRepository.class);
......
...@@ -20,21 +20,28 @@ public abstract class Repository<T> ...@@ -20,21 +20,28 @@ public abstract class Repository<T>
{ {
} }
abstract List<T> getAll();
public void add(T item) public void add(T item)
{ {
datastore.save(item); datastore.save(item);
} }
Class getRepositoryType() throws ClassNotFoundException public List<T> getAll()
{ {
return Class.forName((((ParameterizedType) this.getClass().getGenericSuperclass()) //todo: unchecked cast
.getActualTypeArguments()[0]).getTypeName()); return datastore.createQuery(getRepositoryType()).asList();
} }
public void clean() throws ClassNotFoundException public void clean()
{ {
datastore.getCollection(getRepositoryType()).drop(); datastore.getCollection(getRepositoryType()).drop();
} }
Class getRepositoryType() {
try {
return Class.forName((((ParameterizedType) this.getClass().getGenericSuperclass())
.getActualTypeArguments()[0]).getTypeName());
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Class not found");
}
}
} }
...@@ -25,11 +25,6 @@ public class SolutionsRepository extends Repository<Solution> ...@@ -25,11 +25,6 @@ public class SolutionsRepository extends Repository<Solution>
{ {
} }
public List<Solution> getAll()
{
return datastore.createQuery(Solution.class).asList();
}
public List<Solution> getByTeam(Team team) public List<Solution> getByTeam(Team team)
{ {
//todo: merge with upper //todo: merge with upper
......
...@@ -53,11 +53,6 @@ public class TasksRepository extends Repository<Task> ...@@ -53,11 +53,6 @@ public class TasksRepository extends Repository<Task>
.asList(); .asList();
} }
public List<Task> getAll()
{
return datastore.createQuery(Task.class).asList();
}
//todo: refactor? //todo: refactor?
public Map<List<String>, Integer> getUserFlagsHashes(String username) public Map<List<String>, Integer> getUserFlagsHashes(String username)
{ {
......
...@@ -42,9 +42,4 @@ public class TeamsRepository extends Repository<Team> ...@@ -42,9 +42,4 @@ public class TeamsRepository extends Repository<Team>
{ {
} }
public List<Team> getAll()
{
return datastore.createQuery(Team.class).asList();
}
} }
...@@ -41,10 +41,4 @@ public class UsersRepository extends Repository<User> ...@@ -41,10 +41,4 @@ public class UsersRepository extends Repository<User>
.field("password").equal(Hex.encodeHexString(messageDigest.digest(basicCredentials.getPassword().getBytes()))) .field("password").equal(Hex.encodeHexString(messageDigest.digest(basicCredentials.getPassword().getBytes())))
.get(); .get();
} }
@Override
public List getAll()
{
return null;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment