You are here: start » addaconnectorlatesttweet | Show pagesource | Backlinks | Old revisions | Index | Recent changes |

How do I...add a connector to fetch the latest Tweet?


see the video

(This tutorial was developed for Bonita Open Solution Preview Version, November 2009)


Use this “How to” to create a simple example Process with a fun connector. When you run the Process, you will see a form with a “Get latest tweet” field – enter the subject of your choice and the Process will go fetch the latest tweet on that subject keyword.

There is a nice code for “Search for Tweets” at Twitter4J - A Java library for the Twitter API (H/T to Yusuke Yamamoto for Twitter4J).

Copy it here to use in this Process:

    Twitter twitter = new Twitter();
    Query query = new Query("source:twitter4j yusukey");
    QueryResult result = twitter.search(query);
    System.out.println("hits:" + result.getTotal());
    for (Tweet tweet : result.getTweets()) {
        System.out.println(tweet.getFromUser() + ":" + tweet.getText());
    }

Open BonitaStudio. (NOTE: this tutorial was developed for Bonita Open Solution M5 Version.)

Open a New Process. The whiteboard shows a Start and a Step.

Open Bonita Studio

Create a new Connector. Go to the Task Bar and click New Connector.

Set the description of your Connector

When the Set the description of your Connector appears, add:

  • Connector ID: GetLatestTweetAbout
  • Description: Get the latest tweet about a subject
  • Category: Social

Under Specify the pages of the wizard of your connector, click Create.

Create the wizard for your Connector – define fields

When the Create the wizard for your Connector appears, enter:

  • Page ID: query
  • Page title: query

Click Create to define the fields:

  • Field name: query
  • Mandatory Mandatory
  • Widget: text
  • Data type: text

Click OK to return to Set the description of your Connector. Select Create to define the output.

Create the wizard for your Connector – define output

  • Field name: tweet
  • Data type: text

Click Finish.


The java source file for the Connector opens. Here you can paste in the code “Search for Tweets” from Twitter4J.

Java source file ready to edit

Highlight the first auto-generated method stub and paste in the “Search for Tweets” code.

Paste in "search" code from Twitter4J

Import the Twitter 4J Query. Use the Eclipse shortcut Ctrl+shift+O to bring up the Organize Inputs window.

Select twitter4J.Query

The Connector code needs a bit of cleaning up. When it is done, it should look like this:

Connector code


Return to MyProcess by clicking the Whiteboard tab. Click on the Pool and then on Data→ Add to define 2 new text variables:

define "query" variable as text define "out" variable as text

Global data added


Go to Pool → Details → Forms and check Skip the start process forms.

Skip start process forms


Click on Step1, go to Details → General and rename the Step to Get latest tweet.

rename the first step to "Get latest tweet"

Go to Details - > Connectors → Add. Enter connector name: “Get latest tweet”.

Add new connector

Click Next. Select Social and choose the Connector you have just created.

Choose new Connector

Click Next. Select the variable ${query} and again click Next.

Select query variable

Map the tweet Connector output to the variable “out”. Click Finish.

Map output to variable


Go back to the Whiteboard, and add a new Step and an End.

Add a Step and an End

Change the Step to Human and rename it to Read tweet.

Change Step to Human

Go to Details - > Actors and select Group→ Initiator.

Select initiator as Actor


Save your Process and click Run. Bonita Forms Application will present the default form:

Bonita Form "Get latest tweet"

Ignore “out” and enter “BonitaSoft” in “query”. Click Submit.

Try a search on "BonitaSoft"

In the next form, you’ll see the “latest tweet” in the “out” field.


To get the latest tweets on all your favorites, click Submit again, open your Bonita User Experience and click Start a Case.

Start a new case

Get another tweet

 
addaconnectorlatesttweet.txt · Last modified: 2011/11/07 08:28 (external edit)