forked from se-edu/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from yichong96/import_command
Import and Export command
- Loading branch information
Showing
22 changed files
with
657 additions
and
239 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
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
48 changes: 24 additions & 24 deletions
48
src/main/java/seedu/address/logic/commands/ExportCommand.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 |
---|---|---|
@@ -1,65 +1,65 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FILENAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FOLDERNAME; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.CardFolderNotFoundException; | ||
import seedu.address.model.Model; | ||
import seedu.address.storage.csvmanager.CardFolderExport; | ||
import seedu.address.storage.csvmanager.CsvFile; | ||
import seedu.address.storage.csvmanager.exceptions.CsvManagerNotInitialized; | ||
|
||
|
||
/** | ||
* Exports single or multiple card folders into a .json file. Users must specify file name to export card folders to. | ||
* Exports single or multiple card folders into a .csv file. | ||
*/ | ||
public class ExportCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "export"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": exports single or multiple card folders into" | ||
+ "a .csv file. " | ||
+ "Users must include the .csv extension.\n" | ||
+ "Parameters: " | ||
+ PREFIX_FOLDERNAME + "CARD_FOLDER_NAME [MORE CARD_FOLDER_NAMES]..." | ||
+ PREFIX_FILENAME + "Filename.csv\n" | ||
+ "Example: " + COMMAND_WORD + "f/Human_anatomy f/Bone_structure n/myfilename.csv"; | ||
+ "their respective .csv files." | ||
+ "Parameters: INDEX (Index specifies the card folder index to export) \n" | ||
+ "Can specify more than one card folder index to export" | ||
+ "Example: " + COMMAND_WORD + "1 3 5 7"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Successfully exported card folders to: $1%s"; | ||
public static final String MESSAGE_SUCCESS = "Successfully exported card folders"; | ||
|
||
public static final String MESSAGE_MISSING_CARD_FOLDERS = "Could not find the specified folder: "; | ||
public static final String MESSAGE_MISSING_CARD_FOLDERS = "Could not find the specified folder index: "; | ||
|
||
public static final String MESSAGE_FILE_OPS_FAILURE = "Could not export to specified file"; | ||
|
||
private Set<CardFolderExport> cardFolders; | ||
private CsvFile filename; | ||
private List<Integer> cardFolderIndexes; | ||
|
||
public ExportCommand(Set<CardFolderExport> cardFolders, CsvFile filename) { | ||
this.cardFolders = cardFolders; | ||
this.filename = filename; | ||
public ExportCommand(List<Integer> cardFolderIndexes) { | ||
this.cardFolderIndexes = cardFolderIndexes; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
// check whether model contains the card folders desired. Catch exception thrown | ||
|
||
if (model.isInFolder()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_COMMAND_INSIDE_FOLDER); | ||
} | ||
try { | ||
model.exportCardFolders(cardFolders, filename); | ||
model.exportCardFolders(cardFolderIndexes); | ||
} catch (CardFolderNotFoundException e) { | ||
throw new CommandException(MESSAGE_MISSING_CARD_FOLDERS + e.getMessage()); | ||
} catch (IOException e) { | ||
throw new CommandException(MESSAGE_FILE_OPS_FAILURE); | ||
} catch (CsvManagerNotInitialized e) { | ||
throw new CommandException(Messages.MESSAGE_CSV_MANAGER_NOT_INITIALIZED); | ||
} | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, filename)); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| other instanceof ExportCommand // instanceof handles nulls | ||
&& (cardFolders.containsAll(((ExportCommand) other).cardFolders) | ||
&& filename.equals(((ExportCommand) other).filename)); | ||
&& cardFolderIndexes.containsAll(((ExportCommand) other).cardFolderIndexes); | ||
} | ||
} |
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
Oops, something went wrong.