Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AY2324S1-CS2103-F13-2/tp
Browse files Browse the repository at this point in the history
…into add-leave
  • Loading branch information
nixonwidjaja committed Oct 4, 2023
2 parents 5a95f02 + 1c95258 commit 7f5dc84
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 26 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
[![CI Status](https://github.com/se-edu/addressbook-level3/workflows/Java%20CI/badge.svg)](https://github.com/se-edu/addressbook-level3/actions)
[![CI Status](https://github.com/se-edu/addressbook-level3/workflows/Java%20CI/badge.svg)](https://github.com/AY2324S1-CS2103-F13-2/tp/actions)

![Ui](docs/images/Ui.png)

* This is **a sample project for Software Engineering (SE) students**.<br>
* This is **a project that utilises CLI to aid HR admins with their administrative tasks.**.<br>
Example usages:
* as a starting point of a course project (as opposed to writing everything from scratch)
* as a case study
* The project is constructed based an ongoing software project (called _AddressBook3_) for a desktop application (called _HR Insight_) used for managing employee details.
* As a HR admin, I can perform basic CRUD operations (Add/Delete/List) for all the employees in my organisation.
* As a HR admin, I can list all the employees in the organisation.
* As a HR admin, I can better forecast manpower issues by tracking which months have the highest number of leaves.
* As a HR admin, I can better plan birthday celebrations by tracking which employees have birthdays for that particular month.
* As a HR admin, I can process employee's claims efficiently and accurately.

* The project is constructed based an ongoing software project (called _HR Insight_), a desktop application used for managing employee details.
* It is **written in OOP fashion**. It provides a **reasonably well-written** code base **bigger** (around 6 KLoC) than what students usually write in beginner-level SE modules, without being overwhelmingly big.
* It comes with a **reasonable level of user and developer documentation**.
* It is named `AddressBook Level 3` (`AB3` for short) because it was initially created as a part of a series of `AddressBook` projects (`Level 1`, `Level 2`, `Level 3` ...).
* For the detailed documentation of this project, see the **[Address Book Product Website](https://se-education.org/addressbook-level3)**.
* This project is a **part of the se-education.org** initiative. If you would like to contribute code to this project, see [se-education.org](https://se-education.org#https://se-education.org/#contributing) for more info.

* It is named `HR Insight` because it provides HR employees an extensive insight into an organisation.
* For the detailed documentation of this project, see the **[HR Insight Product Website](https://ay2324s1-cs2103-f13-2.github.io/tp/)**.
* This project is a **part of the CS2103** course structure.
16 changes: 8 additions & 8 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,27 +346,27 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli

**Extensions**

* 2a. User didn't provide an index and/or claim amount.
* 3a. User didn't provide an index and/or claim amount.

* 2a1. HR Insight shows an error message.
* 3a1. HR Insight shows an error message.

Use case ends.

* 3a. User provides a wrong index (Either negative or more than current headcount).
* 3b. User provides a wrong index (Either negative or more than current headcount).

* 3a1. HR Insight shows an error message.
* 3b1. HR Insight shows an error message.

Use case ends.

* 4a. User didn't provide +/- when stating the claim amount.
* 3c. User didn't provide +/- when stating the claim amount.

* 4a1. HR Insight shows an error message.
* 3c1. HR Insight shows an error message.

Use case ends.

* 5a. User provides a claim amount that is greater than the employee's current entitlement fund balance (Only Applicable for -).
* 3d. User provides a claim amount that is greater than the employee's current entitlement fund balance (Only Applicable for -).

* 5a1. HR Insight shows an error message.
* 3d1. HR Insight shows an error message.

Use case ends.

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class Messages {
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
public static final String MESSAGE_EMPTY_DEPARTMENT_FILTER = "department name cannot be empty!";

public static final String MESSAGE_LIST_SUCCESS = "Listed all employees (%1$d)";

public static final String MESSAGE_FILTER_SUCCESS = "Listed filtered employees (%1$d)";

/**
* Returns an error message indicating the duplicate prefixes.
Expand Down
29 changes: 26 additions & 3 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.function.Predicate;

import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Lists all persons in the address book to the user.
Expand All @@ -12,13 +16,32 @@ public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_SUCCESS = "Listed all employees";
public final String message;

public final Predicate<Person> predicate;

/**
* Initializes ListCommand non-filtered list
*/
public ListCommand() {
this.predicate = PREDICATE_SHOW_ALL_PERSONS;
this.message = Messages.MESSAGE_LIST_SUCCESS;
}

/**
* Initializes ListCommand for filtered List
*
* @param predicate predicate for the filtering
*/
public ListCommand(Predicate<Person> predicate) {
this.predicate = predicate;
this.message = Messages.MESSAGE_FILTER_SUCCESS;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(MESSAGE_SUCCESS);
model.updateFilteredPersonList(predicate);
return new CommandResult(String.format(message, model.getFilteredPersonList().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Command parseCommand(String userInput) throws ParseException {
return new FindCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
return new ListCommand();
return new ListCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/seedu/address/logic/parser/ListCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Department;
import seedu.address.model.person.MatchingDepartmentPredicate;


/**
* Parses input arguments and creates a new ListCommand object
*/
public class ListCommandParser implements Parser<ListCommand> {

/**
* Parses {@code userInput} into a command and returns it.
*
* @param args arguments
* @throws ParseException if {@code userInput} does not conform the expected format
*/
@Override
public ListCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_DEPARTMENT);
if (argMultimap.getValue(PREFIX_DEPARTMENT).isEmpty()) {
return new ListCommand();
}
try {
Department filteringDepartment = new Department(argMultimap.getValue(PREFIX_DEPARTMENT).get());
return new ListCommand(new MatchingDepartmentPredicate(filteringDepartment));
} catch (IllegalArgumentException e) {
throw new ParseException(Messages.MESSAGE_EMPTY_DEPARTMENT_FILTER);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.address.model.person;

import java.util.function.Predicate;

/**
* Tests that a {@code Person}'s {@code Department} matches the department name given.
*/
public class MatchingDepartmentPredicate implements Predicate<Person> {

private final Department department;

public MatchingDepartmentPredicate(Department department) {
this.department = department;
}

/**
* Evaluates this predicate on the given argument.
*
* @param person the input argument
* @return {@code true} if the input argument matches the predicate, otherwise {@code false}
*/
@Override
public boolean test(Person person) {
return this.department.equals(person.getDepartment());
}
}
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public void execute_commandExecutionError_throwsCommandException() {
@Test
public void execute_validCommand_success() throws Exception {
String listCommand = ListCommand.COMMAND_WORD;
assertCommandSuccess(listCommand, ListCommand.MESSAGE_SUCCESS, model);
assertCommandSuccess(listCommand, String.format(
Messages.MESSAGE_LIST_SUCCESS, model.getFilteredPersonList().size()), model);
}

@Test
Expand Down
24 changes: 19 additions & 5 deletions src/test/java/seedu/address/logic/commands/ListCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.VALID_DEPARTMENT;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.function.Predicate;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Department;
import seedu.address.model.person.MatchingDepartmentPredicate;
import seedu.address.model.person.Person;



/**
* Contains integration tests (interaction with the Model) and unit tests for ListCommand.
*/
public class ListCommandTest {

private static final Predicate<Person> FILTER_TEST_PREDICATE =
new MatchingDepartmentPredicate(new Department(VALID_DEPARTMENT));
private Model model;
private Model expectedModel;
private Model expectedFilteredModel;

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedFilteredModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedFilteredModel.updateFilteredPersonList(FILTER_TEST_PREDICATE);
}

@Test
public void execute_listIsNotFiltered_showsSameList() {
assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
assertCommandSuccess(new ListCommand(), model, String.format(
Messages.MESSAGE_LIST_SUCCESS, expectedModel.getFilteredPersonList().size()), expectedModel);
}

@Test
public void execute_listIsFiltered_showsEverything() {
showPersonAtIndex(model, INDEX_FIRST_PERSON);
assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
assertCommandSuccess(new ListCommand(FILTER_TEST_PREDICATE), model, String.format(
Messages.MESSAGE_FILTER_SUCCESS, expectedFilteredModel.getFilteredPersonList().size()),
expectedFilteredModel);
}
}

0 comments on commit 7f5dc84

Please sign in to comment.