forked from nusCS2113-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Model: Add backup property to UserPrefs model Add backup file path to user preferences model. Modified equals to compare backup location Modified string builder to include backup path * [Tests] Update JsonUserPrefsStorageTest Modify ExtraValues json test file Add `addressBookBackupFilePath` to typical user prefs json test file * [Model] Add UserPrefs to Model [Model] UserPrefs is required to be in model manager as commands run can affect user preferences which should be part of model. Refer to original AB4 architecture diagram Added getUserPref method to Model interface Fix UserPref model returning wrong path in getAddressBookBackupFilePath [Tests] Fix Stubbed ModelManager in AddCommandTest * Add backup methods to AddressBookStorage Make AddressBookStorage and XmlAddressBookStorage have the required backup methods * Remove UserPrefs comparison from ModelManager As long as AddressBook data are equal, userprefs can be different which is okay * Additional tests for XmlAddressBookStorage * Add basic backup command Backup Command currently calls model.backupAddressBook, perhaps we should raise a backup request event from command direct and get handled by storage manager directly as we do not need to modify the model * Add sample tests for backup command * CheckStyle Fixes * More CheckStyle Fixes * More checkstyle fixes :( * Make backup generic to allow future extensions More tests Bug Fixes * Resolve conflicts * Checkstyle fixes * Add tests to fix coverage * Fix BackupCommandParser tests * Fixs bugs * Last try to fix test on linux * Remove test Impossible to make exception to be thrown on linux even with mocking for invalid paths * Remove unused imports * Implement online backup Create generic online storage module Implement working backup to github gist Modify backup command to accept github backup * Checkstyle and Bug Fixes * Temp Bug Fix
- Loading branch information
1 parent
25088fc
commit 8c48fea
Showing
14 changed files
with
295 additions
and
32 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
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/commons/events/storage/OnlineBackupEvent.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,30 @@ | ||
package seedu.address.commons.events.storage; | ||
|
||
import java.util.Optional; | ||
|
||
import seedu.address.commons.events.BaseEvent; | ||
import seedu.address.model.ReadOnlyAddressBook; | ||
import seedu.address.storage.OnlineStorage; | ||
|
||
//@@author QzSG | ||
/** Indicates a request for online backup*/ | ||
public class OnlineBackupEvent extends BaseEvent { | ||
|
||
public final OnlineStorage.OnlineStorageType target; | ||
public final ReadOnlyAddressBook data; | ||
public final String fileName; | ||
public final Optional<String> authToken; | ||
|
||
public OnlineBackupEvent(OnlineStorage.OnlineStorageType target, ReadOnlyAddressBook data, | ||
String fileName, Optional<String> authToken) { | ||
this.target = target; | ||
this.data = data; | ||
this.fileName = fileName; | ||
this.authToken = authToken; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Saving data online"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/seedu/address/commons/exceptions/OnlineBackupFailureException.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,21 @@ | ||
package seedu.address.commons.exceptions; | ||
|
||
/** | ||
* Signals that some online backup failed for some reason. | ||
*/ | ||
public class OnlineBackupFailureException extends Exception { | ||
/** | ||
* @param message should contain relevant information on failure reason(s) | ||
*/ | ||
public OnlineBackupFailureException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* @param message should contain relevant information on failure reason(s) | ||
* @param cause of the main exception | ||
*/ | ||
public OnlineBackupFailureException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//@@author QzSG | ||
package seedu.address.storage; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.io.IOException; | ||
|
||
import org.kohsuke.github.GHGist; | ||
import org.kohsuke.github.GHGistBuilder; | ||
import org.kohsuke.github.GitHub; | ||
|
||
import seedu.address.commons.exceptions.OnlineBackupFailureException; | ||
|
||
/** | ||
* A class to handle saving data to Github Gists. | ||
*/ | ||
public class GitHubStorage implements OnlineStorage { | ||
|
||
private static GitHub gitHub = null; | ||
private String authToken = null; | ||
|
||
public GitHubStorage(String authToken) { | ||
requireNonNull(authToken); | ||
this.authToken = authToken; | ||
} | ||
|
||
@Override | ||
public void saveContentToStorage(String content, String fileName) throws IOException, OnlineBackupFailureException { | ||
throw new UnsupportedOperationException("This online storage does not " | ||
+ "support saveContentToStorage with 2 variables"); | ||
} | ||
|
||
@Override | ||
public void saveContentToStorage(String content, String fileName, String description) | ||
throws IOException, OnlineBackupFailureException { | ||
requireNonNull(content); | ||
requireNonNull(fileName); | ||
|
||
gitHub = GitHub.connectUsingOAuth(authToken); | ||
GHGistBuilder ghGistBuilder = buildGistFromContent(content, fileName, description); | ||
GHGist ghGist = ghGistBuilder.create(); | ||
} | ||
|
||
private GHGistBuilder buildGistFromContent(String content, String fileName, String description) { | ||
GHGistBuilder ghGistBuilder = new GHGistBuilder(gitHub); | ||
ghGistBuilder.public_(false).description(description).file(fileName, content); | ||
return ghGistBuilder; | ||
} | ||
} |
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,38 @@ | ||
package seedu.address.storage; | ||
|
||
//@@author QzSG | ||
|
||
import java.io.IOException; | ||
|
||
import seedu.address.commons.exceptions.OnlineBackupFailureException; | ||
|
||
/** | ||
* API of the OnlineStorage component | ||
*/ | ||
public interface OnlineStorage { | ||
|
||
/** | ||
* Enum types for support online storage | ||
*/ | ||
enum OnlineStorageType { | ||
GITHUB | ||
} | ||
|
||
/** | ||
* Saves the given {@code content} to the online storage. | ||
* @param content cannot be null. | ||
* @param fileName cannot be null. | ||
* @throws OnlineBackupFailureException if there was any problem saving to online storage. | ||
*/ | ||
void saveContentToStorage(String content, String fileName) throws IOException, OnlineBackupFailureException; | ||
|
||
/** | ||
* Saves the given {@code content} to the online storage. | ||
* @param content cannot be null. | ||
* @param fileName cannot be null. | ||
* @param description can be null. | ||
* @throws OnlineBackupFailureException if there was any problem saving to online storage. | ||
*/ | ||
void saveContentToStorage(String content, String fileName, String description) | ||
throws IOException, OnlineBackupFailureException; | ||
} |
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.