Changed ReadStudentsFileToDB to just read to the memory organization object.

This commit is contained in:
Andrew Lalis 2018-08-30 22:05:17 +02:00
parent ab2414291f
commit 6d7efbe97f
2 changed files with 12 additions and 17 deletions

View File

@ -1,12 +1,11 @@
package nl.andrewlalis; package nl.andrewlalis;
import nl.andrewlalis.model.Organization; import nl.andrewlalis.model.Organization;
import nl.andrewlalis.model.database.Database;
import nl.andrewlalis.ui.control.command.CommandExecutor; import nl.andrewlalis.ui.control.command.CommandExecutor;
import nl.andrewlalis.ui.control.command.executables.ArchiveRepos; import nl.andrewlalis.ui.control.command.executables.ArchiveRepos;
import nl.andrewlalis.ui.control.command.executables.DefineTaTeams; import nl.andrewlalis.ui.control.command.executables.DefineTaTeams;
import nl.andrewlalis.ui.control.command.executables.GenerateAssignmentsRepo; import nl.andrewlalis.ui.control.command.executables.GenerateAssignmentsRepo;
import nl.andrewlalis.ui.control.command.executables.ReadStudentsFileToDB; import nl.andrewlalis.ui.control.command.executables.ReadStudentsFile;
import nl.andrewlalis.ui.view.InitializerApp; import nl.andrewlalis.ui.view.InitializerApp;
import nl.andrewlalis.util.CommandLine; import nl.andrewlalis.util.CommandLine;
import nl.andrewlalis.util.Logging; import nl.andrewlalis.util.Logging;
@ -40,16 +39,12 @@ public class Main {
app.begin(); app.begin();
app.setAccessToken(userOptions.get("token")); app.setAccessToken(userOptions.get("token"));
Database db = new Database("database/initializer.sqlite"); // Initialize executable commands.
executor.registerCommand("read_students", new ReadStudentsFile(organization));
executor.registerCommand("read_students", new ReadStudentsFileToDB(db));
executor.registerCommand("archive_all", new ArchiveRepos()); executor.registerCommand("archive_all", new ArchiveRepos());
executor.registerCommand("generate_assignments", new GenerateAssignmentsRepo()); executor.registerCommand("generate_assignments", new GenerateAssignmentsRepo());
executor.registerCommand("define_ta_teams", new DefineTaTeams(app)); executor.registerCommand("define_ta_teams", new DefineTaTeams(app));
db.initialize();
logger.info("GithubManager for Github Repositories in Educational Organizations. Program initialized."); logger.info("GithubManager for Github Repositories in Educational Organizations. Program initialized.");
} }

View File

@ -1,7 +1,7 @@
package nl.andrewlalis.ui.control.command.executables; package nl.andrewlalis.ui.control.command.executables;
import nl.andrewlalis.model.Organization;
import nl.andrewlalis.model.StudentTeam; import nl.andrewlalis.model.StudentTeam;
import nl.andrewlalis.model.database.Database;
import nl.andrewlalis.ui.control.command.Executable; import nl.andrewlalis.ui.control.command.Executable;
import nl.andrewlalis.util.FileUtils; import nl.andrewlalis.util.FileUtils;
@ -9,24 +9,23 @@ import java.util.List;
/** /**
* Execute this class to read students from a supplied filename and teamsize, and store their * Execute this class to read students from a supplied filename and teamsize, and store their
* information in the database. * information in the application's organization model.
* Requires the following arguments: * Requires the following arguments:
* *
* 1. filename * 1. filename
* 2. teamsize * 2. teamsize
*/ */
public class ReadStudentsFileToDB implements Executable { public class ReadStudentsFile implements Executable {
/** /**
* The database used to store the students. * A reference to the application's organization model.
*/ */
private Database db; private Organization organization;
public ReadStudentsFileToDB(Database db) { public ReadStudentsFile(Organization organization) {
this.db = db; this.organization = organization;
} }
@Override @Override
public boolean execute(String[] args) { public boolean execute(String[] args) {
if (args.length < 2) { if (args.length < 2) {
@ -38,6 +37,7 @@ public class ReadStudentsFileToDB implements Executable {
if (teams == null) { if (teams == null) {
return false; return false;
} }
return this.db.storeStudentTeams(teams); this.organization.setStudentTeams(teams);
return true;
} }
} }