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

Update Asset fields and change method of editing #128

Merged
merged 32 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cc08776
Add id and location to assets
yisiox Mar 24, 2024
0dfff5e
Asset.java: Make factory handle trim
yisiox Mar 24, 2024
301229d
Change edita command to asset
yisiox Mar 24, 2024
301fd68
CommandType.java: Update edita to asset
yisiox Mar 24, 2024
d848954
Fix test checkstyle
yisiox Mar 24, 2024
c5211f3
Add test and bugfix for asset
yisiox Mar 24, 2024
a2d05d8
Fix code style
yisiox Mar 24, 2024
4527ecc
Add tests for asset methods
yisiox Mar 24, 2024
a29de2e
Improve test coverage for command type enum
yisiox Mar 24, 2024
97ec174
Improve test coverage for assets
yisiox Mar 24, 2024
380b54b
Remove location field from asset
yisiox Mar 25, 2024
d0d98c8
Merge branch 'master' into 124-update-asset
aureliony Mar 26, 2024
71451e0
Merge updates from master
yisiox Apr 3, 2024
50e509c
Change asset to be identified by name
yisiox Apr 3, 2024
19e2836
Update regex for fields
yisiox Apr 3, 2024
7d07cf7
Merge branch '124-update-asset' of github.com:AY2324S2-CS2103T-W12-3/…
yisiox Apr 3, 2024
ed195a5
AssetCommand.java: Fix assertion
yisiox Apr 3, 2024
8a6e5e3
Add test for backslash in fields
yisiox Apr 3, 2024
9408eeb
Add missing space
aureliony Apr 3, 2024
c533007
Replace all instances of AssetBook-3 with AssetBook
aureliony Apr 3, 2024
84cd266
Replace AB3 with AB in DG
aureliony Apr 3, 2024
874028a
Replace / with \ in UG
aureliony Apr 3, 2024
3eca109
AssetTest.java: Remove unneeded tests
yisiox Apr 3, 2024
424a315
Merge branch '124-update-asset' of github.com:AY2324S2-CS2103T-W12-3/…
yisiox Apr 3, 2024
17db0b0
Update prefixes in asset command
yisiox Apr 4, 2024
7654d58
Fix typos for AB3
aureliony Apr 4, 2024
ab30a6b
AssetTest.java: Fix unused import
yisiox Apr 4, 2024
3c19b2c
Merge branch '124-update-asset' of github.com:AY2324S2-CS2103T-W12-3/…
yisiox Apr 4, 2024
25344bf
Update prefix of asset command
yisiox Apr 4, 2024
dce3762
Merge branch 'master' into 124-update-asset
bryanyee33 Apr 4, 2024
2b3024f
Fix minor issues
bryanyee33 Apr 4, 2024
0b101ce
Fix inconsistency
bryanyee33 Apr 4, 2024
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
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.util.stream.Stream;
Expand All @@ -16,9 +17,9 @@
/**
* Edits the details of an asset in the address book.
*/
public class EditAssetCommand extends Command {
public class AssetCommand extends Command {

public static final String COMMAND_WORD = "edita";
public static final String COMMAND_WORD = "asset";
public static final Prefix PREFIX_OLD = new Prefix("old/");
public static final Prefix PREFIX_NEW = new Prefix("new/");

Expand All @@ -39,9 +40,8 @@ public class EditAssetCommand extends Command {
* @param target Previous asset to replace.
* @param editedAsset New asset to replace with.
*/
public EditAssetCommand(Asset target, Asset editedAsset) {
requireNonNull(target);
requireNonNull(editedAsset);
public AssetCommand(Asset target, Asset editedAsset) {
requireAllNonNull(target, editedAsset);

this.target = target;
this.editedAsset = editedAsset;
Expand All @@ -68,22 +68,22 @@ public String execute(Model model) throws CommandException {
* and returns an EditCommand object for execution.
* @throws IllegalArgumentException if the user input does not conform the expected format
*/
public static EditAssetCommand of(String args) throws IllegalArgumentException {
public static AssetCommand of(String args) throws IllegalArgumentException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_OLD, PREFIX_NEW);

if (!arePrefixesPresent(argMultimap, PREFIX_OLD, PREFIX_NEW)
|| !argMultimap.getPreamble().isEmpty()) {
throw new IllegalArgumentException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
EditAssetCommand.MESSAGE_USAGE));
AssetCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_OLD, PREFIX_NEW);
Asset target = Asset.of(argMultimap.getValue(PREFIX_OLD).get());
Asset editedAsset = Asset.of(argMultimap.getValue(PREFIX_NEW).get());

return new EditAssetCommand(target, editedAsset);
return new AssetCommand(target, editedAsset);
}

/**
Expand All @@ -101,11 +101,11 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof EditAssetCommand)) {
if (!(other instanceof AssetCommand)) {
return false;
}

EditAssetCommand otherEditCommand = (EditAssetCommand) other;
AssetCommand otherEditCommand = (AssetCommand) other;
return target.equals(otherEditCommand.target)
&& editedAsset.equals(otherEditCommand.editedAsset);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
return EditCommand.of(arguments);
}
},
EDITA {
ASSET {
@Override
public Command createCommand(String arguments) throws IllegalArgumentException {
return EditAssetCommand.of(arguments);
return AssetCommand.of(arguments);

Check warning on line 29 in src/main/java/seedu/address/logic/commands/CommandType.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/CommandType.java#L29

Added line #L29 was not covered by tests
}
},
DELETE {
Expand Down Expand Up @@ -74,7 +74,7 @@
REDO {
@Override
public Command createCommand(String arguments) {
return new RedoCommand();

Check warning on line 77 in src/main/java/seedu/address/logic/commands/CommandType.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/CommandType.java#L77

Added line #L77 was not covered by tests
}
};

Expand Down
31 changes: 13 additions & 18 deletions src/main/java/seedu/address/model/asset/Asset.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* Represents an asset in the address book.
* Guarantees: immutable.
* Guarantees: immutable; name is valid as declared in {@link #isValid(String)}.
*/
public class Asset {

public static final String MESSAGE_CONSTRAINTS = "Asset names can take any values, and it should not be blank";
private static final String VALIDATION_REGEX = "\\S.*";
public static final String MESSAGE_CONSTRAINTS = "Asset name must not be blank";
private static final String VALIDATION_REGEX = "\\s*[^\\s\\\\][^\\\\]*";

private final String assetName;

/**
* Constructs a {@code Asset}.
*
* @param assetName A valid asset name.
*/
public Asset(String assetName) {
requireNonNull(assetName);
assetName = assetName.trim();
checkArgument(isValid(assetName), MESSAGE_CONSTRAINTS);
private Asset(String assetName) {
requireAllNonNull(assetName);
this.assetName = assetName;
}

Expand All @@ -41,14 +35,15 @@ private static boolean isValid(String test) {
}

/**
* Parses a {@code String name} into a {@code Name}.
* Leading and trailing whitespaces will be trimmed.
* Parses a {@code String} of format {@code NAME[#ID]} into a {@code Asset}.
* Leading and trailing whitespaces of each field will be trimmed.
*
* @throws IllegalArgumentException if the given {@code name} is invalid.
*/
public static Asset of(String assetName) throws IllegalArgumentException {
requireNonNull(assetName);
String trimmedName = assetName.trim();
public static Asset of(String assetDescription) throws IllegalArgumentException {
requireNonNull(assetDescription);
checkArgument(isValid(assetDescription), MESSAGE_CONSTRAINTS);
String trimmedName = assetDescription.trim();
return new Asset(trimmedName);
}

Expand Down Expand Up @@ -76,7 +71,7 @@ public int hashCode() {
* Format state as text for viewing.
*/
public String toString() {
return '[' + assetName + ']';
return "[ " + get() + " ]";
}

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/person/fields/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/
public class Address implements Field {

public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
private static final String MESSAGE_CONSTRAINTS = "Addresses can take any values, and it should not be blank";
public static final Prefix PREFIX_ADDRESS = new Prefix("a\\");
private static final String MESSAGE_CONSTRAINTS = "Addresses cannot contain '\\', and should not be blank";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
private static final String VALIDATION_REGEX = "[^\\s].*";
private static final String VALIDATION_REGEX = "\\s*[^\\s\\\\][^\\\\]*";

private final String address;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/fields/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
public class Assets implements Field {

public static final Prefix PREFIX_ASSET = new Prefix("A/");
public static final Prefix PREFIX_ASSET = new Prefix("A\\");
private final Set<Asset> assets;

/**
Expand All @@ -38,7 +38,7 @@ public Assets(Asset... assets) {
public Assets(String... assetNames) {
requireNonNull(assetNames);
this.assets = Stream.of(assetNames)
.map(Asset::new)
.map(Asset::of)
.collect(Collectors.toUnmodifiableSet());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/fields/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

/**
* Represents a Person's email in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValid(String)}
* Guarantees: immutable; is valid as declared in {@link #isValid(String)}.
*/
public class Email implements Field {

public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_EMAIL = new Prefix("e\\");
private static final String SPECIAL_CHARACTERS = "+_.-";
private static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain "
+ "and adhere to the following constraints:\n"
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/seedu/address/model/person/fields/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

/**
* Represents a Person's name in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValid(String)}
* Guarantees: immutable; is valid as declared in {@link #isValid(String)}.
*/
public class Name implements Field {

public static final Prefix PREFIX_NAME = new Prefix("n/");
private static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
public static final Prefix PREFIX_NAME = new Prefix("n\\");
private static final String MESSAGE_CONSTRAINTS = "Names cannot contain '\\', and should not be blank";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
private static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
private static final String VALIDATION_REGEX = "\\s*[^\\s\\\\][^\\\\]*";

private final String name;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/fields/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

/**
* Represents a Person's phone number in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValid(String)}
* Guarantees: immutable; is valid as declared in {@link #isValid(String)}.
*/
public class Phone implements Field {

public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_PHONE = new Prefix("p\\");
private static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
private static final String VALIDATION_REGEX = "\\d{3,}";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/fields/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class Tags implements Field {

public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_TAG = new Prefix("t\\");
private final Set<Tag> tags;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

/**
* Represents a Tag in the address book.
* Guarantees: immutable; name is valid as declared in {@link #isValidTagName(String)}
* Guarantees: immutable; name is valid as declared in {@link #isValid(String)}.
*/
public class Tag {

private static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric";
private static final String MESSAGE_CONSTRAINTS = "Tags cannot contain '\\', and should not be blank";
private static final String VALIDATION_REGEX = "\\p{Alnum}+";

private final String tagName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.AssetCommand.MESSAGE_INVALID_ASSET_NAME;
import static seedu.address.logic.commands.AssetCommand.MESSAGE_NOT_EDITED;
import static seedu.address.logic.commands.AssetCommand.MESSAGE_SUCCESS;
import static seedu.address.logic.commands.CommandTestUtil.assertParseFailure;
import static seedu.address.logic.commands.EditAssetCommand.MESSAGE_INVALID_ASSET_NAME;
import static seedu.address.logic.commands.EditAssetCommand.MESSAGE_NOT_EDITED;
import static seedu.address.logic.commands.EditAssetCommand.MESSAGE_SUCCESS;
import static seedu.address.model.asset.Asset.MESSAGE_CONSTRAINTS;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
Expand All @@ -28,10 +28,10 @@
/**
* Contains integration tests (interaction with the Model) and unit tests for EditCommand.
*/
public class EditAssetCommandTest {
public class AssetCommandTest {

private static final String MESSAGE_INVALID_FORMAT =
String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditAssetCommand.MESSAGE_USAGE);
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssetCommand.MESSAGE_USAGE);
private static final String MESSAGE_CONSTRAINT_NAME = "Names should only contain alphanumeric characters and "
+ "spaces, and it should not be blank";
private final Asset asset1 = Asset.of("laptop");
Expand All @@ -44,7 +44,7 @@ public void execute_validEdit_success() throws CommandException {
Person personWithAsset = new PersonBuilder().withAssets(asset1.get()).build();
model.addPerson(personWithAsset);
Asset editedAsset = new AssetBuilder().build();
EditAssetCommand editCommand = new EditAssetCommand(asset1, editedAsset);
AssetCommand editCommand = new AssetCommand(asset1, editedAsset);

String expectedMessage = String.format(MESSAGE_SUCCESS, editedAsset);

Expand All @@ -55,15 +55,15 @@ public void execute_validEdit_success() throws CommandException {
@Test
public void execute_notEdited_throwsCommandException() {
assertThrows(CommandException.class, MESSAGE_NOT_EDITED, () ->
new EditAssetCommand(asset1, asset1).execute(model));
new AssetCommand(asset1, asset1).execute(model));
}

@Test
public void execute_invalidAsset_throwsCommandException() {
Person personWithAsset = new PersonBuilder().withAssets(asset1.get()).build();
model.addPerson(personWithAsset);
Asset invalidEditedAsset = new AssetBuilder().build();
EditAssetCommand editCommand = new EditAssetCommand(invalidEditedAsset, asset1);
AssetCommand editCommand = new AssetCommand(invalidEditedAsset, asset1);

assertThrows(CommandException.class, MESSAGE_INVALID_ASSET_NAME, () ->
editCommand.execute(model));
Expand All @@ -72,57 +72,57 @@ public void execute_invalidAsset_throwsCommandException() {
@Test
public void execute_emptyDescriptor_throwsCommandException() {
assertThrows(IllegalArgumentException.class, MESSAGE_CONSTRAINTS, () ->
new EditAssetCommand(Asset.of(""), asset1));
new AssetCommand(Asset.of(""), asset1));
}

@Test
public void of_invalidInput_failure() {
// missing field
assertParseFailure(EditAssetCommand::of, "Laptop", MESSAGE_INVALID_FORMAT);
assertParseFailure(AssetCommand::of, "Laptop", MESSAGE_INVALID_FORMAT);
// missing field
assertParseFailure(EditAssetCommand::of, "", MESSAGE_INVALID_FORMAT);
assertParseFailure(AssetCommand::of, "", MESSAGE_INVALID_FORMAT);
// null
assertThrows(NullPointerException.class, () -> EditAssetCommand.of(null));
assertThrows(NullPointerException.class, () -> AssetCommand.of(null));
// unedited
assertThrows(IllegalArgumentException.class, () -> EditAssetCommand.of("Laptop Laptop"));
assertThrows(IllegalArgumentException.class, () -> AssetCommand.of("Laptop Laptop"));
// only alphanum allowed for name
assertThrows(IllegalArgumentException.class, () -> EditAssetCommand.of("Laptop \uD83D\uDC4D"));
assertThrows(IllegalArgumentException.class, () -> AssetCommand.of("Laptop \uD83D\uDC4D"));
}

@Test
public void of_validInput_success() {
assertDoesNotThrow(() -> EditAssetCommand.of(" old/aircon new/desktop"));
assertDoesNotThrow(() -> AssetCommand.of(" old/aircon new/desktop"));
}

@Test
public void equals_sameValues_returnsTrue() {
EditAssetCommand editCommand1 = new EditAssetCommand(asset1, asset2);
EditAssetCommand editCommand2 = new EditAssetCommand(asset1, asset2);
AssetCommand editCommand1 = new AssetCommand(asset1, asset2);
AssetCommand editCommand2 = new AssetCommand(asset1, asset2);
assertEquals(editCommand1, editCommand2);
}

@Test
public void equals_differentValues_returnsFalse() {
EditAssetCommand editCommand1 = new EditAssetCommand(asset1, asset2);
EditAssetCommand editCommand2 = new EditAssetCommand(asset2, asset1);
AssetCommand editCommand1 = new AssetCommand(asset1, asset2);
AssetCommand editCommand2 = new AssetCommand(asset2, asset1);
assertNotEquals(editCommand1, editCommand2);
}

@Test
public void equals_differentObject_returnsFalse() {
EditAssetCommand editCommand = new EditAssetCommand(asset1, asset2);
AssetCommand editCommand = new AssetCommand(asset1, asset2);
assertNotEquals(editCommand, new Object());
}

@Test
public void equals_sameObject_returnsTrue() {
EditAssetCommand editCommand = new EditAssetCommand(asset1, asset2);
AssetCommand editCommand = new AssetCommand(asset1, asset2);
assertTrue(editCommand.equals(editCommand));
}

@Test
public void equals_null_returnsFalse() {
EditAssetCommand editCommand = new EditAssetCommand(asset1, asset2);
AssetCommand editCommand = new AssetCommand(asset1, asset2);
assertFalse(editCommand.equals(null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class CommandTestUtil {
public static final String ASSET_DESC_HAMMER = " " + PREFIX_ASSET + VALID_ASSET_HAMMER;
public static final String ASSET_DESC_AIRCON = " " + PREFIX_ASSET + VALID_ASSET_AIRCON;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James\\"; // '\' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
Expand Down
Loading
Loading