Skip to content

Commit

Permalink
SAK-28088
Browse files Browse the repository at this point in the history
  • Loading branch information
Gundala committed Jan 6, 2015
1 parent cc9b0e7 commit f56f887
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class DecoratedForumInfo {
private Long openDate; // An epoch date in seconds. NOT milliseconds.
private Long closeDate; // An epoch date in seconds. NOT milliseconds.
private String gradebookItemName;
private Long gradebookItemId;

public DecoratedForumInfo(Long forumId, String forumTitle,
List<DecoratedAttachment> attachments, String shortDescription,
Expand All @@ -32,14 +33,15 @@ public DecoratedForumInfo(Long forumId, String forumTitle,
List<DecoratedAttachment> attachments, String shortDescription,
String description, Boolean isLocked, Boolean isPostFirst,
Boolean isAvailabilityRestricted, Long openDate, Long closeDate,
String gradebookItemName) {
String gradebookItemName, Long gradebookItemId) {
this(forumId, forumTitle, attachments, shortDescription, description);
this.isLocked = isLocked;
this.isPostFirst = isPostFirst;
this.isAvailabilityRestricted = isAvailabilityRestricted;
this.openDate = openDate;
this.closeDate = closeDate;
this.gradebookItemName = gradebookItemName;
this.gradebookItemId = gradebookItemId;
}

public Long getForumId() {
Expand Down Expand Up @@ -117,6 +119,14 @@ public String getGradebookItemName() {
public void setGradebookItemName(String gradebookItemName) {
this.gradebookItemName = gradebookItemName;
}

public Long getGradebookItemId() {
return gradebookItemId;
}

public void setGradebookItemId(Long gradebookItemId) {
this.gradebookItemId = gradebookItemId;
}

public String getShortDescription() {
return shortDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class DecoratedTopicInfo {
private Long openDate; // An epoch date in seconds. NOT milliseconds.
private Long closeDate; // An epoch date in seconds. NOT milliseconds.
private String gradebookItemName;
private Long gradebookItemId;

public DecoratedTopicInfo(Long topicId, String topicTitle,
int unreadMessagesCount, int messagesCount, String typeUuid,
Expand All @@ -39,7 +40,7 @@ public DecoratedTopicInfo(Long topicId, String topicTitle,
List<DecoratedAttachment> attachments, String shortDescription,
String description, Boolean isLocked, Boolean isPostFirst,
Boolean isAvailabilityRestricted, Long openDate, Long closeDate,
String gradebookItemName) {
String gradebookItemName, Long gradebookItemId) {

this(topicId, topicTitle, unreadMessagesCount, messagesCount, typeUuid,
attachments, shortDescription, description);
Expand All @@ -49,6 +50,7 @@ public DecoratedTopicInfo(Long topicId, String topicTitle,
this.openDate = openDate;
this.closeDate = closeDate;
this.gradebookItemName = gradebookItemName;
this.gradebookItemId = gradebookItemId;
}

public String getTypeUuid() {
Expand Down Expand Up @@ -139,6 +141,14 @@ public void setGradebookItemName(String gradebookItemName) {
this.gradebookItemName = gradebookItemName;
}

public Long getGradebookItemId() {
return gradebookItemId;
}

public void setGradebookItemId(Long gradebookItemId) {
this.gradebookItemId = gradebookItemId;
}

public List<DecoratedAttachment> getAttachments() {
return attachments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.sakaiproject.api.app.messageforums.ui.PrivateMessageManager;
import org.sakaiproject.api.app.messageforums.ui.UIPermissionsManager;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateTopicImpl;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.cover.EntityManager;
Expand All @@ -48,6 +49,9 @@
import org.sakaiproject.entitybroker.entityprovider.extension.RequestStorage;
import org.sakaiproject.entitybroker.entityprovider.search.Restriction;
import org.sakaiproject.entitybroker.entityprovider.search.Search;
import org.sakaiproject.service.gradebook.shared.Assignment;
import org.sakaiproject.service.gradebook.shared.GradebookNotFoundException;
import org.sakaiproject.service.gradebook.shared.GradebookService;
import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.util.ResourceLoader;

Expand Down Expand Up @@ -353,6 +357,22 @@ public List<?> getEntities(EntityReference ref, Search search) {
}else{
forums = forumManager.getDiscussionForumsWithTopics(siteId);
}

// retrieve all of the gradebook items here so we aren't checking repeatedly
Map<String, Long> gbItemNameToId = new HashMap<String, Long>();
try {
GradebookService gradebookService = (GradebookService)ComponentManager.get("org.sakaiproject.service.gradebook.GradebookService");
List<Assignment> gbItems = gradebookService.getAssignments(siteId);
if (gbItems != null) {
for (Assignment gbItem : gbItems) {
gbItemNameToId.put(gbItem.getName(), gbItem.getId());
}
}
} catch (GradebookNotFoundException gnfe) {
LOG.debug("No gradebook exists for site " + siteId + ". No gb item ids will be included.", gnfe);
} catch (Exception e) {
LOG.debug("Exception attempting to retrieve gradebook information for site " + siteId + ". ", e);
}

for (DiscussionForum forum : forums) {
if(forum.getDraft().equals(Boolean.FALSE)){
Expand All @@ -363,9 +383,15 @@ public List<?> getEntities(EntityReference ref, Search search) {
forumOpenDate = forum.getOpenDate() != null ? forum.getOpenDate().getTime()/1000 : null;
forumCloseDate = forum.getCloseDate() != null ? forum.getCloseDate().getTime()/1000 : null;
}

Long forumGbItemId = null;
if (forum.getDefaultAssignName() != null && !forum.getDefaultAssignName().isEmpty() &&
gbItemNameToId.containsKey(forum.getDefaultAssignName())) {
forumGbItemId = gbItemNameToId.get(forum.getDefaultAssignName());
}

DecoratedForumInfo dForum = new DecoratedForumInfo(forum.getId(), forum.getTitle(), forumAttachments, forum.getShortDescription(), forum.getExtendedDescription(), forum.getLocked(),
forum.getPostFirst(), forum.getAvailabilityRestricted(), forumOpenDate, forumCloseDate, forum.getDefaultAssignName());
forum.getPostFirst(), forum.getAvailabilityRestricted(), forumOpenDate, forumCloseDate, forum.getDefaultAssignName(), forumGbItemId);
List<DiscussionTopic> topics = forum.getTopics();
int viewableTopics = 0;

Expand Down Expand Up @@ -398,9 +424,16 @@ public List<?> getEntities(EntityReference ref, Search search) {
topicOpenDate = topic.getOpenDate() != null ? topic.getOpenDate().getTime()/1000 : null;
topicCloseDate = topic.getCloseDate() != null ? topic.getCloseDate().getTime()/1000 : null;
}

Long topicGbItemId = null;
if (topic.getDefaultAssignName() != null && !topic.getDefaultAssignName().isEmpty() &&
gbItemNameToId.containsKey(topic.getDefaultAssignName())) {
topicGbItemId = gbItemNameToId.get(topic.getDefaultAssignName());
}

dForum.addTopic(new DecoratedTopicInfo(topic.getId(), topic.getTitle(), unreadMessages,
totalMessages, "", attachments, topic.getShortDescription(), topic.getExtendedDescription(), topic.getLocked(), topic.getPostFirst(), topic.getAvailabilityRestricted(),
topicOpenDate, topicCloseDate, topic.getDefaultAssignName()));
topicOpenDate, topicCloseDate, topic.getDefaultAssignName(), topicGbItemId));
viewableTopics++;
}
}
Expand Down

0 comments on commit f56f887

Please sign in to comment.