Skip to content

Commit

Permalink
SAK-30775 Clear caches as site membership updated
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish committed Apr 21, 2016
1 parent 1dd45e2 commit 2f577fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
51 changes: 38 additions & 13 deletions roster2/src/java/org/sakaiproject/roster/impl/SakaiProxyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@

package org.sakaiproject.roster.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
Expand All @@ -49,6 +38,8 @@
import org.sakaiproject.coursemanagement.api.Section;
import org.sakaiproject.coursemanagement.api.exception.IdNotFoundException;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.memory.api.Cache;
import org.sakaiproject.memory.api.MemoryService;
import org.sakaiproject.memory.api.SimpleConfiguration;
Expand Down Expand Up @@ -82,11 +73,12 @@
* @author Adrian Fish ([email protected])
*/
@Setter
public class SakaiProxyImpl implements SakaiProxy {
public class SakaiProxyImpl implements SakaiProxy, Observer {

private static final Log log = LogFactory.getLog(SakaiProxyImpl.class);

private CourseManagementService courseManagementService;
private EventTrackingService eventTrackingService;
private FunctionManager functionManager;
private GroupProvider groupProvider;
private PrivacyManager privacyManager;
Expand Down Expand Up @@ -141,6 +133,8 @@ public void init() {
functionManager.registerFunction(RosterFunctions.ROSTER_FUNCTION_VIEWSITEVISITS, true);
}

eventTrackingService.addObserver(this);

memberComparator = new RosterMemberComparator(getFirstNameLastName());
}

Expand Down Expand Up @@ -1148,4 +1142,35 @@ public Map<String, SitePresenceTotal> getPresenceTotalsForSite(String siteId) {
public boolean getShowVisits() {
return serverConfigurationService.getBoolean("roster.showVisits", false);
}

public void update(Observable o, Object arg) {

if (arg instanceof Event) {
Event event = (Event) arg;
if (SiteService.SECURE_UPDATE_SITE_MEMBERSHIP.equals(event.getEvent())) {
if (log.isDebugEnabled()) log.debug("Site membership updated. Clearing caches ...");
String siteId = event.getContext();

Cache enrollmentsCache = getCache(ENROLLMENTS_CACHE);
enrollmentsCache.remove(siteId);

Cache searchIndexCache = memoryService.getCache(SEARCH_INDEX_CACHE);
searchIndexCache.remove(siteId);

Cache membershipsCache = getCache(MEMBERSHIPS_CACHE);
membershipsCache.remove(siteId);
Site site = getSite(siteId);
if (site != null) {
Set<Role> roles = site.getRoles();
for (Group group : site.getGroups()) {
String gId = group.getId();
membershipsCache.remove(siteId + "#" + gId);
for (Role role : roles) {
membershipsCache.remove(siteId + "#" + gId + "#" + role.getId());
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions roster2/src/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<bean name="org.sakaiproject.roster.api.SakaiProxy"
class="org.sakaiproject.roster.impl.SakaiProxyImpl" init-method="init">
<property name="courseManagementService"><ref bean="org.sakaiproject.coursemanagement.api.CourseManagementService"/></property>
<property name="eventTrackingService"><ref bean="org.sakaiproject.event.api.EventTrackingService"/></property>
<property name="functionManager"><ref bean="org.sakaiproject.authz.api.FunctionManager"/></property>
<property name="groupProvider"><ref bean="org.sakaiproject.authz.api.GroupProvider"/></property>
<property name="privacyManager"><ref bean="org.sakaiproject.api.privacy.PrivacyManager"/></property>
Expand Down

0 comments on commit 2f577fa

Please sign in to comment.