Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interviewee's List to model #74

Merged
merged 25 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a2d0976
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/main
gohruizhi Oct 1, 2019
0c3730a
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/main
gohruizhi Oct 2, 2019
8b09156
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/main
gohruizhi Oct 9, 2019
70b8374
Import from excel function
gohruizhi Oct 10, 2019
9e5d2f3
Adds implementation for ExcelReader
gohruizhi Oct 10, 2019
3dfae0d
debug importExcel classes
gohruizhi Oct 10, 2019
6001c75
Merge branch 'master' into Import
mirozo Oct 10, 2019
1a60860
Check style for Import branch
gohruizhi Oct 10, 2019
019e244
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/mai…
gohruizhi Oct 13, 2019
ef22315
Reads csv file correctly
gohruizhi Oct 13, 2019
ae8bfae
Finished up import interviewers feature
gohruizhi Oct 17, 2019
3c6b8db
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/mai…
gohruizhi Oct 17, 2019
4e482fb
Integrated with Schedule class and removed ScheduleStub
gohruizhi Oct 17, 2019
e593e73
Handles import exceptions
gohruizhi Oct 17, 2019
1409bfe
Corrected Styling
gohruizhi Oct 17, 2019
c805942
Adds test for Import commands
gohruizhi Oct 17, 2019
6c3e550
Corrects styling for Import Tests
gohruizhi Oct 17, 2019
8578ec4
Rename ExcelReader to CsvReader
gohruizhi Oct 17, 2019
9fcfe0c
handles exceptions for import interviewers
gohruizhi Oct 18, 2019
0650d05
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/mai…
gohruizhi Oct 18, 2019
03e1dc9
Merge branch 'master' of https://github.com/AY1920S1-CS2103-F09-1/mai…
gohruizhi Oct 21, 2019
b49e15f
Adds intervieweesList attribute to model
gohruizhi Oct 21, 2019
061ff24
Travis fix
gohruizhi Oct 21, 2019
6a91795
Travis fix
gohruizhi Oct 21, 2019
957febe
Style fix
gohruizhi Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/main/java/seedu/address/logic/commands/ImportCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package seedu.address.logic.commands;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.Schedule;
import seedu.address.model.util.CsvReader;





/**
* Import csv file containing interviewer's/ interviewers's information.
*/
Expand Down Expand Up @@ -37,7 +43,7 @@ public ImportCommand(String args) {
}

@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {

try {
if (this.type.equals("interviewer")) {
Expand All @@ -49,15 +55,14 @@ public CommandResult execute(Model model) {
} else if (this.type.equals("interviewee")) {
return new CommandResult(MESSAGE_NOT_IMPLEMENTED_YET, false, false);
} else {
return new CommandResult(MESSAGE_USAGE, false, false);
throw new CommandException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE));
}
} catch (FileNotFoundException e) {
return new CommandResult(FILE_DOES_NOT_EXIST, false, false);
} catch (IOException e) {
e.printStackTrace();
return new CommandResult("Failed", false, false);
} catch (ArrayIndexOutOfBoundsException e) {
return new CommandResult(INCORRECT_FORMAT, false, false);
} catch (FileNotFoundException fileE) {
throw new CommandException(FILE_DOES_NOT_EXIST, fileE);
} catch (IOException ioe) {
throw new CommandException("Failed", ioe);
} catch (ArrayIndexOutOfBoundsException arrayE) {
throw new CommandException(INCORRECT_FORMAT, arrayE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public ImportCommand parse(String args) throws ParseException {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ImportCommand.MESSAGE_USAGE));
}
String[] strings = trimmedArgs.split(" ");
if (strings.length != 2) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ImportCommand.MESSAGE_USAGE));
}
return new ImportCommand(trimmedArgs);
}
}
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ public interface Model {
*/
void setSchedulesList(List<Schedule> schedulesList);

/**
* Sets interviewee's data.
*/
void setIntervieweesList(List<Interviewee> list);

/** Returns the schedulesList **/
List<Schedule> getSchedulesList();

/** Returns the intervieweesList **/
List<Interviewee> getIntervieweesList();

/**
* Returns a list of observable list of the schedules.
*/
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ModelManager implements Model {
private final UserPrefs userPrefs;
private final FilteredList<Person> filteredPersons;
private final List<Schedule> schedulesList;
private List<Interviewee> intervieweesList;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
Expand Down Expand Up @@ -111,6 +112,20 @@ public List<Schedule> getSchedulesList() {
return schedulesList;
}

/**
* Sets interviewee's data.
* @param list list of interviewees
*/
public void setIntervieweesList(List<Interviewee> list) {
intervieweesList = cloneIntervieweesList(list);
logger.fine("interviewee's list is updated");
}

/** Returns the intervieweesList **/
public List<Interviewee> getIntervieweesList() {
return intervieweesList;
}

/**
* Returns a list of observable list of the schedules.
*/
Expand Down Expand Up @@ -222,6 +237,20 @@ private static List<Schedule> cloneSchedulesList(List<Schedule> list) {
return listClone;
}

/**
* Returns the deep copy of the interviewee's list given.
*
* @param list the list of interviewees to be copied.
* @return a deep copy of interviewee's list.
*/
private static List<Interviewee> cloneIntervieweesList(List<Interviewee> list) {
List<Interviewee> listClone = new LinkedList<>();
for (Interviewee interviewee : list) {
listClone.add(interviewee);
}
return listClone;
}

//=========== AddressBook ================================================================================

@Override
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/seedu/address/model/util/CsvReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public class CsvReader {

/**
* Constructor for CsvReader object to read from excel.
<<<<<<< HEAD
* @param filePath Path of csv file
=======
* @param filePath
>>>>>>> 8d5e5072afe29f45a0772570f143a75cefd6b715
*/
public CsvReader(String filePath) {
this.filePath = filePath;
Expand Down Expand Up @@ -64,8 +68,9 @@ public ArrayList<Schedule> read() throws IOException {
}

private static int getValue(String element) {
String[] strings = element.split("= ");
return Integer.parseInt(strings[1]);
String[] strings = element.split("=");
String trimmedString = strings[1].trim();
return Integer.parseInt(trimmedString);
}

private boolean fileExists() {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public LinkedList<Schedule> getSchedulesList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void setIntervieweesList(List<Interviewee> intervieweesList) {
throw new AssertionError("This method should not be called.");
}

@Override
public List<Interviewee> getIntervieweesList() {
throw new AssertionError("This method should not be called.");
}

@Override
public List<ObservableList<ObservableList<String>>> getObservableLists() {
throw new AssertionError("This method should not be called.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package seedu.address.logic.commands;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;

import org.junit.jupiter.api.Test;
Expand All @@ -22,11 +21,4 @@ public void interviewerImportCommandSuccess() {
assertCommandSuccess(importCommand, model, expectedCommandResult, expectedModel);
}

@Test
public void interviewerImportCommandFailure() {
ImportCommand importCommand = new ImportCommand(INTERVIEWER + " " + INVALID_FILE_PATH);
CommandResult expectedCommandResult = new CommandResult(ImportCommand.FILE_DOES_NOT_EXIST, false, false);
assertEquals(importCommand.execute(model), expectedCommandResult);
}

}