From 0233221c8ddc576324a109dc7ee7dd5da0811c2b Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 28 Aug 2018 08:34:07 +0200 Subject: [PATCH] Adding retrieval methods. --- .../nl/andrewlalis/git_api/GithubManager.java | 5 ++-- .../andrewlalis/model/database/Database.java | 30 +++++++++++++++---- .../executables/GenerateAssignmentsRepo.java | 16 ++++++++++ .../executables/GenerateStudentRepos.java | 12 ++++++++ .../andrewlalis/ui/view/InitializerApp.java | 1 - 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateAssignmentsRepo.java create mode 100644 src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateStudentRepos.java diff --git a/src/main/java/nl/andrewlalis/git_api/GithubManager.java b/src/main/java/nl/andrewlalis/git_api/GithubManager.java index 6d543bf..d188e53 100644 --- a/src/main/java/nl/andrewlalis/git_api/GithubManager.java +++ b/src/main/java/nl/andrewlalis/git_api/GithubManager.java @@ -87,7 +87,7 @@ public class GithubManager { * @param allTeachingAssistants A team consisting of all teaching assistants. * @throws IOException If an HTTP request failed. */ - private void setupAssignmentsRepo(String assignmentsRepoName, String description, TATeam allTeachingAssistants) throws IOException { + public void setupAssignmentsRepo(String assignmentsRepoName, String description, TATeam allTeachingAssistants) throws IOException { // Check if the repository already exists. GHRepository existingRepo = this.organization.getRepository(assignmentsRepoName); if (existingRepo != null) { @@ -128,7 +128,7 @@ public class GithubManager { * @param prefix The prefix to append to the front of the repo name. * @throws IOException If an HTTP request fails. */ - private void setupStudentTeam(StudentTeam team, TATeam taTeam, String prefix) throws IOException { + public void setupStudentTeam(StudentTeam team, TATeam taTeam, String prefix) throws IOException { // First check that the assignments repo exists, otherwise no invitations can be sent. if (this.assignmentsRepo == null) { logger.warning("Assignments repository must be created before student repositories."); @@ -219,6 +219,7 @@ public class GithubManager { protectionBuilder.enable(); logger.fine("Protected master branch of repository: " + repo.getName()); } catch (IOException e) { + logger.severe("Could not protect master branch of repository: " + repo.getName()); e.printStackTrace(); } } diff --git a/src/main/java/nl/andrewlalis/model/database/Database.java b/src/main/java/nl/andrewlalis/model/database/Database.java index d8878c3..180124e 100644 --- a/src/main/java/nl/andrewlalis/model/database/Database.java +++ b/src/main/java/nl/andrewlalis/model/database/Database.java @@ -2,10 +2,7 @@ package nl.andrewlalis.model.database; import nl.andrewlalis.model.*; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; +import java.sql.*; import java.util.List; import java.util.logging.Logger; @@ -60,7 +57,7 @@ public class Database { try { statement.execute(); } catch (SQLException e) { - logger.severe("SQLException while executing prepared statement: " + statement.toString() + ". Code: " + e.getErrorCode()); + logger.severe("SQLException while executing prepared statement:\n" + statement.toString() + "\nCode: " + e.getErrorCode()); return false; } } @@ -70,7 +67,7 @@ public class Database { try { statement.execute(); } catch (SQLException e) { - logger.severe("SQLException while inserting into table: " + statement.toString() + ". Code: " + e.getErrorCode()); + logger.severe("SQLException while inserting into table:\n" + statement.toString() + "\nCode: " + e.getErrorCode()); return false; } } @@ -102,6 +99,25 @@ public class Database { } } + private Student retrieveStudent(int id) { + + } + + private Person retrievePerson(int id) { + try { + logger.finest("Retrieving person (id=" + id + ")."); + String sql = "SELECT * FROM persons WHERE id=?"; + PreparedStatement stmt = this.connection.prepareStatement(sql); + stmt.setInt(1, id); + ResultSet result = stmt.executeQuery(); + Person p = new Person(id, result.getString("name"), result.getString("email_address"), result.getString("github_username")); + } catch (SQLException e) { + logger.severe("SQL Exception while retrieving Person.\n" + e.getMessage()); + e.printStackTrace(); + return false; + } + } + /** * Stores a teaching assistant without a team. * @param ta The teaching assistant to store. @@ -129,6 +145,7 @@ public class Database { stmt.execute(); return true; } catch (SQLException e) { + logger.severe("SQL Exception while inserting TeachingAssistant.\n" + e.getMessage()); e.printStackTrace(); return false; } @@ -202,6 +219,7 @@ public class Database { stmt.execute(); return true; } catch (SQLException e) { + logger.severe("SQL Exception while inserting Student into database.\n" + e.getMessage()); e.printStackTrace(); return false; } diff --git a/src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateAssignmentsRepo.java b/src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateAssignmentsRepo.java new file mode 100644 index 0000000..d09d887 --- /dev/null +++ b/src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateAssignmentsRepo.java @@ -0,0 +1,16 @@ +package nl.andrewlalis.ui.control.command.executables; + +import nl.andrewlalis.git_api.GithubManager; + +/** + * Generates the assignments repository, with the supplied github manager, as well as the following extra arguments: + */ +public class GenerateAssignmentsRepo extends GithubExecutable { + + @Override + protected boolean executeWithManager(GithubManager manager, String[] args) { + + manager.setupAssignmentsRepo(args[0], args[1], ); + } + +} diff --git a/src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateStudentRepos.java b/src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateStudentRepos.java new file mode 100644 index 0000000..41f7975 --- /dev/null +++ b/src/main/java/nl/andrewlalis/ui/control/command/executables/GenerateStudentRepos.java @@ -0,0 +1,12 @@ +package nl.andrewlalis.ui.control.command.executables; + +import nl.andrewlalis.git_api.GithubManager; + +public class GenerateStudentRepos extends GithubExecutable { + + @Override + protected boolean executeWithManager(GithubManager manager, String[] args) { + return false; + } + +} diff --git a/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java b/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java index 78fe78f..e7384e5 100644 --- a/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java +++ b/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java @@ -37,7 +37,6 @@ public class InitializerApp extends JFrame { private JTextField assignmentsRepoField = new JTextField(); private JTextField teachingAssistantsField = new JTextField(); private JTextField studentRepoField = new JTextField(); - private JTextField teamSizeField = new JTextField(); /** * The executor responsible for performing meaningful actions.