Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete feature change #281

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ public CommandResult execute(Model model) throws CommandException {
if (fullOriginUuid == fullTargetUuid) {
throw new CommandException("Relationships must be between 2 different people");
}
String relationTypeWithS = model.relationTypeExistsWithOrWithoutS(relationshipDescriptor);
if (relationTypeWithS != null) {
String errorMessage = String.format("Sorry, the relation type '%s' exists. Either use '%s', "
+ "or delete it and add the relation type back how you'd like", relationTypeWithS,
relationTypeWithS);
throw new CommandException(errorMessage);
}
try {
if (isRoleBased) {
RoleBasedRelationship toAdd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_UUID);
}
}
String relationTypeWithS = model.relationTypeExistsWithOrWithoutS(relationshipDescriptor);
if (relationTypeWithS != null) {
String errorMessage = String.format("Sorry, the relation type '%s' exists. Either use '%s', "
+ "or delete it and add the relation type back how you'd like", relationTypeWithS,
relationTypeWithS);
throw new CommandException(errorMessage);
}
if (isRelationType) {
try {
model.deleteRelationType(relationshipDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ public CommandResult execute(Model model) throws CommandException {
if (fullTargetUuid == null || fullOriginUuid == null) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_UUID);
}
String relationTypeWithS = model.relationTypeExistsWithOrWithoutS(oldRelationshipDescriptor);
if (relationTypeWithS != null) {
String errorMessage = String.format("Sorry, the relation type '%s' exists. Either use '%s', "
+ "or delete it and add the relation type back how you'd like", relationTypeWithS,
relationTypeWithS);
throw new CommandException(errorMessage);
}
String relationTypeWithS2 = model.relationTypeExistsWithOrWithoutS(newRelationshipDescriptor);
if (relationTypeWithS2 != null) {
String errorMessage = String.format("Sorry, the relation type '%s' exists. Either use '%s', "
+ "or delete it and add the relation type back how you'd like", relationTypeWithS2,
relationTypeWithS2);
throw new CommandException(errorMessage);
}
try {
Relationship toEditOff = new Relationship(fullOriginUuid, fullTargetUuid, oldRelationshipDescriptor);
Relationship toEditIn = new Relationship(fullOriginUuid, fullTargetUuid, newRelationshipDescriptor);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,4 @@ public RoleBasedRelationship getBioparentsCount(Model model, String originUuid,
String role2) throws CommandException {
return relationships.getBioparentsCount(model, originUuid, targetUuid, role1, role2);
}

public String relationTypeExistsWithOrWithoutS(String relationshipDescriptor) {
return relationships.relationTypeExistsWithOrWithoutS(relationshipDescriptor);
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,4 @@ public interface Model {

RoleBasedRelationship getBioparentsCount(Model model, String originUuid,
String targetUuid, String role1, String role2) throws CommandException;
String relationTypeExistsWithOrWithoutS(String relationshipDescriptor);
}
5 changes: 0 additions & 5 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,4 @@ public RoleBasedRelationship getBioparentsCount(Model model, String originUuid,
String role1, String role2) throws CommandException {
return addressBook.getBioparentsCount(model, originUuid, targetUuid, role1, role2);
}

@Override
public String relationTypeExistsWithOrWithoutS(String relationshipDescriptor) {
return addressBook.relationTypeExistsWithOrWithoutS(relationshipDescriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -615,35 +615,6 @@ public RoleBasedRelationship getBioparentsCount(Model model, String originUuid,
return toAdd;
}

/**
* Checks if a relationship type exists in the tracker with or without an 's' at the end.
* @param descriptor The descriptor to check.
* @return The descriptor with an 's' at the end if it exists, null otherwise.
*/
public String relationTypeExistsWithOrWithoutS(String descriptor) {
String descriptorWithoutS = removeChars(descriptor); //string without any s at the end
if (descriptor.equals("bioparents") || descriptor.equals("spouses")
|| descriptor.equals("siblings") || descriptor.equals("friends")) {
return null;
} else if (descriptorWithoutS.equals("bioparent") || descriptorWithoutS.equals("spouse")
|| descriptorWithoutS.equals("sibling") || descriptorWithoutS.equals("friend")) {
return descriptorWithoutS + "s";
}
return null;
}

/**
* Removes all the 's' characters at the end of a string.
* @param str The string to remove characters from.
* @return The modified string with 's' characters removed from the end.
*/
public static String removeChars(String str) {
while (str.endsWith("s")) {
str = str.substring(0, str.length() - 1);
}
return str;
}

/**
* Resets the relationship descriptors to their default values.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ public RoleBasedRelationship getBioparentsCount(Model model, String originUuid,
throw new AssertionError("This method should not be called.");
}

@Override
public String relationTypeExistsWithOrWithoutS(String relationshipDescriptor) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Relationship> getFilteredRelationshipList() {
throw new AssertionError("This method should not be called.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package seedu.address.logic.relationship;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersonsUuid.getTypicalAddressBook;

import java.util.UUID;

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

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.relationship.Relationship;
import seedu.address.testutil.TypicalPersonsUuid;

class DeleteRelationshipCommandTest {
private Model model;
Expand Down Expand Up @@ -94,29 +90,4 @@ void execute_invalidRelationshipType_throwsCommandException() {

assertThrows(CommandException.class, () -> deleteRelationshipCommand.execute(model));
}

@Test
public void execute_hasDescriptorInvalidRoleFail_addsRelationship() {
Model model = new ModelManager();
AddressBook typicalPersonsAddressBook = TypicalPersonsUuid.getTypicalAddressBook();
model.setAddressBook(typicalPersonsAddressBook);
String originUuid = "0001";
String targetUuid = "0002";
String otherRelationshipDescriptor = "bioparents";
String newRelationshipDescriptor = "bioparent";

Relationship otherRelationship = new Relationship(
UUID.fromString("00000000-0000-0000-0000-000000000001"),
UUID.fromString("00000000-0000-0000-0000-000000000005"), otherRelationshipDescriptor);
model.addRelationship(otherRelationship);
model.addRolelessDescriptor(otherRelationshipDescriptor);

AddRelationshipCommand editCommand = new AddRelationshipCommand(originUuid, targetUuid,
newRelationshipDescriptor);
CommandException exception = Assertions.assertThrows(CommandException.class, () -> editCommand.execute(model),
"Expected CommandException");
assertEquals("Sorry, the relation type 'bioparents' exists. Either use 'bioparents', "
+ "or delete it and add the relation type back how you'd like",
exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,35 +444,4 @@ public void execute_hasDescriptorInvalidRoleless_addsRelationship() {
+ "if the new relationship is the same as the old one.",
exception.getMessage());
}

@Test
public void execute_hasDescriptorInvalidRolelessFail_addsRelationship() {
Model model = new ModelManager();
AddressBook typicalPersonsAddressBook = TypicalPersonsUuid.getTypicalAddressBook();
model.setAddressBook(typicalPersonsAddressBook);
String originUuid = "0001";
String targetUuid = "0002";
String otherRelationshipDescriptor = "siblings";
String oldRelationshipDescriptor = "popsicle";
String newRelationshipDescriptor = "sibling";

Relationship oldRelationship = new Relationship(
UUID.fromString("00000000-0000-0000-0000-000000000001"),
UUID.fromString("00000000-0000-0000-0000-000000000002"), oldRelationshipDescriptor);
Relationship otherRelationship = new Relationship(
UUID.fromString("00000000-0000-0000-0000-000000000001"),
UUID.fromString("00000000-0000-0000-0000-000000000005"), otherRelationshipDescriptor);
model.addRelationship(otherRelationship);
model.addRelationship(oldRelationship);
model.addRolelessDescriptor(otherRelationshipDescriptor);
model.addRolelessDescriptor(oldRelationshipDescriptor);

EditRelationshipCommand editCommand = new EditRelationshipCommand(originUuid, targetUuid,
oldRelationshipDescriptor, newRelationshipDescriptor);
CommandException exception = assertThrows(CommandException.class, () -> editCommand.execute(model),
"Expected CommandException");
assertEquals("Sorry, the relation type 'siblings' exists. Either use 'siblings', "
+ "or delete it and add the relation type back how you'd like",
exception.getMessage());
}
}
Loading