Skip to content

Commit

Permalink
Edit command text returns and date format
Browse files Browse the repository at this point in the history
  • Loading branch information
H4mes committed Mar 21, 2024
1 parent 941b7d6 commit 465a113
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 24 deletions.
29 changes: 20 additions & 9 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic;

import java.time.format.DateTimeFormatter;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -55,16 +56,26 @@ public static String format(Person person) {
* Formats the {@code article} for display to the user.
*/
public static String format(Article article) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");

Check warning on line 59 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L59

Added line #L59 was not covered by tests
final StringBuilder builder = new StringBuilder();
builder.append("; Title: ")
.append(article.getTitle())
.append("; Authors: ")
.append(article.getAuthors())
.append("; Publication Date: ")
.append(article.getPublicationDate())
.append("; Source: ")
.append(article.getSources())
.append("; Category: ")
builder.append(article.getTitle())
.append("; Authors: ");

Check warning on line 62 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L61-L62

Added lines #L61 - L62 were not covered by tests
for (int i = 0; i < article.getAuthors().length; i++) {
builder.append(article.getAuthors()[i]);

Check warning on line 64 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L64

Added line #L64 was not covered by tests
if (i < article.getAuthors().length - 1) {
builder.append(", ");

Check warning on line 66 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L66

Added line #L66 was not covered by tests
}
}
builder.append("; Publication Date: ")
.append(article.getPublicationDateAsString())
.append("; Source: ");

Check warning on line 71 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L69-L71

Added lines #L69 - L71 were not covered by tests
for (int i = 0; i < article.getSources().length; i++) {
builder.append(article.getSources()[i]);

Check warning on line 73 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L73

Added line #L73 was not covered by tests
if (i < article.getSources().length - 1) {
builder.append(", ");

Check warning on line 75 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L75

Added line #L75 was not covered by tests
}
}
builder.append("; Category: ")

Check warning on line 78 in src/main/java/seedu/address/logic/Messages.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/Messages.java#L78

Added line #L78 was not covered by tests
.append(article.getCategory())
.append("; Status: ")
.append(article.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Represents a command with functionality pertaining to persons.
*/
public abstract class PersonCommand extends Command {

@Override
public String getCommandType() {
return "personCommand";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class AddArticleCommand extends ArticleCommand {
public static final String COMMAND_PREFIX = "-a";

// To be edited for use in test cases later on.
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an article to the article book. ";
public static final String MESSAGE_USAGE = COMMAND_WORD + " " + COMMAND_PREFIX
+ ": Adds an article to the article book. ";

public static final String MESSAGE_SUCCESS = "New article added: %1$s";
public static final String MESSAGE_DUPLICATE_ARTICLE = "This article already exists in the article book";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
public abstract class ArticleCommand extends Command {

Check warning on line 8 in src/main/java/seedu/address/logic/commands/articlecommands/ArticleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/articlecommands/ArticleCommand.java#L8

Added line #L8 was not covered by tests

@Override
public String getCommandType() {
return "articleCommand";

Check warning on line 12 in src/main/java/seedu/address/logic/commands/articlecommands/ArticleCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/articlecommands/ArticleCommand.java#L12

Added line #L12 was not covered by tests
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DeleteArticleCommand extends ArticleCommand {
public static final String COMMAND_PREFIX = "-a";

// To be edited for use in test cases later on.
public static final String MESSAGE_USAGE = COMMAND_WORD
public static final String MESSAGE_USAGE = COMMAND_WORD + " " + COMMAND_PREFIX
+ ": Deletes the article identified by the index number used in the displayed article list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " " + COMMAND_PREFIX + " 1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class EditArticleCommand extends ArticleCommand {
public static final String COMMAND_PREFIX = "-a";

// To be edited for use in test cases later on.
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the article identified "
public static final String MESSAGE_USAGE = COMMAND_WORD + " " + COMMAND_PREFIX
+ ": Edits the details of the article identified "
+ "by the index number used in the displayed article list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public class FindArticleCommand extends ArticleCommand {

public static final String COMMAND_PREFIX = "-a";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all articles whose titles contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " " + COMMAND_PREFIX + " HDB UDP TCP";
public static final String MESSAGE_USAGE = COMMAND_WORD + " " + COMMAND_PREFIX
+ ": Finds all articles whose titles contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " " + COMMAND_PREFIX + " HDB UDP TCP";

private final TitleContainsKeywordsPredicate predicate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class ListArticleCommand extends ArticleCommand {

public static final String MESSAGE_SUCCESS = "Listed all articles";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AddArticleCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_TITLE, PREFIX_AUTHOR, PREFIX_PUBLICATION_DATE, PREFIX_SOURCE,
PREFIX_CATEGORY, PREFIX_STATUS);

if (!arePrefixesPresent(argMultimap, PREFIX_TITLE, PREFIX_AUTHOR, PREFIX_PUBLICATION_DATE, PREFIX_SOURCE,
if (!arePrefixesPresent(argMultimap, PREFIX_TITLE, PREFIX_AUTHOR, PREFIX_PUBLICATION_DATE,
PREFIX_CATEGORY, PREFIX_STATUS) || !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddArticleCommand.MESSAGE_USAGE));
}
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import static seedu.address.model.article.Article.Status.DRAFT;
import static seedu.address.model.article.Article.Status.PUBLISHED;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -165,10 +168,18 @@ public static String[] parseAuthors(List<String> authors) throws ParseException
*/
public static LocalDateTime parsePublicationDate(String publicationDate) throws ParseException {
requireNonNull(publicationDate);
String trimmedPublicationDate = publicationDate.trim();
LocalDateTime parsedDate = LocalDateTime.parse(trimmedPublicationDate);
//removed the check for publication date validity
return parsedDate;
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
String trimmedPublicationDate = publicationDate.trim();
Date tempDate = dateFormat.parse(trimmedPublicationDate);
LocalDateTime parsedDate = tempDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
parsedDate.withSecond(0);

Check warning on line 176 in src/main/java/seedu/address/logic/parser/ParserUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/ParserUtil.java#L172-L176

Added lines #L172 - L176 were not covered by tests
//removed the check for publication date validity
return parsedDate;
} catch (java.text.ParseException e) {
throw new ParseException("Invalid publication date");

Check warning on line 180 in src/main/java/seedu/address/logic/parser/ParserUtil.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/ParserUtil.java#L178-L180

Added lines #L178 - L180 were not covered by tests
}

}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/article/Article.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model.article;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Represents an article in the address book.
Expand Down Expand Up @@ -53,6 +54,11 @@ public LocalDateTime getPublicationDate() {
return this.publicationDate;
}

public String getPublicationDateAsString() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
return this.publicationDate.format(formatter);

Check warning on line 59 in src/main/java/seedu/address/model/article/Article.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/article/Article.java#L58-L59

Added lines #L58 - L59 were not covered by tests
}

public String[] getSources() {
return this.sources;

Check warning on line 63 in src/main/java/seedu/address/model/article/Article.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/article/Article.java#L63

Added line #L63 was not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/ArticleCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ArticleCard(Article article, int displayedIndex) {
Arrays.stream(article.getSources())
.sorted()
.forEach(source -> sources.getChildren().add(new Label(source)));
publicationDate.setText(article.getPublicationDate().toString());
publicationDate.setText(article.getPublicationDateAsString());
category.setText(article.getCategory());
status.setText(article.getStatus().toString());
}

Check warning on line 64 in src/main/java/seedu/address/ui/ArticleCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/ArticleCard.java#L51-L64

Added lines #L51 - L64 were not covered by tests
Expand Down

0 comments on commit 465a113

Please sign in to comment.