Skip to content

Commit

Permalink
Implement basic Outlet class
Browse files Browse the repository at this point in the history
Known issues with reading from JSON. Preliminary commit for merging with
upstream changes.
  • Loading branch information
H4mes committed Mar 28, 2024
1 parent d9307fb commit dec126c
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.model.article.Article;
import seedu.address.model.article.Article.Status;
import seedu.address.model.article.Author;
import seedu.address.model.article.Outlet;
import seedu.address.model.article.Source;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -92,14 +93,15 @@ private static Article createEditedArticle(Article articleToEdit, EditArticleDes

String title = editArticleDescriptor.getTitle().orElse(articleToEdit.getTitle());
Set<Author> authors = editArticleDescriptor.getAuthors().orElse(articleToEdit.getAuthors());
LocalDateTime publicationDate = editArticleDescriptor.getPublicationDate()
.orElse(articleToEdit.getPublicationDate());
Set<Source> sources = editArticleDescriptor.getSources().orElse(articleToEdit.getSources());
Set<Tag> tags = editArticleDescriptor.getTags().orElse(articleToEdit.getTags());
Outlet outlet = editArticleDescriptor.getOutlet().orElse(articleToEdit.getOutlet());
LocalDateTime publicationDate = editArticleDescriptor.getPublicationDate()
.orElse(articleToEdit.getPublicationDate());
Status status = editArticleDescriptor.getStatus().orElse(articleToEdit.getStatus());

return new Article(title, authors, publicationDate,
sources, tags, status); // Include all article attributes here.
return new Article(title, authors, sources, tags,
outlet, publicationDate, status); // Include all article attributes here.
}

