Skip to content

Commit

Permalink
SAK-40694 - Add POST to Scores feature to AGS (sakaiproject#6106)
Browse files Browse the repository at this point in the history
  • Loading branch information
csev authored Oct 8, 2018
1 parent ae033fc commit f99b4f6
Showing 1 changed file with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
// /imsblis/lti13/lineitem/{signed-placement}
if (parts.length == 6 && "lineitem".equals(parts[3]) && "scores".equals(parts[5])) {
String signed_placement = parts[4];
handleLineItemScore(signed_placement, request, response);
String lineItem = null;
handleLineItemScore(signed_placement, lineItem, request, response);
return;
}

Expand All @@ -268,7 +269,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
if (parts.length == 7 && "lineitems".equals(parts[3]) && "scores".equals(parts[6])) {
String signed_placement = parts[4];
String lineItem = parts[5];
handleLineItemsScore(signed_placement, lineItem, request, response);
handleLineItemScore(signed_placement, lineItem, request, response);
return;
}

Expand Down Expand Up @@ -496,8 +497,19 @@ protected void handleTokenPost(String tool_id, HttpServletRequest request, HttpS
}
}

protected void handleLineItemScore(String signed_placement, HttpServletRequest request, HttpServletResponse response) {
protected void handleLineItemScore(String signed_placement, String lineItem, HttpServletRequest request, HttpServletResponse response) {

// Make sure the lineItem id is a long
Long assignment_id = null;
if ( lineItem != null ) {
try {
assignment_id = Long.parseLong(lineItem);
} catch (NumberFormatException e) {
LTI13Util.return400(response, "Bad value for assignment_id "+lineItem);
log.error("Bad value for assignment_id "+lineItem);
return;
}
}
// Load the access token, checking the the secret
SakaiAccessToken sat = getSakaiAccessToken(tokenKeyPair.getPublic(), request, response);
log.debug("sat={}", sat);
Expand Down Expand Up @@ -545,10 +557,10 @@ protected void handleLineItemScore(String signed_placement, HttpServletRequest r
return;
}

String assignment = (String) content.get(LTIService.LTI_TITLE);
if (assignment == null || assignment.length() < 1) {
log.error("Could not determine assignment title {}", content.get(LTIService.LTI_ID));
LTI13Util.return400(response, "Could not determine assignment title");
String assignment_name = (String) content.get(LTIService.LTI_TITLE);
if (assignment_name == null || assignment_name.length() < 1) {
log.error("Could not determine assignment_name title {}", content.get(LTIService.LTI_ID));
LTI13Util.return400(response, "Could not determine assignment_name");
return;
}

Expand All @@ -557,8 +569,9 @@ protected void handleLineItemScore(String signed_placement, HttpServletRequest r
return;
}

String context_id = site.getId();
if (!checkUserInSite(site, userId)) {
log.warn("User {} not found in siteId={}", userId, site.getId());
log.warn("User {} not found in siteId={}", userId, context_id);
LTI13Util.return400(response, "User does not belong to site");
return;
}
Expand All @@ -568,8 +581,21 @@ protected void handleLineItemScore(String signed_placement, HttpServletRequest r
return;
}

Object retval = SakaiBLTIUtil.setGradeLTI13(site, sat.tool_id, content, userId, assignment, scoreGiven, scoreMaximum, comment);
log.debug("Lineitem retval={}",retval);
Object retval;
if ( assignment_id == null ) {
retval = SakaiBLTIUtil.setGradeLTI13(site, sat.tool_id, content, userId, assignment_name, scoreGiven, scoreMaximum, comment);
log.debug("Lineitem retval={}",retval);
} else {
// TODO: Could make a new method collapsing these tool calls into a single scan
Assignment assnObj = LineItemUtil.getAssignmentByKeyDAO(context_id, sat.tool_id, assignment_id);
if ( assnObj == null || assnObj.getName() == null ) {
LTI13Util.return400(response, "Unable to load assignment "+assignment_id);
return;
}
assignment_name = assnObj.getName();
retval = SakaiBLTIUtil.setGradeLTI13(site, sat.tool_id, content, userId, assignment_name, scoreGiven, scoreMaximum, comment);
log.debug("Lineitem retval={}",retval);
}
}

/*
Expand Down Expand Up @@ -652,9 +678,9 @@ protected void handleNamesAndRoles(String signed_placement, HttpServletRequest r
int releaseEmail = getInt(tool.get(LTIService.LTI_SENDEMAILADDR));
// int allowOutcomes = getInt(tool.get(LTIService.LTI_ALLOWOUTCOMES));

String assignment = (String) content.get(LTIService.LTI_TITLE);
if (assignment == null || assignment.length() < 1) {
assignment = null;
String assignment_name = (String) content.get(LTIService.LTI_TITLE);
if (assignment_name == null || assignment_name.length() < 1) {
assignment_name = null;
}

String maintainRole = site.getMaintainRole();
Expand Down Expand Up @@ -719,7 +745,7 @@ protected void handleNamesAndRoles(String signed_placement, HttpServletRequest r
jo.put("roles", roles);

JSONObject sakai_ext = new JSONObject();
if ( sat.hasScope(SakaiAccessToken.SCOPE_BASICOUTCOME) && assignment != null ) {
if ( sat.hasScope(SakaiAccessToken.SCOPE_BASICOUTCOME) && assignment_name != null ) {
String placement_secret = (String) content.get(LTIService.LTI_PLACEMENTSECRET);
String placement_id = getPlacementId(signed_placement);
String result_sourcedid = SakaiBLTIUtil.getSourceDID(user, placement_id, placement_secret);
Expand Down Expand Up @@ -1238,22 +1264,10 @@ private void handleLineItemsGet(String signed_placement, boolean all, LineItem f
first = false;
out.print(JacksonUtil.prettyPrint(item));
}
first = false;
out.println("");
out.println("]");
}

/**
* Update a score
*
* @param signed_placement
* @param lineItem
* @param request
* @param response
*/
private void handleLineItemsScore(String signed_placement, String lineItem, HttpServletRequest request, HttpServletResponse response) {
LTI13Util.return400(response, "handleLineItemsPost not Implemented");
}
/**
* Provide the detail or results for a tool created lineitem
* @param signed_placement
Expand Down

0 comments on commit f99b4f6

Please sign in to comment.