Skip to content

Commit

Permalink
Merge pull request #107 from ReganChoy/branch-Set_Command
Browse files Browse the repository at this point in the history
Add feature Set command
  • Loading branch information
yorklim authored Apr 3, 2024
2 parents 5fe1564 + 8759750 commit d7eafc6
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 6 deletions.
17 changes: 15 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Ready to head straight into the action? You can refer to our [Quick Start](#quic
<div style="page-break-after: always;"></div>

## Using this guide
This guide walks you through all the features of ClientCare and can be used as a quick reference whenever you need any help. If you're just getting started with ClientCare, we welcome you to start from our [Introduction](#introduction) section to learn more about the app. For setting up ClientCare, you might find the [Quick Start](#quick-start) section helpful.
This guide walks you through all the features of ClientCare and can be used as a quick reference whenever you need any help. If you're just getting started with ClientCare, we welcome you to start from our [Introducing ClientCare](#introducing-clientcare) section to learn more about the app. For setting up ClientCare, you might find the [Quick Start](#quick-start) section helpful.

Ready to use ClientCare? You can check out our [Features](#features) section. For ease of reference, the
[Features](#features) section is divided into subsections corresponding to each main feature:
Expand Down Expand Up @@ -79,7 +79,7 @@ You might encounter these call-outs while reading through the guide, which conta
<div style="page-break-after: always;"></div>


## Introduction
## Introducing ClientCare
Made for insurance agents and clients, by insurance agents and clients.
ClientCare is the easiest way to manage your clients and schedules, all in one place.
Powerful features and intuitive design, all packaged into one neat desktop app. ClientCare is supported on all
Expand Down Expand Up @@ -533,6 +533,19 @@ Rather, you will see him under the Schedule Display.
<br/>
<br/>

### Setting last met overdue period: `set`

Feel that 90 days is too short or long of a period? You can set your own desired overdue duration with `set`.

Format: `set NUMBER_OF_DAYS`

* Sets the last met overdue to `NUMBER_OF_DAYS`.
* The number of days **must be a non-negative integer** 0, 1, 2, 3, …​

Examples:
* `set 75` updates the last met overdue duration to 75 days. Clients who you have not met in more than 75 days or
no appointments are scheduled will show up in the Last Met reminder display.

### Scheduling appointments : `schedule`

Got a new appointment or a postpone is needed?
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.SetStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.UserPrefsStorage;
Expand Down Expand Up @@ -133,6 +134,13 @@ protected Config initConfig(Path configFilePath) {
} catch (IOException e) {
logger.warning("Failed to save config file : " + StringUtil.getDetails(e));
}

try {
SetStorage.loadData();
} catch (IOException e) {
logger.warning("SetData is invalid.");
}

return initializedConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class LastMetCommand extends Command {
private final LastMet lastMet;

/**
* Creates a LastMetCommand to update last mete date of the specified {@code Person}
* Creates a LastMetCommand to update last met date of the specified {@code Person}
*/
public LastMetCommand(Index index, LastMet lastMet) {
requireNonNull(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MarkCommand extends Command {
public static final String MESSAGE_SUCCESS = "Your schedule with %1$s has been marked as done.";
private final Index index;
/**
* Creates a LastMetCommand to update last mete date of the specified {@code Person}
* Creates a MarkCommand to complete the schedule of the specified {@code Person}
*/
public MarkCommand(Index index) {
requireNonNull(index);
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/seedu/address/logic/commands/SetCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.LastMet;
import seedu.address.model.person.Person;
import seedu.address.storage.SetStorage;

/**
* Sets the LastMet Overdue time period for all Clients.
*/
public class SetCommand extends Command {
public static final String COMMAND_WORD = "set";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": sets the LastMet overdue time period. "
+ "Parameters: "
+ "NUMBER_OF_DAYS "
+ "Example: " + COMMAND_WORD + " "
+ "90.\n "
+ "NUMBER_OF_DAYS must be an integer and be at least 0.";

public static final String MESSAGE_SUCCESS = "LastMet Overdue time period has been set to %1$s days.";
/**
* Creates a LastMetCommand to update last mete date of the specified {@code Person}
*/
private int overdueTimePeriod;

/**
* Creates a SetCommand to update last met overdue duration of the LastMet class
*/
public SetCommand(Integer numberOfDays) {
requireNonNull(numberOfDays);

this.overdueTimePeriod = numberOfDays;
}
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

LastMet.setLastMetDuration(this.overdueTimePeriod);
List<Person> lastShownList = model.getSortedFilteredPersonList();

int numberOfClients = lastShownList.size();

for (int i = 0; i < numberOfClients; i++) {
//Index index = Index.fromZeroBased(i);
Person personToCheck = lastShownList.get(i);
personToCheck.getLastMet().checkOverdue();
}

SetStorage.setData(this.overdueTimePeriod);
return new CommandResult(String.format(MESSAGE_SUCCESS, this.overdueTimePeriod));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof SetCommand)) {
return false;
}

SetCommand otherSetCommand = (SetCommand) other;
return overdueTimePeriod == (otherSetCommand.overdueTimePeriod);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("overdueTimePeriod", overdueTimePeriod)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import seedu.address.logic.commands.MarkCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.commands.ScheduleCommand;
import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.commands.SortCommand;
import seedu.address.logic.commands.ViewCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -109,6 +110,9 @@ public Command parseCommand(String userInput) throws ParseException {
case SortCommand.COMMAND_WORD:
return new SortCommandParser().parse(arguments);

case SetCommand.COMMAND_WORD:
return new SetCommandParser().parse(arguments);

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/seedu/address/logic/parser/SetCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.util.stream.Stream;

import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new SetCommand object
*/
public class SetCommandParser {

/**
* Parses the given {@code String} of arguments in the context of the SetCommand
* and returns an SetCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public SetCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args);

if (!arePrefixesPresent(argMultimap)
|| argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCommand.MESSAGE_USAGE));
}

int numberOfDays;
try {
numberOfDays = Integer.parseInt(argMultimap.getPreamble());

checkIfNegativeNumber(numberOfDays);
} catch (NumberFormatException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCommand.MESSAGE_USAGE), ive);
} catch (ParseException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCommand.MESSAGE_USAGE));
}
return new SetCommand(numberOfDays);
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}

private void checkIfNegativeNumber(int days) throws ParseException {
if (days < 0) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCommand.MESSAGE_USAGE));
}
}
}
13 changes: 12 additions & 1 deletion src/main/java/seedu/address/model/person/LastMet.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ public static void setLastMetDuration(long days) {
lastMetDuration = days;
}

/**
* Method updates and set the new LastMetDuration before overdue.
* @param days
*/
public static void setLastMetDuration(int days) {
lastMetDuration = days;
}

public static long getLastMetDuration() {
return lastMetDuration;
}

private void checkOverdue() {
/**
* Method checks for the number of days since the last meeting has exceeded the LastMet reminder period.
*/
public void checkOverdue() {
long periodGap = getPeriodGap();
if (periodGap > lastMetDuration) {
this.isOverdue = true;
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/seedu/address/storage/SetStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package seedu.address.storage;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

import seedu.address.model.person.LastMet;

/**
* This class is responsible for loading and storing the LastMet Overdue value
*/
public class SetStorage {
private static int value;
private static final String PATH = "data/setvalue.txt";

private SetStorage(int day) {
value = day;
}

public int getValue() {
return value;
}

public static void setData(int days) {
value = days;
storeData();
}

/**
* Loads the LastMet Overdue value from setvalue.txt
* @throws IOException
*/
public static void loadData() throws IOException {
File file = new File(PATH);

file.getParentFile().mkdirs();

if (!file.exists()) {
file.createNewFile();
value = 90;
storeData();
} else {
try {
checkContents(file);
} catch (NumberFormatException e) {
createNewFile();
}
}
}

/**
* Stores the LastMet Overdue value into setvalue.txt
*/
public static void storeData() {
try {
FileWriter writer = new FileWriter(PATH);
String setValue = Integer.toString(value);

writer.write(setValue);
writer.close();
} catch (IOException e) {
System.out.println("Error");
}
}

/**
* Reset the setvalue.txt file if value is invalid
*/
public static void createNewFile() {
value = 90;
storeData();
}

/**
* Checks the contents of setvalue.txt
*/
public static void checkContents(File file) throws IOException {
Scanner scanner = new Scanner(file);

if (file.length() == 0) {
createNewFile();
} else {
String input = scanner.nextLine();
Integer inputConverted = Integer.valueOf(input);

if (inputConverted instanceof Integer) {
if (inputConverted < 0) {
createNewFile();
} else {
value = inputConverted;
}
LastMet.setLastMetDuration(value);
} else {
createNewFile();
}
}
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) thro
logger.fine("Attempting to write to data file: " + filePath);
addressBookStorage.saveAddressBook(addressBook, filePath);
}

}
Loading

0 comments on commit d7eafc6

Please sign in to comment.