Skip to content

Commit

Permalink
SAK-46621 - Make a empty array of content_items non-fatal (sakaiproje…
Browse files Browse the repository at this point in the history
  • Loading branch information
csev authored Dec 23, 2021
1 parent cb4bbe6 commit 8774834
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
5 changes: 3 additions & 2 deletions basiclti/basiclti-tool/src/bundle/ltitool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gen.transfer=Transfer
gen.privacy=Privacy
gen.insert=Install New Tool
gen.alert=Alert:
gen.note=Note:
gen.success=Success
gen.failure=Failure
gen.tools=View Tools
Expand Down Expand Up @@ -105,14 +106,14 @@ error.contentitem.bad=Error in returned ContentItemResponse
error.contentitem.missing=Missing tool key in ContentItemResponse
error.contentitem.incorrect=Incorrect tool key in ContentItemResponse
error.contentitem.no.validate=OAuth validation error
error.contentitem.no.ltilink=Missing LtiLinkItem in ContentItemResponse @graph
error.contentitem.no.ltilink=Missing LTI Resource Link in ContentItemResponse @graph
error.contentitem.missing.url=LTILink Item missing launch url
error.contentitem.content.insert=Unable to insert ContentItem
error.contentitem.content.launch=Could not retrieve Launch URL from ContentItem
error.contentitem.no.fileitem==Missing FileItem in ContentItemResponse @graph
error.deeplink.bad=Error in Deep Link Response
error.deeplink.no.ltilink=Missing ltiResourceLink in Deep Link Response
error.deeplink.no.ltilink=Missing LTI resource link in Deep Link Response
error.deeplink.no.fileitem=Missing file item in Deep Link Response
error.deeplink.no.import.url=Could not find url to import in file item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ public String buildErrorPanelContext(VelocityPortlet portlet, Context context,
return "lti_error";
}

/**
* Setup the velocity context and choose the template for the response.
*/
public String buildFinishedPanelContext(VelocityPortlet portlet, Context context,
RunData rundata, SessionState state) {
context.put("tlang", rb);
context.put("includeLatestJQuery", PortalUtils.includeLatestJQuery("LTIAdminTool"));
state.removeAttribute(STATE_ID);
state.removeAttribute(STATE_TOOL_ID);
state.removeAttribute(STATE_POST);
state.removeAttribute(STATE_SUCCESS);
state.removeAttribute(STATE_REDIRECT_URL);
return "lti_finished";
}

public String buildMainPanelContext(VelocityPortlet portlet, Context context,
RunData data, SessionState state) {
// default to site view
Expand Down Expand Up @@ -1599,8 +1614,10 @@ public void doSingleContentItemResponse(RunData data, Context context) {
// to make sure it is properly re-established
String sakaiSession = data.getParameters().getString(RequestFilter.ATTR_SESSION);
String errorPanel = "Error";
String finishedPanel = "Finished";
if ( sakaiSession != null ) {
errorPanel = errorPanel + "&" + RequestFilter.ATTR_SESSION + "=" + sakaiSession;
finishedPanel = finishedPanel + "&" + RequestFilter.ATTR_SESSION + "=" + sakaiSession;
}

// Check for a returned error message from LTI
Expand Down Expand Up @@ -1681,7 +1698,7 @@ public void doSingleContentItemResponse(RunData data, Context context) {
JSONObject item = dlr.getItemOfType(DeepLinkResponse.TYPE_FILEITEM);
if (item == null) {
addAlert(state, rb.getString("error.deeplink.no.fileitem"));
switchPanel(state, errorPanel);
switchPanel(state, finishedPanel);
return;
}
handleImportCartridge(data, context, state, errorPanel, returnUrl, item, sakaiSession);
Expand All @@ -1691,7 +1708,7 @@ public void doSingleContentItemResponse(RunData data, Context context) {
JSONObject item = dlr.getItemOfType(DeepLinkResponse.TYPE_LTILINKITEM);
if (item == null) {
addAlert(state, rb.getString("error.deeplink.no.ltilink"));
switchPanel(state, errorPanel);
switchPanel(state, finishedPanel);
return;
}

Expand Down Expand Up @@ -1849,11 +1866,21 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
String peid = ((JetspeedRunData) data).getJs_peid();
SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);

// If we find our way to an error panel, we need to pass along the session
// to make sure it is properly re-established
String sakaiSession = data.getParameters().getString(RequestFilter.ATTR_SESSION);
String errorPanel = "Error";
String finishedPanel = "Finished";
if ( sakaiSession != null ) {
errorPanel = errorPanel + "&" + RequestFilter.ATTR_SESSION + "=" + sakaiSession;
finishedPanel = finishedPanel + "&" + RequestFilter.ATTR_SESSION + "=" + sakaiSession;
}

// Check for a returned error message from LTI
String lti_errormsg = data.getParameters().getString("lti_errormsg");
if (lti_errormsg != null && lti_errormsg.trim().length() > 0) {
addAlert(state, lti_errormsg);
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

Expand All @@ -1866,21 +1893,21 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
String flow = data.getParameters().getString(FLOW_PARAMETER);
if (flow == null) {
addAlert(state, rb.getString("error.missing.flow"));
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

// Retrieve the tool associated with the content item
Long toolKey = foorm.getLongNull(data.getParameters().getString(LTIService.LTI_TOOL_ID));
if (toolKey == 0 || toolKey < 0) {
addAlert(state, rb.getString("error.contentitem.missing"));
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}
Map<String, Object> tool = ltiService.getTool(toolKey, getSiteId(state));
if (tool == null) {
addAlert(state, rb.getString("error.contentitem.missing"));
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

Expand All @@ -1897,7 +1924,7 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
isDeepLink = DeepLinkResponse.isRequest(id_token);
} catch (Exception e) {
addAlert(state, rb.getString("error.deeplink.bad") + " (" + e.getMessage() + ")");
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

Expand All @@ -1907,7 +1934,7 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
String keyset = (String) tool.get(LTIService.LTI13_TOOL_KEYSET);
if (keyset == null) {
addAlert(state, rb.getString("error.tool.missing.keyset"));
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

Expand All @@ -1916,14 +1943,14 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
dlr = SakaiBLTIUtil.getDeepLinkFromToken(tool, id_token); // Also checks security
} catch (Exception e) {
addAlert(state, rb.getString("error.deeplink.bad") + " (" + e.getMessage() + ")");
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

JSONArray links = dlr.getDeepLinks();
if (links == null) {
addAlert(state, rb.getString("error.deeplink.no.ltilinks"));
switchPanel(state, "Error");
addAlert(state, rb.getString("error.deeplink.no.ltilink"));
switchPanel(state, finishedPanel);
return;
}

Expand Down Expand Up @@ -2015,7 +2042,7 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
contentItem = SakaiBLTIUtil.getContentItemFromRequest(tool);
} catch (Exception e) {
addAlert(state, rb.getString("error.contentitem.bad") + " (" + e.getMessage() + ")");
switchPanel(state, "Error");
switchPanel(state, errorPanel);
return;
}

Expand Down Expand Up @@ -2117,7 +2144,6 @@ public void doMultipleContentItemResponse(RunData data, Context context) {
state.setAttribute(STATE_CONTENT_ITEM_FAILURES, failures);
state.setAttribute(STATE_CONTENT_ITEM_SUCCESSES, new Integer(goodcount));

String sakaiSession = data.getParameters().getString(RequestFilter.ATTR_SESSION);
if (sakaiSession == null) {
switchPanel(state, forward);
} else {
Expand Down
4 changes: 4 additions & 0 deletions basiclti/basiclti-tool/src/webapp/vm/lti_finished.vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="portletBody">
#if ($alertMessage)<div class="sak-banner-success">$tlang.getString("gen.note") $formattedText.escapeHtml($alertMessage)</div>#end
<p>$tlang.getString("operation.complete")</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,6 @@ public DeepLinkResponse(String id_token)
throw new java.lang.RuntimeException("Incorrect MESSAGE_TYPE");
}

deep_links = BasicLTIUtil.getArray(body, DEEP_LINKS);
if ( deep_links == null || deep_links.size() < 1 ) {
throw new java.lang.RuntimeException("A deep link response must include at least one content_item");
}

String returnedData = (String) body.get(DATA);
if ( returnedData == null || returnedData.length() < 1 ) {
throw new java.lang.RuntimeException("Missing data element from ContentItem return");
Expand Down Expand Up @@ -313,6 +308,7 @@ public JSONArray getDeepLinks()
*/
public JSONObject getItemOfType(String itemType)
{
if ( deep_links == null ) return null;
for ( Object i : deep_links ) {
if ( ! (i instanceof JSONObject) ) continue;
JSONObject item = (JSONObject) i;
Expand Down

0 comments on commit 8774834

Please sign in to comment.