Skip to content

Commit

Permalink
Enable Edit Command to remove task's parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
howitzerg committed Nov 3, 2016
1 parent 4fbe607 commit 41a926c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/main/java/seedu/task/logic/Logic.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.task.logic;

import javafx.collections.ObservableList;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.logic.commands.CommandResult;
import seedu.task.model.task.ReadOnlyTask;

Expand All @@ -12,8 +13,9 @@ public interface Logic {
* Executes the command and returns the result.
* @param commandText The command as entered by the user.
* @return the result of the command execution.
* @throws IllegalValueException
*/
CommandResult execute(String commandText);
CommandResult execute(String commandText) throws IllegalValueException;

/** Returns the filtered list of tasks */
ObservableList<ReadOnlyTask> getFilteredTaskList();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/task/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import seedu.task.commons.core.ComponentManager;
import seedu.task.commons.core.Config;
import seedu.task.commons.core.LogsCenter;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.logic.commands.Command;
import seedu.task.logic.commands.CommandResult;
import seedu.task.logic.parser.Parser;
Expand Down Expand Up @@ -31,7 +32,7 @@ public LogicManager(Model model, Storage storage, Config config) {


@Override
public CommandResult execute(String commandText) {
public CommandResult execute(String commandText) throws IllegalValueException {
logger.info("----------------[USER COMMAND][" + commandText + "]");
Command command = parser.parseCommand(commandText);
command.setData(model);
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/seedu/task/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,36 @@ public class AddCommand extends Command {
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommand(String taskName, String startDate,String startTime,String dueDate, String dueTime, String importance, Set<String> tags)
throws IllegalValueException {
public AddCommand(String taskName, String startDate, String startTime, String dueDate, String dueTime,
String importance, Set<String> tags) throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}

//@@author A0139824X
//Data preprocessing
if (taskName == EditCommand.DELETE_TASK_OBJECT_STRING) {
taskName = "";
}
if (startDate == EditCommand.DELETE_TASK_OBJECT_STRING) {
startDate = "";
}
if (startTime == EditCommand.DELETE_TASK_OBJECT_STRING) {
startTime = "";
}
if (dueDate == EditCommand.DELETE_TASK_OBJECT_STRING) {
dueDate = "";
}
if (dueTime == EditCommand.DELETE_TASK_OBJECT_STRING) {
dueTime = "";
}
if (importance == EditCommand.DELETE_TASK_OBJECT_STRING) {
importance = "";
}

//@@author

this.toAdd = new Task(
new TaskName(taskName),
new EventStart(new Date(startDate), new Time(startTime)),
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/task/logic/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import seedu.task.commons.core.EventsCenter;
import seedu.task.commons.core.Messages;
import seedu.task.commons.events.ui.IncorrectCommandAttemptedEvent;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.model.Model;

/**
Expand All @@ -29,8 +30,9 @@ public static String getMessageForTaskListShownSummary(int displaySize) {
* Executes the command and returns the result message.
*
* @return feedback message of the operation result for display
* @throws IllegalValueException
*/
public abstract CommandResult execute();
public abstract CommandResult execute() throws IllegalValueException;

/**
* Provides any needed dependencies to the command. Commands making use of
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/seedu/task/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class EditCommand extends Command {
+ ": edits the task identified by the index number used in the last task listing.\n"
+ "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1";
public static final String MESSAGE_EDIT_TASK_SUCCESS = "Edited Task: %1$s";
public static final String DELETE_TASK_OBJECT_STRING = "-";

public final int targetIndex;
private final Task toEdit;
Expand Down Expand Up @@ -64,7 +65,7 @@ public EditCommand(String string, String taskName, String startDate, String star
}

@Override
public CommandResult execute() {
public CommandResult execute() throws IllegalValueException {

UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

Expand All @@ -91,16 +92,24 @@ public CommandResult execute() {
if (this.toEdit.getDeadline().getDueDate().toString().equals(EMPTY_TASK_OBJECT_STRING)
|| this.toEdit.getDeadline().getDueDate().toString().equals(DEFAULT_DATE_STRING)) {
this.toEdit.setDueDate(taskToEdit.getDeadline().getDueDate());
} else if (this.toEdit.getDeadline().getDueDate().toString().equals(DELETE_TASK_OBJECT_STRING)) {
this.toEdit.setDueDate(new Date(""));
}
if (this.toEdit.getDeadline().getDueTime().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
this.toEdit.setDueTime(taskToEdit.getDeadline().getDueTime());
} else if (this.toEdit.getDeadline().getDueTime().toString().equals(DELETE_TASK_OBJECT_STRING)) {
this.toEdit.setDueTime(new Time(""));
}
if (this.toEdit.getEventStart().getStartDate().toString().equals(EMPTY_TASK_OBJECT_STRING)
|| this.toEdit.getEventStart().getStartDate().toString().equals(DEFAULT_DATE_STRING)) {
this.toEdit.setStartDate(taskToEdit.getEventStart().getStartDate());
} else if (this.toEdit.getEventStart().getStartDate().toString().equals(DELETE_TASK_OBJECT_STRING)) {
this.toEdit.setStartDate(new Date(""));
}
if (this.toEdit.getEventStart().getStartTime().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
this.toEdit.setStartTime(taskToEdit.getEventStart().getStartTime());
} else if (this.toEdit.getEventStart().getStartTime().toString().equals(DELETE_TASK_OBJECT_STRING)) {
this.toEdit.setStartTime(new Time(""));
}
if (this.toEdit.getTags().getInternalList().toString().equals(EMPTY_TAG_OBJECT_STRING)) {
this.toEdit.setTags(taskToEdit.getTags());
Expand All @@ -110,6 +119,8 @@ public CommandResult execute() {
}
if (this.toEdit.getImportance().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
this.toEdit.setImportance(taskToEdit.getImportance());
} else if (this.toEdit.getImportance().toString().equals(DELETE_TASK_OBJECT_STRING)) {
this.toEdit.setImportance(new Importance(""));
}
model.editTask(taskToEdit, this.toEdit);

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/seedu/task/model/task/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Date {
public static final String DATE_30DAYS_VALIDATION_REGEX = "((0[1-9]|([1-2][0-9])|30)(0[469]|11)([2-9]\\d{3})$){0,1}";
public static final String DATE_FEB_NONLEAPYEAR_VALIDATION_REGEX = "((0[1-9]|(1[0-9])|2[0-8])(0[1-9]|1[0-2])([2-9]\\d{3})$){0,1}";
public static final String DATE_FEB_LEAPYEAR_VALIDATION_REGEX = "((0[1-9]|(1[0-9])|2[0-9])(0[1-9]|1[0-2])([2-9]\\d{3})$){0,1}";
public static final String DELETE_TASK_OBJECT_STRING = "-";

private final String date;

Expand All @@ -30,11 +31,13 @@ public Date(String date) throws IllegalValueException {
if (date == null)
date = "";
date = date.trim();
if (!isValidDateFormat(date)) {
throw new IllegalValueException(MESSAGE_DATE_CONSTRAINTS);
}
if (!isValidDate(date)) {
throw new IllegalValueException(MESSAGE_INVALID_DATE);
if (!date.equals(DELETE_TASK_OBJECT_STRING)) {
if (!isValidDateFormat(date)) {
throw new IllegalValueException(MESSAGE_DATE_CONSTRAINTS);
}
if (!isValidDate(date)) {
throw new IllegalValueException(MESSAGE_INVALID_DATE);
}
}
this.date = date;
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/seedu/task/model/task/Importance.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Importance {

public static final String MESSAGE_IMPORTANCE_CONSTRAINTS = "Task importance is denoted by number of *";
public static final String IMPORTANCE_VALIDATION_REGEX = "[*]{0,3}";
public static final String DELETE_TASK_OBJECT_STRING = "-";

public final String value;

Expand All @@ -20,15 +21,15 @@ public class Importance {
* @throws IllegalValueException if given address string is invalid.
*/
public Importance(String importance) throws IllegalValueException {
if (importance == null)
importance = "";
this.value = importance;

if (!isValidImportance(importance)) {
throw new IllegalValueException(MESSAGE_IMPORTANCE_CONSTRAINTS);
}
if (importance == null)
importance = "";

if (!importance.equals(DELETE_TASK_OBJECT_STRING))
if (!isValidImportance(importance)) {
throw new IllegalValueException(MESSAGE_IMPORTANCE_CONSTRAINTS);
}

this.value = importance;
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/seedu/task/model/task/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Time {
public static final String MESSAGE_INVALID_TIME = "Time provided is invalid";
public static final String TIME_VALIDATION_REGEX = "(([0-1]?[0-9]|2[0-3])[0-5][0-9]$){0,1}";
public static final String INTEGER = "(\\d{4}){0,1}";
public static final String DELETE_TASK_OBJECT_STRING = "-";

private final String time;

Expand All @@ -28,11 +29,13 @@ public Time(String time) throws IllegalValueException {
if (time == null)
time = "";
time = time.trim();
if (!isValidTimeFormat(time)) {
throw new IllegalValueException(MESSAGE_TIME_CONSTRAINTS);
}
if (!isValidTime(time)) {
throw new IllegalValueException(MESSAGE_TIME_CONSTRAINTS);
if (!(time.equals(DELETE_TASK_OBJECT_STRING))) {
if (!isValidTimeFormat(time)) {
throw new IllegalValueException(MESSAGE_TIME_CONSTRAINTS);
}
if (!isValidTime(time)) {
throw new IllegalValueException(MESSAGE_TIME_CONSTRAINTS);
}
}
this.time = time;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/seedu/task/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.stage.Stage;
import seedu.task.commons.core.LogsCenter;
import seedu.task.commons.events.ui.IncorrectCommandAttemptedEvent;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.commons.util.FxViewUtil;
import seedu.task.logic.Logic;
import seedu.task.logic.commands.*;
Expand Down Expand Up @@ -77,7 +78,11 @@ private void handleCommandInputChanged() {
* #handleIncorrectCommandAttempted}
*/
setStyleToIndicateCorrectCommand();
mostRecentResult = logic.execute(previousCommandTest);
try {
mostRecentResult = logic.execute(previousCommandTest);
} catch (IllegalValueException e) {
e.printStackTrace();
}
resultDisplay.postMessage(mostRecentResult.feedbackToUser);
logger.info("Result: " + mostRecentResult.feedbackToUser);
}
Expand Down

0 comments on commit 41a926c

Please sign in to comment.