Skip to content

Commit daf1002

Browse files
CRUD Metric (#82)
* Metric: Update implementations * Add AddMetricCommandParser * Add AddMetricCommand class * Implement AddMetricCommandParser * Update HireLah! add metric functionality * AddMetricCommand: Fix bugs * Implement DeleteMetricCommand * Add ListMetricCommand class * Add EditMetricCommand class * Add EditMetricCommandParser * Implement HireLah! to perform edit metric * fix checkstyle * Update CRUD Metric to be done after finalizing session * Update AddMetricCommand to relax the restriction of metric params * Fix checksty;e * Fix checkstyle * Fix checkstyle Co-authored-by: CornCobs <[email protected]>
1 parent a55a623 commit daf1002

19 files changed

+608
-143
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import java.util.List;
6+
7+
import seedu.address.commons.exceptions.IllegalValueException;
8+
import seedu.address.logic.commands.exceptions.CommandException;
9+
import seedu.address.model.Model;
10+
import seedu.address.model.hirelah.AttributeList;
11+
import seedu.address.model.hirelah.MetricList;
12+
13+
/**
14+
* AddMetricCommand describes the behavior of HireLah!
15+
* when a user wants to delete the metric from the list.
16+
*/
17+
18+
public class AddMetricCommand extends AddCommand {
19+
public static final String COMMAND_WORD = "metric";
20+
public static final String MESSAGE_HAS_NOT_FINALIZED = "The session has not been finalized. Please finalize it"
21+
+ " before adding metrics.";
22+
public static final String MESSAGE_SUCCESS = "New metric added: %1$s";
23+
public static final String MESSAGE_USAGE = "new " + COMMAND_WORD + ": Adds an metric to the Metric list.\n"
24+
+ "Parameters: "
25+
+ "NAME -a attributePrefix1 -w weight1 -a attributePrefix2 -w weight2\n"
26+
+ "Example: new " + COMMAND_WORD + " extremeLeader -a lea -w 0.7 -a te -w 0.6";
27+
28+
29+
private final String toAdd;
30+
private final List<String> attributePrefixes;
31+
private final List<Double> addedWeights;
32+
33+
/**
34+
* Creates an AddMetricCommand to add the specified {@code Metric}
35+
*/
36+
37+
public AddMetricCommand(String toAdd, List<String> attributePrefixes, List<Double> addedWeights) {
38+
this.toAdd = toAdd;
39+
this.attributePrefixes = attributePrefixes;
40+
this.addedWeights = addedWeights;
41+
}
42+
43+
@Override
44+
public CommandResult execute(Model model) throws CommandException {
45+
requireNonNull(model);
46+
47+
if (!model.isfinalisedInterviewProperties()) {
48+
throw new CommandException(MESSAGE_HAS_NOT_FINALIZED);
49+
}
50+
51+
MetricList metrics = model.getMetricList();
52+
AttributeList attributes = model.getAttributeList();
53+
54+
try {
55+
metrics.add(toAdd, attributes, attributePrefixes, addedWeights);
56+
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd), ToggleView.METRIC);
57+
} catch (IllegalValueException e) {
58+
throw new CommandException(e.getMessage());
59+
}
60+
}
61+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import seedu.address.commons.exceptions.IllegalValueException;
6+
import seedu.address.logic.commands.exceptions.CommandException;
7+
import seedu.address.model.Model;
8+
import seedu.address.model.hirelah.Metric;
9+
import seedu.address.model.hirelah.MetricList;
10+
11+
/**
12+
* DeleteMetricCommand describes the behavior when the
13+
* client wants to delete an attribute from the list.
14+
*/
15+
16+
public class DeleteMetricCommand extends DeleteCommand {
17+
public static final String COMMAND_WORD = "metric";
18+
public static final String MESSAGE_HAS_NOT_FINALIZED = "The session has not been finalized. Please finalize it"
19+
+ " before deleting metrics.";
20+
public static final String MESSAGE_USAGE = COMMAND_WORD
21+
+ ": Deletes the metric identified by its prefix.\n"
22+
+ "Parameters: PREFIX\n"
23+
+ "Example: delete " + COMMAND_WORD + " lea";
24+
25+
public static final String MESSAGE_DELETE_METRIC_SUCCESS = "Deleted Metric with prefix: %1$s";
26+
27+
private final String metricPrefix;
28+
29+
public DeleteMetricCommand(String metricPrefix) {
30+
this.metricPrefix = metricPrefix;
31+
}
32+
33+
@Override
34+
public CommandResult execute(Model model) throws CommandException {
35+
requireNonNull(model);
36+
if (!model.isfinalisedInterviewProperties()) {
37+
throw new CommandException(MESSAGE_HAS_NOT_FINALIZED);
38+
}
39+
40+
MetricList metrics = model.getMetricList();
41+
try {
42+
Metric metric = metrics.delete(metricPrefix);
43+
return new CommandResult(String.format(MESSAGE_DELETE_METRIC_SUCCESS,
44+
metric), ToggleView.METRIC);
45+
} catch (IllegalValueException e) {
46+
throw new CommandException(e.getMessage());
47+
}
48+
}
49+
50+
@Override
51+
public boolean equals(Object other) {
52+
return other == this // short circuit if same object
53+
|| (other instanceof DeleteMetricCommand // instanceof handles nulls
54+
&& metricPrefix.equals(((DeleteMetricCommand) other).metricPrefix)); // state check
55+
}
56+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import java.util.List;
6+
7+
import seedu.address.commons.exceptions.IllegalValueException;
8+
import seedu.address.logic.commands.exceptions.CommandException;
9+
import seedu.address.model.Model;
10+
import seedu.address.model.hirelah.AttributeList;
11+
import seedu.address.model.hirelah.MetricList;
12+
13+
/**
14+
* EditMetricCommand describes the behavior of HireLah!
15+
* when a user wants to edit a metric.
16+
*/
17+
18+
public class EditMetricCommand extends EditCommand {
19+
public static final String COMMAND_WORD = "metric";
20+
public static final String MESSAGE_HAS_NOT_FINALIZED = "The session has not been finalized. Please finalize it"
21+
+ " before editing metrics.";
22+
public static final String MESSAGE_USAGE = COMMAND_WORD
23+
+ ": Edits the metric identified by the prefix.\n"
24+
+ "Parameters: IDENTIFIER NAME [-n NEW_NAME] [-a ATTRIBUTE_1] [-w WEIGHT_1]\n"
25+
+ "Example: edit " + COMMAND_WORD + " extremeLeadership -n extremeDictatorship -a lea -w 100";
26+
27+
public static final String MESSAGE_EDIT_METRIC_SUCCESS = "Successfully edited Metric";
28+
29+
private final String toEdit;
30+
private final String updatedName;
31+
private final List<String> attributePrefixes;
32+
private final List<Double> weightages;
33+
34+
public EditMetricCommand(String toEdit, String updatedName, List<String> attributePrefixes,
35+
List<Double> weightages) {
36+
this.toEdit = toEdit;
37+
this.updatedName = updatedName;
38+
this.attributePrefixes = attributePrefixes;
39+
this.weightages = weightages;
40+
}
41+
42+
@Override
43+
public CommandResult execute(Model model) throws CommandException {
44+
requireNonNull(model);
45+
if (!model.isfinalisedInterviewProperties()) {
46+
throw new CommandException(MESSAGE_HAS_NOT_FINALIZED);
47+
}
48+
49+
MetricList metrics = model.getMetricList();
50+
AttributeList attributes = model.getAttributeList();
51+
52+
try {
53+
metrics.edit(toEdit, updatedName, attributes, attributePrefixes, weightages);
54+
return new CommandResult(MESSAGE_EDIT_METRIC_SUCCESS, ToggleView.METRIC);
55+
} catch (IllegalValueException e) {
56+
throw new CommandException(e.getMessage());
57+
}
58+
}
59+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import seedu.address.logic.commands.exceptions.CommandException;
6+
import seedu.address.model.Model;
7+
8+
/**
9+
* ListMetricCommand describes the behavior when the
10+
* client wants to list the metrics available.
11+
*/
12+
public class ListMetricCommand extends ListCommand {
13+
public static final String COMMAND_WORD = "metric";
14+
public static final String MESSAGE_SUCCESS = "Here is the list of metrics:";
15+
public static final String MESSAGE_USAGE = "list " + COMMAND_WORD + ": List the metrics from the Metric list. "
16+
+ "Example: list " + COMMAND_WORD;
17+
18+
/**
19+
* Creates a ListMetricCommand to list the {@code Metric}
20+
*/
21+
public ListMetricCommand() {
22+
23+
}
24+
25+
@Override
26+
public CommandResult execute(Model model) throws CommandException {
27+
requireNonNull(model);
28+
return new CommandResult(MESSAGE_SUCCESS, ToggleView.METRIC);
29+
}
30+
}

src/main/java/seedu/address/logic/commands/ToggleView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public enum ToggleView {
88
INTERVIEWEE,
99
QUESTION,
1010
SESSION,
11-
TRANSCRIPT
11+
TRANSCRIPT,
12+
METRIC
1213
}

src/main/java/seedu/address/logic/parser/AddCommandParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import seedu.address.logic.commands.AddAttributeCommand;
1010
import seedu.address.logic.commands.AddCommand;
1111
import seedu.address.logic.commands.AddIntervieweeCommand;
12+
import seedu.address.logic.commands.AddMetricCommand;
1213
import seedu.address.logic.commands.AddQuestionCommand;
1314
import seedu.address.logic.parser.exceptions.ParseException;
1415

@@ -46,6 +47,9 @@ public AddCommand parse(String arguments) throws ParseException {
4647
case AddQuestionCommand.COMMAND_WORD:
4748
return new AddQuestionCommand(addArguments.trim());
4849

50+
case AddMetricCommand.COMMAND_WORD:
51+
return new AddMetricCommandParser().parse(addArguments.trim());
52+
4953
default:
5054
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
5155
}

src/main/java/seedu/address/logic/parser/AddIntervieweeCommandParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class AddIntervieweeCommandParser implements Parser<AddIntervieweeCommand
1919
* @throws ParseException if the user input does not conform the expected format
2020
*/
2121
public AddIntervieweeCommand parse(String arguments) throws ParseException {
22-
System.out.println("'" + arguments + "'");
2322
ArgumentMultimap argMultimap =
2423
ArgumentTokenizer.tokenize(arguments, PREFIX_ALIAS);
2524

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package seedu.address.logic.parser;
2+
3+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4+
import static seedu.address.logic.parser.CliSyntax.PREFIX_ATTRIBUTE;
5+
import static seedu.address.logic.parser.CliSyntax.PREFIX_WEIGHTAGE;
6+
7+
import java.util.List;
8+
import java.util.stream.Collectors;
9+
10+
import seedu.address.logic.commands.AddMetricCommand;
11+
import seedu.address.logic.parser.exceptions.ParseException;
12+
13+
/**
14+
* Parses input arguments and creates a new object of type AddMetricCommand
15+
*/
16+
public class AddMetricCommandParser implements Parser<AddMetricCommand> {
17+
private static final String MESSAGE_INCOMPLETE_ARGUMENT = "Missing attribute and weightage details.\n%s";
18+
private static final String MESSAGE_INVALID_WEIGHTAGE_FORMAT = "There is an invalid format of the weightage."
19+
+ "Please ensure your weightage are in numbers.";
20+
21+
/**
22+
* Parses the given {@code String} of arguments in the context of the AddMetricCommand
23+
* and returns an AddMetricCommand object for execution.
24+
*
25+
* @param arguments the arguments to be parsed
26+
* @throws ParseException if the user input does not conform the expected format
27+
*/
28+
public AddMetricCommand parse(String arguments) throws ParseException {
29+
ArgumentMultimap argMultimap =
30+
ArgumentTokenizer.tokenize(arguments, PREFIX_ATTRIBUTE, PREFIX_WEIGHTAGE);
31+
32+
if (arguments.equals("")) {
33+
throw new ParseException(
34+
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddMetricCommand.MESSAGE_USAGE));
35+
} else if (!argMultimap.arePrefixesPresent(PREFIX_ATTRIBUTE)
36+
|| !argMultimap.arePrefixesPresent(PREFIX_WEIGHTAGE)) {
37+
throw new ParseException(
38+
String.format(MESSAGE_INCOMPLETE_ARGUMENT, AddMetricCommand.MESSAGE_USAGE));
39+
} else {
40+
List<String> weightages = argMultimap.getAllValues(PREFIX_WEIGHTAGE);
41+
try {
42+
List<Double> castedWeightages = weightages.stream().map(Double::valueOf).collect(Collectors.toList());
43+
return new AddMetricCommand(argMultimap.getPreamble(), argMultimap.getAllValues(PREFIX_ATTRIBUTE),
44+
castedWeightages);
45+
} catch (NumberFormatException e) {
46+
throw new ParseException(MESSAGE_INVALID_WEIGHTAGE_FORMAT);
47+
}
48+
}
49+
}
50+
}

src/main/java/seedu/address/logic/parser/ArgumentTokenizer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ private static List<PrefixPosition> findPrefixPositions(String argsString, Prefi
5353
positions.add(extendedPrefix);
5454
prefixPosition = findPrefixPosition(argsString, prefix.getPrefix(), prefixPosition);
5555
}
56-
5756
return positions;
5857
}
5958

src/main/java/seedu/address/logic/parser/CliSyntax.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public class CliSyntax {
1111
public static final Prefix PREFIX_NEW = new Prefix("-n");
1212
public static final Prefix PREFIX_ATTRIBUTE = new Prefix("-a");
1313
public static final Prefix PREFIX_WEIGHTAGE = new Prefix("-w");
14+
public static final Prefix PREFIX_NAME = new Prefix("-n");
1415
}

0 commit comments

Comments
 (0)