forked from AY2324S1-CS2103T-T09-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,122 additions
and
345 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/address/logic/commands/addRoles/AddClientRoleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package seedu.address.logic.commands.addRoles; | ||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.TabIndex; | ||
import seedu.address.logic.commands.add.AddDeveloperCommand; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.client.ClientRoles; | ||
|
||
public class AddClientRoleCommand extends Command { | ||
public static final String COMMAND_WORD = "add-client-role"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a role for clients to the address book. " | ||
+ "Parameters: " + PREFIX_ROLE + "ROLE " | ||
+ "Example: " + PREFIX_ROLE + "Developer "; | ||
|
||
public static final String MESSAGE_SUCCESS = "New role for client added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_DEVELOPER = "This client role already exists in the address book"; | ||
private final String toAdd; | ||
|
||
/** | ||
* Creates an AddDeveloperRoleCommand to add the specified {@code Developer} | ||
*/ | ||
public AddClientRoleCommand(String role) { | ||
requireNonNull(role); | ||
toAdd = role; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (ClientRoles.isValidRole(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_DEVELOPER); | ||
} | ||
|
||
String successMessage = String.format(MESSAGE_SUCCESS, Messages.format(toAdd)); | ||
TabIndex index = TabIndex.Client; | ||
|
||
ClientRoles newRole = new ClientRoles(toAdd.toString()); | ||
ClientRoles.addClientRole(newRole); | ||
return new CommandResult(successMessage, index); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddDeveloperCommand)) { | ||
return false; | ||
} | ||
|
||
AddClientRoleCommand otherAddClientRoleCommand = (AddClientRoleCommand) other; | ||
return toAdd.equals(otherAddClientRoleCommand.toAdd); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toAdd", toAdd) | ||
.toString(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/address/logic/commands/addRoles/AddDeveloperRoleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package seedu.address.logic.commands.addRoles; | ||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.TabIndex; | ||
import seedu.address.logic.commands.add.AddDeveloperCommand; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.developer.DeveloperRoles; | ||
|
||
public class AddDeveloperRoleCommand extends Command { | ||
public static final String COMMAND_WORD = "add-developer-role"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a role for developers to the address book. " | ||
+ "Parameters: " + PREFIX_ROLE + "ROLE " | ||
+ "Example: " + PREFIX_ROLE + "Developer "; | ||
|
||
public static final String MESSAGE_SUCCESS = "New role for developer added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_DEVELOPER = "This developer role already exists in the address book"; | ||
private final String toAdd; | ||
|
||
/** | ||
* Creates an AddDeveloperRoleCommand to add the specified {@code Developer} | ||
*/ | ||
public AddDeveloperRoleCommand(String role) { | ||
requireNonNull(role); | ||
toAdd = role; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (DeveloperRoles.isValidRole(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_DEVELOPER); | ||
} | ||
|
||
String successMessage = String.format(MESSAGE_SUCCESS, Messages.format(toAdd)); | ||
TabIndex index = TabIndex.Developer; | ||
|
||
DeveloperRoles newRole = new DeveloperRoles(toAdd.toString()); | ||
DeveloperRoles.addDeveloperRole(newRole); | ||
return new CommandResult(successMessage, index); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddDeveloperCommand)) { | ||
return false; | ||
} | ||
|
||
AddDeveloperRoleCommand otherAddDeveloperRoleCommand = (AddDeveloperRoleCommand) other; | ||
return toAdd.equals(otherAddDeveloperRoleCommand.toAdd); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toAdd", toAdd) | ||
.toString(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/seedu/address/logic/commands/deleteRoles/DeleteClientRoleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package seedu.address.logic.commands.deleteRoles; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.TabIndex; | ||
import seedu.address.logic.commands.delete.DeleteClientCommand; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.client.ClientRoles; | ||
|
||
public class DeleteClientRoleCommand extends Command { | ||
public static final String COMMAND_WORD = "delete-client-role"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Delete a role for clients in the address book. " | ||
+ "Parameters: " + PREFIX_ROLE + "ROLE " | ||
+ "Example: " + PREFIX_ROLE + "Developer "; | ||
|
||
public static final String MESSAGE_SUCCESS = "Role for client deleted: %1$s"; | ||
public static final String MESSAGE_CANNOT_DELETE_REPEAT = "This client role cannot be deleted " | ||
+ "as there are clients of this role"; | ||
public static final String MESSAGE_CANNOT_DELETE_PREXISTS = "You are not allowed to delete this client role."; | ||
public static final String MESSAGE_CANNOT_DELETE_NONEXISTING = "This client role does not exist. "; | ||
public static final String MESSAGE_EXISTING_CLIENT_ROLES = "These are the existing client roles: \n" | ||
+ ClientRoles.printRoles(); | ||
|
||
private final String toAdd; | ||
|
||
/** | ||
* Creates an AddDeveloperRoleCommand to add the specified {@code Developer} | ||
*/ | ||
public DeleteClientRoleCommand(String role) { | ||
requireNonNull(role); | ||
toAdd = role; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (!ClientRoles.isRemovableRole(model, toAdd)) { //if when u search role result != 1 | ||
if (!ClientRoles.isNoRepeat()) { | ||
throw new CommandException(MESSAGE_CANNOT_DELETE_REPEAT); | ||
} else if (!ClientRoles.isNotDefault()) { | ||
throw new CommandException(MESSAGE_CANNOT_DELETE_PREXISTS); | ||
} else if (ClientRoles.isNotInList()) { | ||
throw new CommandException(MESSAGE_CANNOT_DELETE_NONEXISTING + MESSAGE_EXISTING_CLIENT_ROLES); | ||
} | ||
} | ||
|
||
String successMessage = String.format(MESSAGE_SUCCESS, Messages.format(toAdd)); | ||
TabIndex index = TabIndex.Client; | ||
|
||
ClientRoles newRole = new ClientRoles(toAdd.toString()); | ||
ClientRoles.deleteClientRole(newRole); | ||
return new CommandResult(successMessage, index); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteClientCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteClientRoleCommand otherDeleteClientRoleCommand = (DeleteClientRoleCommand) other; | ||
return toAdd.equals(otherDeleteClientRoleCommand.toAdd); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toAdd", toAdd) | ||
.toString(); | ||
} | ||
} |
Oops, something went wrong.