Google Drive Spreadsheet Data JavaAgent (Messages Box)

/**
 * Created from copy: 2014.18.08.12.01.AM
 * GoogleAddMessagesForXpagesJavaAgent | WorksheetsAddMessagesJavaAgent.java
 * Insert Row(s) to Worksheets in specific Spreadsheet, housed on Google Drive
 */
//...
//Google imports
import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*; //...
//Java imports
import java.io.IOException;
import java.net.*;
import java.util.*;

//...
//Lotus Domino imports
import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Document;
import lotus.domino.Session;
import lotus.domino.View;
import lotus.domino.local.Database;

/**
 * @author Dököll Solutions, Inc.
 * @version 2014.18.08.12.01.AM
 * 
 */
public class WorksheetsAddMessagesJavaAgent extends AgentBase {

	//declare and initialise variables for Worksheets data
	static String GOOGLE_MSG_SHEET_VIEW = "GoogleMessageWorksheetsDataView";
	
	private String UserName = "username";
	private String RoleID = "roleid";
	private String VideoID = "videoid";
	private String EmbedCode = "embedcode";
	private String MessageBox = "messages";
	private String PageID = "pageid";
	private String UserIP = "userip";
	private String DateCreated = "datecreated";
	
	
	// 2014.05.18.10.39.PM

	public void NotesMain() {

		try {

			Session session = getSession();
			// load info to console for debugging purposes

			// load agentContext
			AgentContext agentContext = session.getAgentContext();
			// ...
			// find database based on session found
			Database database = (Database) agentContext.getCurrentDatabase();
			// Find view in question according to current database
			View view = database.getView(GOOGLE_MSG_SHEET_VIEW);
			// declare document variables
			Document currDoc;
			Document tempDoc;
			// grab first doc
			currDoc = view.getFirstDocument();

			while (currDoc != null) {
				// prepare values to plug into Google Spredsheet/Worksheet(s)
				String SubjectUserName = currDoc
						.getItemValueString("subjectUserName");
				String SubjectUserRole = currDoc
						.getItemValueString("subjectUserRole");
				String SubjectVideoID = currDoc.getItemValueString("subjectVideoID");
				String SubjectEmbedCode = currDoc
						.getItemValueString("subjectEmbedCode");
				String SubjectMessages = currDoc
				.getItemValueString("subjectMessageBox");
				String SubjectPageID = currDoc
				.getItemValueString("PageID");
				String SubjectUserIP = currDoc
				.getItemValueString("UserIP");
				String SubjectDateCreated = currDoc
				.getItemValueString("subjectDateCreated");

				//TODO: Get a Google Drive account before running this code
				//      Add a Spreadsheet, and a new Worksheet
				//...
				// grab Google Creds
				String USERNAME = "yourgmailaccount@gmail.com";
				String PASSWORD = "yourgmailpassword";

				SpreadsheetService service = new SpreadsheetService(
						"CompanyMessagesSpreasheets");

				try {
					service.setUserCredentials(USERNAME, PASSWORD);
				} catch (AuthenticationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				// 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 = null;
				try {
					SPREADSHEET_FEED_URL = new URL(
							"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
				} catch (MalformedURLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				try {
					// Make a request to the API and get all spreadsheets.
					SpreadsheetFeed feed = (SpreadsheetFeed) service.getFeed(
							SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
					List<SpreadsheetEntry> 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());

					// 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 = (ListFeed) service.getFeed(listFeedUrl,
							ListFeed.class);

					// Create a local representation of the new row, based on declared variables...
					//...
					ListEntry row = new ListEntry();
					row.getCustomElements().setValueLocal(UserName,
							SubjectUserName);
					row.getCustomElements().setValueLocal(RoleID,
							SubjectUserRole);
					row.getCustomElements().setValueLocal(VideoID, SubjectVideoID);
					row.getCustomElements()
							.setValueLocal(EmbedCode, SubjectEmbedCode);
					row.getCustomElements()
					.setValueLocal(MessageBox, SubjectMessages);
					//...
					row.getCustomElements()
					.setValueLocal(PageID, SubjectPageID);
					row.getCustomElements()
					.setValueLocal(UserIP, SubjectUserIP);
					row.getCustomElements()
					.setValueLocal(DateCreated, SubjectDateCreated);

					// Send the new row to the API for insertion.
					row = (ListEntry) service.insert(listFeedUrl, row);
				} catch (MalformedURLException 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();
				}

				// Get next document
				tempDoc = view.getNextDocument(currDoc);

				// recycle currDoc
				currDoc.recycle();
				// set currDoc to tempDoc
				currDoc = tempDoc;

				session.recycle();

			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}





Use this XSnippet to connect to Google and grab Spreadsheets data into NSF for viewing...  See tutorials and programs for added info, configuration and so on...
http://openntf.org/main.nsf/project.xsp?r=project/D%C3%B6cu%20Content%20V3.0

Coming Soon!
https://www.youtube.com/watch?v=ehDcHKAjLcc&list=PLL0J_OmDhsPRlf8JS5ovTLdvVHnzLRECe

Java
Köll S Cherizard
August 20, 2014 11:59 PM
Rating
9

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...