forked from nus-cs2103-AY1617S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Maven Google Calendar SDK * SyncManager * Create new classes * Sync command * Add more gradle dependencies * Create Sync & SyncProvider interfaces * ModelManager supports Sync * Sync methods in Model * Add Sync to parser * SyncManager * Sync provider Google * Google stuff * Revert bad merge change * Basic event adding hooks workings * tag code * CRUD support * Cleanup * Sync on/off is now persisted using credential file * Multithreading and concurrency * Multithreading and concurrency support in SyncProvider made it trival to support adding add tasks when Sync is turned on * Small cleanup * Add mockito dependency * SyncManagerTests * Testing sync on/off * Remove sync on * tag syncmanagertest * Simple testing in GoogleTests * Add invalid sync * deleteCalendadrMethod * Much more Google calendar testing * test sync on too * tag code * Add comments
- Loading branch information
Showing
13 changed files
with
760 additions
and
2 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
src/main/java/seedu/agendum/logic/commands/SyncCommand.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,60 @@ | ||
package seedu.agendum.logic.commands; | ||
|
||
import seedu.agendum.commons.exceptions.IllegalValueException; | ||
|
||
public class SyncCommand extends Command { | ||
// COMMAND_WORD, COMMAND_FORMAT, COMMAND_DESCRIPTION are for display in help window | ||
public static final String COMMAND_WORD = "sync"; | ||
private static final String COMMAND_FORMAT = "sync <on/off>"; | ||
private static final String COMMAND_DESCRIPTION = "Turn syncing on or off"; | ||
private static final String MESSAGE_USAGE = COMMAND_WORD + "- " | ||
+ COMMAND_DESCRIPTION; | ||
|
||
public static final String SYNC_ON_MESSAGE = "Google Calendar Sync is on"; | ||
public static final String SYNC_OFF_MESSAGE = "Google Calendar Sync is off"; | ||
|
||
public static final String MESSAGE_WRONG_OPTION = "Invalid option for sync."; | ||
|
||
private boolean syncOption; | ||
|
||
//@@author A0003878Y | ||
/** | ||
* Convenience constructor using name | ||
* | ||
* @throws IllegalValueException if any of the raw values are invalid | ||
*/ | ||
public SyncCommand(String option) throws IllegalValueException { | ||
|
||
if (option.trim().equalsIgnoreCase("on")) { | ||
syncOption = true; | ||
} else if (option.trim().equalsIgnoreCase("off")) { | ||
syncOption = false; | ||
} else { | ||
throw new IllegalValueException(MESSAGE_WRONG_OPTION); | ||
} | ||
} | ||
|
||
@Override | ||
public CommandResult execute() { | ||
if (syncOption) { | ||
model.activateModelSyncing(); | ||
return new CommandResult(SYNC_ON_MESSAGE); | ||
} else { | ||
model.deactivateModelSyncing(); | ||
return new CommandResult(SYNC_OFF_MESSAGE); | ||
} | ||
} | ||
|
||
//@@author | ||
public static String getName() { | ||
return COMMAND_WORD; | ||
} | ||
|
||
public static String getFormat() { | ||
return COMMAND_FORMAT; | ||
} | ||
|
||
public static String getDescription() { | ||
return COMMAND_DESCRIPTION; | ||
} | ||
} |
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,30 @@ | ||
package seedu.agendum.sync; | ||
|
||
import seedu.agendum.model.task.Task; | ||
|
||
//@@author A0003878Y | ||
public interface Sync { | ||
|
||
/** Enum used to persist SyncManager status **/ | ||
enum SyncStatus { | ||
RUNNING, NOTRUNNING | ||
} | ||
|
||
/** Retrieve sync manager sync status **/ | ||
SyncStatus getSyncStatus(); | ||
|
||
/** Sets sync manager sync status **/ | ||
void setSyncStatus(SyncStatus syncStatus); | ||
|
||
/** Turn on syncing **/ | ||
void startSyncing(); | ||
|
||
/** Turn off syncing **/ | ||
void stopSyncing(); | ||
|
||
/** Add Task to sync provider **/ | ||
void addNewEvent(Task task); | ||
|
||
/** Remove task from sync provider **/ | ||
void deleteEvent(Task task); | ||
} |
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,58 @@ | ||
package seedu.agendum.sync; | ||
|
||
import seedu.agendum.commons.core.ComponentManager; | ||
import seedu.agendum.commons.core.LogsCenter; | ||
import seedu.agendum.model.task.Task; | ||
|
||
import java.util.logging.Logger; | ||
|
||
//@@author A0003878Y | ||
public class SyncManager extends ComponentManager implements Sync { | ||
private final Logger logger = LogsCenter.getLogger(SyncManager.class); | ||
private SyncStatus syncStatus = SyncStatus.NOTRUNNING; | ||
|
||
private final SyncProvider syncProvider; | ||
|
||
public SyncManager(SyncProvider syncProvider) { | ||
this.syncProvider = syncProvider; | ||
this.syncProvider.setManager(this); | ||
|
||
syncProvider.startIfNeeded(); | ||
} | ||
|
||
@Override | ||
public SyncStatus getSyncStatus() { | ||
return syncStatus; | ||
} | ||
|
||
@Override | ||
public void setSyncStatus(SyncStatus syncStatus) { | ||
this.syncStatus = syncStatus; | ||
} | ||
|
||
@Override | ||
public void startSyncing() { | ||
syncProvider.start(); | ||
} | ||
|
||
@Override | ||
public void stopSyncing() { | ||
syncProvider.stop(); | ||
} | ||
|
||
@Override | ||
public void addNewEvent(Task task) { | ||
if (syncStatus == SyncStatus.RUNNING) { | ||
if (task.getStartDateTime().isPresent() && task.getEndDateTime().isPresent()) { | ||
syncProvider.addNewEvent(task); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void deleteEvent(Task task) { | ||
if (syncStatus == SyncStatus.RUNNING) { | ||
syncProvider.deleteEvent(task); | ||
} | ||
} | ||
} |
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,31 @@ | ||
package seedu.agendum.sync; | ||
|
||
import seedu.agendum.model.task.Task; | ||
|
||
//@@author A0003878Y | ||
public abstract class SyncProvider { | ||
|
||
/** Sync provider's keep a reference to the manager so that they can set it's | ||
* sync status **/ | ||
protected Sync syncManager; | ||
|
||
/** Start sync provider and perform initialization **/ | ||
public abstract void start(); | ||
|
||
/** Start sync provider if it needs to be started **/ | ||
public abstract void startIfNeeded(); | ||
|
||
/** Stop sync provider and perform cleanup **/ | ||
public abstract void stop(); | ||
|
||
/** Add event into sync provider **/ | ||
public abstract void addNewEvent(Task task); | ||
|
||
/** Delete event from sync provider **/ | ||
public abstract void deleteEvent(Task task); | ||
|
||
/** Set sync provider's sync manager **/ | ||
public void setManager(Sync syncManager) { | ||
this.syncManager = syncManager; | ||
} | ||
} |
Oops, something went wrong.