/**
* Created: 2014.01.12.7.06.AM
* NotesLogEventListProcessing
* NotesLog items to be converted to TXT/CSV/XML data for Xpages
* TODO: Before running code, be sure to remove System.outs, meant for Testing...
*/
import lotus.domino.*;
import java.util.*;
/**
* @author Dököll Solutions, Inc.
* @version 2014.01.12.7.06.AM
*
*/
public class JavaAgent extends AgentBase {
//TODO: Create TXT, CSV, and XML files with the results, feed to Xpages
public void NotesMain() {
try {
//Grab session, yank database out of that
Session session = getSession();
System.out.println("FOUND_SESSION " + session);
//...
Database database = session.getDatabase("", "log.nsf");
System.out.println("FOUND_DATABASE " + session);
//Create a date based on session, we want today's date
DateTime dtToday = session.createDateTime("Today");
System.out.println("FOUND_DATE " + dtToday);
//Convert this date to String, endsWith or startsWith can't search therefore
String ConvertDateToString = dtToday.toString();
System.out.println("FOUND_DATE_CONVERSION " + ConvertDateToString);
//Fetch EventList through Forms, by pass the MiscEvents view
//TODO: Grab EventList View if you need specific dates
DocumentCollection docColl = database.search("Form = 'Events'");
Document logDoc = docColl.getFirstDocument();
//Enter Loop, we are looking at only todays docs/Events
System.out.println("BEGIN LOOP...");
while (logDoc != null) {
// Grab EventList items
//System.out.println("Grabbing EventList items...");
Vector itemsList = logDoc.getItemValue("EventList");
//Run through Events line by line
for (Enumeration values = itemsList.elements(); values
.hasMoreElements();) {
String eventFetch = (String) values.nextElement();
//grab only the Events that match the search criteria, date and text
if (eventFetch.startsWith(ConvertDateToString)
&& eventFetch.endsWith("Anonymous")) {
eventFetch = eventFetch.substring(0, eventFetch.indexOf("Anonymous"));
//TODO: Perhaps beign conversion to XML and so on here...
System.out.println("FOUND_LOG " + eventFetch);
}
//...
if (eventFetch.startsWith(ConvertDateToString)
&& eventFetch.endsWith("docucontent.nsf")) {
eventFetch = eventFetch.substring(0, eventFetch.indexOf("docucontent.nsf"));
//...
System.out.println("FOUND_DB " + eventFetch);
}
}
//grab additional log items, as necessary...
logDoc = docColl.getNextDocument();
}
} catch (Exception e) {
e.printStackTrace();
}
}//end of program...
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>
//UPDATE: 2014.01.14.8.13.PM
//If you want to throw the log retrieved to your browser, you might want to try the following,
//which would then give you the ability to split it into parts and be consumed in such way that is understandable, columns and so on
//thus further remove the need to add a CSV or TXT file to File Server, example C:\\temp\\la la la... you can go dynamic on this thing
//DateTime dtToday = session.createDateTime("Today");
// PrintWriter...
PrintWriter pw = getAgentOutput();
// Content type set at Txt
// TODO: Figure out a better version to load a CSV file to browser
// currently, the csv downloads to local directory
pw.println("Content-type:text/txt");
String dtToday = ("01/12/2014");
System.out.println("FOUND_DATE " + dtToday);
String ConvertDateToString = dtToday.toString();
System.out.println("FOUND_DATE_CONVERSION " + ConvertDateToString);
DocumentCollection docColl = database.search("Form = 'Events'");
Document logDoc = docColl.getFirstDocument();
System.out.println("BEGIN LOOP...");
while (logDoc != null) {
// Grab EventList items
System.out.println("Grabbing EventList items...");
Vector itemsList = logDoc.getItemValue("EventList");
for (Enumeration values = itemsList.elements(); values
.hasMoreElements();) {
String eventFetch = (String) values.nextElement();
if (eventFetch.startsWith(ConvertDateToString)
&& eventFetch.endsWith("Anonymous")) {
eventFetch = eventFetch.substring(0, eventFetch.indexOf("Anonymous"));
// write records from view into a Text file and show it in the
// browser
pw.println(eventFetch);
//System.out.println("FOUND_LOG " + eventFetch);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>
//UPDATE: 2014.01.22.9.01.PM
//say you had a need to match new NotesLog errors against researched items, troubleshooting logs and so on... you might want to try below,
//load specific/understandable values, split as columns to be paired against other v iew items, where fix exists
//Run through Events line by line
for (Enumeration values = itemsList.elements(); values
.hasMoreElements();) {
String eventFetch = (String) values.nextElement();
//grab only the Events that match the search criteria, date and text
//TODO: Retrieve multiple error types and language
if (eventFetch.startsWith(ConvertDateToString)
&& eventFetch.endsWith("(Unknown Source)")) {
eventFetch = eventFetch.substring(0, eventFetch.indexOf("(Unknown Source)"));
//TODO: Perhaps begin conversion to XML and so on here...
//Adding to Notes View
//...
String strEventBitsReplace = eventFetch.toString();
//Write this block better, or add on one line
strEventBitsReplace = strEventBitsReplace.replaceAll(":", ",");
strEventBitsReplace = strEventBitsReplace.replaceAll(" ", ",");
//Split items and load to awaiting array variable...
String[] strColSplit = strEventBitsReplace.split(",");
//plug array values into local String variables
String strDateTime = strColSplit[0].trim(); //DateAndTime
String strHour = strColSplit[1].trim(); //Hour
String strMinute = strColSplit[2].trim(); //Minute
String strSeconds = strColSplit[3].trim(); //Seconds
String strAmPm = strColSplit[4].trim(); //AmPm
String strErrorLang = strColSplit[5].trim(); //ErrorLang
String strErrorRequest = strColSplit[6].trim(); //ErrorRequest
String strErrorOrig = strColSplit[7].trim(); // ErrorOrig
//Troubleshoot this one, but do not add to NSF back-end
String strErrorDummy = strColSplit[8].trim(); //Dummy
String strErrorAt = strColSplit[9].trim(); //ErrorAt
String strErrorDescrip = strColSplit[10].trim(); //ErrorDescrip
//Convert/format time data for FileTime column
String ConvertStringToString = strHour +":"+ strMinute +":"+ strSeconds;
//FOR DEBUG ONLY:
//use this sparingly, you are re-populating Log.nsf
//throw the data in a CSV file, or test Notes documents created
//...
//System.out.println("FOUND_LOG " + DateTime + " " + ConvertStringToString + " " + AmPm+ " " + ErrorLang + " " + ErrorOrig+ " " + ErrorSpace+ " " + ErrorDummy+ " " + ErrorAt+ " " + ErrorDescrip);
//...
//these documents will be available in docucontent.nsf
Database currDatabase = session.getDatabase("", "docucontent.nsf");
System.out.println("FOUND_DATABASE " + session);
//Create a date based on session, we want today's date
//DateTime dtToday = session.createDateTime("Today");
//declare and initialise document variable
//create document(s)
Document submitDocument = (Document) currDatabase.createDocument();
//load to form in your back-end
submitDocument.replaceItemValue("Form", "NewNotesLogErrorsReport");
submitDocument.replaceItemValue("FileDate", strDateTime);
submitDocument.replaceItemValue("FileTime", ConvertStringToString);
submitDocument.replaceItemValue("ErrorAmPm", strAmPm);
submitDocument.replaceItemValue("ErrorRequest", strErrorRequest);
submitDocument.replaceItemValue("ErrorDescrip", strErrorDescrip);
submitDocument.replaceItemValue("ErrorAt", strErrorAt);
submitDocument.replaceItemValue("ErrorOrigin", strErrorOrig);
//save this document, otherwise it is not recorded in the back-end
submitDocument.save();
}