Knowledge Sharing
Döcu Content
Google Worksheets
JavaAgent/JavaBean
Xpages Application
System Requirements:
Download Domino Designer 8.5.3 Environment (DDE)
http://www.ibm.com/developerworks/downloads/ls/dominodesigner/
Download /Make available Google Spreadsheets API
https://developers.google.com/google-apps/spreadsheets/
https://developers.google.com/google-apps/documents-list/
Introduction:
In this tutorial, we are connecting to Google to read a Spreadsheet and listing its Worksheets using a button. Slight modifcation is made to existing code to convert to JavaAgent, JavaBean written to run code through Browser. See below for code samples to use to run the program, Xpages XSP file included..
Disclaimer:
Information contained in the following is presented as is. This tutorial assumes you have basic Lotus Notes Configuration, Programming knowledge, and are familiar with Google APIs.
Döcu Content JavaAgent/JavaBean/Xpages
At this point, we assume you have gone through the prior tutorial, and maintained JAR configuration to be able to use the Google Spreadsheet API. Copy and paste code below into DDE and submit a new Worksheet, areas of interests are highlighted for your convenience.
Related Info:
https://www.youtube.com/watch?v=GCPsQwv7xVo&list=UUSImDTpK0oe7QrPsYOE4nww
Copy and Paste Page Design code
More than likely, you have also configured faces config XML file in this application. Load the Xpage to your Browser and click that button.
ReadGoogleDriveWorkSheetJavaAgent.java;
/**
* Created from copy: 2014.05.15.9.14.PM
* GoogleSpreadsheetsGoodJavaAgentCopy | ReadGoogleDriveWorkSheetJavaAgent.java
* List Worksheets in specific Spreadsheet, housed on Google Drive
*/
...
Google imports
import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
import com.google.gdata.data.spreadsheet.SpreadsheetFeed;
import com.google.gdata.data.spreadsheet.WorksheetEntry;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
...
Java imports
import java.io.IOException;
import java.net.URL;
import java.util.List;
...
Lotus Domino imports
import lotus.domino.AgentBase;
/**
* @author Dököll Solutions, Inc.
* @version 2014.05.15.9.14.PM
*
*/
public class ReadGoogleDriveWorkSheetJavaAgent extends AgentBase {
public ReadGoogleDriveWorkSheetJavaAgent() {
...
}
button code...
public void NotesMain() {
try {
TODO: see about connecting automatically...
existing Google Drive login creds...
String USERNAME = "yourgoogleaccount@gmail.com";
String PASSWORD = "youraccountpassword";
SpreadsheetService service = new SpreadsheetService(
"MySpreadsheetIntegration");
service.setUserCredentials(USERNAME, PASSWORD);
TODO: Authorize the service object for a specific user (see other
sections)
Define the URL to request. This should never change.
URL 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 = service.getFeed(SPREADSHEET_FEED_URL,
SpreadsheetFeed.class);
List spreadsheets = feed.getEntries();
if (spreadsheets.size() == 0) {
TODO: There were no spreadsheets, act accordingly.
}
TODO: Choose a spreadsheet more intelligently based on your
app's needs.
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());
Create a local representation of the new worksheet.
WorksheetEntry worksheet = new WorksheetEntry();
worksheet
.setTitle(new PlainTextConstruct("Groovy Dököll Worksheet"));
worksheet.setColCount(10);
worksheet.setRowCount(20);
Send the local representation of the worksheet to the API for
creation. The URL to use here is the worksheet feed URL of our
spreadsheet.
URL worksheetFeedUrl = spreadsheet.getWorksheetFeedUrl();
service.insert(worksheetFeedUrl, worksheet);
} catch (AuthenticationException e) {
TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
TODO Auto-generated catch block
e.printStackTrace();
} finally {
}
}
}
RunGoogleSpreadsheetsBean.java;
/**
* Created from Copy: 2014.05.15.9.16.AM
* RunGoogleSpreadsheetsBean.java
* Run JavaAgent, Connect to Google | Create New Worksheet
*/
package com.dokoll.solutions.inc.google.dev;
...
Faces imports
import javax.faces.context.FacesContext;
...
Domino imports
import lotus.domino.NotesException;
import lotus.domino.local.Database;
...
Apache imports
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Dököll Solutions, Inc.
* @version 2014.05.15.9.16.AM
*
*/
...
public class RunGoogleSpreadsheetsBean {
button code
public void doRunSpreadsheetData() throws NotesException{
set up the loggers
Log log = LogFactory.getLog(RunGoogleSpreadsheetsBean.class);
Log debug = LogFactory.getLog("DEBUG");
tell what they are
System.out.println("log is a " + log.getClass().getName());
System.out.println("debug is a " + debug.getClass().getName());
log.info("an info message");
debug.debug("a debug message");
log.info("another info message");
debug.debug("another debug message");
...
get the current database being used
Database database= (Database) FacesContext.getCurrentInstance()
.getApplication().getVariableResolver()
.resolveVariable(FacesContext.getCurrentInstance(), "database");
System.out.println("Database Obtained..." + database);
System.out.println("Connecting to Google...");
...
Run the agent...
database.getAgent("GoogleSpreadsheetsGoodJavaAgentCopy").runOnServer();
}
}
Döcu Content Console View (Console/Drive)
Full page design: Here is the button in question...
[UPDATE 2015.07.10.19.AM]: there was an issue submitting XML code specific to below Xpages Design showing the button, please reference Related Information at the end of this tutorial for the full document, please excuse the inconvenience.
bottom part of the document
TIP: You may want to Extract part of the Spreadsheet listing code to loop through and list worksheet(s) by name via yet another Xpages form, or to existing submit page...
Conclusion:
You can now run code from a button to add Worksheets to existing Spreadsheet, publically available on Google Drive.
Questions, comments, please post a brief message on our Contact form on the main site.
Related Info:
http://www.dokollsolutionsinc.com/CutAndPasteGoogleSheetXpages.html
http://www.openntf.org/main.nsf/project.xsp?r=project/D%C3%B6cu%20Content%20V3.0
Thank you for coming...
Version:2014.05.17.1.41.AM