Skip to content

Commit

Permalink
Merge 32132a4 into 5d9262f
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihong8888 committed Oct 10, 2018
2 parents 5d9262f + 32132a4 commit 73d4375
Show file tree
Hide file tree
Showing 26 changed files with 428 additions and 46 deletions.
20 changes: 19 additions & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ public void init() throws Exception {
*/
private Model initModelManager(Storage storage, UserPrefs userPrefs) {
Optional<ReadOnlyAddressBook> addressBookOptional;
Optional<ReadOnlyScheduleList> scheduleListOptional;

ReadOnlyAddressBook initialData;
ReadOnlyExpensesList initialExpenses;
ReadOnlyScheduleList initialSchedule;

initialExpenses = new ExpensesList();
initialSchedule = new ScheduleList();

try {
addressBookOptional = storage.readAddressBook();
Expand All @@ -119,6 +120,23 @@ private Model initModelManager(Storage storage, UserPrefs userPrefs) {
initialData = new AddressBook();
}

try {
scheduleListOptional = storage.readScheduleList();
if (!scheduleListOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a schedule List");
initialSchedule = new ScheduleList();
} else {
initialSchedule = scheduleListOptional.get();
}
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty ScheduleList");
initialSchedule = new ScheduleList();

} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty ScheduleList");
initialSchedule = new ScheduleList();
}

return new ModelManager(initialData, initialExpenses, initialSchedule, userPrefs);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;
import seedu.address.model.schedule.Schedule;

/**
* Represents a selection change in the Schedule List Panel
*/
public class SchedulePanelSelectionChangedEvent extends BaseEvent {


private final Schedule newSelection;

public SchedulePanelSelectionChangedEvent(Schedule newSelection) {
this.newSelection = newSelection;
}

@Override
public String toString() {
return getClass().getSimpleName();
}

public Schedule getNewSelection() {
return newSelection;
}
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Person;
import seedu.address.model.schedule.Schedule;

/**
* API of the Logic component
Expand All @@ -22,6 +23,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of schedule */
ObservableList<Schedule> getFilteredScheduleList();

/** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */
ListElementPointer getHistorySnapshot();
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.schedule.Schedule;

/**
* The main LogicManager of the app.
Expand Down Expand Up @@ -45,6 +46,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Schedule> getFilteredScheduleList() {
return model.getFilteredScheduleList();
}

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/seedu/address/logic/commands/AddScheduleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.schedule.Schedule;

/**
Expand All @@ -22,14 +23,17 @@ public class AddScheduleCommand extends Command {
+ "Parameters: "
+ PREFIX_EMPLOYEEID + "[6digit] "
+ PREFIX_SCHEDULE_DATE + "[DD/MM/YYYY] "
+ PREFIX_SCHEDULE_TYPE + "[WORKING/LEAVE] "
+ "Example: " + COMMAND_WORD + " 000001 "
+ PREFIX_SCHEDULE_DATE + "02/02/2018"
+ PREFIX_SCHEDULE_TYPE + "[WORKING/LEAVE] \n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_EMPLOYEEID + "000001 "
+ PREFIX_SCHEDULE_DATE + "02/02/2018 "
+ PREFIX_SCHEDULE_TYPE + "LEAVE";

public static final String MESSAGE_SUCCESS = "New schedule added: %1$s";
public static final String MESSAGE_DUPLICATE_SCHEDULE = "This schedule already exists in the address book";
public static final String MESSAGE_EMPLOYEE_ID_NOT_FOUND = "Employee Id not found in address book";

private Person toCheckEmployeeId;
private final Schedule toAddSchedule;

/**
Expand All @@ -38,18 +42,20 @@ public class AddScheduleCommand extends Command {
public AddScheduleCommand(Schedule schedule) {
requireAllNonNull(schedule);
this.toAddSchedule = schedule;
toCheckEmployeeId = new Person(schedule.getEmployeeId());
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
if (model.hasSchedule(toAddSchedule)) {
throw new CommandException(MESSAGE_DUPLICATE_SCHEDULE);
} else if (!model.hasEmployeeId(toCheckEmployeeId)) {
throw new CommandException(MESSAGE_EMPLOYEE_ID_NOT_FOUND);
}

model.addSchedule(toAddSchedule);
model.commitScheduleList();
return new CommandResult(String.format(MESSAGE_SUCCESS, toAddSchedule));

}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static Date parseDate(String date) throws ParseException {
requireNonNull(date);
String trimmedDate = date.trim();
if (!Date.isValidDate(trimmedDate)) {
throw new ParseException(Date.MESSAGE_DATE_CONSTRAINTS);
throw new ParseException(Date.MESSAGE_DATE_CONSTRAINTS_DEFAULT);
}
return new Date(trimmedDate);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface Model {
boolean hasExpenses(Expenses expenses);
boolean hasPerson(Person person);
boolean hasSchedule(Schedule schedule);
boolean hasEmployeeId(Person person);

/**
* Deletes the given person.
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public boolean hasPerson(Person person) {
return versionedAddressBook.hasPerson(person);
}

@Override
public boolean hasEmployeeId(Person person) {
requireNonNull(person);
return versionedAddressBook.hasEmployeeId(person);
}

@Override
public boolean hasSchedule(Schedule target) {
requireNonNull(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public boolean hasPerson(Person person) {
return persons.contains(person);
}

/**
* Returns true if a person with the same identity as {@code person} exists in the address book.
*/
public boolean hasEmployeeId(Person person) {
requireNonNull(person);
return persons.containsEmployeeId(person);
}

/**
* Adds a person to the address book.
* The person must not already exist in the address book.
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;

import seedu.address.model.person.tag.Tag;
import seedu.address.model.util.SampleDataUtil;

/**
* Represents a Person in the address book.
Expand Down Expand Up @@ -50,6 +51,22 @@ public Person(EmployeeId employeeId, Name name, DateOfBirth dateOfBirth, Phone p
this.tags.addAll(tags);
}

public Person(EmployeeId employeeId) {
SampleDataUtil sample = new SampleDataUtil();
requireAllNonNull(employeeId);
this.employeeId = employeeId;
this.name = new Name(sample.SAMPLE_NAME.toString());
this.dateOfBirth = new DateOfBirth(sample.SAMPLE_DATEOFBIRTH.toString());
this.phone = new Phone(sample.SAMPLE_PHONE.toString());
this.email = new Email(sample.SAMPLE_EMAIL.toString());
this.department = new Department(sample.SAMPLE_DEPARTMENT.toString());
this.position = new Position(sample.SAMPLE_POSITION.toString());
this.address = new Address(sample.SAMPLE_ADDRESS.toString());
this.salary = new Salary(sample.SAMPLE_SALARY.toString());
this.bonus = new Bonus(sample.SAMPLE_BONUS.toString());
this.tags.addAll(new HashSet<>());
}

public EmployeeId getEmployeeId() {
return employeeId;
}
Expand Down Expand Up @@ -112,6 +129,18 @@ public boolean isSamePerson(Person otherPerson) {
&& (otherPerson.getPhone().equals(getPhone()) || otherPerson.getEmail().equals(getEmail()));
}

/**
* Returns true if both persons of the same employee id.
*/
public boolean isSameEmployeeId(Person person) {
if (person.getEmployeeId() == this.getEmployeeId()) {
return true;
}

return person.getEmployeeId() != null
&& person.getEmployeeId().equals(getEmployeeId());
}

/**
* Returns true if both persons have the same identity and data fields.
* This defines a stronger notion of equality between two persons.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public boolean contains(Person toCheck) {
return internalList.stream().anyMatch(toCheck::isSamePerson);
}

/**
* Returns true if the list contains an equivalent person as the given argument.
*/
public boolean containsEmployeeId(Person toCheck) {
requireNonNull(toCheck);
return internalList.stream().anyMatch(toCheck::isSameEmployeeId);
}


/**
* Adds a person to the list.
* The person must not already exist in the list.
Expand Down
78 changes: 68 additions & 10 deletions src/main/java/seedu/address/model/schedule/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@
* Guarantees: immutable; is valid as declared in {@link #Date(String)}
*/
public class Date {
public static final String MESSAGE_DATE_CONSTRAINTS =
"Date of Birth should only be in the format of DD/MM/YYYY and it should not be blank";
public static final String DATE_VALIDATION_REGEX = "[0-3][0-9]/[0-1][0-9]/[0-2][0-9]{3}";
public static final String DATE_VALIDATION_REGEX = "(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((20)\\d\\d)";

public final String date;
public static final String MESSAGE_DATE_CONSTRAINTS_DEFAULT =
"Date should only be in the format of DD/MM/YYYY, it should not be blank and within "
+ "01/01/2000 to 31/12/2099?";

private static final String MESSAGE_DATE_INVALID_FEB_DATE =
"29, 30 and 31 are invalid dates of February";
private static final String MESSAGE_DATE_INVALID_FEB_DATE_LEAP_YEAR =
"30 and 31 are invalid dates of February on a leap year";

private static final String MESSAGE_DATE_INVALID_MONTH_DATE =
"april, june, sep, nov does not have 31 days";

private static String dateConstraintsError = MESSAGE_DATE_CONSTRAINTS_DEFAULT;

public final String value;

/**
* Constructs a {@code dateOfBirth}.
Expand All @@ -27,32 +39,78 @@ public class Date {

public Date(String date) {
requireNonNull(date);
checkArgument(isValidDate(date), MESSAGE_DATE_CONSTRAINTS);
this.date = date;
checkArgument(isValidDate(date), dateConstraintsError);
value = date;
}


/**
* Returns true if a given string is a valid date of birth.
*/
public static boolean isValidDate(String test) {
return test.matches(DATE_VALIDATION_REGEX);
String day;
String month;
String year;

if (test.matches(DATE_VALIDATION_REGEX)) {
String[] date = test.split("/");

day = date[0];
month = date[1];
year = date[2];

return checkValidDate(year, month, day);
}
return false;
}

/**
* Check if date is a valid date on the Calendar.
* @param year
* @param month
* @param day
*/

public static boolean checkValidDate (String year, String month, String day) {
boolean isLeapYear = ((Integer.valueOf(year) % 4 == 0)
&& (Integer.valueOf(year) % 100 != 0) || (Integer.valueOf(year) % 400 == 0));


if ("02".equals(month)) {
if ((isLeapYear) && ((
"30".equals(day)) || ("31".equals(day)))) {
dateConstraintsError = MESSAGE_DATE_INVALID_FEB_DATE_LEAP_YEAR;
return false; //29 Feb is a valid leap year. 30, 31 is invalid.
} else if (("29".equals(day)) || ("30".equals(day)) || ("31".equals(day))) {
dateConstraintsError = MESSAGE_DATE_INVALID_FEB_DATE;
return false; //29,30,31 Feb is a invalid in non-leap year
}
}

if (("31".equals(day)) && ((
"04".equals(month)) || ("06".equals(month)) || ("09".equals(month)) || ("11".equals(month)))) {
dateConstraintsError = MESSAGE_DATE_INVALID_MONTH_DATE;
return false; // april, june, sep, nov does not have 31 days
}
dateConstraintsError = MESSAGE_DATE_CONSTRAINTS_DEFAULT;
return true;
}

@Override
public String toString() {
return date;
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Date // instanceof handles nulls
&& date.equals(((Date) other).date)); // state check
&& value.equals(((Date) other).value)); // state check
}

@Override
public int hashCode() {
return date.hashCode();
return value.hashCode();
}

}

0 comments on commit 73d4375

Please sign in to comment.