forked from nus-cs2103-AY1718S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commands to support importing job entries individually (nus-cs210…
…3-AY1718S2#99) * Process resources * Fix ImportSessionTest * checkstyle * Update UML diagrams * Add UML diagram for ImportSession closeSession() * edit * optimize code * fix ImportSession test case * edit test * Move methods, fields and constants from ImportSession to SessionData. * Add classes to support seesionData persistent data. WIP. * Revert "Add classes to support seesionData persistent data. WIP." This reverts commit a9f0eff. * Add classes to support session data persistence. WIP. * Revert "Add classes to support session data persistence. WIP." This reverts commit bebb8ea. * Add import and save commands. * Add command to list jobs * Add acceptAll, rejectAll and switch commmands * Add accept and reject command. * uncomment check in date * Modify ModelStub * Remove unused imports
- Loading branch information
1 parent
bdf26a5
commit 67299ac
Showing
36 changed files
with
954 additions
and
191 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+4.26 KB
...n.ImportSessionTest/CS2103-testsheet.xlsx → CS2103-testsheet.xlsx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/seedu/carvicim/commons/events/ui/DisplayAllJobsEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package seedu.carvicim.commons.events.ui; | ||
|
||
import javafx.collections.ObservableList; | ||
import seedu.carvicim.commons.events.BaseEvent; | ||
import seedu.carvicim.model.job.Job; | ||
|
||
/** | ||
* Represents a selection change in the Employee List Panel | ||
*/ | ||
//@@author yuhongherald | ||
public class DisplayAllJobsEvent extends BaseEvent { | ||
|
||
|
||
private final ObservableList<Job> jobList; | ||
|
||
public DisplayAllJobsEvent(ObservableList<Job> jobList) { | ||
this.jobList = jobList; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
public ObservableList<Job> getJobList() { | ||
return jobList; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/seedu/carvicim/logic/commands/AcceptAllCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package seedu.carvicim.logic.commands; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import seedu.carvicim.logic.commands.exceptions.CommandException; | ||
import seedu.carvicim.model.job.Job; | ||
import seedu.carvicim.storage.session.ImportSession; | ||
import seedu.carvicim.storage.session.exceptions.DataIndexOutOfBoundsException; | ||
import seedu.carvicim.storage.session.exceptions.UnitializedException; | ||
|
||
//@@author yuhongherald | ||
|
||
/** | ||
* Accepts all remaining unreviewed job entries into Servicing Manager | ||
*/ | ||
public class AcceptAllCommand extends UndoableCommand { | ||
|
||
public static final String COMMAND_WORD = "acceptAll"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Accepts all unreviewed job entries. " | ||
+ "Example: " + COMMAND_WORD; | ||
|
||
public static final String MESSAGE_SUCCESS = "%d job entries accepted!"; | ||
|
||
public String getMessageSuccess(int entries) { | ||
return String.format(MESSAGE_SUCCESS, entries); | ||
} | ||
|
||
@Override | ||
public CommandResult executeUndoableCommand() throws CommandException { | ||
ImportSession importSession = ImportSession.getInstance(); | ||
try { | ||
importSession.reviewAllRemainingJobEntries(true); | ||
List<Job> jobs = new ArrayList<>(importSession.getSessionData().getReviewedJobEntries()); | ||
model.addJobs(jobs); | ||
importSession.closeSession(); | ||
return new CommandResult(getMessageSuccess(jobs.size())); | ||
} catch (DataIndexOutOfBoundsException e) { | ||
throw new CommandException("Excel file has bad format. Try copying the cell values into a new excel file " | ||
+ "before trying again"); | ||
} catch (IOException e) { | ||
throw new CommandException("Unable to export file. Please close the application and try again."); | ||
} catch (UnitializedException e) { | ||
throw new CommandException(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AcceptAllCommand); // instanceof handles nulls | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/seedu/carvicim/logic/commands/AcceptCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package seedu.carvicim.logic.commands; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import seedu.carvicim.commons.core.EventsCenter; | ||
import seedu.carvicim.commons.events.ui.DisplayAllJobsEvent; | ||
import seedu.carvicim.logic.commands.exceptions.CommandException; | ||
import seedu.carvicim.model.job.Job; | ||
import seedu.carvicim.storage.session.ImportSession; | ||
import seedu.carvicim.storage.session.exceptions.DataIndexOutOfBoundsException; | ||
import seedu.carvicim.storage.session.exceptions.InvalidDataException; | ||
|
||
//@@author yuhongherald | ||
|
||
/** | ||
* Accepts an unreviewed job entry using job number and adds into servicing manager | ||
*/ | ||
public class AcceptCommand extends UndoableCommand { | ||
|
||
public static final String COMMAND_WORD = "accept"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Accepts job entry using job number. " | ||
+ "Example: " + COMMAND_WORD + " JOB_NUMBER"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Job #%d accepted!"; | ||
|
||
private int jobNumber; | ||
|
||
public AcceptCommand(int jobNumber) { | ||
this.jobNumber = jobNumber; | ||
} | ||
|
||
public String getMessageSuccess() { | ||
return String.format(MESSAGE_SUCCESS, jobNumber); | ||
} | ||
|
||
@Override | ||
public CommandResult executeUndoableCommand() throws CommandException { | ||
ImportSession importSession = ImportSession.getInstance(); | ||
try { | ||
importSession.getSessionData().reviewJobEntryUsingJobNumber(jobNumber, true, ""); | ||
|
||
} catch (DataIndexOutOfBoundsException e) { | ||
throw new CommandException("Excel file has bad format. Try copying the cell values into a new excel file " | ||
+ "before trying again"); | ||
} catch (InvalidDataException e) { | ||
throw new CommandException(e.getMessage()); | ||
} | ||
ObservableList<Job> jobList = FXCollections.observableList( | ||
ImportSession.getInstance().getSessionData().getUnreviewedJobEntries()); | ||
if (!model.isViewingImportedJobs()) { | ||
model.switchJobView(); | ||
} | ||
EventsCenter.getInstance().post( | ||
new DisplayAllJobsEvent(FXCollections.unmodifiableObservableList(jobList))); | ||
return new CommandResult(getMessageSuccess()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AcceptCommand); // instanceof handles nulls | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/carvicim/logic/commands/ImportCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package seedu.carvicim.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import seedu.carvicim.commons.core.EventsCenter; | ||
import seedu.carvicim.commons.events.ui.DisplayAllJobsEvent; | ||
import seedu.carvicim.logic.commands.exceptions.CommandException; | ||
import seedu.carvicim.model.job.Job; | ||
import seedu.carvicim.storage.session.ImportSession; | ||
import seedu.carvicim.storage.session.exceptions.FileAccessException; | ||
import seedu.carvicim.storage.session.exceptions.FileFormatException; | ||
|
||
//@@author yuhongherald | ||
|
||
/** | ||
* Attempts to import specified file into Servicing Manager | ||
*/ | ||
public class ImportCommand extends UndoableCommand { | ||
|
||
public static final String COMMAND_WORD = "import"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Imports an excel file for reviewing. " | ||
+ "Parameters: FILEPATH\n" | ||
+ "Example: " + COMMAND_WORD + "yourfile.xls"; | ||
|
||
public static final String MESSAGE_SUCCESS = "%s has been imported, with %d job entries!"; | ||
|
||
private final String filePath; | ||
|
||
public ImportCommand(String filePath) { | ||
requireNonNull(filePath); | ||
this.filePath = filePath; | ||
} | ||
|
||
public String getMessageSuccess(int entries) { | ||
return String.format(MESSAGE_SUCCESS, filePath, entries); | ||
} | ||
|
||
@Override | ||
public CommandResult executeUndoableCommand() throws CommandException { | ||
ImportSession importSession = ImportSession.getInstance(); | ||
try { | ||
importSession.initializeSession(filePath); | ||
} catch (FileAccessException e) { | ||
throw new CommandException(e.getMessage()); | ||
} catch (FileFormatException e) { | ||
throw new CommandException("Excel file first row headers are not defined properly. " | ||
+ "Type 'help' to read more."); | ||
} | ||
|
||
ObservableList<Job> jobList = FXCollections.observableList( | ||
ImportSession.getInstance().getSessionData().getUnreviewedJobEntries()); | ||
if (!model.isViewingImportedJobs()) { | ||
model.switchJobView(); | ||
} | ||
EventsCenter.getInstance().post( | ||
new DisplayAllJobsEvent(FXCollections.unmodifiableObservableList(jobList))); | ||
return new CommandResult(getMessageSuccess(importSession.getSessionData() | ||
.getUnreviewedJobEntries().size())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ImportCommand // instanceof handles nulls | ||
&& filePath.equals(((ImportCommand) other).filePath)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/seedu/carvicim/logic/commands/ListJobCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package seedu.carvicim.logic.commands; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import seedu.carvicim.commons.core.EventsCenter; | ||
import seedu.carvicim.commons.events.ui.DisplayAllJobsEvent; | ||
import seedu.carvicim.model.job.Job; | ||
import seedu.carvicim.storage.session.ImportSession; | ||
|
||
/** | ||
* Lists all jobs in the carvicim book to the user. | ||
*/ | ||
//@@author yuhongherald | ||
public class ListJobCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "listj"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all jobs"; | ||
|
||
|
||
@Override | ||
public CommandResult execute() { | ||
ObservableList<Job> jobList; | ||
if (model.isViewingImportedJobs()) { | ||
jobList = FXCollections.observableList( | ||
ImportSession.getInstance().getSessionData().getUnreviewedJobEntries()); | ||
} else { | ||
jobList = model.getFilteredJobList(); | ||
} | ||
EventsCenter.getInstance().post( | ||
new DisplayAllJobsEvent(FXCollections.unmodifiableObservableList(jobList))); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
Oops, something went wrong.