ahulme

Bb DevCon 2017 Starter B2 Hands on Session

Blog Post created by ahulme on Mar 10, 2017

For those of you joining the DevCon in Milan we will be running a Get you started session for Building Blocks using the fantastic Building Block template from the 'All the Ducks' Team.  This uses Stripes as its framework and Gradle to Build the project.

 

This will be a Multi-part series of Blog posts designed to get your up and running with your first B2.

 

If you would like to join the session then it will be helpful to run though this guide before hand and install Eclipse and Git Bash.

 

We will cover in the session:

 

  1. Getting you started with Eclipse
  2. Language pack Bundles
  3. API calls
  4. Data Handling

 

 

Install Eclipse:

 

Download and install Eclipse from Eclipse - The Eclipse Foundation open source community website.

 

Download Git bash for Windows Git - Downloading Package

 

Getting Started.

 

Launch git bash and CD to your Work space. I am using

 

ahulme@AHULMEP50 MINGW64 ~

$ cd workspace/devday/

 

Clone the template to your local Workspace.  Note the First part of the directory name shroud be you Vendor ID. In my case I am using bbs  (Use lowercase chars) and then the name of the B2.  This example uses bbs-yourb2name

 

 

ahulme@AHULMEP50 MINGW64 ~/workspace/devday

$ git clone https://github.com/AllTheDucks/atd-b2-stub.git bbs-yourb2name

Cloning into 'bbs-yourb2name'...

remote: Counting objects: 712, done.

remote: Total 712 (delta 0), reused 0 (delta 0), pack-reused 712 eceiving objects:  99% (705/712)

Receiving objects: 100% (712/712), 206.33 KiB | 0 bytes/s, done.

Resolving deltas: 100% (323/323), done.

Checking connectivity... done.

 

Change into the project directory

 

ahulme@AHULMEP50 MINGW64 ~/workspace/devday

$ cd bbs-yourb2name/

 

Run the initB2 task and answer all the questions.  Make sure you set the Vendor ID to match the one used above and the B2 handle as the same name as above.

 

ahulme@AHULMEP50 MINGW64 ~/workspace/devday/bbs-yourb2name (master)

$ ./gradlew initB2

:initB2

Defaults found for generating building block

> Building 0% > :initB2

What is your Vendor Id (e.g. usq, unsw, qut, swin, etc)? (No spaces) [BBS] bbs

What is your Vendor Name (e.g. University of Antarctica)? [Blackboard Support]

