From b54b1fe32d7a9ff3cc98a2fa2e32dcc609ecf947 Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sat, 8 Sep 2018 16:50:18 +0200 Subject: [PATCH] Use absolute path in CSV reader now. --- src/main/java/nl/andrewlalis/Main.java | 1 + src/main/java/nl/andrewlalis/model/Student.java | 17 ++++++++++++++++- .../listeners/ReadStudentsFileListener.java | 2 +- .../java/nl/andrewlalis/util/FileUtils.java | 1 + .../java/nl/andrewlalis/util/TeamGenerator.java | 4 ++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/nl/andrewlalis/Main.java b/src/main/java/nl/andrewlalis/Main.java index a9674db..f2c82f4 100644 --- a/src/main/java/nl/andrewlalis/Main.java +++ b/src/main/java/nl/andrewlalis/Main.java @@ -44,6 +44,7 @@ public class Main { executor.registerCommand("list_errors", new ListErrors()); executor.registerCommand("delete_repos", new DeleteRepos()); executor.registerCommand("delegate_student_teams", new DelegateStudentTeams(app)); + executor.registerCommand("setup_student_repos", new SetupStudentRepos()); logger.info("GithubManager for Github Repositories in Educational Organizations.\n" + "© Andrew Lalis (2018), All rights reserved.\n" + diff --git a/src/main/java/nl/andrewlalis/model/Student.java b/src/main/java/nl/andrewlalis/model/Student.java index ec8712b..67e2f3e 100644 --- a/src/main/java/nl/andrewlalis/model/Student.java +++ b/src/main/java/nl/andrewlalis/model/Student.java @@ -1,13 +1,23 @@ package nl.andrewlalis.model; +import nl.andrewlalis.model.error.Error; +import nl.andrewlalis.model.error.Severity; +import nl.andrewlalis.ui.view.InitializerApp; + import java.util.List; import java.util.Map; +import java.util.logging.Logger; /** * Represents one student's github information. */ public class Student extends Person { + private static final Logger logger = Logger.getLogger(Student.class.getName()); + static { + logger.setParent(Logger.getGlobal()); + } + /** * A list of partners that the student has said that they would like to be partners with. */ @@ -39,7 +49,12 @@ public class Student extends Person { public StudentTeam getPreferredTeam(Map studentMap) { StudentTeam t = new StudentTeam(); for (int partnerNumber : this.getPreferredPartners()) { - t.addMember(studentMap.get(partnerNumber)); + if (!studentMap.containsKey(partnerNumber)) { + InitializerApp.organization.addError(new Error(Severity.MEDIUM, "Student " + this.getNumber() + " has non-existent preferred partner with id: " + partnerNumber)); + logger.warning("Student has non-existent partner id: " + partnerNumber + '\n' + this); + } else { + t.addMember(studentMap.get(partnerNumber)); + } } t.addMember(this); return t; diff --git a/src/main/java/nl/andrewlalis/ui/control/listeners/ReadStudentsFileListener.java b/src/main/java/nl/andrewlalis/ui/control/listeners/ReadStudentsFileListener.java index 046e78d..e65e7ba 100644 --- a/src/main/java/nl/andrewlalis/ui/control/listeners/ReadStudentsFileListener.java +++ b/src/main/java/nl/andrewlalis/ui/control/listeners/ReadStudentsFileListener.java @@ -44,7 +44,7 @@ public class ReadStudentsFileListener extends ExecutableListener { String teamSizeString = JOptionPane.showInputDialog(this.app, "Enter the student team size.", "Team Size", JOptionPane.QUESTION_MESSAGE); if (teamSizeString != null) { this.executor.executeCommand("read_students", new String[]{ - chooser.getSelectedFile().getName(), + chooser.getSelectedFile().getAbsolutePath(), teamSizeString }); } diff --git a/src/main/java/nl/andrewlalis/util/FileUtils.java b/src/main/java/nl/andrewlalis/util/FileUtils.java index dc76bb9..2d56eab 100644 --- a/src/main/java/nl/andrewlalis/util/FileUtils.java +++ b/src/main/java/nl/andrewlalis/util/FileUtils.java @@ -54,6 +54,7 @@ public class FileUtils { return studentTeams; } catch (IOException | ArrayIndexOutOfBoundsException e) { logger.severe("Unable to generate studentTeams from CSV file, exiting. " + e.getMessage()); + e.printStackTrace(); return null; } } diff --git a/src/main/java/nl/andrewlalis/util/TeamGenerator.java b/src/main/java/nl/andrewlalis/util/TeamGenerator.java index 96800ed..6bc00b5 100644 --- a/src/main/java/nl/andrewlalis/util/TeamGenerator.java +++ b/src/main/java/nl/andrewlalis/util/TeamGenerator.java @@ -155,6 +155,10 @@ public class TeamGenerator { } } Student s = new Student(Integer.parseInt(record.get(3)), record.get(2), record.get(1), record.get(4), preferredIds); + if (studentMap.containsValue(s)) { + InitializerApp.organization.addError(new Error(Severity.HIGH, "Duplicate entries for student:\n" + s + "\nSince records are in chronological order, this more recent duplicate will override the previous value.")); + logger.warning("Duplicate entry found for student: " + s + "\nOverwriting previous value."); + } studentMap.put(s.getNumber(), s); } logger.fine("Read " + studentMap.size() + " students from records.");