Skip to content

Commit

Permalink
Add interviewee's List to model (#74)
Browse files Browse the repository at this point in the history
* Import from excel function

* Adds implementation for ExcelReader

* debug importExcel classes

* Check style for Import branch

* Reads csv file correctly

* Finished up import interviewers feature

* Integrated with Schedule class and removed ScheduleStub

* Handles import exceptions

* Corrected Styling

* Adds test for Import commands

* Corrects styling for Import Tests

* Rename ExcelReader to CsvReader

* handles exceptions for import interviewers

* Adds intervieweesList attribute to model

* Travis fix

* Travis fix

* Style fix
  • Loading branch information
mirozo authored and ChrisKheng committed Oct 23, 2019
1 parent dae47ae commit 803944d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 19 deletions.
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 @@ -232,6 +247,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);
}

}

0 comments on commit 803944d

Please sign in to comment.