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.
Create a new Connector. Go to the Task Bar and click New Connector.
When the Set the description of your Connector appears, add:
Under Specify the pages of the wizard of your connector, click Create.
When the Create the wizard for your Connector appears, enter:
Click Create to define the fields:
Click OK to return to Set the description of your Connector. Select Create to define the output.
Click Finish.
The java source file for the Connector opens. Here you can paste in the code “Search for Tweets” from Twitter4J.
Highlight the first auto-generated method stub and paste in the “Search for Tweets” code.
Import the Twitter 4J Query. Use the Eclipse shortcut Ctrl+shift+O to bring up the Organize Inputs window.
The Connector code needs a bit of cleaning up. When it is done, it should look like this:
Return to MyProcess by clicking the Whiteboard tab. Click on the Pool and then on Data→ Add to define 2 new text variables:
Go to Pool → Details → Forms and check Skip the start process forms.
Click on Step1, go to Details → General and rename the Step to Get latest tweet.
Go to Details - > Connectors → Add. Enter connector name: “Get latest tweet”.
Click Next. Select Social and choose the Connector you have just created.
Click Next. Select the variable ${query} and again click Next.
Map the tweet Connector output to the variable “out”. Click Finish.
Go back to the Whiteboard, and add a new Step and an End.
Change the Step to Human and rename it to Read tweet.
Go to Details - > Actors and select Group→ Initiator.
Save your Process and click Run. Bonita Forms Application will present the default form:
Ignore “out” and enter “BonitaSoft” in “query”. Click Submit.
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.