Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1819S2#75 from wSemis/branch-test
Browse files Browse the repository at this point in the history
[V1.2] Copy enhanced, taskcopy, result_display ui enhanced
  • Loading branch information
kthSim authored Mar 19, 2019
2 parents 10a1177 + d9bddc5 commit ecfe502
Show file tree
Hide file tree
Showing 23 changed files with 405 additions and 44 deletions.
15 changes: 11 additions & 4 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,21 @@ Makes an exact copy of a person’s data and adds it to the personnel data
records. This is implemented in the case that multiple people share
similar details.

Format: `copy INDEX`
Format: `copy INDEX [Count]`

Note: If the copied entry is not modified before exiting the program,
there will be a notification.
there will be a confirmation.

Example:


* `copy 3` +
Makes a copy of the person at index 3 and inserts it at the bottom of
the current personnel records with a copy tag.

* `copy 3 4` +
Makes 4 copies of the person at index 3 and inserts them at the bottom of
the current personnel records with a copy tag.

=== Record: Access a person’s dental records
==== record add

Expand Down Expand Up @@ -507,10 +510,14 @@ Clears all personnel data and records from the application
Format: `clear`

=== Exit
Exits the program
Exits the program. You won't be able to exit if copies exist

Format: `exit`

=== Exit anyway
Exits the program. You can exit under no circumstances

Format: `exit!`

=== Appointments [Coming in v2.0]
Schedule patient appointments.
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ public void start(Stage primaryStage) {
@Override
public void stop() {
logger.info("============================ [ Stopping Address Book ] =============================");
if (model.checkNoCopy()) {
logger.info("No copies left");
} else {
logger.info("Unedited copies exist");
}
try {
storage.saveUserPrefs(model.getUserPrefs());
} catch (IOException e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ public interface Logic {
* @see seedu.address.model.Model#setSelectedPerson(Person)
*/
void setSelectedPerson(Person person);

boolean checkNoCopy();
}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
return commandResult;
}

@Override
public boolean checkNoCopy() { return model.checkNoCopy(); }

@Override
public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/seedu/address/logic/commands/CopyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.patient.Patient;
import seedu.address.model.patient.exceptions.PersonIsNotPatient;
import seedu.address.model.person.Person;

/**
* Adds a person to the address book.
* Copy a temporary person to the address book.
*/
public class CopyCommand extends Command {

public static final String COMMAND_WORD = "copy";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Have a temporary duplicate person in the addressbook. "
+ "Parameters: Index (Must be an integer)"
+ "Example: " + COMMAND_WORD + " 1 ";
+ "Parameters: Index (Must be an integer) [Number of Copies]"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_SUCCESS = "Person copied: %1$s";

private final Index index;

private final int numOfCopies;

/**
* Creates an AddCommand to add the specified {@code Person}
* Creates an CopyCommand to add the specified {@code Person}
*/
public CopyCommand(Index index) {
public CopyCommand(Index index, int numOfCopies) {
requireNonNull(index);
this.index = index;
this.numOfCopies = numOfCopies;
}

@Override
Expand All @@ -45,9 +50,18 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

Person personToCopy = lastShownList.get(index.getZeroBased());
Person copyPerson = personToCopy.copy();
Person copyPerson;

requireNonNull(personToCopy);
if (personToCopy instanceof Patient) {
copyPerson = personToCopy.copy();
} else {
throw new PersonIsNotPatient();
}

model.addPerson(copyPerson);
for (int i = 0; i < numOfCopies; i++) {
model.addPerson(copyPerson);
}
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, copyPerson));
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/seedu/address/logic/commands/ExitAnywayCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package seedu.address.logic.commands;

import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Terminates the program without any checking
*/
public class ExitAnywayCommand extends Command {
public static final String COMMAND_WORD = "exit!";

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";

@Override
public CommandResult execute(Model model, CommandHistory history) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
}

}
12 changes: 10 additions & 2 deletions src/main/java/seedu/address/logic/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ public class ExitCommand extends Command {

public static final String COMMAND_WORD = "exit";

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";
static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";

private static final String MEESAGE_COPY_EXIST = "!eExists unedited copies in addressbook.\n"
+ "No copies will be saved.\n"
+ "Use exit! to exit anyway";

@Override
public CommandResult execute(Model model, CommandHistory history) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
if (model.checkNoCopy()) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
} else {
return new CommandResult(MEESAGE_COPY_EXIST);
}
}

}
70 changes: 70 additions & 0 deletions src/main/java/seedu/address/logic/commands/TaskcopyCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.task.Task;

