Skip to content

Commit

Permalink
SAK-30372 - Initial version of the objects - more cleanup to do
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Feb 27, 2016
1 parent 16c58c5 commit 5020404
Show file tree
Hide file tree
Showing 14 changed files with 898 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* $URL$
* $Id$
*
* Copyright (c) 2006-2009 The Sakai Foundation
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.sakaiproject.basiclti.util;

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.tsugi.basiclti.BasicLTIUtil;
import org.tsugi.casa.CASAUtil;
import org.tsugi.lti2.LTI2Config;

import org.sakaiproject.lti2.SakaiLTI2Config;
import org.sakaiproject.lti2.SakaiLTI2Base;

import org.sakaiproject.tool.api.Tool;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.component.cover.ServerConfigurationService;

/**
* Some Sakai Utility code for IMS CASA
* This is mostly code to support the Sakai conventions for
* dealing with CASA.
*/
@SuppressWarnings("deprecation")
public class SakaiCASAUtil {

private static Log M_log = LogFactory.getLog(SakaiCASAUtil.class);

public static JSONObject getCASAEntry(String toolRegistration)
{
Tool theTool = ToolManager.getTool(toolRegistration);
if ( theTool == null ) return null;
LTI2Config cnf = new SakaiLTI2Config();
boolean sample = false;
if ( cnf.getGuid() == null ) {
cnf = new SakaiLTI2Base();
sample = true;
}

JSONObject jsonResponse = new JSONObject();
JSONObject identity = new JSONObject();
identity.put("product_instance_guid", cnf.getService_owner_id());
identity.put("originator_id", cnf.getService_owner_id());
identity.put("id", toolRegistration);
jsonResponse.put("identity", identity);
JSONObject use = new JSONObject();
use.put(CASAUtil.TITLE_SCHEMA,theTool.getTitle());
use.put(CASAUtil.TEXT_SCHEMA,theTool.getDescription());
JSONArray contact = new JSONArray();
JSONObject name = new JSONObject();
name.put("name", cnf.getService_owner_owner_name());
name.put("email", cnf.getService_owner_support_email());
contact.add(name);
use.put(CASAUtil.CONTACT_SCHEMA, contact);
use.put(CASAUtil.ICON_SCHEMA, "https://www.apereo.org/sites/all/themes/apereo/images/apereo-logo-white-bg.png");

JSONObject launch = new JSONObject();
launch.put("launch_url", ServerConfigurationService.getServerUrl() + "/imsblis/provider/"+toolRegistration);
use.put(CASAUtil.LAUNCH_SCHEMA, launch);

JSONObject original = new JSONObject();
original.put("use", use);
original.put("timestamp", "2015-01-02T22:17:00.371Z");
original.put("uri", ServerConfigurationService.getServerUrl());
original.put("share", Boolean.TRUE);
original.put("propagate", Boolean.TRUE);
jsonResponse.put("original", original);

return jsonResponse;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;

import org.tsugi.basiclti.BasicLTIConstants;
import org.tsugi.basiclti.BasicLTIUtil;
import org.tsugi.basiclti.BasicLTIProviderUtil;
Expand All @@ -55,6 +58,7 @@
import org.sakaiproject.lti.api.SiteMembershipUpdater;
import org.sakaiproject.lti.api.SiteMembershipsSynchroniser;
import org.sakaiproject.basiclti.util.SakaiBLTIUtil;
import org.sakaiproject.basiclti.util.SakaiCASAUtil;
import org.sakaiproject.basiclti.util.LegacyShaUtil;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
Expand Down Expand Up @@ -222,6 +226,7 @@ public int compare(Object o1, Object o2) {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doPost(request, response);
}

Expand Down Expand Up @@ -254,6 +259,11 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
return;
}

if ( "/casa.json".equals(request.getPathInfo()) ) {
handleCASAList(request, response);
return;
}

if (M_log.isDebugEnabled()) {
Map<String, String[]> params = (Map<String, String[]>) request
.getParameterMap();
Expand Down Expand Up @@ -915,4 +925,27 @@ public void run() {

ltiService.insertMembershipsJob(siteId, membershipsId, membershipsUrl, oauth_consumer_key, callbackType);
}

private void handleCASAList(HttpServletRequest request, HttpServletResponse response) {

JSONArray retval = new JSONArray();
String allowedToolsConfig = ServerConfigurationService.getString("basiclti.provider.allowedtools", "");

String[] allowedTools = allowedToolsConfig.split(":");
List<String> allowedToolsList = Arrays.asList(allowedTools);
for (String toolId : allowedToolsList) {
JSONObject entry = SakaiCASAUtil.getCASAEntry(toolId);
retval.add(entry);
}

// System.out.println("retval="+retval);
try {
response.setContentType("application/json");
PrintWriter out = response.getWriter();
out.write(retval.toString());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
90 changes: 90 additions & 0 deletions basiclti/tsugi-util/src/java/org/tsugi/casa/CASAUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* $URL$
* $Id$
*
* Copyright (c) 2016- Charles R. Severance
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package org.tsugi.casa;

import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.HashMap;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.tsugi.basiclti.BasicLTIUtil;
import org.tsugi.basiclti.BasicLTIConstants;
import org.tsugi.lti2.objects.StandardServices;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

public class CASAUtil {

// We use the built-in Java logger because this code needs to be very generic
private static Logger M_log = Logger.getLogger(CASAUtil.class.toString());

/*
$entry = new stdClass();
$entry->identity = new stdClass();
$entry->identity->product_instance_guid = $CFG->product_instance_guid;
$entry->identity->originator_id = $CFG->casa_originator_id;
// id an string unique to the app among all apps published by the publisher.
$entry->identity->id = $id;
$orig = new stdClass();
$orig->timestamp = "2015-01-02T22:17:00.371Z";
$orig->uri = $CFG->wwwroot;
$orig->share = true;
$orig->propagate = true;
$use = new stdClass();
$use->{"1f2625c2-615f-11e3-bf13-d231feb1dc81"} = $title;
$use->{"b7856963-4078-4698-8e95-8feceafe78da"} = $text;
// $use->{"d59e3a1f-c034-4309-a282-60228089194e"} = [{"name":"Paul Gray","email":"[email protected]"}],
if ( $icon !== false ) $use->{"d25b3012-1832-4843-9ecf-3002d3434155"} = $icon;
$launch = new stdClass();
$script = isset($REGISTER_LTI2['script']) ? $REGISTER_LTI2['script'] : "index.php";
$script = $CFG->wwwroot . '/' . str_replace("register.php", $script, $path);
$launch->launch_url = $script;
$launch->registration_url = $CFG->wwwroot . '/lti/register.php';
$use->{"f6820326-5ea3-4a02-840d-7f91e75eb01b"} = $launch;
$orig->use = $use;
$entry->original = $orig;
$output[] = $entry;
*/

public static final String TITLE_SCHEMA = "1f2625c2-615f-11e3-bf13-d231feb1dc81";
public static final String TITLE = "title";
public static final String TEXT_SCHEMA = "b7856963-4078-4698-8e95-8feceafe78da";
public static final String TEXT = "text";
public static final String CONTACT_SCHEMA = "d59e3a1f-c034-4309-a282-60228089194e";
public static final String CONTACT = "contact";
public static final String CONTACT_NAME = "name";
public static final String CONTACT_EMAIL = "email";
public static final String LAUNCH_SCHEMA = "f6820326-5ea3-4a02-840d-7f91e75eb01b";
public static final String LAUNCH = "launch";
public static final String ICON_SCHEMA = "d25b3012-1832-4843-9ecf-3002d3434155";
public static final String ICON = "icon_path";

private static final String EMPTY_JSON_OBJECT = "{\n}\n";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

package org.tsugi.casa.objects;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Generated;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import org.tsugi.jackson.objects.JacksonBase;
import org.tsugi.casa.CASAUtil;

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@Generated("com.googlecode.jsonschema2pojo")
@JsonPropertyOrder({
"identity",
"original"
// TODO: "requires"
})

public class Application extends JacksonBase {

@JsonProperty("identity")
private Identity identity;
@JsonProperty("original")
private Original original;

// Constructor
public Application(Identity identity, Original original) {
this.identity = identity;
this.original = original;
}

@JsonProperty("identity")
public Identity getIdentity() {
return identity;
}

@JsonProperty("identity")
public void setIdentity(Identity identity) {
this.identity = identity;
}

@JsonProperty("original")
public Original getOriginal() {
return original;
}

@JsonProperty("original")
public void setOriginal(Original original) {
this.original = original;
}


/*
From: https://gist.github.com/pfgray/acca0e7966e452cb7c58
[{
"identity":{
"originator_id":"a9a860ae-7c0f-4c12-a1cf-9fe490ee1f49",
"id":"local-lti-provider"
},
"original":{
"timestamp":"2015-01-02T22:17:00.371Z",
"uri":"http://lti-provider.paulgray.net",
"share":true,
"propagate":true,
"use":{
"f6820326-5ea3-4a02-840d-7f91e75eb01b":{
"registration_url":"http://lti-provider.paulgray.net/register",
"launch_url":"http://www.google.com"
},
"1f2625c2-615f-11e3-bf13-d231feb1dc81":"Local Mock Lti2 Provider",
"d59e3a1f-c034-4309-a282-60228089194e":[{"name":"Paul Gray","email":"[email protected]"}],
"c80df319-d5da-4f59-8ca3-c89b234c5055":["dev","lti"],
"c6e33506-b170-475b-83e9-4ecd6b6dd42a":["lti"],
"d25b3012-1832-4843-9ecf-3002d3434155":"http://www.iconsdb.com/icons/preview/green/literature-xxl.png",
},
"require":{}
}
}]
*/
}

25 changes: 25 additions & 0 deletions basiclti/tsugi-util/src/java/org/tsugi/casa/objects/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

package org.tsugi.casa.objects;

public class Contact extends org.tsugi.shared.objects.Contact {

public Contact(String name, String email) {
super(name,email);
}

/*
"use":{
"f6820326-5ea3-4a02-840d-7f91e75eb01b":{
"registration_url":"http://lti-provider.paulgray.net/register",
"launch_url":"http://www.google.com"
},
"1f2625c2-615f-11e3-bf13-d231feb1dc81":"Local Mock Lti2 Provider",
"d59e3a1f-c034-4309-a282-60228089194e":[{"name":"Paul Gray","email":"[email protected]"}],
"c80df319-d5da-4f59-8ca3-c89b234c5055":["dev","lti"],
"c6e33506-b170-475b-83e9-4ecd6b6dd42a":["lti"],
"d25b3012-1832-4843-9ecf-3002d3434155":"http://www.iconsdb.com/icons/preview/green/literature-xxl.png",
},
*/
}

Loading

0 comments on commit 5020404

Please sign in to comment.