Skip to content

Commit

Permalink
SAK-43645 Turnitin API error if instructor info is null (sakaiproject…
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored May 14, 2020
1 parent 2ebe544 commit 3ffee07
Showing 1 changed file with 11 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2256,11 +2256,16 @@ private String getTEM(String cid) {
*/
@SuppressWarnings("unchecked")
public Map getInstructorInfo(String siteId) {
return getInstructorInfo(siteId, false);
}

@SuppressWarnings("unchecked")
public Map getInstructorInfo(String siteId, boolean ignoreUseSource) {

log.debug("Getting instructor info for site " + siteId);

Map togo = new HashMap();
if (!turnitinConn.isUseSourceParameter()) {
if (!turnitinConn.isUseSourceParameter() && !ignoreUseSource) {
togo.put("uem", turnitinConn.getDefaultInstructorEmail());
togo.put("ufn", turnitinConn.getDefaultInstructorFName());
togo.put("uln", turnitinConn.getDefaultInstructorLName());
Expand Down Expand Up @@ -2291,53 +2296,11 @@ public Map getInstructorInfo(String siteId) {
if (inst == null) {
log.error("Instructor is null in getAbsoluteInstructorInfo");
} else {
togo.put("uem", getEmail(inst));
togo.put("ufn", inst.getFirstName());
togo.put("uln", inst.getLastName());
togo.put("uid", inst.getId());
togo.put("username", inst.getDisplayName());
}
}

return togo;
}

@SuppressWarnings("unchecked")
public Map getInstructorInfo(String siteId, boolean ignoreUseSource) {
Map togo = new HashMap();
if (!turnitinConn.isUseSourceParameter() && ignoreUseSource == false) {
togo.put("uem", turnitinConn.getDefaultInstructorEmail());
togo.put("ufn", turnitinConn.getDefaultInstructorFName());
togo.put("uln", turnitinConn.getDefaultInstructorLName());
togo.put("uid", turnitinConn.getDefaultInstructorId());
} else {
String INST_ROLE = "section.role.instructor";
User inst = null;
try {
Site site = siteService.getSite(siteId);
User user = userDirectoryService.getCurrentUser();
if (site.isAllowed(user.getId(), INST_ROLE)) {
inst = user;
} else {
Set<String> instIds = getActiveInstructorIds(INST_ROLE, site);
if (instIds.size() > 0) {
inst = userDirectoryService.getUser((String) instIds.toArray()[0]);
}
}
} catch (IdUnusedException e) {
log.error("Unable to fetch site in getAbsoluteInstructorInfo: " + siteId, e);
} catch (UserNotDefinedException e) {
log.error("Unable to fetch user in getAbsoluteInstructorInfo", e);
}

if (inst == null) {
log.error("Instructor is null in getAbsoluteInstructorInfo");
} else {
togo.put("uem", getEmail(inst));
togo.put("ufn", inst.getFirstName());
togo.put("uln", inst.getLastName());
togo.put("uid", inst.getId());
togo.put("username", inst.getDisplayName());
togo.put("uem", StringUtils.trimToEmpty(getEmail(inst)));
togo.put("ufn", StringUtils.trimToEmpty(inst.getFirstName()));
togo.put("uln", StringUtils.trimToEmpty(inst.getLastName()));
togo.put("uid", StringUtils.trimToEmpty(inst.getId()));
togo.put("username", StringUtils.trimToEmpty(inst.getDisplayName()));
}
}

Expand Down

0 comments on commit 3ffee07

Please sign in to comment.