Skip to content

Commit

Permalink
Merge pull request #61 from jasonchristopher21/branch-fix-field-model
Browse files Browse the repository at this point in the history
Integrate Attribute with Person, Task and Group
  • Loading branch information
Eclipse-Dominator authored Oct 27, 2022
2 parents 450468c + bc40201 commit f4a03a9
Show file tree
Hide file tree
Showing 46 changed files with 1,412 additions and 365 deletions.
57 changes: 0 additions & 57 deletions src/main/java/seedu/address/logic/commands/AddFieldCommand.java

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.attribute.Address;
import seedu.address.model.attribute.AttributeList;
import seedu.address.model.attribute.Email;
import seedu.address.model.attribute.Name;
import seedu.address.model.attribute.Phone;
import seedu.address.model.person.Fields;
import seedu.address.model.person.Person;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -102,7 +102,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
// Address updatedAddress =
// editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Fields updatedFields = editPersonDescriptor.getFields().orElse(personToEdit.getFields());
AttributeList updatedFields = editPersonDescriptor.getFields().orElse(personToEdit.getFields());

// return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
// updatedTags, updatedFields);
Expand Down Expand Up @@ -140,7 +140,7 @@ public static class EditPersonDescriptor {
private Email email;
private Address address;
private Set<Tag> tags;
private Fields fields;
private AttributeList fields;

public EditPersonDescriptor() {
}
Expand Down Expand Up @@ -197,11 +197,11 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setFields(Fields fields) {
public void setFields(AttributeList fields) {
this.fields = fields;
}

public Optional<Fields> getFields() {
public Optional<AttributeList> getFields() {
return Optional.ofNullable(fields);
}

Expand Down
51 changes: 0 additions & 51 deletions src/main/java/seedu/address/logic/commands/RemoveFieldCommand.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package seedu.address.logic.commands.attributes;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import seedu.address.logic.commands.Command;

/**
* Adds an attribute to a person.
*/
public abstract class AddAttributeCommand extends Command {

public static final String COMMAND_WORD = "addfield";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a custom field to the address book. "
+ "Parameters: CUSTOM_PREFIX FIELD";

protected final String attributeName;
protected final String attributeContent;

/**
* Constructs a new AddAttributeCommand instance.
*
* @param attributeName The name of the attribute to be added.
* @param attributeContent The content of the attribute to be added.
*/
public AddAttributeCommand(String attributeName, String attributeContent) {
requireAllNonNull(attributeName, attributeContent);
this.attributeName = attributeName;
this.attributeContent = attributeContent;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddAttributeCommand // instanceof handles nulls
&& attributeName.equals(((AddAttributeCommand) other).attributeName)
&& attributeContent.equals(((AddAttributeCommand) other).attributeContent));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.commands.attributes;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.attribute.exceptions.AttributeException;
import seedu.address.model.group.Group;
import seedu.address.model.group.exceptions.GroupOutOfBoundException;

/**
* Adds a group attribute to the address book.
*/
public class AddGroupAttributeCommand extends AddAttributeCommand {

public static final String MESSAGE_SUCCESS = "New field added: %s, with value: %s";

private final Index groupIndex; // change this to UUID later

/**
* Constructs an AddGroupAttributeCommand instance.
* @param groupIndex index of the group.
* @param attributeName the name of the attribute to be added.
* @param attributeContent the content of the attribute to be added.
*/
public AddGroupAttributeCommand(Index groupIndex, String attributeName, String attributeContent) {
super(attributeName, attributeContent);
requireNonNull(groupIndex);
this.groupIndex = groupIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
try {
Group group = model.getFromFilteredTeams(groupIndex);
group.addAttribute(attributeName, attributeContent);
} catch (GroupOutOfBoundException | AttributeException ae) {
throw new CommandException(ae.getMessage());
}
return new CommandResult(String.format(MESSAGE_SUCCESS, attributeName, attributeContent));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (super.equals(other)
&& (other instanceof AddGroupAttributeCommand
&& groupIndex.equals(((AddGroupAttributeCommand) other).groupIndex)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.commands.attributes;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.attribute.exceptions.AttributeException;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.PersonOutOfBoundException;

/**
* Adds a person attribute to the address book.
*/
public class AddPersonAttributeCommand extends AddAttributeCommand {

public static final String MESSAGE_SUCCESS = "New field added: %s, with value: %s";

private final Index personIndex; // change this to UUID later

/**
* Constructs an AddPersonAttributeCommand instance.
* @param personIndex index of the person.
* @param attributeName the name of the attribute to be added.
* @param attributeContent the content of the attribute to be added.
*/
public AddPersonAttributeCommand(Index personIndex, String attributeName, String attributeContent) {
super(attributeName, attributeContent);
requireNonNull(personIndex);
this.personIndex = personIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
try {
Person person = model.getFromFilteredPerson(personIndex);
person.addAttribute(attributeName, attributeContent);
} catch (PersonOutOfBoundException | AttributeException e) {
throw new CommandException(e.getMessage());
}
return new CommandResult(String.format(MESSAGE_SUCCESS, attributeName, attributeContent));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (super.equals(other)
&& (other instanceof AddPersonAttributeCommand
&& personIndex.equals(((AddPersonAttributeCommand) other).personIndex)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.commands.attributes;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.attribute.exceptions.AttributeException;
import seedu.address.model.task.Task;
import seedu.address.model.task.exceptions.TaskOutOfBoundException;

/**
* Adds a task attribute to the address book.
*/
public class AddTaskAttributeCommand extends AddAttributeCommand {

public static final String MESSAGE_SUCCESS = "New field added: %s, with value: %s";

private final Index taskIndex; // change this to UUID later

/**
* Constructs an AddTaskAttributeCommand instance.
* @param taskIndex index of the task.
* @param attributeName the name of the attribute to be added.
* @param attributeContent the content of the attribute to be added.
*/
public AddTaskAttributeCommand(Index taskIndex, String attributeName, String attributeContent) {
super(attributeName, attributeContent);
requireNonNull(taskIndex);
this.taskIndex = taskIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
try {
Task task = model.getFromFilteredTasks(taskIndex);
task.addAttribute(attributeName, attributeContent);
} catch (TaskOutOfBoundException | AttributeException ae) {
throw new CommandException(ae.getMessage());
}
return new CommandResult(String.format(MESSAGE_SUCCESS, attributeName, attributeContent));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (super.equals(other)
&& (other instanceof AddTaskAttributeCommand
&& taskIndex.equals(((AddTaskAttributeCommand) other).taskIndex)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package seedu.address.logic.commands.attributes;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import seedu.address.logic.commands.Command;

/**
* Edits an existing attribute in the AddressBook.
*/
public abstract class EditAttributeCommand extends Command {
public static final String COMMAND_WORD = "editfield";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits a custom field of a Person/Task/Team in the address book. "
+ "Parameters: CUSTOM_PREFIX FIELD";

protected final String attributeName;
protected final String attributeContent;

/**
* Constructs a new EditAttributeCommand instance.
*
* @param attributeName The name of the attribute to be added.
* @param attributeContent The content of the attribute to be added.
*/
public EditAttributeCommand(String attributeName, String attributeContent) {
requireAllNonNull(attributeName, attributeContent);
this.attributeName = attributeName;
this.attributeContent = attributeContent;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof EditAttributeCommand // instanceof handles nulls
&& attributeName.equals(((EditAttributeCommand) other).attributeName)
&& attributeContent.equals(((EditAttributeCommand) other).attributeContent));
}
}
Loading

0 comments on commit f4a03a9

Please sign in to comment.