// Set the traversal context on client context so that it can be used by
// any other classes that will make use of the same.
sharepointClientContext.setTraversalContext(traversalContext);
final SharepointClient sharepointClient = new SharepointClient(
clientFactory, sharepointClientContext);
sharepointClientContext.setBatchHint(hint);
SPDocumentList rsAll = null;
// First, get the documents discovered in the previous crawl cycle.
// The true flag indicates that we want to check if there are any
// pending docs from previous crawl cycle
rsAll = traverse(sharepointClient, true);
if ((rsAll != null) && (rsAll.size() > 0)) {
LOGGER.info("Traversal returned " + rsAll.size()
+ " documents discovered in the previous batch traversal(s).");
} else {
LOGGER.info("No documents to be sent from previous batch traversal(s). Recrawling...");
try {
sharepointClient.updateGlobalState(globalState);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Exception while updating global state.... ", e);
} catch (final Throwable t) {
LOGGER.log(Level.SEVERE, "Error while updating global state.... ", t);
}
// The 'false' flag indicates that we want to scan for all lists for
// any updates and just not the subset. This is required as the
// above call to updateGlobalState(globalState) might have
// discovered docs in one or more (worst case all) list states
final SPDocumentList rs = traverse(sharepointClient, false);
if (rs != null) {
LOGGER.info("Traversal returned " + rs.size()
+ " documents discovered in the current batch traversal.");
if (rsAll == null) {
rsAll = rs;
} else {
rsAll.addAll(rs);
}
} else {
LOGGER.info("No documents to be sent from the current crawl cycle.");
}
if (sharepointClient.isDoCrawl() && (null == rsAll || rsAll.size() == 0)
&& null != globalState.getLastCrawledWeb()) {
LOGGER.log(Level.INFO, "Setting LastCrawledWebStateID and LastCrawledListStateID as null and updating the state file to reflect that a full crawl has completed...");
globalState.setLastCrawledWeb(null);
globalState.setLastCrawledList(null);
globalState.saveState();