Hi,
I’m trying to implement a Google Spreadsheet Connector for adding a row to a spreadsheet, but I’m having lots of problems. These are the steps I’m following:
1.- Create a new connector definition. The configuration I’ve used for this purpose is the following:
- ID, title etc…
- Inputs: login, password, spreadsheet_id, worksheet_id, entry. All of them required and typed like java.lang.String. Each one has a default value, based on a spreadsheet I have for testing
- Empty list of pages. I don’t need any pages, I want this conector in an activity without asking info.
- Empty list of outputs. The result I need is a new row in a spreadsheet. No output variables are needed.
- No languages selected at the final window.
2.- Create a new implementation for the previous definition:
- For doing this part, I’m using the Bonita documentation and the Google API for spreadsheet documentation, but I don’t know how to integrate them together. My code doesn’t use, at this moment, any input data. It’s like this:
/**
*
*/
package org.mycompany.connector;
import org.bonitasoft.engine.connector.ConnectorException;
import com.google.gdata.client.authn.oauth.;
import com.google.gdata.client.spreadsheet.;
import com.google.gdata.data.;
import com.google.gdata.data.batch.;
import com.google.gdata.data.spreadsheet.;
import com.google.gdata.util.;
import java.io.IOException;
import java.net.;
import java.util.;
/**
*The connector execution will follow the steps
-
1 - setInputParameters() → the connector receives input parameters values
-
2 - validateInputParameters() → the connector can validate input parameters values
-
3 - connect() → the connector can establish a connection to a remote server (if necessary)
-
4 - executeBusinessLogic() → execute the connector
-
5 - getOutputParameters() → output are retrieved from connector
-
6 - disconnect() → the connector can close connection to remote server (if any)
*/
public class SpreadsheetImpl extends AbstractSpreadsheetImpl {@Override
protected void executeBusinessLogic() throws ConnectorException{
//Get access to the connector input parameters
//getLogin();
//getPassword();
//getSpreadsheet_id();
//getWorksheet_id();
//getEntry();//TODO execute your business logic here SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration"); //service.setProtocolVersion(SpreadsheetService.Versions.V3); try { service.setUserCredentials("javiermmm.fujitsu@gmail.com", "<my_password>"); } catch (AuthenticationException e) { // TODO Bloque catch generado automáticamente e.printStackTrace(); } // Define the URL to request. This should never change. URL SPREADSHEET_FEED_URL; try { SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full"); // Make a request to the API and get all spreadsheets. SpreadsheetFeed feed; try { feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class); List<SpreadsheetEntry> spreadsheets = feed.getEntries(); if (spreadsheets.size() == 0) { // TODO: There were no spreadsheets, act accordingly. System.out.println("No hay spreadsheets"); } // TODO: Choose a spreadsheet more intelligently based on your // app's needs. SpreadsheetEntry spreadsheet = spreadsheets.get(0); System.out.println(spreadsheet.getTitle().getPlainText()); // Get the first worksheet of the first spreadsheet. // TODO: Choose a worksheet more intelligently based on your // app's needs. WorksheetFeed worksheetFeed = service.getFeed(spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class); List<WorksheetEntry> worksheets = worksheetFeed.getEntries(); WorksheetEntry worksheet = worksheets.get(0); // Fetch the list feed of the worksheet. URL listFeedUrl = worksheet.getListFeedUrl(); ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class); // Create a local representation of the new row. ListEntry row = new ListEntry(); row.getCustomElements().setValueLocal("Company Name", "Company_Bonita"); row.getCustomElements().setValueLocal("Customer Name", "Customer_Bonita"); row.getCustomElements().setValueLocal("Date", "hoy, lunes"); // Send the new row to the API for insertion. row = service.insert(listFeedUrl, row); } catch (IOException e) { // TODO Bloque catch generado automáticamente e.printStackTrace(); } catch (ServiceException e) { // TODO Bloque catch generado automáticamente e.printStackTrace(); } } catch (MalformedURLException e) { // TODO Bloque catch generado automáticamente e.printStackTrace(); } //WARNING : Set the output of the connector execution. If outputs are not set, connector fails
}
@Override
public void connect() throws ConnectorException{
//[Optional] Open a connection to remote server}
@Override
public void disconnect() throws ConnectorException{
//[Optional] Close connection to remote server}
}
When I saved my code, without errors (what have been hard), I try to attach the connector to an activity, and after fill the data required (name, event, etc.), the Bonita window doesn’t enable the buttons next or finish, so I cannot continue to test it.
Besides, I’ve thought that maybe this behavior, could be origined for the lack of dependencies, so I tried to add dependencies editing the definition and the implementation of the connector and adding them with the wizard, but I’m having the same problem: I clcik on add in the dependencies section, and a window is opened. I click the import button, and I select the .jar files I have, but the Accept button is not enabled at any moment.
For this reason, I’ve thought to try the code in an eclipse project (I’ve followed the google intruction of adding the dependencies set of google services + java mail + JavaBeans Activation Framework with the ‘add external Jars’ option in eclipse) , independent of Bonita BPM, but I’m having a different problem. When I launch the main method I got the following error:
java.lang.NoClassDefFoundError: com/google/common/collect/Maps
on executing the line
SpreadsheetService service = new SpreadsheetService(“MySpreadsheetIntegration”);
Diving in Google, I’ve found that error may be solved by including another .jar (guava-r07.jar), and it seems it works, but now the problem is that in the next line
service.setUserCredentials(“javiermmm.fujitsu@gmail.com”, “my_password”);
The application doesn’t throw any error but, it waits forever, I don’t know why.
I’m getting crazy with that, so I would thank any help about that.
Is my code, correct?
Is my configuration correct?
Why Bonita doesn’enable the buttons?
I’ve searched in the community too, but the only post I found relevant, does not have any solution.
Has anybody, a tutorial, or similar for making connectors for Google services (better if spreadsheets)?
Tnaks in advance,
Regards.