Commit adcce1b7 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

implement register teams command

parent 012cb848
......@@ -6,6 +6,7 @@ import com.google.inject.Injector;
import com.mongodb.MongoClient;
import commands.PurgeDatabaseCommand;
import commands.RegisterTasksCommand;
import commands.RegisterTeamsCommand;
import core.ApplicationConfiguration;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
......@@ -37,6 +38,7 @@ public class CTFApplication extends Application<ApplicationConfiguration>
bootstrap.addBundle(new AssetsBundle("/assets", "/page", "index.html"));
bootstrap.addCommand(new PurgeDatabaseCommand());
bootstrap.addCommand(new RegisterTasksCommand());
bootstrap.addCommand(new RegisterTeamsCommand());
Stream.of("org.webjars.npm", "org.webjars.bower")
.map(WebJarBundle::new)
.forEach(bootstrap::addBundle);
......
package commands;
import com.google.inject.Guice;
import com.google.inject.Injector;
import core.ApplicationConfiguration;
import io.dropwizard.cli.ConfiguredCommand;
import io.dropwizard.setup.Bootstrap;
import modules.ApplicationModule;
import net.sourceforge.argparse4j.inf.Namespace;
import org.mongodb.morphia.Datastore;
import repositories.TeamsRepository;
public class RegisterTeamsCommand extends ConfiguredCommand<ApplicationConfiguration>
{
private static final String COMMAND_NAME = "registertasks";
private static final String COMMAND_DESCRIPTION = "Register tasks";
public RegisterTeamsCommand()
{
super(COMMAND_NAME, COMMAND_DESCRIPTION);
}
private void initializeTasks(ApplicationConfiguration applicationConfiguration, Injector injector)
{
Datastore datastore = injector.getInstance(Datastore.class);
TeamsRepository teamsRepository = injector.getInstance(TeamsRepository.class);
teamsRepository.clean();
applicationConfiguration.getTeams().forEach(team -> {
team.getMembers().stream().forEach(datastore::save); //todo: use usersrepostiroy to save?
datastore.save(team);
});
}
@Override
protected void run(Bootstrap<ApplicationConfiguration> bootstrap, Namespace namespace, ApplicationConfiguration applicationConfiguration) throws Exception
{
//todo: move and merge with app setup
Injector injector = Guice.createInjector(new ApplicationModule(applicationConfiguration));
initializeTasks(applicationConfiguration, injector);
}
}
......@@ -48,15 +48,6 @@ public class TeamsRepository implements Repository {
return datastore.createQuery(Team.class).asList();
}
//todo: move to command
public void initialize() {
this.clean();
applicationConfiguration.getTeams().forEach(team -> {
team.getMembers().stream().forEach(user -> datastore.save(user));
datastore.save(team);
});
}
//todo: move to interface
//todo: use default as interface-implemented methods
public void add(Team team) {
......
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