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 importAll command (nus-cs2103-AY1718S2#78)
* fix merge errors * Add dummy classes to support import feature * Add details in JobEntry and SessionData * more edits * Add classes to support ImportSession * Apply SLAP to make methods smaller * Add ImportSession method to read excel file. * Add SheetHeaderFields class * Add SheetWithHeaderFields to extract row and column operations * Finish ImportSession feature to write to file * trailing whitespace * Extract messages in ImportSession as constants. Write dummy ImportAllCommand, with functional support classes. * Use unmodifiableList for getting lists in sessionData and jobEntry. * Implement importAll command * fix modelStub * fix checkstyle error * fix checkstyle error * Rename method addUnreviewedJobEntries to addSheet
- Loading branch information
1 parent
65c10ef
commit 3be6a04
Showing
28 changed files
with
1,184 additions
and
21 deletions.
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
src/main/java/seedu/address/logic/commands/ImportAllCommand.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,74 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.io.IOException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.job.Job; | ||
import seedu.address.model.session.ImportSession; | ||
import seedu.address.model.session.exceptions.DataIndexOutOfBoundsException; | ||
import seedu.address.model.session.exceptions.FileAccessException; | ||
import seedu.address.model.session.exceptions.FileFormatException; | ||
|
||
//@@author yuhongherald | ||
/** | ||
* Attempts to import all (@code JobEntry) into Servicing Manager | ||
*/ | ||
public class ImportAllCommand extends UndoableCommand { | ||
|
||
public static final String COMMAND_WORD = "importAll"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Imports job entries from from an excel file. " | ||
+ "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 ImportAllCommand(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) { | ||
e.printStackTrace(); | ||
} catch (FileFormatException e) { | ||
throw new CommandException("Excel file first row headers are not defined properly. " | ||
+ "Type 'help' to read more."); | ||
} | ||
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."); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ImportAllCommand // instanceof handles nulls | ||
&& filePath.equals(((ImportAllCommand) other).filePath)); | ||
} | ||
|
||
} |
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
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
32 changes: 32 additions & 0 deletions
32
src/main/java/seedu/address/logic/parser/ImportAllCommandParser.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,32 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.ParserUtil.parseFilename; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.ImportAllCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
//@@author yuhongherald | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class ImportAllCommandParser implements Parser<ImportAllCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arg | ||
* uments in the context of the ImportAllCommand | ||
* and returns an ImportAllCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ImportAllCommand parse(String args) throws ParseException { | ||
try { | ||
String filePath = parseFilename(args); | ||
return new ImportAllCommand(filePath); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ImportAllCommand.MESSAGE_USAGE)); | ||
} | ||
} | ||
|
||
} |
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
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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/seedu/address/model/session/ExcelColumnSpannable.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,20 @@ | ||
package seedu.address.model.session; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.apache.poi.ss.usermodel.Sheet; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
|
||
import seedu.address.model.session.exceptions.DataIndexOutOfBoundsException; | ||
|
||
//@@author yuhongherald | ||
/** | ||
* For fields that resides in one or more columns | ||
*/ | ||
public interface ExcelColumnSpannable { | ||
public int getStartIndex(); | ||
public int getEndIndex(); | ||
public ArrayList<String> readData(Workbook workbook, int sheetNumber, int rowNumber) | ||
throws DataIndexOutOfBoundsException; | ||
public ArrayList<String> readDataFromSheet(Sheet sheet, int rowNumber) throws DataIndexOutOfBoundsException; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/seedu/address/model/session/ExcelRowReference.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,18 @@ | ||
package seedu.address.model.session; | ||
|
||
/** | ||
* For row entries of an excel sheet | ||
*/ | ||
public interface ExcelRowReference { | ||
|
||
/** | ||
* Returns the excel sheet number of this element. | ||
*/ | ||
public int getSheetNumber(); | ||
|
||
/** | ||
* Returns the excel row number of this element | ||
* @return | ||
*/ | ||
public int getRowNumber(); | ||
} |
Oops, something went wrong.