What is your Vendor Website (e.g. http://www.myu.edu.au/)? (No spaces) [http://community.blackboard.com/]

What is your B2 Handle (e.g. jshack, autosignon, etc)? (No spaces)  yourb2name

What is your B2 Name (e.g. Student View)? Dev Day2016         *Note I created this in January and forgot we moved on a year, its just to cold in Jan to think....

What is the base java package of your project? (e.g. au.edu.uni.myproject) ? (No spaces) com.devday

Do you want to use the course event listener? (Y/N) Y

Do you want to use the Schema.xml? (Y/N) Y

Do you want a system tool? (Y/N) Y

Do you want a course tool? (Y/N) Y

Initializing Building Block bbs-yourb2name

Initialized empty Git repository in C:/Users/ahulme/workspace/devday/bbs-yourb2name/.git/

 

BUILD SUCCESSFUL

 

Total time: 1 mins 59.188 secs

 

Import the Project into Eclipse.

 

File > Import > Gradle Project

 

Browse to the Directory your created and Select Build model.  Check the Project and finish.  This has now imported this into your work-space.

 

 

 

This is the project as it looks in Eclipse.    There are 3 stripes action classes in src > com.devday.stripes .  These control the actions for the Course Tool, System Tool and Config tool.  The JSP files for these tools can be found in src > main > webapp > WEB-INF > jsp.  The language bundles are in  src > main > webapp > WEB-INF > bundles

 

 

Build the B2.

 

Without making any changes we can Build this B2 and Deploy it to Blackboard.  This will create a course tool, a system tool, Some Database Schema objects and a Config tool for the B2.

 

Right click gradlew > run as > Gradle STS Build

Set the task to build > apply and then run

 

Console Output:

 

[sts] -----------------------------------------------------

[sts] Starting Gradle build for the following tasks:

[sts]      build

[sts] -----------------------------------------------------

:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.7

1 warning

 

:processResources

:classes

:war

:assemble

:compileTestJava UP-TO-DATE

:processTestResources UP-TO-DATE

:testClasses UP-TO-DATE

:test UP-TO-DATE

:check UP-TO-DATE

:build

 

BUILD SUCCESSFUL

 

Total time: 1.584 secs

[sts] -----------------------------------------------------

[sts] Build finished succesfully!

[sts] Time taken: 0 min, 1 sec

[sts] -----------------------------------------------------

 

Deploy To Blackboard.

 

System admin GUI > Building Blocks > installed tools > Upload Building block

 

If you see this error in Red you will need to enable B2's to add custom objects. Building Blocks > Global Settings

 

Error: Could not install plugin.name. There are associated database changes and the global setting has been set to prevent any Building Block from creating custom database objects.

 

 

 

The war file can be found in the build\libs\ directory of the project space.

 

There will be a new tool now in the System admin panel highlighted below.

 

 

Click on this new link and you will see the tool.  As we have not configured this tool to do anything as yet a simple message will show to confirm it is working.   Note the URL used for this tool is https://Yoururl.com/webapps/bbs-yourb2name-BBLEARN/systemtool

 

 

The course tool is set by default to be unavailable courses so you can either set this globally or set on a per course bases for testing.  In a course  Customization > Tool Availability  > find the tool called Dev Day2016 and enable it.  You can then find this tool under tools and select it.

 

 

 

 

The B2 also has a config page for setting Global Configurations.  This can be access though the settings page and has buy default a String and an Integer value. We can change these and add more if required.

 

 

 

 

 

Course Tool Action.

 

This controls the Behavior when the course tool link is selected.  The URL https://finn.pd.local/webapps/bbs-yourb2name-BBLEARN/systemtool is mapped to this CourseToolActoin.java and the default action is to rerun the JSP /WEB-INF/jsp/course-tool.jsp

 

package com.devday.stripes;

import com.alltheducks.bb.stripes.BlackboardActionBeanContext;
import com.alltheducks.bb.stripes.EntitlementRestrictions;
import com.alltheducks.bb.stripes.LoginRequired;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;

@LoginRequired
@EntitlementRestrictions(entitlements = "bbs.yourb2name.course.VIEW", errorPage = "/error.jsp")
@UrlBinding("/coursetool")
public class CourseToolAction implements ActionBean {

    private BlackboardActionBeanContext context;

    @DefaultHandler
    public Resolution displayPage() {
        return new ForwardResolution("/WEB-INF/jsp/course-tool.jsp");
    }

    @Override
    public ActionBeanContext getContext() {
        return context;
    }

    @Override
    public void setContext(ActionBeanContext context) {
        this.context = (BlackboardActionBeanContext)context;
    }
}

 

 

A simple course Tool Project:

 

lets use our basic course tool to display some information about the course.  The FULL URL called for the tool link is https://finn.pd.local/webapps/bbs-yourb2name-BBLEARN/coursetool?course_id=_36_1  and this contain the course Pk1.  We can use this to get the course Pk1 and use the context to get the Course Title

 

Add the following to the CourseToolActoin.java on line 32 to setup our Getters and Setters.

 

private String course_title;

public String getCourse_title() {return course_title; }

public void setCourse_title(String course_title) { this.course_title = course_title; }

   

private String course_id;

public String getCourse_id() {return course_id; }

public void setCourse_id(String course_id) { this.course_id = course_id; }

 

The course Pk1 will be automatically mapped to the action bean course_id as this is provided in the URL.  We can set the Course Title using the context Stripes Action Bean.

 

package com.devday.stripes;

import com.alltheducks.bb.stripes.BlackboardActionBeanContext;
import com.alltheducks.bb.stripes.EntitlementRestrictions;
import com.alltheducks.bb.stripes.LoginRequired;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;

@LoginRequired
@EntitlementRestrictions(entitlements = "bbs.yourb2name.course.VIEW", errorPage = "/error.jsp")
@UrlBinding("/coursetool")
public class CourseToolAction implements ActionBean {

    private BlackboardActionBeanContext context;

    @DefaultHandler
    public Resolution displayPage() {
        
        //Set the actionbean.course_id to the  Course Title from the context
        course_title = context.getCourse().getTitle();
        
        
        return new ForwardResolution("/WEB-INF/jsp/course-tool.jsp");
    }

    @Override
    public ActionBeanContext getContext() {
        return context;
    }

    @Override
    public void setContext(ActionBeanContext context) {
        this.context = (BlackboardActionBeanContext)context;
    }
    
    
    private String course_title; 
       public String getCourse_title() {return course_title; }
    public void setCourse_title(String course_title) { this.course_title = course_title; }
    
    private String course_id; 
       public String getCourse_id() {return course_id; }
    public void setCourse_id(String course_id) { this.course_id = course_id; }
    
}


 

in the course_tools.jsp add in the actionBeans to display the Course Title and Pk1

 

 

Outcomes