*
*/
private void pollSourceDatabase(NotesSession ns, NotesDatabase cdb,
NotesDocument srcdbDoc, NotesView templateView, NotesDateTime pollTime) {
final String METHOD = "pollSourceDatabase";
NotesDateTime lastUpdated = null;
Vector<?> lastUpdatedV = null;
LOGGER.entering(CLASS_NAME, METHOD);
try {
// There are configuration options to stop and disable databases
// In either of these states, we skip processing the database
if (1 != srcdbDoc.getItemValueInteger(NCCONST.DITM_CRAWLENABLED)) {
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Skipping database - Database is DISABLED.");
return;
}
if (1 == srcdbDoc.getItemValueInteger(NCCONST.DITM_STOPPED)) {
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Skipping database - Database is STOPPED.");
return;
}
// When was this database last updated?
lastUpdatedV = srcdbDoc.getItemValue(NCCONST.DITM_LASTUPDATE);
if (0 < lastUpdatedV.size()) {
lastUpdated = (NotesDateTime) lastUpdatedV.firstElement();
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Last processed time was " + lastUpdated);
} else {
lastUpdated = ns.createDateTime("1/1/1980");
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Database has never been processed.");
}
// What's our poll interval?
double pollInterval = srcdbDoc.getItemValueInteger(
NCCONST.DITM_UPDATEFREQUENCY);
double elapsedMinutes = pollTime.timeDifference(lastUpdated) / 60;
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Time difference is : " + elapsedMinutes);
// Check poll interval
if (pollInterval > elapsedMinutes) {
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Skipping database - Poll interval has not yet elapsed.");
lastUpdated.recycle();
ns.recycle(lastUpdatedV);
return;
}
// Get modified documents
NotesDatabase srcdb = ns.getDatabase(null, null);
srcdb.openByReplicaID(
srcdbDoc.getItemValueString(NCCONST.DITM_SERVER),
srcdbDoc.getItemValueString(NCCONST.DITM_REPLICAID));
// Did the database open succeed? If not exit
if (!srcdb.isOpen()) {
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Skipping database - Database could not be opened.");
lastUpdated.recycle();
ns.recycle(lastUpdatedV);
srcdb.recycle();
return;
}
String dbName = srcdbDoc.getItemValueString(NCCONST.DITM_DBNAME);
String authType = srcdbDoc.getItemValueString(NCCONST.DITM_AUTHTYPE);
LOGGER.log(Level.FINE,
"{0} database is configured using {1} authentication type",
new Object[] {dbName, authType});
if (processACL(ns, cdb, srcdb, srcdbDoc)) {
// Scan database ACLs and update H2 cache
LOGGER.log(Level.FINE, "Scan ACLs and update H2 for {0} replica",
srcdb.getReplicaID());
notesConnectorSession.getUserGroupManager().updateRoles(srcdb);
// If the ACL has changed and we are using per Document
// ACLs we need to resend all documents.
if (authType.contentEquals(NCCONST.AUTH_ACL)) {
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Database ACL has changed - Resetting last update "
+ "to reindex all document ACLs.");
lastUpdated = ns.createDateTime("1/1/1980");
}
}
// From the template, we get the search string to determine
// which documents should be processed
NotesDocument templateDoc = templateView.getDocumentByKey(
srcdbDoc.getItemValueString(NCCONST.DITM_TEMPLATE), true);
String searchString = templateDoc.getItemValueString(
NCCONST.TITM_SEARCHSTRING);
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
"Search string is: " + searchString);
NotesDocumentCollection dc = srcdb.search(searchString, lastUpdated, 0);
LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
srcdb.getFilePath() + " Number of documents to be processed: "
+ dc.getCount());
NotesDocument curDoc = dc.getFirstDocument();
while (null != curDoc) {
String NotesURL = curDoc.getNotesURL();
LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
"Processing document " + NotesURL);
if (curDoc.hasItem(NCCONST.NCITM_CONFLICT)) {
LOGGER.logp(Level.FINER, CLASS_NAME, METHOD,
"Skipping conflict document " + NotesURL);
NotesDocument prevDoc = curDoc;
curDoc = dc.getNextDocument(prevDoc);
prevDoc.recycle();
continue;
}
// Create a new crawl request
NotesDocument crawlRequestDoc = cdb.createDocument();
crawlRequestDoc.appendItemValue(NCCONST.NCITM_STATE, NCCONST.STATENEW);
crawlRequestDoc.appendItemValue(NCCONST.ITM_MIMETYPE,
NCCONST.DEFAULT_DOCMIMETYPE);
// Create the fields necessary to crawl the document
crawlRequestDoc.appendItemValue(NCCONST.ITMFORM,
NCCONST.FORMCRAWLREQUEST);
crawlRequestDoc.appendItemValue(NCCONST.NCITM_UNID,
curDoc.getUniversalID());
crawlRequestDoc.appendItemValue(NCCONST.NCITM_REPLICAID,
srcdbDoc.getItemValueString(NCCONST.DITM_REPLICAID));
crawlRequestDoc.appendItemValue(NCCONST.NCITM_SERVER,
srcdbDoc.getItemValueString(NCCONST.DITM_SERVER));
crawlRequestDoc.appendItemValue(NCCONST.NCITM_TEMPLATE,
srcdbDoc.getItemValueString(NCCONST.DITM_TEMPLATE));
crawlRequestDoc.appendItemValue(NCCONST.NCITM_DOMAIN,
srcdbDoc.getItemValueString(NCCONST.DITM_DOMAIN));
crawlRequestDoc.appendItemValue(NCCONST.NCITM_AUTHTYPE,
srcdbDoc.getItemValueString(NCCONST.DITM_AUTHTYPE));
// Map the lock field directly across
crawlRequestDoc.appendItemValue(NCCONST.ITM_LOCK,
srcdbDoc.getItemValueString(NCCONST.DITM_LOCKATTRIBUTE)
.toLowerCase());
// Add any database level meta data to the document
crawlRequestDoc.appendItemValue(NCCONST.ITM_GMETAREPLICASERVERS,
srcdbDoc.getItemValue(NCCONST.DITM_REPLICASERVERS));
crawlRequestDoc.appendItemValue(NCCONST.ITM_GMETACATEGORIES,
srcdbDoc.getItemValue(NCCONST.DITM_DBCATEGORIES));
crawlRequestDoc.appendItemValue(NCCONST.ITM_GMETADATABASE,
srcdbDoc.getItemValueString(NCCONST.DITM_DBNAME));
crawlRequestDoc.appendItemValue(NCCONST.ITM_GMETANOTESLINK, NotesURL);
crawlRequestDoc.save();
crawlRequestDoc.recycle(); //TEST THIS
crawlRequestDoc = null;
NotesDateTime lastModified = curDoc.getLastModified();
if (lastModified.timeDifference(lastUpdated) > 0) {
lastUpdated = lastModified;
}
NotesDocument prevDoc = curDoc;
curDoc = dc.getNextDocument(prevDoc);
prevDoc.recycle();