Skip to content

Commit

Permalink
Merge pull request sakaiproject#1161 from csev/SAK-29328
Browse files Browse the repository at this point in the history
SAK-29328 - Deal with LTI 2.0 and ContentItem in Sakai.
  • Loading branch information
csev committed Oct 7, 2015
2 parents 9779b52 + b8e1d0b commit eecc775
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,10 @@ public interface LTIService {
"allowroster:checkbox:label=bl_allowroster",
"allowsettings:checkbox:label=bl_allowsettings",
// Hide these from end users until they are working in the various Sakai tools
"pl_header:header:fields=pl_launch,pl_linkselection,pl_fileitem,pl_contenteditor,pl_assessmentselection",
"pl_header:header:fields=pl_launch,pl_linkselection,pl_importitem,pl_fileitem,pl_contenteditor,pl_assessmentselection",
"pl_launch:checkbox:label=bl_pl_launch",
"pl_linkselection:checkbox:label=bl_pl_linkselection",
"pl_importitem:checkbox:label=bl_pl_importitem:role=admin",
"pl_fileitem:checkbox:label=bl_pl_fileitem:role=admin",
"pl_contenteditor:checkbox:label=bl_pl_contenteditor:role=admin",
"pl_assessmentselection:checkbox:label=bl_pl_assessmentselection:role=admin",
Expand Down Expand Up @@ -880,6 +881,7 @@ public interface LTIService {
static final String LTI_PL_LAUNCH = "pl_launch";
static final String LTI_PL_LINKSELECTION = "pl_linkselection";
static final String LTI_PL_FILEITEM = "pl_fileitem";
static final String LTI_PL_IMPORTITEM = "pl_importitem";
static final String LTI_PL_CONTENTEDITOR = "pl_contenteditor";
static final String LTI_PL_ASSESSMENTSELECTION = "pl_assessmentselection";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.imsglobal.json.IMSJSONRequest;
import org.imsglobal.lti2.LTI2Config;
import org.imsglobal.lti2.LTI2Constants;
import org.imsglobal.lti2.LTI2Messages;
import org.imsglobal.lti2.LTI2Util;
import org.imsglobal.lti2.ToolProxy;
import org.imsglobal.lti2.ContentItem;
Expand Down Expand Up @@ -224,8 +225,21 @@ protected ToolConsumer getToolConsumerProfile(Map<String, Object> deploy, String
ToolConsumer consumer = new ToolConsumer(profile_id+"", resourceUrl+"#", cnf);
consumer.allowSplitSecret();
consumer.allowHmac256();
consumer.addCapability(ContentItem.getCapability(ContentItem.TYPE_LTILINKITEM));
consumer.addCapability(ContentItem.getCapability(ContentItem.TYPE_FILEITEM));
consumer.addCapability(SakaiBLTIUtil.CANVAS_PLACEMENTS_COURSENAVIGATION);
consumer.addCapability(SakaiBLTIUtil.CANVAS_PLACEMENTS_ASSIGNMENTSELECTION);
// Not yet supported in Sakai
// consumer.addCapability(SakaiBLTIUtil.CANVAS_PLACEMENTS_ACCOUNTNAVIGATION);

if ( foorm.getLong(deploy.get(LTIService.LTI_ALLOWCONTENTITEM)) > 0 ) {
consumer.addCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST);
// Not yet supported in Sakai
// consumer.addCapability(SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTANY);
consumer.addCapability(SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTFILE);
consumer.addCapability(SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTLINK);
consumer.addCapability(SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTIMPORT);
consumer.addCapability(SakaiBLTIUtil.CANVAS_PLACEMENTS_LINKSELECTION);
consumer.addCapability(SakaiBLTIUtil.CANVAS_PLACEMENTS_CONTENTIMPORT);
}

if (foorm.getLong(deploy.get(LTIService.LTI_SENDEMAILADDR)) > 0 ) {
consumer.allowEmail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ public class SakaiBLTIUtil {
public static final String LTI1_PATH = "/imsblis/service/";
public static final String LTI2_PATH = "/imsblis/lti2/";

public static final String SAKAI_CONTENTITEM_SELECTANY = "Sakai.contentitem.selectAny";
public static final String SAKAI_CONTENTITEM_SELECTFILE = "Sakai.contentitem.selectFile";
public static final String SAKAI_CONTENTITEM_SELECTIMPORT = "Sakai.contentitem.selectImport";
public static final String SAKAI_CONTENTITEM_SELECTLINK = "Sakai.contentitem.selectLink";

public static final String CANVAS_PLACEMENTS_COURSENAVIGATION = "Canvas.placements.courseNavigation";
public static final String CANVAS_PLACEMENTS_ACCOUNTNAVIGATION = "Canvas.placements.accountNavigation";
public static final String CANVAS_PLACEMENTS_ASSIGNMENTSELECTION = "Canvas.placements.assignmentSelection";
public static final String CANVAS_PLACEMENTS_LINKSELECTION = "Canvas.placements.linkSelection";
public static final String CANVAS_PLACEMENTS_CONTENTIMPORT = "Canvas.placements.contentImport";

public static void dPrint(String str)
{
if ( verbosePrint ) System.out.println(str);
Expand Down Expand Up @@ -1166,6 +1177,9 @@ public static String[] postContentItemSelectionRequest(Long toolKey, Map<String,
int debug = getInt(tool.get(LTIService.LTI_DEBUG));
debug = 1;

String customstr = toNull((String) tool.get(LTIService.LTI_CUSTOM) );
parseCustom(ltiProps, customstr);

Map<String,String> extra = new HashMap<String,String> ();
ltiProps = BasicLTIUtil.signProperties(ltiProps, launch_url, "POST",
consumerkey, secret, null, null, null, extra);
Expand Down
3 changes: 2 additions & 1 deletion basiclti/basiclti-impl/src/bundle/ltiservice.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ bl_allowcontentitem=Allow External Tool to configure itself (the tool must suppo
pl_header=Indicate the following types of Content Item Selection launches this tool can handle. Not all tools can handle Content Item Selection launches. If you enable a tool which is not capable of responding to a particular request, it will likely fail when you try to use it.
bl_pl_launch=Allow the tool to be launched as a link (this is typically true for most tools)
bl_pl_linkselection=Allow external tool to configure itself (the tool must support the IMS Content-Item message)
bl_pl_fileitem=Allow the tool to provide a file (usually to be imported into a tool like Lessons)
bl_pl_importitem=Allow the tool to provide a common cartridge (usually to be imported into a tool like Lessons)
bl_pl_fileitem=Allow the tool to provide a file (usually as part of a file picker)
bl_pl_contenteditor=Allow the tool to be used from the rich content editor to select content
bl_pl_assessmentselection=Allow the tool to be one of the assessment types
bl_allowcustom=Allow additional custom parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,58 @@ public String prepareValidate(Map<String,Object> deploy, List<Map<String,Object>
return "lti_error";
}

if ( toolProxyBinding.enabledCapability(LTI2Messages.BASIC_LTI_LAUNCH_REQUEST,
ContentItem.getCapability(ContentItem.TYPE_LTILINKITEM) ) ) {
JSONObject launchMessage = toolProxyBinding.getMessageOfType(LTI2Messages.BASIC_LTI_LAUNCH_REQUEST);
JSONObject selectMessage = toolProxyBinding.getMessageOfType(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST);

if ( launchMessage != null ) {
newTool.put(LTIService.LTI_PL_LAUNCH, new Integer(1));
}

// Look for capabilities for Sakai
boolean sakaiplacements = false;
if ( toolProxyBinding.enabledCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST,
SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTANY ) ) {
newTool.put(LTIService.LTI_PL_LINKSELECTION, new Integer(1));
newTool.put(LTIService.LTI_PL_FILEITEM, new Integer(1));
newTool.put(LTIService.LTI_PL_IMPORTITEM, new Integer(1));
sakaiplacements = true;
}

if ( toolProxyBinding.enabledCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST,
SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTFILE ) ) {
newTool.put(LTIService.LTI_PL_FILEITEM, new Integer(1));
sakaiplacements = true;
}

if ( toolProxyBinding.enabledCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST,
SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTLINK ) ) {
newTool.put(LTIService.LTI_PL_LINKSELECTION, new Integer(1));
sakaiplacements = true;
}

if ( toolProxyBinding.enabledCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST,
SakaiBLTIUtil.SAKAI_CONTENTITEM_SELECTIMPORT ) ) {
newTool.put(LTIService.LTI_PL_IMPORTITEM, new Integer(1));
sakaiplacements = true;
}

// If we did not see any Sakai commentary about placements, look to the Canvas variants
boolean selection = sakaiplacements;
if ( ! sakaiplacements && toolProxyBinding.enabledCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST,
SakaiBLTIUtil.CANVAS_PLACEMENTS_LINKSELECTION ) ) {
newTool.put(LTIService.LTI_PL_LINKSELECTION, new Integer(1));
selection = true;
}

if ( toolProxyBinding.enabledCapability(LTI2Messages.BASIC_LTI_LAUNCH_REQUEST,
ContentItem.getCapability(ContentItem.TYPE_FILEITEM) ) ) {
if ( ! sakaiplacements && toolProxyBinding.enabledCapability(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST,
SakaiBLTIUtil.CANVAS_PLACEMENTS_CONTENTIMPORT ) ) {
newTool.put(LTIService.LTI_PL_FILEITEM, new Integer(1));
selection = true;
}

// When in doubt, assume LINKSELECTION
if ( !selection && toolProxyBinding.getMessageOfType(LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST) != null ) {
newTool.put(LTIService.LTI_PL_LINKSELECTION, new Integer(1));
}

newTool.put(LTIService.LTI_TOOL_PROXY_BINDING, tool_proxy_binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ public String getErrorMessage()
return errorMessage;
}

/**
* Get an LTI 2.x Capability String
*/
public static String getCapability(String type)
{
return "ContentItem." + type;
}

/**
* Build up a ContentItem launch URL from a base url, return url and extra data
*/
Expand Down
22 changes: 13 additions & 9 deletions basiclti/basiclti-util/src/java/org/imsglobal/lti2/ToolProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,20 @@ private String parseToolProfileInternal(List<Properties> theTools, Properties in
for ( Object m : messages ) {
JSONObject message = (JSONObject) m;
String message_type = (String) message.get(LTI2Constants.MESSAGE_TYPE);
if ( ! "basic-lti-launch-request".equals(message_type) ) continue;
if ( path != null ) {
return "A resource_handler cannot have more than one basic-lti-launch-request message RT="+resource_type_code;
if ( LTI2Messages.BASIC_LTI_LAUNCH_REQUEST.equals(message_type) ||
LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST.equals(message_type) ) {
if ( path != null ) {
return "A resource_handler cannot have more than one message_type RT="+resource_type_code;
}
path = (String) message.get(LTI2Constants.PATH);
if ( path == null ) {
return "A launch message must have a path RT="+resource_type_code;
}
parameter = getArray(message,LTI2Constants.PARAMETER);
enabled_capability = getArray(message, LTI2Constants.ENABLED_CAPABILITY);
} else {
return "Only "+LTI2Messages.BASIC_LTI_LAUNCH_REQUEST+" and "+LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST+ " are allowed message_types RT="+resource_type_code;
}
path = (String) message.get(LTI2Constants.PATH);
if ( path == null ) {
return "A basic-lti-launch-request message must have a path RT="+resource_type_code;
}
parameter = getArray(message,LTI2Constants.PARAMETER);
enabled_capability = getArray(message, LTI2Constants.ENABLED_CAPABILITY);
}

// Ignore everything except launch handlers
Expand Down

0 comments on commit eecc775

Please sign in to comment.