Skip to content

Commit

Permalink
DASH-299 add checks to site publicity into isAvailable() calls
Browse files Browse the repository at this point in the history
git-svn-id: https://source.sakaiproject.org/svn/dashboard/trunk@313575 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
zqian committed May 13, 2014
1 parent f928c6e commit 5ab69fc
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ public interface SakaiProxy {
* @return the site, or null if the siteId does not identify a site that can be returned.
*/
public Site getSite(String siteId);

/**
* Returns whether a site is published or not
*
* @param siteId
* @return true if the site is published; false otherwise
*/
public boolean isSitePublished(String siteId);

/**
* Wrapper for ServerConfigurationService.getString("skin.repo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.sakaiproject.dash.listener.EventProcessor;
import org.sakaiproject.dash.logic.DashboardLogic;
import org.sakaiproject.dash.app.SakaiProxy;
import org.sakaiproject.dash.entity.AssignmentSupport.AssignmentEntityType;
import org.sakaiproject.dash.model.Context;
import org.sakaiproject.dash.model.NewsItem;
import org.sakaiproject.dash.model.SourceType;
Expand Down Expand Up @@ -338,6 +339,24 @@ public void init() {
}

public boolean isAvailable(String entityReference) {
try
{
String channelId = getChannelIdFromReference(entityReference);
AnnouncementChannel channel = (AnnouncementChannel) announcementService.getChannel(channelId);
String siteId = channel.getContext();
if (!sakaiProxy.isSitePublished(siteId))
{
// return false if site is unpublished
return false;
}
}
catch (Exception e)
{
logger.warn(this + " isAvailable error getting announcement channel object for announcement message " + entityReference);
return false;
}

// now that we have published site
AnnouncementMessage announcement = (AnnouncementMessage) sakaiProxy.getEntity(entityReference);
if(announcement != null) {
if(announcement.getHeader().getDraft()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.sakaiproject.entitybroker.EntityBroker;
import org.sakaiproject.entitybroker.entityprovider.extension.ActionReturn;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.user.api.User;
import org.sakaiproject.util.ResourceLoader;

Expand Down Expand Up @@ -282,6 +283,13 @@ public void init() {

public boolean isAvailable(String entityReference) {
Assignment assn = (Assignment) sakaiProxy.getEntity(entityReference);
String siteId = assn.getContext();
if (!sakaiProxy.isSitePublished(siteId))
{
// return false if site is unpublished
return false;
}

if (assn != null){
return isAvailable(assn);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.content.api.ContentCollection;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.content.api.ResourceType;
import org.sakaiproject.dash.listener.EventProcessor;
Expand Down Expand Up @@ -273,11 +274,35 @@ public boolean isAvailable(String entityReference) {
if(resource == null) {
logger.warn("isAvailable() problem retrieving resource with entity reference " + entityReference);
} else {
String siteId = getSiteIdFromResource(resource);
if (!sakaiProxy.isSitePublished(siteId))
{
// return false if site is unpublished
return false;
}

isAvailable = resource.isAvailable();
}
}
return isAvailable;
}

/**
* extract the site id from the resource object
* @param resource
* @return
*/
private String getSiteIdFromResource(ContentResource resource) {
ContentCollection collection = resource.getContainingCollection();
String collectionId = collection.getId();
while (!ContentHostingService.COLLECTION_SITE.equals(collection.getId()))
{
// continue
collectionId = collection.getId();
collection = collection.getContainingCollection();
}
return collectionId.replaceAll(ContentHostingService.COLLECTION_SITE, "").replaceAll("/", "");
}

public boolean isUserPermitted(String sakaiUserId, String entityReference,
String contextId) {
Expand Down Expand Up @@ -667,7 +692,8 @@ private NewsItem addContentNewsItem(Event event, ContentResource resource) {
if (!sakaiProxy.isAttachmentResource(resource.getId()))
{
// only when the resource is not attachment
Context context = dashboardLogic.getContext(event.getContext());
String contextString = event.getContext();
Context context = dashboardLogic.getContext(contextString);

String labelKey = "resource.added";
SourceType sourceType = null;
Expand Down Expand Up @@ -723,9 +749,14 @@ private NewsItem addContentNewsItem(Event event, ContentResource resource) {
if (dashboardLogic.getNewsItem(resourceReference) == null)
{
newsItem = dashboardLogic.createNewsItem(title, eventTime, labelKey , resourceReference, context, sourceType, resource.getContentType());
dashboardLogic.createNewsLinks(newsItem);

// check whether the associated site is published or not;
// do not create any links if the site is unpublished
boolean sitePublished = false;

if(dashboardLogic.isAvailable(newsItem.getEntityReference(), RESOURCE_TYPE_IDENTIFIER)) {
dashboardLogic.createNewsLinks(newsItem);

// entity is available now -- check for retract date
Date retractDate = getRetractDate(newsItem.getEntityReference());
if(retractDate != null && retractDate.after(new Date())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.announcement.api.AnnouncementMessage;
import org.sakaiproject.calendar.api.Calendar;
import org.sakaiproject.calendar.api.CalendarEvent;
import org.sakaiproject.calendar.api.CalendarService;
import org.sakaiproject.calendar.api.RecurrenceRule;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.dash.listener.EventProcessor;
Expand All @@ -53,6 +55,10 @@
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.time.api.TimeRange;
import org.sakaiproject.time.api.TimeService;
import org.sakaiproject.user.api.User;
Expand Down Expand Up @@ -84,6 +90,16 @@ public void setTimeService(TimeService timeService) {
this.timeService = timeService;
}

protected CalendarService calendarService;
public void setCalendarService(CalendarService calendarService) {
this.calendarService = calendarService;
}

protected SiteService siteService;
public void setSiteService(SiteService siteService) {
this.siteService = siteService;
}

protected DashboardLogic dashboardLogic;
public void setDashboardLogic(DashboardLogic dashboardLogic) {
this.dashboardLogic = dashboardLogic;
Expand Down Expand Up @@ -275,7 +291,42 @@ public void init() {
}

public boolean isAvailable(String entityReference) {
return true;
boolean rv = false;
if(entityReference == null) {
logger.warn(this + "isAvailable() invoked with null entity reference");
} else {
CalendarEvent cEvent = (CalendarEvent) sakaiProxy.getEntity(entityReference);

if(cEvent != null) {
String calendarRef = cEvent.getCalendarReference();
try
{
Calendar calendar = calendarService.getCalendar(calendarRef);
String siteId = calendar.getContext();
try
{
Site s = siteService.getSite(siteId);
if (s.isPublished())
{
rv = true;
}
}
catch (IdUnusedException exception)
{
logger.warn(this + " isAvailable: cannot find site " + siteId + " " + exception.getMessage());
}
}
catch (IdUnusedException exception)
{
logger.warn(this + " isAvailable: cannot find calendar " + calendarRef + " " + exception.getMessage());
}
catch (PermissionException exception)
{
logger.warn(this + " isAvailable: don't have permission to get calendar " + calendarRef + " " + exception.getMessage());
}
}
}
return rv;
}

public boolean isUserPermitted(String sakaiUserId, String entityReference,
Expand Down Expand Up @@ -429,44 +480,63 @@ public void processEvent(Event event) {
String cEventReference = cEvent.getReference();

Context context = dashboardLogic.getContext(eventContextString);

SourceType sourceType = dashboardLogic.getSourceType(IDENTIFIER);

// Third parameter in dashboardLogic.createCalendarItem() below should be a key for a label such as "Due Date: " or "Accept Until: "
// from dash_entity properties bundle for use in the dashboard list
String type = cEvent.getType();
// Based on the event-type, we may be able to select a key for a label?
String key = null;
if(type == null) {
key = "schedule.key2";
} else {
key = scheduleEventTypeMap.get(type);
if(key == null) {
key = "schedule.key2";
if (context != null)
{
boolean sitePublished = false;
try
{
Site s = siteService.getSite(context.getContextId());
if (s.isPublished())
{
sitePublished = true;
}
}
}
// is this a repeating event?
RecurrenceRule recurrenceRule = cEvent.getRecurrenceRule();
if(recurrenceRule == null) {
// not a repeating event so create one calendar event
CalendarItem calendarItem = dashboardLogic.createCalendarItem(cEvent.getDisplayName(), new Date(cEvent.getRange().firstTime().getTime()), key, cEventReference, context, sourceType, type, null, null);
dashboardLogic.createCalendarLinks(calendarItem);
} else {
// this is a repeating event -- create a repeating calendar item
String frequency = recurrenceRule.getFrequency();
int maxCount = recurrenceRule.getCount();
int interval = recurrenceRule.getInterval();

Date lastDate = null;
if(recurrenceRule.getUntil() != null) {
lastDate = new Date(recurrenceRule.getUntil().getTime());
catch (IdUnusedException exception)
{
logger.warn(this + " ScheduleNewEventProcessor.processEvent(): cannot find site " + context.getContextId() + " " + exception.getMessage());
}

RepeatingCalendarItem repeatingCalendarItem = dashboardLogic.createRepeatingCalendarItem(cEvent.getDisplayName(), new Date(cEvent.getRange().firstTime().getTime()),
lastDate, key, cEventReference, context, sourceType, frequency, maxCount);
SourceType sourceType = dashboardLogic.getSourceType(IDENTIFIER);

// Third parameter in dashboardLogic.createCalendarItem() below should be a key for a label such as "Due Date: " or "Accept Until: "
// from dash_entity properties bundle for use in the dashboard list
String type = cEvent.getType();
// Based on the event-type, we may be able to select a key for a label?
String key = null;
if(type == null) {
key = "schedule.key2";
} else {
key = scheduleEventTypeMap.get(type);
if(key == null) {
key = "schedule.key2";
}
}
// is this a repeating event?
RecurrenceRule recurrenceRule = cEvent.getRecurrenceRule();
if(recurrenceRule == null) {
// not a repeating event so create one calendar event
CalendarItem calendarItem = dashboardLogic.createCalendarItem(cEvent.getDisplayName(), new Date(cEvent.getRange().firstTime().getTime()), key, cEventReference, context, sourceType, type, null, null);
if (sitePublished)
{
dashboardLogic.createCalendarLinks(calendarItem);
}
} else {
// this is a repeating event -- create a repeating calendar item
String frequency = recurrenceRule.getFrequency();
int maxCount = recurrenceRule.getCount();
int interval = recurrenceRule.getInterval();

Date lastDate = null;
if(recurrenceRule.getUntil() != null) {
lastDate = new Date(recurrenceRule.getUntil().getTime());
}

logger.debug(repeatingCalendarItem);
}
RepeatingCalendarItem repeatingCalendarItem = dashboardLogic.createRepeatingCalendarItem(cEvent.getDisplayName(), new Date(cEvent.getRange().firstTime().getTime()),
lastDate, key, cEventReference, context, sourceType, frequency, maxCount);

logger.debug(repeatingCalendarItem);
}
}

} else {
// for now, let's log the error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public void addCalendarItemsForRepeatingCalendarItem(RepeatingCalendarItem repea
// TODO: handle error: entityType cannot be null
logger.warn("TODO: handle error: entityType cannot be null");
} else if(dashboardEntityInfo instanceof RepeatingEventGenerator) {

List<CalendarItem> oldDates = dao.getCalendarItems(repeatingEvent);
Map<Date, CalendarItem> oldDatesMap = new HashMap<Date, CalendarItem>();
for(CalendarItem cItem: oldDates) {
Expand Down Expand Up @@ -205,7 +204,12 @@ public void addCalendarItemsForRepeatingCalendarItem(RepeatingCalendarItem repea
buf.append(entry.getValue());
logger.warn(buf);
} else {
createCalendarLinks(calendarItem);

if (dashboardEntityInfo.isAvailable(calendarItem.getEntityReference()))
{
// after checking for availability
createCalendarLinks(calendarItem);
}
}
}
} catch(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ public Site getSite(String siteId) {
return site;
}

/*
* (non-Javadoc)
* @see org.sakaiproject.dash.app.SakaiProxy#isSitePublished(java.lang.String)
*/
public boolean isSitePublished(String siteId) {
Site site = getSite(siteId);
return site != null? site.isPublished(): false;
}

/*
* (non-Javadoc)
* @see org.sakaiproject.dash.app.SakaiProxy#getSkinRepoProperty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public Site getSite(String siteId) {
}
return site;
}

public boolean isSitePublished(String siteId) {
Site site = getSite(siteId);
return site != null? site.isPublished(): false;
}

public String getSkinRepoProperty() {
// TODO Auto-generated method stub
Expand Down
2 changes: 2 additions & 0 deletions dashboard/pack/src/webapp/WEB-INF/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@
<property name="dashboardLogic" ref="org.sakaiproject.dash.logic.DashboardLogic"></property>
<property name="sakaiProxy" ref="org.sakaiproject.dash.app.SakaiProxy"></property>
<property name="timeService" ref="org.sakaiproject.time.api.TimeService"></property>
<property name="calendarService" ref="org.sakaiproject.calendar.api.CalendarService"></property>
<property name="siteService" ref="org.sakaiproject.site.api.SiteService"></property>
</bean>

<bean id="org.sakaiproject.dash.entity.EntitySupportUtil"
Expand Down

0 comments on commit 5ab69fc

Please sign in to comment.