/**
* Copy a temporary person to the address book.
*/
public class TaskcopyCommand extends Command {

public static final String COMMAND_WORD = "taskcopy";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Have a temporary duplicate task in the addressbook. "
+ "Parameters: Index (Must be an integer) [Number of Copies]"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_SUCCESS = "Person copied: %1$s";

private final Index index;

private final int numOfCopies;

/**
* Creates an TaskcopyCommand to add the specified {@code Person}
*/
public TaskcopyCommand(Index index, int numOfCopies) {
requireNonNull(index);
this.index = index;
this.numOfCopies = numOfCopies;
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Task> lastShownList = model.getFilteredTaskList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Task taskToCopy = lastShownList.get(index.getZeroBased());
Task copytask = taskToCopy;

for (int i = 0; i < numOfCopies; i++) {
requireNonNull(taskToCopy);
copytask = taskToCopy.copy();
model.addTask(copytask);
}

model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, copytask));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof TaskcopyCommand // instanceof handles nulls
&& index.equals(((TaskcopyCommand) other).index));
}
}
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.logic.commands.CopyCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitAnywayCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.ExportCommand;
import seedu.address.logic.commands.FindCommand;
Expand All @@ -28,6 +29,7 @@
import seedu.address.logic.commands.TaskAddCommand;
import seedu.address.logic.commands.TaskDeleteCommand;
import seedu.address.logic.commands.TaskEditCommand;
import seedu.address.logic.commands.TaskcopyCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand All @@ -54,7 +56,7 @@ public Command parseCommand(String userInput) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
}

final String commandWord = matcher.group("commandWord");
final String commandWord = matcher.group("commandWord").toLowerCase();
final String arguments = matcher.group("arguments");
switch (commandWord) {
case AddCommand.COMMAND_WORD:
Expand Down Expand Up @@ -123,6 +125,12 @@ public Command parseCommand(String userInput) throws ParseException {
case TaskDeleteCommand.COMMAND_WORD:
return new TaskDeleteCommandParser().parse(arguments);

case TaskcopyCommand.COMMAND_WORD:
return new TaskcopyCommandParser().parse(arguments);

case ExitAnywayCommand.COMMAND_WORD:
return new ExitAnywayCommand();

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import javafx.util.Pair;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.CopyCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand All @@ -22,14 +23,18 @@ public CopyCommand parse(String args) throws ParseException {
requireNonNull(args);

Index index;
int numOfCopies;

try {
index = ParserUtil.parseIndex(args);
Pair<Index, Integer> parsedPair = ParserUtil.parseCopy(args);
index = parsedPair.getKey();
numOfCopies = parsedPair.getValue();

} catch (ParseException pe) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, CopyCommand.MESSAGE_USAGE), pe);
}


return new CopyCommand(index);
return new CopyCommand(index, numOfCopies);
}
}
41 changes: 41 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javafx.util.Pair;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -278,4 +279,44 @@ public static ParsedInOut parseImportExport(String input) throws ParseException

return new ParsedInOut(new File(filepath), parsedIndex);
}

/**
* Parse a {@code String argument} from copy or taskcopy command to number of copies needed
* @param input input from copy or taskcopy command
* @return number of copies requested
* @throws ParseException
*/
public static Pair<Index, Integer> parseCopy(String input) throws ParseException {
requireNonNull(input);
input = input.trim();

String[] parsedInput = input.split("\\s+");
Index i;
int numOfCopies;

if (parsedInput.length == 1) {

try {
i = parseIndex(parsedInput[0]);
} catch (NumberFormatException e) {
throw new ParseException("Wrong input format!");
}
return new Pair(i, 1);
} else if (parsedInput.length == 2) {

try {
i = parseIndex(parsedInput[0]);
numOfCopies = Integer.parseInt(parsedInput[1]);
} catch (NumberFormatException e) {
throw new ParseException("Wrong input format!");
}
if (numOfCopies < 1) {
throw new ParseException("Input number must be positive!");
}

return new Pair(i, numOfCopies);
}

throw new ParseException("Wrong number of arguments");
}
}
Loading

0 comments on commit ecfe502

Please sign in to comment.