Skip to content

Commit

Permalink
fix Recurring bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuoZhuolin committed Oct 30, 2016
1 parent 55946b1 commit 8c5adfb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/main/java/seedu/taskell/logic/commands/DoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import seedu.taskell.commons.core.UnmodifiableObservableList;
import seedu.taskell.commons.exceptions.IllegalValueException;
import seedu.taskell.model.task.ReadOnlyTask;
import seedu.taskell.model.task.RecurringType;
import seedu.taskell.model.task.Task;
import seedu.taskell.model.task.TaskDate;
import seedu.taskell.model.task.TaskStatus;
Expand Down Expand Up @@ -44,20 +45,21 @@ public CommandResult execute() {
ReadOnlyTask taskToDone = lastShownList.get(targetIndex - 1);
Task newTask = null;

try {
if(taskToDone.getRecurringType().equals("daily")){
try {

if (taskToDone.getRecurringType().recurringType.equals(RecurringType.DAILY_RECURRING)) {
newTask = new Task(taskToDone.getDescription(), taskToDone.getTaskType(), taskToDone.getStartDate().getNextDay(), taskToDone.getEndDate().getNextDay(),
taskToDone.getStartTime(), taskToDone.getEndTime(), taskToDone.getTaskPriority(), taskToDone.getRecurringType(), taskToDone.getTaskStatus(), taskToDone.getTags());

}else if(taskToDone.getRecurringType().equals("weekly")){
} else if (taskToDone.getRecurringType().recurringType.equals(RecurringType.WEEKLY_RECURRING)) {
newTask = new Task(taskToDone.getDescription(), taskToDone.getTaskType(), taskToDone.getStartDate().getNextWeek(), taskToDone.getEndDate().getNextWeek(),
taskToDone.getStartTime(), taskToDone.getEndTime(), taskToDone.getTaskPriority(), taskToDone.getRecurringType(), taskToDone.getTaskStatus(), taskToDone.getTags());

}else if(taskToDone.getRecurringType().equals("monthly")){
} else if (taskToDone.getRecurringType().recurringType.equals(RecurringType.MONTHLY_RECURRING)) {
newTask = new Task(taskToDone.getDescription(), taskToDone.getTaskType(), taskToDone.getStartDate().getNextMonth(), taskToDone.getEndDate().getNextMonth(),
taskToDone.getStartTime(), taskToDone.getEndTime(), taskToDone.getTaskPriority(), taskToDone.getRecurringType(), taskToDone.getTaskStatus(), taskToDone.getTags());

}else if(taskToDone.getRecurringType().equals("neverRecur")){
} else if (taskToDone.getRecurringType().recurringType.equals(RecurringType.DEFAULT_RECURRING)) {
newTask = new Task(taskToDone.getDescription(), taskToDone.getTaskType(), taskToDone.getStartDate(), taskToDone.getEndDate(),
taskToDone.getStartTime(), taskToDone.getEndTime(), taskToDone.getTaskPriority(), taskToDone.getRecurringType(), finsihedStatus, taskToDone.getTags());
}
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/seedu/taskell/logic/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import seedu.taskell.logic.commands.list.ListDoneCommand;
import seedu.taskell.logic.commands.list.ListPriorityCommand;
import seedu.taskell.model.tag.Tag;
import seedu.taskell.model.task.FloatingTask;
import seedu.taskell.model.task.RecurringType;
import seedu.taskell.model.task.Task;
import seedu.taskell.model.task.TaskDate;
Expand Down Expand Up @@ -481,7 +482,7 @@ private Command prepareAdd(String args) {
boolean hasEndDate = false;
boolean hasStartTime = false;
boolean hasEndTime = false;

boolean hasRecurring = false;
while (!initialQueue.isEmpty()) {
token = initialQueue.poll().trim();
String tempToken = "";
Expand Down Expand Up @@ -559,10 +560,12 @@ private Command prepareAdd(String args) {
return new IncorrectCommand(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
} else {
System.out.println(token);

recurringType = token.substring(token.indexOf(RecurringType.PREFIX) + 2);
hasRecurring = true;
recurrenceCount++;
}

} else if (TaskDate.isValidDate(token)) {
if (byQueue.isEmpty() && onQueue.isEmpty() && atQueue.isEmpty() && fromQueue.isEmpty()
&& toQueue.isEmpty()) {
Expand Down Expand Up @@ -681,12 +684,16 @@ private Command prepareAdd(String args) {
return new IncorrectCommand(ive.getMessage());
}
} else {
try {
return new AddCommand(description, Task.FLOATING_TASK, startDate, endDate, startTime, endTime,
taskPriority, recurringType, getTagsFromArgs(tagString));
} catch (IllegalValueException ive) {
UndoCommand.deletePreviousCommand();
return new IncorrectCommand(ive.getMessage());
if(hasRecurring){
return new IncorrectCommand(FloatingTask.RECURRING_TYPE_NOT_ALLOWED);
}else{
try {
return new AddCommand(description, Task.FLOATING_TASK, startDate, endDate, startTime, endTime,
taskPriority, recurringType, getTagsFromArgs(tagString));
} catch (IllegalValueException ive) {
UndoCommand.deletePreviousCommand();
return new IncorrectCommand(ive.getMessage());
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/taskell/model/task/FloatingTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* Guarantees: details are present and not null, field values are validated.
*/
public class FloatingTask extends Task {


public static final String RECURRING_TYPE_NOT_ALLOWED = "Floating task cannot be recurring";

public FloatingTask(String description, String taskPriority, String recurringType, String taskStatus, UniqueTagList tags) throws IllegalValueException {
this(new Description(description),
FLOATING_TASK,
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/taskell/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void execute_add_invalidTaskData() throws Exception {
assertCommandBehavior(
"add Valid Description with startDate after endDate from 1-jan-2200 to 1-jan-2100", EventTask.MESSAGE_EVENT_CONSTRAINTS);
assertCommandBehavior(
"add Valid Description with startTime before Today's current time at 2am", EventTask.MESSAGE_EVENT_CONSTRAINTS);
"add Valid Description with startTime before Today's current time at 12am", EventTask.MESSAGE_EVENT_CONSTRAINTS);
assertCommandBehavior(
"add Valid Description p/invalidPriority ", TaskPriority.MESSAGE_TASK_PRIORITY_CONSTRAINTS);
assertCommandBehavior(
Expand Down

0 comments on commit 8c5adfb

Please sign in to comment.