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();
}
dc.recycle();
// Set last modified date
LOGGER.log(Level.FINE,
"[{0}] Source database last updated: {1}", new Object[] {
srcdbDoc.getItemValueString(NCCONST.DITM_DBNAME), lastUpdated});
srcdbDoc.replaceItemValue(NCCONST.DITM_LASTUPDATE, lastUpdated);
srcdbDoc.save();
// TODO: Handle db.search for case where there are more
// that 5000 documents
// Suspect this limitation is for DIIOP only and not for RPC access
// Have sucessfully tested up to 9000 documents
// Recycle our objects
srcdb.recycle();
templateDoc.recycle();
lastUpdated.recycle();
ns.recycle(lastUpdatedV);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, CLASS_NAME, e);