CONNECTORS-1747: Add global config flag to disable hopcount tracking completely

git-svn-id: https://svn.apache.org/repos/asf/manifoldcf/trunk@1910036 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 7039068..97fe0fe 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,9 @@
 CONNECTORS-1743: Retry on 502 and 503 errors in Solr connector.
 (Markus Günther)
 
+CONNECTORS-1747: Add global property to disable hopcount for all connectors.
+(Mingchun Zhao)
+
 ======================= Release 2.24 =====================
 
 CONNECTORS-1739: Reuse escaping facilities.
diff --git a/framework/crawler-ui/src/main/webapp/editjob.jsp b/framework/crawler-ui/src/main/webapp/editjob.jsp
index 01d8716..9e7d9ac 100644
--- a/framework/crawler-ui/src/main/webapp/editjob.jsp
+++ b/framework/crawler-ui/src/main/webapp/editjob.jsp
@@ -54,6 +54,13 @@
   INotificationConnectorPool notificationConnectorPool = NotificationConnectorPoolFactory.make(threadContext);
   ITransformationConnectorPool transformationConnectorPool = TransformationConnectorPoolFactory.make(threadContext);
 
+  ILockManager lockManager = LockManagerFactory.make(threadContext);
+
+  /** If the global cluster property "storehopcount" is set to false(defaults to true), disable support for hopcount handling completely,
+  * the "Hop Filters" tab should not appear in the UI for any job.
+  */
+  Boolean storeHopCount = lockManager.getSharedConfiguration().getBooleanProperty("org.apache.manifoldcf.crawler.jobs.storehopcount",true);
+
   // Figure out tab name and sequence number
   String tabName = variableContext.getParameter("tabname");
   String tabSequenceNumber = variableContext.getParameter("sequencenumber");
@@ -218,7 +225,7 @@
   {
     tabsArray.add(Messages.getString(pageContext.getRequest().getLocale(),"editjob.Scheduling"));
     sequenceArray.add(null);
-    if (relationshipTypes != null && relationshipTypes.length > 0)
+    if (storeHopCount && relationshipTypes != null && relationshipTypes.length > 0)
     {
       tabsArray.add(Messages.getString(pageContext.getRequest().getLocale(),"editjob.HopFilters"));
       sequenceArray.add(null);
@@ -902,7 +909,11 @@
   }
 
   // Hop Filters tab
-  if (tabName.equals(Messages.getString(pageContext.getRequest().getLocale(),"editjob.HopFilters")) && tabSequenceInt == -1)
+  if (!storeHopCount)
+  {
+    // Do nothing
+  }
+  else if (tabName.equals(Messages.getString(pageContext.getRequest().getLocale(),"editjob.HopFilters")) && tabSequenceInt == -1)
   {
     if (relationshipTypes != null)
     {
diff --git a/framework/crawler-ui/src/main/webapp/viewjob.jsp b/framework/crawler-ui/src/main/webapp/viewjob.jsp
index 0ed0e56..8be7ed6 100644
--- a/framework/crawler-ui/src/main/webapp/viewjob.jsp
+++ b/framework/crawler-ui/src/main/webapp/viewjob.jsp
@@ -46,6 +46,13 @@
   INotificationConnectorPool notificationConnectorPool = NotificationConnectorPoolFactory.make(threadContext);
   ITransformationConnectorPool transformationConnectorPool = TransformationConnectorPoolFactory.make(threadContext);
 
+  ILockManager lockManager = LockManagerFactory.make(threadContext);
+
+  /** If the global cluster property "storehopcount" is set to false(defaults to true), disable support for hopcount handling completely,
+  * the hopcount information should not appear in the UI for any job.
+  */
+  Boolean storeHopCount = lockManager.getSharedConfiguration().getBooleanProperty("org.apache.manifoldcf.crawler.jobs.storehopcount",true);
+
   String jobID = variableContext.getParameter("jobid");
   IJobDescription job = manager.load(new Long(jobID));
   if (job == null)
@@ -595,7 +602,7 @@
       }
     }
 
-    if (relationshipTypes != null && relationshipTypes.length > 0)
+    if (storeHopCount && relationshipTypes != null && relationshipTypes.length > 0)
     {
       int k = 0;
       while (k < relationshipTypes.length)
diff --git a/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java b/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java
index 5731be3..f5edb9d 100644
--- a/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java
+++ b/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/HopCount.java
@@ -148,6 +148,14 @@
   /** Thread context */
   protected IThreadContext threadContext;
   
+  /** Lock manager */
+  protected final ILockManager lockManager;
+
+  /** If the global cluster property "storehopcount" is set to false(defaults to true), disable support for hopcount handling completely,
+  * the hopcount will never be recorded in the "intrinsiclink" or "hopcount" tables for any job at all.
+  */
+  protected static Boolean storeHopCount = true;
+
   /** Constructor.
   *@param database is the database handle.
   */
@@ -158,6 +166,8 @@
     this.threadContext = tc;
     intrinsicLinkManager = new IntrinsicLink(database);
     deleteDepsManager = new HopDeleteDeps(database);
+    lockManager = LockManagerFactory.make(tc);
+    storeHopCount = lockManager.getSharedConfiguration().getBooleanProperty("org.apache.manifoldcf.crawler.jobs.storehopcount",true);
   }
 
   /** Install or upgrade.
@@ -389,6 +399,12 @@
     // this method would need to be revised to not process any additions until the finishParents() call
     // is made.  At the moment, revertParents() is not used by any thread.
     // TBD, MHL
+    if (!storeHopCount)
+    {
+      // Do nothing
+      return null;
+    }
+
     boolean[] rval = new boolean[targetDocumentIDHashes.length];
     for (int i = 0; i < rval.length; i++)
     {