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

Fix all storage issues #151

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class SetProjectStatusCommand extends SetStatusCommand {

public static final String MESSAGE_USAGE = COMMAND_WORD + " [complete/incomplete] /to PROJECT_NAME";
public static final String MESSAGE_USAGE = COMMAND_WORD + " [complete/incomplete] /of PROJECT_NAME";

public static final String MESSAGE_SUCCESS = "The project %1$s is set as %2$s.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class SetTaskStatusCommand extends SetStatusCommand {

public static final String MESSAGE_USAGE = COMMAND_WORD + " [complete/incomplete] /to TASK_NAME /in PROJECT_NAME";
public static final String MESSAGE_USAGE = COMMAND_WORD + " [complete/incomplete] /of TASK_NAME /in PROJECT_NAME";

public static final String MESSAGE_SUCCESS = "The task %1$s is set as %2$s.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ public class SetStatusCommandParser implements Parser<SetStatusCommand> {
public SetStatusCommand parse(String args) throws ParseException {
try {

if (args.contains(" /to ")) {
String status = args.split(" /to ")[0].trim();
String projectString = args.split(" /to ")[1].trim();
if ((projectString.length() == 0) || (status.length() == 0)) {
throw new ParseException("Please enter the status and project fields");
}
Project project = new Project(ParserUtil.parseName(projectString));
return new SetProjectStatusCommand(status, project);
}

if (!args.contains(" /of ")) {
throw new ParseException(String.format(
MESSAGE_INVALID_COMMAND_FORMAT,
Expand All @@ -41,6 +31,16 @@ public SetStatusCommand parse(String args) throws ParseException {

String status = args.split(" /of")[0].trim();
String taskAndProject = args.split(" /of")[1].trim();

if (!args.contains(" /in ")) {
if ((taskAndProject.length() == 0) || (status.length() == 0)) {
throw new ParseException("Please enter the status and project fields");
}
Project project = new Project(ParserUtil.parseName(taskAndProject));
return new SetProjectStatusCommand(status, project);

}

if ((taskAndProject.length() == 0) || (status.length() == 0)) {
throw new ParseException("Please enter the status, project and task fields");
}
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Person {
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy");

private List<Member> team = new ArrayList<>();
private String status = "None";
private String status;
private String category;

private List<Comment> comments = new ArrayList<>();
Expand All @@ -54,6 +54,17 @@ private Person(Name name, List<Task> tasks) {
this.name = name;
}


/**
* Adds task to the Person object
*/
public void addTask(Task task) {
taskList.add(task);
}
public void setTaskList(List<Task> taskList) {
this.taskList.addAll(taskList);
}

public void addMember(Member member) {
team.add(member);
}
Expand Down Expand Up @@ -145,6 +156,12 @@ public String getCategory() {
: category;
}

public String getStatus() {
return status == null
? ""
: status;
}

public List<Task> getUndoneTasks() {
ArrayList<Task> tmp = new ArrayList<>();
for (Task task : taskList) {
Expand Down Expand Up @@ -211,6 +228,10 @@ public String getTeam() {
.collect(Collectors.joining(", "));
}

public List<Member> getTeamList() {
return team;
}

public List<Comment> getComments() {
return comments;
}
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/seedu/address/model/project/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Project {
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM d yyyy");

private List<Member> team = new ArrayList<>();
private String status = "None";
private String status;
private String category;

private List<Comment> comments = new ArrayList<>();
Expand Down Expand Up @@ -76,6 +76,15 @@ public void addTask(Task task) {
taskList.add(task);
}

public void setTaskList(List<Task> taskList) {
this.taskList.addAll(taskList);
}


public void setCommentList(List<Comment> commentList) {
this.comments.addAll(commentList);
}

/**
* removes a project in the specified project
* @param task task to be removed from the project list
Expand Down Expand Up @@ -203,7 +212,9 @@ public List<Task> getUndoneTasks() {
* @return the string represeting the status of the task
*/
public String getStatus() {
return status;
return status == null
? ""
: status;
}

/**
Expand Down Expand Up @@ -262,6 +273,10 @@ public String getTeam() {
.collect(Collectors.joining(", "));
}

public List<Member> getTeamList() {
return team;
}

public List<Comment> getComments() {
return comments;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/project/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public Task(String name) {
this.status = true;
}



/**
* Assigns a Person to the task
* @param member the person assigned to the task
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedComment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package seedu.address.storage;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.project.Comment;
import seedu.address.model.project.Member;

/**
* Jackson-friendly version of {@link Comment}.
*/
public class JsonAdaptedComment {
private final String authorName;
private final String comment;


/**
* Constructs a {@code JsonAdaptedComment} with the given comment details.
*/
@JsonCreator
public JsonAdaptedComment(@JsonProperty("authorName") String authorName,
@JsonProperty("comment") String comment) {

this.comment = comment;
this.authorName = authorName;
}

/**
* Converts a given {@code Member} into this class for Jackson use.
*/
public JsonAdaptedComment(Comment comment) {
this.comment = comment.toString();
this.authorName = comment.getMember().toString();
}





/**
* Converts this Jackson-friendly adapted Member object into the model's {@code Member} object.
*
* @throws IllegalValueException if there were any data constraints violated in the adapted Member.
*/
public Comment toModelType() throws IllegalValueException {
Member author = new Member(authorName);
return new Comment(comment, author);
}
}
47 changes: 47 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedMember.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.address.storage;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.project.Member;



/**
* Jackson-friendly version of {@link Member}.
*/

public class JsonAdaptedMember {
private final String name;

/**
* Constructs a {@code JsonAdaptedMember} with the given {@code name}.
*/
@JsonCreator
public JsonAdaptedMember(String name) {
this.name = name;
}

/**
* Converts a given {@code Member} into this class for Jackson use.
*/
public JsonAdaptedMember(Member source) {
name = source.getName().fullName;
}

@JsonValue
public String getMemberName() {
return name;
}

/**
* Converts this Jackson-friendly adapted Member object into the model's {@code Member} object.
*
* @throws IllegalValueException if there were any data constraints violated in the adapted Member.
*/
public Member toModelType() throws IllegalValueException {

return new Member(name);
}
}
88 changes: 81 additions & 7 deletions src/main/java/seedu/address/storage/JsonAdaptedProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Name;
import seedu.address.model.project.Comment;
import seedu.address.model.project.Member;
import seedu.address.model.project.Project;
import seedu.address.model.tag.Tag;
import seedu.address.model.project.Task;


/**
* Jackson-friendly version of {@link Project}.
Expand All @@ -22,17 +26,43 @@ class JsonAdaptedProject {
private final String deadline;
private final List<JsonAdaptedTag> tags = new ArrayList<>();
private final String category;
private final String projectStatus;

private final List<JsonAdaptedMember> team = new ArrayList<>();
private final List<JsonAdaptedTask> doneTaskList = new ArrayList<>();
private final List<JsonAdaptedTask> undoneTaskList = new ArrayList<>();
private final List<JsonAdaptedComment> commentList = new ArrayList<>();


/**
* Constructs a {@code JsonAdaptedPerson} with the given person details.
* Constructs a {@code JsonAdaptedProject} with the given project details.
*/
@JsonCreator
public JsonAdaptedProject(@JsonProperty("name") String name, @JsonProperty("deadline") String deadline,
@JsonProperty("category") String category, @JsonProperty("address") String address,
@JsonProperty("tags") List<JsonAdaptedTag> tags) {
@JsonProperty("category") String category,
@JsonProperty("projectStatus") String projectStatus,
@JsonProperty("team") List<JsonAdaptedMember> team,
@JsonProperty("doneTaskList") List<JsonAdaptedTask> doneTaskList,
@JsonProperty("undoneTaskList") List<JsonAdaptedTask> undoneTaskList,
@JsonProperty("commentList") List<JsonAdaptedComment> commentList) {
this.name = name;
this.deadline = deadline;
this.category = category;
this.projectStatus = projectStatus;
if (team != null) {
this.team.addAll(team);
}
if (doneTaskList != null) {
this.doneTaskList.addAll(doneTaskList);
}
if (undoneTaskList != null) {
this.undoneTaskList.addAll(undoneTaskList);
}

if (commentList != null) {
this.commentList.addAll(commentList);
}

}

/**
Expand All @@ -42,6 +72,21 @@ public JsonAdaptedProject(Project source) {
name = source.getName().fullName;
deadline = source.getDeadlineString();
category = source.getCategory();
projectStatus = source.getStatus();
team.addAll(source.getTeamList().stream()
.map(JsonAdaptedMember::new)
.collect(Collectors.toList()));
doneTaskList.addAll(source.getDoneTasks().stream()
.map(JsonAdaptedTask::new)
.collect(Collectors.toList()));
undoneTaskList.addAll(source.getUndoneTasks().stream()
.map(JsonAdaptedTask::new)
.collect(Collectors.toList()));

commentList.addAll(source.getComments().stream()
.map(JsonAdaptedComment::new)
.collect(Collectors.toList()));

}

/**
Expand All @@ -50,9 +95,25 @@ public JsonAdaptedProject(Project source) {
* @throws IllegalValueException if there were any data constraints violated in the adapted person.
*/
public Project toModelType() throws IllegalValueException {
final List<Tag> projectTags = new ArrayList<>();
for (JsonAdaptedTag tag : tags) {
projectTags.add(tag.toModelType());
final List<Member> members = new ArrayList<>();
for (JsonAdaptedMember member : team) {
members.add(member.toModelType());
}

final List<Task> tasks = new ArrayList<>();
for (JsonAdaptedTask task : doneTaskList) {
Task current = task.toModelType();
current.setComplete();
tasks.add(current);
}
for (JsonAdaptedTask task : undoneTaskList) {
tasks.add(task.toModelType());

}

final List<Comment> comments = new ArrayList<>();
for (JsonAdaptedComment comment : commentList) {
comments.add(comment.toModelType());
}

if (name == null) {
Expand All @@ -70,6 +131,19 @@ public Project toModelType() throws IllegalValueException {
if (category != null && category.length() != 0) {
toReturn.setCategory(category);
}
if (projectStatus != null && projectStatus.length() != 0) {
if (projectStatus.equals("complete")) {
toReturn.setComplete();
} else {
toReturn.setIncomplete();
}
}
toReturn.assignTeam(members);
toReturn.setTaskList(tasks);

toReturn.setCommentList(comments);


return toReturn;
}

Expand Down
Loading
Loading