Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems...

36
Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami

Transcript of Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems...

Page 1: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Using Template Variables and Creating Your Own Custom Template Variables

Brett StephensSystems AnalystLearning Platforms TeamUniversity of Miami

Page 2: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Definitions

• Template Variable–@[email protected]@X@–Used in content items or portal modules

• Institutional Role–Community Engagement license–Student, Faculty, etc–Used for branding and availability of tabs & modules

Page 3: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

The Challenge

• UM participating in NSSE

• Administered by Indiana University

• 5,342 students (freshmen and seniors) at UM selected to participate

• 15,000 users on UM’s Blackboard every week

Page 4: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

What We Did

Page 5: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

How?

Page 6: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Why a Custom Template Variable?

• Survey links specific to user

• No Authentication

•@[email protected]@X@ used where URL would be–@X@...@X@ replaced by output of java method

Page 7: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Institutional Role Usage

• The NSSE module was only displayed to survey participants (NSSE role)

• NSSE role assigned to users via SIS Flatfile upload

Page 8: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Module Availability based on Institutional Role(s)

Page 9: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Standard Template Variables

Page 10: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Standard Template Variables

• @[email protected]@X@

• Objects with template variables–User–Course–Content–Request–System

Page 11: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Standard Template Variables

–Locale (en_US)

–Role (system)

– Institution_role

–Secondary_institution_role

• @[email protected]@X@– @[email protected]_uid@X@

• User–batch_uid

– id

–full_name

–pk_string (_751_1)

Page 12: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Standard Template Variables

• Course–batch_uid

– id

–course_name

–pk_string (_2702_1)

–url (/courses/1/BIL206/)

–Role (of user in course)

–Locale (en_US)

Page 13: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Standard Template Variables

• Content– id or pk_string (_37_1)–url

• Request– id– locale–Return (return url)

• System–site_id

Page 14: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Example Uses of Template Variables

Link to content item within description (banner image)

/webapps/blackboard/content/launchLink.jsp?course_id=

@[email protected]_string@X@&

content_id=@[email protected]_string@X@

Instead of

/webapps/blackboard/content/launchLink.jsp?

course_id=_355958_1&content_id=_6028740_1

Page 15: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Example Uses of Template Variables

Custom Course GreetingHello @[email protected]@X@, welcome to @[email protected]_name@X@

User_list_context_menu & course_list_context_menu links in B2s (in bb-manifest.xml)

<url value="userinfo.jsp?user_id=@X@target_user.username@X@"/><url value="courseinfo.jsp?course_id=@[email protected]@X@"/>

Page 16: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Defining Custom Template Variables in a Building Block

Page 17: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Resolution of a Template Variable

@X@umia_user.nsse_link@X@

CustomResolverGet user_id from context

Query umia_surveylinks table with user_id

return surveylink

Replace @X@umia_user.nsse_link@X@ with surveylink

Page 18: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Important Files in the B2

• Bb-manifest.xml

• Schema.xml

• Config.jsp

• CustomContextHandler.java

• CustomResolver.java

Page 19: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Bb-manifest.xml

<extension-defs>

<definition namespace="blackboard.platform">

<extension id="customContextHandler“

point="blackboard.platform.contextHandler"

class="edu.miami.nsse.CustomContextHandler"

singleton="false" />

</definition>

</extension-defs>

Page 20: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Bb-manifest.xml

<http-actions>

<config value="admin/config.jsp" />

</http-actions>

<schema-dirs>

<schema-dir dir-name="main" />

</schema-dirs>

Page 21: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Bb-manifest.xml

<permissions> <permission type="attribute"

name="user.authinfo" actions="get" />

<permission type="runtime"

name="db.connection.*" />

</permissions>

Page 22: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Schema.xml<table name="umia_surveylinks">

<column name="user_id" data-type="nvarchar(20)" nullable="false"/>

<column name="link" data-type="nvarchar(300)" nullable="false"/>

<primary-key name="umia_surveylinks_pk1" unique="true" comment="Unique primary key">

<columnref name="user_id" />

</primary-key>

</table>

Page 23: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Db Table Sample Data

USER_ID SURVEY_LINKusername1 http://fakesurveylink.com/3E01512username2 http://fakesurveylink.com/1E6867Fusername3 http://fakesurveylink.com/1F5B55D

Page 24: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Config.jsp

Page 25: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Config.jsp

• Get db connection from BbDatabase conn manager

• Tokenize and iterate through csv file– INSERT INTO umia_surveylinks (user_id, link) VALUES

(?, ?)–setString(1, user_id)–setString(2, surveylink)

• Catch SQLException– release connection

Page 26: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomContextHandler.java

public List<ContextEntry> resolveKeys(HttpServletRequest request, BbPersistenceManager unused) {

CustomResolver resolver = new CustomResolver(request);

Resolver.attachResolverToContext(resolver);

return new LinkedList<ContextEntry>();}

Page 27: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

public String[] getKeys() {

return (new String[] {"umia_user"});

}

Page 28: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

public String resolve(String method, String attributes[]) {

String varout = "";

ContextManagerFactory.getInstance()

.setContext(_request);

Context ctx = ContextManagerFactory.getInstance().getContext();

Page 29: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

String userid = ctx.getUser().getUserName();

Connection conn = null;

StringBuilder queryString = new StringBuilder("");

ConnectionManager cManager = null;

PreparedStatement selectQuery = null;

Page 30: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

if ("NSSE_link".equalsIgnoreCase(method)) {

try {

cManager = BbDatabase.getDefaultInstance()

.getConnectionManager();

conn = cManager.getConnection();

queryString.append("SELECT link

FROM umia_surveylinks ");

Page 31: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

queryString.append("WHERE user_id = ?");

selectQuery =

conn.prepareStatement(queryString.toString());

selectQuery.setString(1, userid);

ResultSet rSet = selectQuery.executeQuery();

while(rSet.next()){

varout = rSet.getString("link");

}

Page 32: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

selectQuery.close();

cManager.releaseConnection(conn);

} catch (java.sql.SQLException sE){

LogServiceFactory.getInstance().logError("NSSE SQL Exception:", sE);

} catch (ConnectionNotAvailableException cE) {

LogServiceFactory.getInstance().logError("NSSE Connection Exception:", cE); }

Page 33: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

CustomResolver.java

finally {

if (conn != null) cManager.releaseConnection(conn);

}

return varout;

Page 34: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Outcome of Our Efforts

•Overall Participation: 27%

• 34% Completed Survey Through Blackboard Learn Link

Page 35: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Conclusion

• Why This Worked (as well as it did)–Simplicity–Logic detached from presentation

• What I Learned–Reuse database connections when possible–Close database connections!

Page 36: Using Template Variables and Creating Your Own Custom Template Variables Brett Stephens Systems Analyst Learning Platforms Team University of Miami.

Questions?

Slides and Resourses:brettstephens.com/devcon2015

Brett [email protected]