Sakai Tools - The Basics - Building a simple (legacy) tool.

Sakai Tools - The Basics - Building a simple (legacy) tool.

What you'll find in this section: 

In this section, you will learn the basics about sakai tools. 

We will add a module to the sakai sourcecode and lay the foundation for the further development.

The tool will not do anything exciting until now but it is able to startup and says "Hello, World!" in a blank page if you navigate to the tool in sakai. 


Prior Knowledge: 

  • You must be able to deploy sakai and you should have an instance up and running. 
  • You should have a basic knowledge about programming in Java, Maven and Spring. 

Create or add a module inside sakai project source code

Sakai Tools live as Modules in the sakai project. You can add your contributed modules (e.g. https://github.com/sakaicontrib ) or your own modules. 

For example, use your IDE for that. The following screenshots are made in Intellij. This example tool is called "tasklist"

Do this in Intellij:  rightclick on main folder sakai and select new → Module → Maven

select Parent: Sakai Master 

and choose a proper GroupId and ArtifactId ( see Sakai app and tool naming tips )


Module contents ( additional Info at Sakai application (tool) structure) :

1. The tool pom.xml: 

This is the (base-) pom.xml of your module. It inherits from the master-pom and contains all parts of the tool-structure as modules.



2. The tool module

The tool-module contains the basic webapp settings.


Take a look on the tool structure: 

! Hint: Take care that your Java-Classes are at ${tool-root}/src/java/...  instead of ${tool-root}/src/main/java/...  Otherwise Maven will not compile your classes  (because sakai team defined that in master/pom.xml )


2.1 tool module pom.xml

The important parts of your tool-pom.xml are as follows: 

  • parent: The tool-pom.xml inherits from the previous generated pom.xml
  • packaging: The tool should be packaged as war
  • dependencies:  you need to add sakaiproject.kernel - modules to your tool-library. These are: 
    • sakai-component-manager
    • sakai-kernel-api
    • sakai-kernel-util

 


2.2 web.xml 

under ${tool-root}/tool/src/webapp/WEB-INF/web.xml

Define a display-name and a description.

Define a servlet

  • servlet-name: sakai.${tool-name}
  • servlet-class: basic Java class (e.g. org.sakaiproject.tool.tasklist.TasklistTool
  • load-on-startup: enable (1) 


(Additional Reading: General Information about Filter and Listener)

Define the sakai request filter in a filter element

web.xml
<filter>
    <filter-name>sakai.request</filter-name>
    <filter-class>org.sakaiproject.util.RequestFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>sakai.request</filter-name>
    <servlet-name>sakai.tasklist</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>


The ToolListener is a sakai-kernel functionality that is responsible for recognizing your tool and make it accessible for the system. Be sure to have the kernel-modules on your library (see tool-pom.xml) 



web.xml
<listener>
    <listener-class>org.sakaiproject.util.ToolListener</listener-class>
</listener>

The SakaiContextLoaderListener  increases the counter for active context children if the tool is initialized and decreases it, if the tool is destroyed (see org.sakaiproject.component.impl.SpringCompMgr.java for details) and initializes the application context for the tool (org.springframework.web.context.ContextLoader.class)

web.xml
<listener>
<listener-class>org.sakaiproject.util.SakaiContextLoaderListener</listener-class>
</listener>





2.3 tool-registration file


The sakai kernel class ToolListener will search for the tool descriptor. This is an xml file placed at ${tool-root}/tool/src/webapp/WEB-INF/tools/

The file should be named ${tool-name}.tool.xml

Inside the file, define the tool-id, the title and the description. Further define <category> Elements for the parts of the system, that should provide your tool (e.g. course, project) 


2.4 Any Java class logic delivering the content 

This class (defined in web.xml) will respond if someone navigates to your tool. Here's a very basic example HttpServlet: