Skip to content

Commit

Permalink
SAK-25845 - Postem should try to lookup eid if id fails
Browse files Browse the repository at this point in the history
git-svn-id: https://source.sakaiproject.org/svn/postem/trunk@306989 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
jonespm committed Mar 11, 2014
1 parent 9d85757 commit 419991d
Showing 1 changed file with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.zip.DataFormatException;

import javax.faces.FactoryFinder;
Expand Down Expand Up @@ -72,16 +69,14 @@
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.util.ResourceLoader;

import org.sakaiproject.user.api.User;

import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.user.api.UserNotDefinedException;

public class PostemTool {

protected Log logger = LogFactory.getLog(PostemTool.class);


protected GradebookManager gradebookManager;

protected ArrayList gradebooks;

protected Gradebook currentGradebook;
Expand Down Expand Up @@ -579,11 +574,15 @@ else if(currentGradebook.getTitle().trim().length() > TITLE_MAX_LENGTH) {
String csvURL = new String(cr.getContent());
//Load the URL
csv = URLConnectionReader.getText(csvURL);
logger.debug(csv);
if (LOG.isDebugEnabled()) {
LOG.debug(csv);
}
}
else {
csv = new String(cr.getContent());
logger.debug(csv);
if (LOG.isDebugEnabled()) {
LOG.debug(csv);
}
}
CSV grades = new CSV(csv, withHeader, csv_delim);

Expand Down Expand Up @@ -1061,10 +1060,15 @@ private boolean usernamesValid(CSV studentGrades) {
row++;
String usr = (String) studentIter.next();

if (LOG.isDebugEnabled()) {
LOG.debug("usernamesValid : username=" + usr);
LOG.debug("usernamesValid : siteMembers" + siteMembers);
}
if (usr == null || usr.equals("")) {

usersAreValid = false;
blankRows.add(new Integer(row));
} else if(siteMembers == null || (siteMembers != null && !siteMembers.contains(getUserId(usr)))) {
} else if(siteMembers == null || (siteMembers != null && !siteMembers.contains(getUserDefined(usr)))) {
usersAreValid = false;
invalidUsernames.add(usr);
}
Expand Down Expand Up @@ -1131,14 +1135,37 @@ private String getCurrentSiteId()
return placement.getContext();
}

private String getUserId(String usr)
//Returns getUser and getUserByEid on the input string
//@return Either the id of the user, or the same string if not defined
private String getUserDefined(String usr)
{
//Set the original user id
String userId = usr;
User userinfo;
try {
return UserDirectoryService.getUserId(usr);
userinfo = UserDirectoryService.getUser(usr);
userId = userinfo.getId();
if (LOG.isDebugEnabled()) {
LOG.debug("getUserDefined: username for " + usr + " is " + userId);
}
return userId;
}
catch (UserNotDefinedException e) {
return usr;
try
{
// try with the user eid
userinfo = UserDirectoryService.getUserByEid(usr);
userId = userinfo.getId();
}
catch (UserNotDefinedException ee)
{
//This is mostly expected behavior, don't need to notify about it, the UI can handle it
if (LOG.isDebugEnabled()) {
LOG.debug("getUserDefined: User Not Defined" + userId);
}
}
}
return userId;
}

private List getSiteMembers() {
Expand Down

0 comments on commit 419991d

Please sign in to comment.