From 5c3ddc6e29d2615023835a72ee4870ac9f715f17 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 28 Aug 2018 15:06:28 +0200 Subject: [PATCH 1/2] Moved retrieval code to bottom of database file. --- .../andrewlalis/model/database/Database.java | 86 +++++++++---------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/java/nl/andrewlalis/model/database/Database.java b/src/main/java/nl/andrewlalis/model/database/Database.java index 14c8626..5ac46e9 100644 --- a/src/main/java/nl/andrewlalis/model/database/Database.java +++ b/src/main/java/nl/andrewlalis/model/database/Database.java @@ -100,49 +100,6 @@ public class Database { } } - /** - * Retrieves a list of preferred partners that each student has set. - * @param studentId The student id to search by. - * @return A list of student id's for all students that the given student wishes to be their partner. - */ - private List retrievePreferredPartners(int studentId) { - try { - logger.finest("Retrieving preferred partners of student: " + studentId); - String sql = "SELECT partner_id FROM student_preferred_partners WHERE student_id=?;"; - PreparedStatement stmt = this.connection.prepareStatement(sql); - stmt.setInt(1, studentId); - ResultSet results = stmt.executeQuery(); - List partners = new ArrayList<>(); - while (results.next()) { - partners.add(results.getInt(1)); - } - return partners; - } catch (SQLException e) { - logger.severe("SQL Exception while retrieving preferred partners of student: " + studentId + '\n' + e.getMessage()); - e.printStackTrace(); - return new ArrayList<>(); - } - } - - /** - * Retrieves a student by their id. - * @param id The id of the student (student number) - * @return The student corresponding to this number, or null if it could not be found. - */ - public Student retrieveStudent(int id) { - try { - String sql = "SELECT * FROM persons WHERE id=?"; - PreparedStatement stmt = this.connection.prepareStatement(sql); - stmt.setInt(1, id); - ResultSet result = stmt.executeQuery(); - return new Student(id, result.getString("name"), result.getString("email_address"), result.getString("github_username"), this.retrievePreferredPartners(id)); - } catch (SQLException e) { - logger.severe("SQL Exception while retrieving Student.\n" + e.getMessage()); - e.printStackTrace(); - return null; - } - } - /** * Stores a teaching assistant without a team. * @param ta The teaching assistant to store. @@ -258,4 +215,47 @@ public class Database { } } + /** + * Retrieves a list of preferred partners that each student has set. + * @param studentId The student id to search by. + * @return A list of student id's for all students that the given student wishes to be their partner. + */ + private List retrievePreferredPartners(int studentId) { + try { + logger.finest("Retrieving preferred partners of student: " + studentId); + String sql = "SELECT partner_id FROM student_preferred_partners WHERE student_id=?;"; + PreparedStatement stmt = this.connection.prepareStatement(sql); + stmt.setInt(1, studentId); + ResultSet results = stmt.executeQuery(); + List partners = new ArrayList<>(); + while (results.next()) { + partners.add(results.getInt(1)); + } + return partners; + } catch (SQLException e) { + logger.severe("SQL Exception while retrieving preferred partners of student: " + studentId + '\n' + e.getMessage()); + e.printStackTrace(); + return new ArrayList<>(); + } + } + + /** + * Retrieves a student by their id. + * @param id The id of the student (student number) + * @return The student corresponding to this number, or null if it could not be found. + */ + public Student retrieveStudent(int id) { + try { + String sql = "SELECT * FROM persons WHERE id=?"; + PreparedStatement stmt = this.connection.prepareStatement(sql); + stmt.setInt(1, id); + ResultSet result = stmt.executeQuery(); + return new Student(id, result.getString("name"), result.getString("email_address"), result.getString("github_username"), this.retrievePreferredPartners(id)); + } catch (SQLException e) { + logger.severe("SQL Exception while retrieving Student.\n" + e.getMessage()); + e.printStackTrace(); + return null; + } + } + } -- 2.34.1 From ef14733fa8e2d29eafe56bdaebfeaf3edcc9f0c3 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 28 Aug 2018 20:27:41 +0200 Subject: [PATCH 2/2] Added skeleton classes for defining TA teams. --- .../nl/andrewlalis/model/DatabaseObject.java | 9 +++++++++ .../command/executables/DefineTaTeams.java | 13 +++++++++++++ .../executables/ReadStudentsFileToDB.java | 3 +++ .../listeners/DefineTaTeamsListener.java | 18 ++++++++++++++++++ .../nl/andrewlalis/ui/view/InitializerApp.java | 12 +++--------- .../java/nl/andrewlalis/util/FileUtils.java | 1 - 6 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/main/java/nl/andrewlalis/model/DatabaseObject.java create mode 100644 src/main/java/nl/andrewlalis/ui/control/command/executables/DefineTaTeams.java create mode 100644 src/main/java/nl/andrewlalis/ui/control/listeners/DefineTaTeamsListener.java diff --git a/src/main/java/nl/andrewlalis/model/DatabaseObject.java b/src/main/java/nl/andrewlalis/model/DatabaseObject.java new file mode 100644 index 0000000..9928da2 --- /dev/null +++ b/src/main/java/nl/andrewlalis/model/DatabaseObject.java @@ -0,0 +1,9 @@ +package nl.andrewlalis.model; + +public abstract class DatabaseObject { + + public abstract DatabaseObject retrieve(); + + public abstract boolean store(); + +} diff --git a/src/main/java/nl/andrewlalis/ui/control/command/executables/DefineTaTeams.java b/src/main/java/nl/andrewlalis/ui/control/command/executables/DefineTaTeams.java new file mode 100644 index 0000000..cccd3e8 --- /dev/null +++ b/src/main/java/nl/andrewlalis/ui/control/command/executables/DefineTaTeams.java @@ -0,0 +1,13 @@ +package nl.andrewlalis.ui.control.command.executables; + +import nl.andrewlalis.git_api.GithubManager; + + +public class DefineTaTeams extends GithubExecutable { + + @Override + protected boolean executeWithManager(GithubManager manager, String[] args) { + return false; + } + +} diff --git a/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java b/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java index 2d3ddc3..664f7bd 100644 --- a/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java +++ b/src/main/java/nl/andrewlalis/ui/control/command/executables/ReadStudentsFileToDB.java @@ -35,6 +35,9 @@ public class ReadStudentsFileToDB implements Executable { String filename = args[0]; int teamSize = Integer.parseUnsignedInt(args[1]); List teams = FileUtils.getStudentTeamsFromCSV(filename, teamSize); + if (teams == null) { + return false; + } return this.db.storeStudentTeams(teams); } } diff --git a/src/main/java/nl/andrewlalis/ui/control/listeners/DefineTaTeamsListener.java b/src/main/java/nl/andrewlalis/ui/control/listeners/DefineTaTeamsListener.java new file mode 100644 index 0000000..0e85be3 --- /dev/null +++ b/src/main/java/nl/andrewlalis/ui/control/listeners/DefineTaTeamsListener.java @@ -0,0 +1,18 @@ +package nl.andrewlalis.ui.control.listeners; + +import nl.andrewlalis.ui.control.command.CommandExecutor; +import nl.andrewlalis.ui.view.InitializerApp; + +import java.awt.event.ActionEvent; + +public class DefineTaTeamsListener extends ExecutableListener { + + public DefineTaTeamsListener(CommandExecutor executor, InitializerApp app) { + super(executor, app); + } + + @Override + public void actionPerformed(ActionEvent actionEvent) { + + } +} diff --git a/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java b/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java index 2ff6c2a..7db93eb 100644 --- a/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java +++ b/src/main/java/nl/andrewlalis/ui/view/InitializerApp.java @@ -35,9 +35,6 @@ public class InitializerApp extends JFrame { private JTextField organizationField = new JTextField(); private JTextField accessTokenField = new JTextField(); - private JTextField assignmentsRepoField = new JTextField(); - private JTextField teachingAssistantsField = new JTextField(); - private JTextField studentRepoField = new JTextField(); /** * The executor responsible for performing meaningful actions. @@ -103,12 +100,6 @@ public class InitializerApp extends JFrame { this.organizationField.setText("InitializerTesting"); infoInputPanel.add(generateTextFieldPanel("Access Token", this.accessTokenField)); this.accessTokenField.setText("haha get your own"); - infoInputPanel.add(generateTextFieldPanel("Assignments Repo Name", this.assignmentsRepoField)); - this.assignmentsRepoField.setText("assignments_2018"); - infoInputPanel.add(generateTextFieldPanel("TA-All Team Name", this.teachingAssistantsField)); - this.teachingAssistantsField.setText("teaching-assistants"); - infoInputPanel.add(generateTextFieldPanel("Student Repo Prefix", this.studentRepoField)); - this.studentRepoField.setText("advoop_2018"); githubManagerPanel.add(infoInputPanel, BorderLayout.NORTH); @@ -128,6 +119,9 @@ public class InitializerApp extends JFrame { generateAssignmentsRepoButton.addActionListener(new GenerateAssignmentsRepoListener(this.executor, this)); commonActionsPanel.add(generateAssignmentsRepoButton); + JButton defineTaTeamsButton = new JButton("Define TA Teams"); + commonActionsPanel.add(defineTaTeamsButton); + githubManagerPanel.add(commonActionsPanel, BorderLayout.CENTER); return githubManagerPanel; diff --git a/src/main/java/nl/andrewlalis/util/FileUtils.java b/src/main/java/nl/andrewlalis/util/FileUtils.java index 972ffb1..dc76bb9 100644 --- a/src/main/java/nl/andrewlalis/util/FileUtils.java +++ b/src/main/java/nl/andrewlalis/util/FileUtils.java @@ -54,7 +54,6 @@ public class FileUtils { return studentTeams; } catch (IOException | ArrayIndexOutOfBoundsException e) { logger.severe("Unable to generate studentTeams from CSV file, exiting. " + e.getMessage()); - System.exit(1); return null; } } -- 2.34.1