Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import teammates.common.util.Assumption;
import teammates.common.util.FieldValidator;
import teammates.common.util.JsonUtils;
import teammates.common.util.SanitizationHelper;
Expand All @@ -11,7 +12,7 @@

public class TopicAttributes extends EntityAttributes<Topic> {

/* Variable declarations */
/* Variable declarations */
public String id;
public String creator;
public String name;
Expand All @@ -35,54 +36,54 @@ public TopicAttributes(String topicID, String creator, String name, String desc,
public static Builder builder(String topicID, String creator, String name, String desc, ArrayList<Reply> replies, Integer count,Integer viewCounter) {
return new Builder(topicID, creator, name, desc, replies, count,viewCounter);
}

/* Getters */

public Integer getViewCounter() {
return viewCounter;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getCreator() {
return creator;
}

public String getDesc() {
return desc;
}

public void setCount(Integer count) {
this.count = count;
}

public ArrayList<RepliesAttributes> getReplies(){
return replies;
}

public Integer getCount() {
return count;
}


/* Setters */

public void setViewCounter(Integer viewCounter) {
this.viewCounter = viewCounter;
}

public void setReplies(ArrayList<RepliesAttributes> replies)
{
this.replies = replies;
}


/* Function to add a reply to the topic count iterated as it is used as partial key to identify reply*/
public void addReply(RepliesAttributes reply)
{
Expand All @@ -93,7 +94,7 @@ public void addReply(RepliesAttributes reply)
replies.add(reply);
count++;
}

/* Used to validate strings stored in topic */
@Override
public List<String> getInvalidityInfo() { FieldValidator validator = new FieldValidator();
Expand All @@ -115,32 +116,32 @@ public Topic toEntity() {
}
return new Topic(getId(), getCreator(), getName(), getDesc(), repliesEntity, count,viewCounter);
}

/* Inherited methods, not all necessary for our functionality */
@Override
public String getIdentificationString() {
return null;
}

@Override
public String getEntityTypeAsString() {
return "Topic";
}

@Override
public String getBackupIdentifier() {
return null;
}

@Override
public String getJsonString() {
return JsonUtils.toJson(this, TopicAttributes.class);
}

@Override
public void sanitizeForSaving() {
}

/* Takes ArrayList of Reply entities, returns array of RepliesAttributes */
/* Required in order to take objects from database and build them back up to a usable state */
public static ArrayList<RepliesAttributes> getRepliesAtt(ArrayList<Reply> replies)
Expand All @@ -151,28 +152,36 @@ public static ArrayList<RepliesAttributes> getRepliesAtt(ArrayList<Reply> replie
for(Reply reply:replies)
{
repliesAtt.add(new RepliesAttributes(reply.getDesc(), reply.getStudentName(), reply.getId(), reply.getDateTime(),reply.getLike(),reply.getDislike()));
}
}
return repliesAtt;
}
return null;
}

public void removeReply(RepliesAttributes reply)
{
replies.remove(reply);
}

/* Calls above method, is used to return a TopicAttributes instance based on a Topic entity in database */
public static class Builder {
private static final String REQUIRED_FIELD_CANNOT_BE_NULL = "Non-null value expected";
private final TopicAttributes topicAttributes;

public Builder(String topicID, String creator, String name, String desc, ArrayList<Reply> replies, Integer count,Integer viewCounter) {
validateRequiredFields(name, desc);
ArrayList<RepliesAttributes> repliesAtt = getRepliesAtt(replies);
topicAttributes = new TopicAttributes(topicID, creator, name, desc, repliesAtt, count,viewCounter);
}

public TopicAttributes build() {
return topicAttributes;
}

private void validateRequiredFields(Object... objects) {
for (Object object : objects) {
Assumption.assertNotNull(REQUIRED_FIELD_CANNOT_BE_NULL, object);
}
}
}
}
13 changes: 12 additions & 1 deletion src/main/java/teammates/common/util/AppUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ public AppUrl withInstructorInstitution(String institute) {
public AppUrl withCourseId(String courseId) {
return withParam(Const.ParamsNames.COURSE_ID, courseId);
}

public AppUrl withTopicName(String topicName) {
return withParam(Const.ParamsNames.TOPIC_NAME, topicName);
}

public AppUrl withTopicId(String topicId) {
return withParam(Const.ParamsNames.TOPIC_ID, topicId);
}

public AppUrl withReplyId(int replyId) {
return withParam(Const.ParamsNames.REPLY_ID, Integer.toString(replyId));
}

public AppUrl withSessionName(String feedbackSessionName) {
return withParam(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
Expand All @@ -45,5 +57,4 @@ public AppUrl withQuestionNumber(String questionNumber) {
public AppUrl withEnableSessionEditDetails(boolean shouldLoadInEditMode) {
return withParam(Const.ParamsNames.FEEDBACK_SESSION_ENABLE_EDIT, Boolean.toString(shouldLoadInEditMode));
}

}
8 changes: 3 additions & 5 deletions src/main/java/teammates/storage/api/TopicsDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected LoadType<Topic> load() {
* Return a topic based of the topicId
* @param topicId Name of the topic
*/

public TopicAttributes getTopic(String topicId) {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, topicId);
return makeAttributesOrNull(getTopicEntity(topicId));
Expand All @@ -55,7 +55,7 @@ public List<TopicAttributes> getTopics(List<String> topicIds) {

return makeAttributes(getTopicEntities(topicIds));
}

/**
* Updates a topic by asserting that a topic with the same id is contained within database already,
* if so the topic is overwritten by new topic with new values
Expand Down Expand Up @@ -155,9 +155,7 @@ public void deleteTopic(String topicID) {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, topicID);
//Only the key is important, the rest are irrelevant
deleteEntity(TopicAttributes
.builder(topicID, null, null, null, null, null,null)
.builder(topicID, "Non-existing", "Non-existing", "Non-existing", null, null,null)
.build());


}
}
Binary file added src/test/java/.DS_Store
Binary file not shown.
Binary file added src/test/java/teammates/.DS_Store
Binary file not shown.
Binary file added src/test/java/teammates/test/.DS_Store
Binary file not shown.
Binary file added src/test/java/teammates/test/cases/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private EntityAttributes<?> getEntity(EntityAttributes<?> expected) {

} else if (expected instanceof StudentAttributes) {
return getStudent((StudentAttributes) expected);

} else if (expected instanceof TopicAttributes) {
return getTopic((TopicAttributes) expected);

Expand Down Expand Up @@ -126,6 +126,7 @@ private void verifyEquals(EntityAttributes<?> expected, EntityAttributes<?> actu
} else if (expected instanceof TopicAttributes) {
TopicAttributes expectedTopic = (TopicAttributes) expected;
TopicAttributes actualTopic = (TopicAttributes) actual;
equalizeIrrelevantData(expectedTopic, actualTopic);
assertEquals(JsonUtils.toJson(expectedTopic), JsonUtils.toJson(actualTopic));

} else if (expected instanceof FeedbackQuestionAttributes) {
Expand Down Expand Up @@ -188,13 +189,20 @@ private void equalizeIrrelevantData(AccountAttributes expected, AccountAttribute
}

protected abstract CourseAttributes getCourse(CourseAttributes course);

protected abstract TopicAttributes getTopic(TopicAttributes topic);

private void equalizeIrrelevantData(CourseAttributes expected, CourseAttributes actual) {
// Ignore time field as it is stamped at the time of creation in testing
expected.createdAt = actual.createdAt;
}

private void equalizeIrrelevantData(TopicAttributes expected, TopicAttributes actual) {
System.out.println(actual.toString());
expected.id = actual.id;
expected.replies = actual.replies;
expected.viewCounter = actual.viewCounter;
}

protected abstract FeedbackQuestionAttributes getFeedbackQuestion(FeedbackQuestionAttributes fq);

Expand Down
Loading