Skip to content

Commit

Permalink
STAT-243: switched to User.getSortName() for user listing instead of …
Browse files Browse the repository at this point in the history
…User.getDisplayName() (consistency across Sakai tools). To stick with previous behavior, a new setting on sakai.properties must be used: sortUsersByDisplayName@org.sakaiproject.sitestats.api.StatsManager=true

git-svn-id: https://source.sakaiproject.org/svn/sitestats/trunk@78671 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
nfgrilo committed Jun 21, 2010
1 parent 313bf76 commit 92e5df2
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.sakaiproject.javax.PagingPosition;
import org.sakaiproject.sitestats.api.event.EventRegistryService;
import org.sakaiproject.user.api.User;


public interface StatsManager {
Expand Down Expand Up @@ -142,6 +143,9 @@ public interface StatsManager {
/** Are exporting reports enabled? */
public boolean isEnableReportExport();

/** Is user name sorted using User.getSortName()? Otherwise, User.getDisplayName() should be used. */
public boolean isSortUsersByDisplayName();

// ################################################################
// Preferences
// ################################################################
Expand Down Expand Up @@ -486,6 +490,20 @@ public int getResourceStatsRowCount(
*/
public Set<String> getSiteUsers(String siteId);

/**
* Get user display name (will return User.getSortName() unless "sortUsersByDisplayName@org.sakaiproject.sitestats.api.StatsManager = true" specified in sakai.properties).
* @param userId User ID
* @return The user display name
*/
public String getUserNameForDisplay(String userId);

/**
* Get user display name (will return User.getSortName() unless "sortUsersByDisplayName@org.sakaiproject.sitestats.api.StatsManager = true" specified in sakai.properties).
* @param userId An User object.
* @return The user display name
*/
public String getUserNameForDisplay(User user);

/**
* Get users with at least one visit in site.
* @param siteId Site identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class StatsManagerImpl extends HibernateDaoSupport implements StatsManage
private boolean lastJobRunDateVisible = true;
private boolean isEventContextSupported = false;
private boolean enableReportExport = true;
private boolean sortUsersByDisplayName = false;

/** Controller fields */
private boolean showAnonymousAccessEvents = true;
Expand Down Expand Up @@ -250,6 +251,13 @@ public void setLastJobRunDateVisible(boolean value) {
public boolean isLastJobRunDateVisible(){
return lastJobRunDateVisible;
}

public void setSortUsersByDisplayName(boolean sortUsersByDisplayName) {
this.sortUsersByDisplayName = sortUsersByDisplayName;
}
public boolean isSortUsersByDisplayName() {
return sortUsersByDisplayName;
}

public void setEventRegistryService(EventRegistryService eventRegistryService) {
this.M_ers = eventRegistryService;
Expand Down Expand Up @@ -512,6 +520,25 @@ public Set<String> getSiteUsers(String siteId) {
return null;
}

public String getUserNameForDisplay(String userId) {
String name = null;
try{
User user = M_uds.getUser(userId);
name = getUserNameForDisplay(user);
}catch(UserNotDefinedException e){
name = msgs.getString("user_unknown");
}
return name;
}

public String getUserNameForDisplay(User user) {
if(isSortUsersByDisplayName()) {
return user.getDisplayName();
}else{
return user.getSortName();
}
}

public Set<String> getUsersWithVisits(final String siteId) {
if(siteId == null){
throw new IllegalArgumentException("Null siteId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1248,11 +1248,7 @@ private Comparable getStatValue(Stat s, String fieldCode, Class periodGrouping)
}else if(("?").equals(userId)) {
name = msgs.getString("user_anonymous_access");
}else{
try{
name = M_uds.getUser(userId).getDisplayName();
}catch(UserNotDefinedException e1){
name = msgs.getString("user_unknown");
}
name = M_sm.getUserNameForDisplay(userId);
}
}else{
name = msgs.getString("user_unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public byte[] getReportAsExcel(Report report, String sheetName) {
try{
User user = M_uds.getUser(userId);
userEid = user.getDisplayId();
userName = user.getDisplayName();
userName = M_sm.getUserNameForDisplay(user);
}catch(UserNotDefinedException e1){
userEid = userId;
userName = msgs.getString("user_unknown");
Expand Down Expand Up @@ -932,7 +932,7 @@ public String getReportAsCsv(Report report) {
try{
User user = M_uds.getUser(userId);
userEid = user.getDisplayId();
userName = user.getDisplayName();
userName = M_sm.getUserNameForDisplay(user);
}catch(UserNotDefinedException e1){
userEid = userId;
userName = msgs.getString("user_unknown");
Expand Down Expand Up @@ -1196,11 +1196,7 @@ private String getUserDisplayName(String userId) {
}else if(("?").equals(userId)) {
userName = msgs.getString("user_anonymous_access");
}else{
try{
userName = M_uds.getUser(userId).getDisplayName();
}catch(UserNotDefinedException e1){
userName = msgs.getString("user_unknown");
}
userName = M_sm.getUserNameForDisplay(userId);
}
}else{
userName = msgs.getString("user_unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void generateReportTable(List<Stat> data, ReportParams params) throws SA
try{
User user = M_uds.getUser(id);
userId = user.getDisplayId();
userName = user.getDisplayName();
userName = M_sm.getUserNameForDisplay(user);
}catch(UserNotDefinedException e1){
userId = id;
userName = msgs.getString("user_unknown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.sakaiproject.sitestats.api.SummaryActivityTotals;
import org.sakaiproject.sitestats.api.SummaryVisitsChartData;
import org.sakaiproject.sitestats.api.SummaryVisitsTotals;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserNotDefinedException;

public class FakeStatsManager implements StatsManager {

Expand Down Expand Up @@ -353,4 +355,20 @@ public int getPresenceStatsRowCount(String siteId, Date iDate, Date fDate, List<
return 0;
}

public String getUserNameForDisplay(String userId) {
return userId;
}

public String getUserNameForDisplay(User user) {
if(isSortUsersByDisplayName()) {
return user.getDisplayName();
}else{
return user.getSortName();
}
}

public boolean isSortUsersByDisplayName() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,7 @@ public void populateItem(Item item, String componentId, IModel model) {
}else if(("?").equals(userId)) {
name = (String) new ResourceModel("user_anonymous_access").getObject();
}else{
try{
name = Locator.getFacade().getUserDirectoryService().getUser(userId).getDisplayName();
}catch(UserNotDefinedException e1){
name = (String) new ResourceModel("user_unknown").getObject();
}
name= Locator.getFacade().getStatsManager().getUserNameForDisplay(userId);
}
}else{
name = (String) new ResourceModel("user_unknown").getObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ public String getDisplayValue(Object object) {
return Web.escapeHtml(userId);
}
StringBuilder buff = new StringBuilder();
buff.append(u.getDisplayName());
buff.append(Locator.getFacade().getStatsManager().getUserNameForDisplay(u));
buff.append(" (");
buff.append(u.getDisplayId());
buff.append(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,8 @@ public int compare(Stat r1, Stat r2) {
return res;
else return -res;
}else if(fieldName.equals(COL_USERNAME)){
String s1;
try{
s1 = M_uds.getUser(r1.getUserId()).getDisplayName().toLowerCase();
}catch(UserNotDefinedException e){
s1 = "-";
}
String s2;
try{
s2 = M_uds.getUser(r2.getUserId()).getDisplayName().toLowerCase();
}catch(UserNotDefinedException e){
s2 = "-";
}
String s1 = Locator.getFacade().getStatsManager().getUserNameForDisplay(r1.getUserId()).toLowerCase();
String s2 = Locator.getFacade().getStatsManager().getUserNameForDisplay(r2.getUserId()).toLowerCase();
int res = collator.compare(s1, s2);
if(sortAscending)
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,7 @@ public String getTooltip() {
}else if(("?").equals(mostActiveUser)) {
name = (String) new ResourceModel("user_anonymous_access").getObject();
}else{
try{
name = Locator.getFacade().getUserDirectoryService().getUser(mostActiveUser).getDisplayName();
}catch(UserNotDefinedException e1){
name = (String) new ResourceModel("user_unknown").getObject();
}
name = Locator.getFacade().getStatsManager().getUserNameForDisplay(mostActiveUser);
}
return name;
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,7 @@ public String getTooltip() {
}else if(("?").equals(user)) {
name = (String) new ResourceModel("user_anonymous_access").getObject();
}else{
try{
name = Locator.getFacade().getUserDirectoryService().getUser(user).getDisplayName();
}catch(UserNotDefinedException e1){
name = (String) new ResourceModel("user_unknown").getObject();
}
name = Locator.getFacade().getStatsManager().getUserNameForDisplay(user);
}
return name;
}else{
Expand Down

0 comments on commit 92e5df2

Please sign in to comment.