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
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);
......
......@@ -20,7 +20,7 @@ public class RegisterTeamsCommand extends ConfiguredCommand<ApplicationConfigura
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);
UsersRepository usersRepository = injector.getInstance(UsersRepository.class);
......
......@@ -20,21 +20,28 @@ public abstract class Repository<T>
{
}
abstract List<T> getAll();
public void add(T item)
{
datastore.save(item);
}
Class getRepositoryType() throws ClassNotFoundException
public List<T> getAll()
{
return Class.forName((((ParameterizedType) this.getClass().getGenericSuperclass())
.getActualTypeArguments()[0]).getTypeName());
//todo: unchecked cast
return datastore.createQuery(getRepositoryType()).asList();
}
public void clean() throws ClassNotFoundException
public void clean()
{
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>
{
}
public List<Solution> getAll()
{
return datastore.createQuery(Solution.class).asList();
}
public List<Solution> getByTeam(Team team)
{
//todo: merge with upper
......
......@@ -53,11 +53,6 @@ public class TasksRepository extends Repository<Task>
.asList();
}
public List<Task> getAll()
{
return datastore.createQuery(Task.class).asList();
}
//todo: refactor?
public Map<List<String>, Integer> getUserFlagsHashes(String username)
{
......
......@@ -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>
.field("password").equal(Hex.encodeHexString(messageDigest.digest(basicCredentials.getPassword().getBytes())))
.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