@Override
Expand Down Expand Up @@ -134,9 +136,10 @@ public static class EditArticleDescriptor {

private String title;
private Set<Author> authors;
private LocalDateTime publicationDate;
private Set<Source> sources;
private Set<Tag> tags;
private Outlet outlet;
private LocalDateTime publicationDate;
private Status status;

public EditArticleDescriptor() {}
Expand All @@ -147,17 +150,18 @@ public EditArticleDescriptor() {}
public EditArticleDescriptor(EditArticleDescriptor toCopy) {
setTitle(toCopy.title);
setAuthors(toCopy.authors);
setPublicationDate(toCopy.publicationDate);
setSources(toCopy.sources);
setTags(toCopy.tags);
setOutlet(toCopy.outlet);
setPublicationDate(toCopy.publicationDate);
setStatus(toCopy.status);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(title, authors, publicationDate, sources, tags, status);
return CollectionUtil.isAnyNonNull(title, authors, sources, outlet, publicationDate, tags, status);
}

public void setTitle(String title) {
Expand Down Expand Up @@ -200,6 +204,13 @@ public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

public void setOutlet(Outlet outlet) {
this.outlet = outlet;
}

public Optional<Outlet> getOutlet() {
return Optional.ofNullable(outlet);
}
public void setStatus(Status status) {
this.status = status;
}
Expand All @@ -224,8 +235,9 @@ public boolean equals(Object other) {
// Add more equality checks for article attributes below here.
return Objects.equals(title, otherEditArticleDescriptor.title)
&& Objects.equals(authors, otherEditArticleDescriptor.authors)
&& Objects.equals(publicationDate, otherEditArticleDescriptor.publicationDate)
&& Objects.equals(sources, otherEditArticleDescriptor.sources)
&& Objects.equals(outlet, otherEditArticleDescriptor.outlet)
&& Objects.equals(publicationDate, otherEditArticleDescriptor.publicationDate)
&& Objects.equals(tags, otherEditArticleDescriptor.tags)
&& Objects.equals(status, otherEditArticleDescriptor.status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ARTICLETAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AUTHOR;
import static seedu.address.logic.parser.CliSyntax.PREFIX_OUTLET;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PUBLICATION_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SOURCE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS;
Expand All @@ -16,6 +17,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.article.Article;
import seedu.address.model.article.Author;
import seedu.address.model.article.Outlet;
import seedu.address.model.article.Source;
import seedu.address.model.tag.Tag;

Expand All @@ -31,8 +33,8 @@ public class AddArticleCommandParser implements Parser<AddArticleCommand> {
*/
public AddArticleCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_TITLE, PREFIX_AUTHOR, PREFIX_PUBLICATION_DATE, PREFIX_SOURCE,
PREFIX_ARTICLETAG, PREFIX_STATUS);
ArgumentTokenizer.tokenize(args, PREFIX_TITLE, PREFIX_AUTHOR, PREFIX_SOURCE, PREFIX_OUTLET,
PREFIX_PUBLICATION_DATE, PREFIX_ARTICLETAG, PREFIX_STATUS);
//Temporarily reinstate source requirement
if (!arePrefixesPresent(argMultimap, PREFIX_TITLE, PREFIX_PUBLICATION_DATE, PREFIX_STATUS)
|| !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -41,13 +43,14 @@ public AddArticleCommand parse(String args) throws ParseException {

String title = ParserUtil.parseTitle(argMultimap.getValue(PREFIX_TITLE).get());
Set<Author> authorList = ParserUtil.parseAuthors(argMultimap.getAllValues(PREFIX_AUTHOR));
LocalDateTime publicationDate = ParserUtil.parsePublicationDate(argMultimap.getValue(PREFIX_PUBLICATION_DATE)
.get());
Set<Source> sourceList = ParserUtil.parseSources(argMultimap.getAllValues(PREFIX_SOURCE));
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_ARTICLETAG));
Outlet outlet = ParserUtil.parseOutlet(argMultimap.getValue(PREFIX_OUTLET).get());
LocalDateTime publicationDate = ParserUtil.parsePublicationDate(argMultimap.getValue(PREFIX_PUBLICATION_DATE)
.get());
Article.Status status = (Article.Status) ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get());

Article article = new Article(title, authorList, publicationDate, sourceList, tagList, status);
Article article = new Article(title, authorList, sourceList, tagList, outlet, publicationDate, status);

return new AddArticleCommand(article);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class CliSyntax {

public static final Prefix PREFIX_TITLE = new Prefix("T/");
public static final Prefix PREFIX_AUTHOR = new Prefix("A/");
public static final Prefix PREFIX_PUBLICATION_DATE = new Prefix("D/");
public static final Prefix PREFIX_SOURCE = new Prefix("SRC/");
public static final Prefix PREFIX_ARTICLETAG = new Prefix("TAG/");
public static final Prefix PREFIX_OUTLET = new Prefix("O/");
public static final Prefix PREFIX_PUBLICATION_DATE = new Prefix("D/");
public static final Prefix PREFIX_STATUS = new Prefix("S/");

}
11 changes: 6 additions & 5 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.article.Article;
import seedu.address.model.article.Author;
import seedu.address.model.article.Outlet;
import seedu.address.model.article.Source;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand Down Expand Up @@ -210,13 +211,13 @@ public static Set<Source> parseSources(Collection<String> sources) throws ParseE
}

/**
* Parses a {@code String category} into a {@code Category}.
* Parses a {@code String outlet} into a {@code Outlet}.
*/
public static String parseCategory(String category) throws ParseException {
requireNonNull(category);
String trimmedCategory = category.trim();
public static Outlet parseOutlet(String outlet) throws ParseException {
requireNonNull(outlet);
String trimmedOutlet = outlet.trim();
//removed the check for category validity
return trimmedCategory;
return new Outlet(trimmedOutlet);
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/seedu/address/model/article/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/
public class Article {
private final String title;
private final Outlet outlet;
private final Set<Author> authors = new HashSet<>();
private final LocalDateTime publicationDate;
private final Set<Source> sources = new HashSet<>();
private final Set<Tag> tags = new HashSet<>();
private final LocalDateTime publicationDate;

/**
* Enumeration of Status of an article.
Expand All @@ -41,14 +42,15 @@ public enum Status {
* @param tags the subject of the article.
* @param status the current status of the article.
*/
public Article(String title, Set<Author> authors, LocalDateTime publicationDate,
Set<Source> sources, Set<Tag> tags, Status status) {
requireAllNonNull(title, authors, publicationDate, sources, tags, status);
public Article(String title, Set<Author> authors, Set<Source> sources, Set<Tag> tags,
Outlet outlet, LocalDateTime publicationDate, Status status) {
requireAllNonNull(title, authors, sources, tags, outlet, publicationDate, status);
this.title = title;
this.authors.addAll(authors);
this.publicationDate = publicationDate;
this.sources.addAll(sources);
this.tags.addAll(tags);
this.outlet = outlet;
this.publicationDate = publicationDate;
this.status = status;
}

Expand All @@ -69,6 +71,10 @@ public String getPublicationDateAsString() {
return this.publicationDate.format(formatter);
}

public Outlet getOutlet() {
return this.outlet;
}

public Set<Source> getSources() {
return Collections.unmodifiableSet(sources);
}
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/model/article/Outlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package seedu.address.model.article;

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

/**
* Represents the news outlet an Article is published by
*/
public class Outlet {
public static final String MESSAGE_CONSTRAINTS = "Outlet names should be alphanumeric";
public static final String VALIDATION_REGEX = "[\\p{Alnum} ]+";

public final String outletName;


/**
* Constructs a {@code outletName}.
*
* @param outletName A valid author name.
*/
public Outlet(String outletName) {
requireNonNull(outletName);
checkArgument(isValidOutletName(outletName), MESSAGE_CONSTRAINTS);
this.outletName = outletName;
}

/**
* Returns true if a given string is a valid outlet name.
*/
public static boolean isValidOutletName(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

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

Outlet otherOutlet = (Outlet) other;
return outletName.equals(otherOutlet.outletName);
}

@Override
public int hashCode() {
return outletName.hashCode();
}

/**
* Format state as text for viewing.
*/
public String toString() {
return '[' + outletName + ']';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.model.article.Article;
import seedu.address.model.article.Article.Status;
import seedu.address.model.article.Author;
import seedu.address.model.article.Outlet;
import seedu.address.model.article.Source;
import seedu.address.model.tag.Tag;

Expand All @@ -21,8 +22,8 @@ public class SampleArticleDataUtil {
public static Article[] getSampleArticles() {
return new Article[]{
new Article("The epitome of pain and suffering by NUS CS students.", getAuthorSet("Alice", "Bob"),
LocalDateTime.now(), getSourceSet("NUS Computing Club"), getTagSet("Student Life"),
Status.PUBLISHED)
getSourceSet("NUS Computing Club"), getTagSet("Student Life"), new Outlet("SOC News Bulletin"),
LocalDateTime.now(), Status.PUBLISHED)
};
}

Expand Down
19 changes: 14 additions & 5 deletions src/main/java/seedu/address/storage/JsonAdaptedArticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.article.Article;
import seedu.address.model.article.Author;
import seedu.address.model.article.Outlet;
import seedu.address.model.article.Source;
import seedu.address.model.tag.Tag;

Expand All @@ -26,36 +27,40 @@ public class JsonAdaptedArticle {
private final LocalDateTime publicationDate;
private final List<JsonAdaptedSource> sources = new ArrayList<>();
private final List<JsonAdaptedTag> tags = new ArrayList<>();
private final String outlet;
private final Article.Status status;

/**
* Construct a {@code JsonAdaptedArticle} with the given article details.
*
* @param title
* @param authors
* @param publicationDate
* @param sources
* @param tags
* @param outlet
* @param publicationDate
* @param status
*/
@JsonCreator
public JsonAdaptedArticle(@JsonProperty("title") String title,
@JsonProperty("authors") List<JsonAdaptedAuthor> authors,
@JsonProperty("publicationDate") LocalDateTime publicationDate,
@JsonProperty("sources") List<JsonAdaptedSource> sources,
@JsonProperty("tags") List<JsonAdaptedTag> tags,
@JsonProperty("outlet") Outlet outlet,
@JsonProperty("publicationDate") LocalDateTime publicationDate,
@JsonProperty("status") Article.Status status) {
this.title = title;
if (authors != null) {
this.authors.addAll(authors);
}
this.publicationDate = publicationDate;
if (sources != null) {
this.sources.addAll(sources);
}
if (tags != null) {
this.tags.addAll(tags);
}
this.outlet = outlet.outletName;
this.publicationDate = publicationDate;
this.status = status;
}
/**
Expand All @@ -67,13 +72,14 @@ public JsonAdaptedArticle(Article sourceArticle) {
authors.addAll(sourceArticle.getAuthors().stream()
.map(JsonAdaptedAuthor::new)
.collect(Collectors.toList()));
publicationDate = sourceArticle.getPublicationDate();
sources.addAll(sourceArticle.getSources().stream()
.map(JsonAdaptedSource::new)
.collect(Collectors.toList()));
tags.addAll(sourceArticle.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList()));
outlet = sourceArticle.getOutlet().outletName;
publicationDate = sourceArticle.getPublicationDate();
status = sourceArticle.getStatus();
}

Expand Down Expand Up @@ -103,12 +109,15 @@ public Article toModelType() throws IllegalValueException {
articleSources.add(source.toModelType());
}


final Set<Author> modelAuthors = new HashSet<>(articleAuthors);

final Set<Source> modelSources = new HashSet<>(articleSources);

final Set<Tag> modelTags = new HashSet<>(articleTags);

return new Article(title, modelAuthors, publicationDate, modelSources, modelTags, status);
final Outlet modelOutlet = new Outlet(outlet);

return new Article(title, modelAuthors, modelSources, modelTags, modelOutlet, publicationDate, status);
}
}
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,4 @@ public void saveArticleBook(ReadOnlyArticleBook articleBook, Path filePath) thro
logger.fine("Attempting to write to data file: " + filePath);
articleBookStorage.saveArticleBook(articleBook, filePath);
}


}
Loading

0 comments on commit dec126c

Please sign in to comment.