Lotus Notes/Domino BlackBerry integration using MDS Studio and Web Services

September 10 2009Not Commented

Categorized Under: Lotus Notes

This tutorial is based on the following software environment.

Windows XP Professional, Lotus Notes Client 7, Domino Server 7, BlackBerry MDS Studio 4.1

Let us first download MDS Studio. Go to http://www.blackberry.com/developers/downloads/index.shtml and download MDS Studio.

Once you downloaded the file, double click on the installer. Click Run.

 mds_install1

Click Next, and accept the terms of the license agreement on all screens. You may change the path in which MDS Studio will be installed. Click Next.

 mds_install2

Enter the user name and company name you entered during registration. Click Next. Enter the URI for your company. Next screen specifies port information. You may leave it as itself. Please ensure that you have disabled any personal firewall which will block ports.

 mds_install3

 Click Next. Next screen is about creating shortcuts. Click Next and install.

 mds_install4

Once installation is complete, press Done button.

mds_install5

Go to Start–>Programs–>Research In Motion–>BlackBerry MDS Studio and open the program. If everything went smoothly, IDE is opened. Go to Help menu and read contents to get familiar with MDS Studio.

Well, now MDS Studio is installed. Let us get into Notes side.

Create a new database in server Go to File–>Database–>New. Give the file name as test.nsf

In ACL give default manager access.

Create Database

Create Database

Open the database in Domino designer. Create new form. In form properties set the Name as Employee. Create a table with four rows and two columns. In table properties set the width of cell as 2.0. Now enter text in left cells for field labels. Type the following as labels from top to bottom in left cells.

  • Employee ID
  • Name
  • Age
  • Designation

Now create fields in the following order from top to bottom in right cells.

  • EmployeeID (Number)
  • EmployeeName (Text)
  • EmployeeAge (Number)
  • EmployeeDesignation (Text)

 

Create a new Action. Name it as Save&Close. Write the formula as

@Command([FileSave]);
@Command([FileCloseWindow]);

Save the form.

employee_form_mds
 

Well, now open the database in Notes client and create some Employee documents. Go to Create–>Employee. Input some test data for all fields and save the document.

employee_document_mds

Repeat the step and create three more documents. Now we have four Employee documents in Test database.

Now we want to create web service for exposing the list of employees.

Go to Designer–>Programmers Pane–>Shared Code–>Web Services. Press New Web Service button. Web Service property box appears. Enter the name as Employee and select Java from Run drop-down menu.

employee_webservice

You could see that one class with Untitled name is created. Replace the entire code with the following snippet.

 
import lotus.domino.*;  
import lotus.domino.types.*;
 
public class EmployeeAction {
 
// This is a template implementation class for your web service. It
// becomes extraneous if you import a WSDL document. Consumers of this
// web service can call any public method in the implementation class.
//
// To obtain a Session object use this code:
 
Session s = WebServiceBase.getCurrentSession();
//write the method to get Employee collection
 
public Employee[] getEmployees(){
 
//declare Employee array
Employee[] employees=null;
 
try{
 
AgentContext agentContext=s.getAgentContext();
//get reference to current database
Database db=agentContext.getCurrentDatabase();
//get collection of Employee documents
DocumentCollection collection=db.search("Form=\"Employee\"");
//initialize employees array with size as employee documents count
employees=new Employee[collection.getCount()];
Document doc=collection.getFirstDocument();
//iterate through employee document collection
int count=0;
while(doc!=null){
//create Employee object
Employee employee=new Employee();
//populate the variables of employee object with the values from employee document
employee.setEmployeeID(doc.getItemValueInteger("EmployeeID"));
employee.setEmployeeName(doc.getItemValueString("EmployeeName"));
employee.setEmployeeAge(doc.getItemValueInteger("EmployeeAge"));
employee.setEmployeeDesignation(doc.getItemValueString("EmployeeDesignation"));
//put the employee object into employees array
employees[count]=employee;
count+=1;
doc=collection.getNextDocument(doc);
}
 
return employees;
 
}catch(Exception e){
e.printStackTrace();
}
 
return null;
 
}
 
}

Now click on New Class action button. Another class named Untitled is created. Replace the code with following snippet.
 

public class Employee {
 
//declare variables
private int employeeID;
private String employeeName;
private int employeeAge;
private String employeeDesignation;
 
//getter methods
 
public int getEmployeeID(){
return employeeID;
}
 
public String getEmployeeName(){
return employeeName;
}
 
public int getEmployeeAge(){
return employeeAge;
}
 
public String getEmployeeDesignation(){
return employeeDesignation;
}
 
//setter methods
 
public void setEmployeeID(int employeeID){
this.employeeID=employeeID;
}
 
public void setEmployeeName(String employeeName){
this.employeeName=employeeName;
}
 
public void setEmployeeAge(int employeeAge){
this.employeeAge=employeeAge;
}
 
public void setEmployeeDesignation(String employeeDesignation){
this.employeeDesignation=employeeDesignation;
}
 
}

Now save the web service. When you try to save the service it displays the following alert box.

employee_webservice1

Right click and select Web Service properties. In properties box, select PortType class as EmployeeAction. Save the web service again.

employee_webservice2

Now we need to test the service. Ensure that http task is running in your Domino server. Open the browser and type the following URL.

http://<servername>/Test.nsf/Employee?wsdl

If everything is OK, you get web service definition in XML format.

Now let us walk through the code.

Employee class is a Java Bean class with some variables and getter/setter methods. Here variables are declared as private and access of them is defined through public getter methods. Similarly you may set the variable values using setter methods. All variables defined in our Employee Notes form are declared as members of Employee Java class.

EmployeeAction is our PortType class in which we define all methods which should be exposed as service methods. Here we define one method named getEmployees(). This method get all Employee documents in Test database, populate the values in Employee objects and return an array of them.

OK, now our service is ready. Let us go back to MDS Studio.

Open Studio. Go to File–>New Project. Select the default option “Quick Start Approach Wizard”. Press Next button.

  mds_project1

Select “WebService Connector Plugin” as existing backend connector. Click Next. Write the WSDL URL as

http://<servername>/Test.nsf/Employee?wsdl

where servername is your Domino server name or IP address. Click Next.

mds_project2

Select getEmployees. Click Next.

mds_project3

Give the Project name as EmployeeService. Press Finish button.

 mds_project4

Now you may see the project and its components in navigator pane. It consists of various components such as Screens, Messages, Data etc.

mds_project5

Now right click on the project Employee Service and click Test. Please wait till simulator gets loaded. It takes sometime to load the simulator, so be patient. If the simulator is loaded for the first time, you have to go through the setup wizard.

blackberry1

You may use arrow keys in your keyboard to move between menus. Use trackball in simulator to select an item. Hit trackball.

Select Next using down arrow key and click trackball in simulator. The only thing you need to change here is your timezone. Rest you keep it as default options. But you may skip email setup option which do not require in our case.

blackberry2

Click Next and Finish at the last step. Now you are taken to the simulator home page. Select Applications menu using down arrow key and click on trackball.

blackberry3

Now you could see applications listing screen. Here you could see all applications deployed in simulator. Select our application and hit trackball.

blackberry4

Now you are taken to main screen with getEmployees label and go button. Hit trackball.

blackberry5

Now you get the list of employees in a tabular format. Congratulations! You have completed the first step towards BlackBerry Domino integration.

mds_project6

Note: Domino web service do not work with session authentication in blackberry. So if you have given no access to default/anonymous users in test db, ensure that you use basic authentication in Domino server.

cheers,

Leave a Reply