Index: apps-parent/apps-perf/src/main/java/com/thesearchagency/perf/AccountLowGranDispatcher.java
===================================================================
--- apps-parent/apps-perf/src/main/java/com/thesearchagency/perf/AccountLowGranDispatcher.java	(revision 28257)
+++ apps-parent/apps-perf/src/main/java/com/thesearchagency/perf/AccountLowGranDispatcher.java	(working copy)
@@ -133,7 +133,7 @@
            
             
             
-            String whHighGranTypes = "('" + DataSourceTable.TypeValue.WH_PIXEL + "','" + DataSourceTable.TypeValue.WH_CLIENT + "','" +DataSourceTable.TypeValue.WH_SEARCHENGINE + "','" + DataSourceTable.TypeValue.WH_POSITION + "')";
+            String whHighGranTypes = "('" + DataSourceTable.TypeValue.WH_PIXEL + "','" + DataSourceTable.TypeValue.WH_CLIENT + "','" +DataSourceTable.TypeValue.WH_SEARCHENGINE + "','" + DataSourceTable.TypeValue.WH_POSITION + "','" + DataSourceTable.TypeValue.WH_PUBLISHER + "')";
             
  
             // Find all accounts that have high-gran data. 
@@ -166,66 +166,7 @@
                 rs.close();
                 
             }
-            
-            // get publisher accounts list from accountDistributionMapTable
-            List<String> publisherFields = new ArrayList<String>();
-            publisherFields.add(AccountDistributionMapTable.ACCOUNT_ID);
-            publisherFields.add(SQLUtil.alias(SQLUtil.dbFunction(SQLUtil.GROUP_CONCAT, SQLUtil.colName(AccountDistributionMapTable.STATUS)), AccountDistributionMapTable.STATUS));
 
-            // config_full = null means not acct/dist not configured?
-            List<String> publisherWhere = new ArrayList<String>();
-            publisherWhere.add(SQLUtil.colWhereNull(AccountDistributionMapTable.CONFIG_FILE, false));
-
-            String publisherGroupBy = AccountDistributionMapTable.colName(AccountDistributionMapTable.ACCOUNT_ID);
-
-            AccountDistributionMapTable admTable = new AccountDistributionMapTable(commonDB);
-            ResultSet publisherResultSet = admTable.select(publisherFields, publisherWhere, publisherGroupBy, null);
-
-            HashSet<Integer> publisherAccounts = new HashSet<Integer>();
-
-            // check if at least one of the distribution for an account is active
-            Pattern publisherPattern = Pattern.compile("\\bactive\\b");
-
-            while (publisherResultSet.next()) {
-                Integer acctID = publisherResultSet.getInt(AccountDistributionMapTable.ACCOUNT_ID);
-                String status = publisherResultSet.getString(AccountDistributionMapTable.STATUS);
-                if (status != null) {
-                    Matcher acitveMatcher = publisherPattern.matcher(status.toLowerCase());
-                    if (acitveMatcher.find()) publisherAccounts.add(acctID);
-                }
-            }
-            
-            // add publisher accounts to dataAccounts list
-            for(Database acctDB: dbMap.keySet()) {
-                JoinTable tab = new JoinTable(acctDB, DataAvailabilityTable.fullTableName(), DataSourceTable.fullTableName(),
-                                             SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.ID),
-                                                             DataAvailabilityTable.colName(DataAvailabilityTable.DATA_SOURCE_ID)),
-                                             JoinTable.JOIN);
-                tab.addJoin(AccountTable.fullTableName(), SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.ACCOUNT_ID),
-                                                                           AccountTable.colName(AccountTable.ID)));
-            
-                Collection<String> where = (Collection<String>)getCondition();
-                where.add(SQLUtil.colWhere(DataAvailabilityTable.colName(DataAvailabilityTable.DATE), TSAConst.DATE_FORMAT.format(theDate)));
-                where.add(SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.ACCOUNT_ID), SQLUtil.IN, publisherAccounts));
-            
-                where.add(SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.TYPE), SQLUtil.EQ, DataSourceTable.TypeValue.WH_PUBLISHER));
-            
-                String order_by = DataSourceTable.colName(DataSourceTable.ACCOUNT_ID);
-            
-                Collection<String> fields = new ArrayList<String>();
-                fields.add(SQLUtil.DISTINCT);
-                fields.add(DataSourceTable.colName(DataSourceTable.ACCOUNT_ID));
-                
-                ResultSet rs = tab.select(fields, where, null, order_by);
-                
-                while(rs.next()) {
-                    Integer acctID = rs.getInt(DataSourceTable.ACCOUNT_ID);
-                    dataAccounts.add(acctID);
-                }
-                rs.close();
-                
-            }
-            
             // There are accounts with no data sources (newly configured, or old ones?) that can be processed for low gran immediately.
             HashSet<Integer> noHighGran = new HashSet<Integer>(allAccounts);
             noHighGran.removeAll(dataAccounts);
@@ -234,10 +175,7 @@
                  completedAccounts.add(acctID);
             }
 
-            // add DataSourceTable.TypeValue.WH_PUBLISHER
-            whHighGranTypes = "('" + DataSourceTable.TypeValue.WH_PIXEL + "','" + DataSourceTable.TypeValue.WH_CLIENT + "','" +DataSourceTable.TypeValue.WH_SEARCHENGINE + "','" + DataSourceTable.TypeValue.WH_POSITION + "','" + DataSourceTable.TypeValue.WH_PUBLISHER + "')";
-            
-            // Look for accounts that have completed WH_PIXEL, WH_CLIENT, and WH_SEARCHENGINE, then dispatch 
+            // Look for accounts that have completed whHighGranTypes, then dispatch 
             while(!done) {
                 
                 for(Database acctDB: dbMap.keySet()) {
@@ -247,7 +185,9 @@
                                                  JoinTable.JOIN);
                     tab.addJoin(AccountTable.fullTableName(), SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.ACCOUNT_ID),
                                                                                AccountTable.colName(AccountTable.ID)));
-                
+                    
+                    joinAccountDistributionMap(tab);
+                    
                     Collection<String> where = (Collection<String>)getCondition();
                     where.add(SQLUtil.colWhere(DataAvailabilityTable.colName(DataAvailabilityTable.DATE), TSAConst.DATE_FORMAT.format(theDate)));
                     where.add(SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.TYPE), SQLUtil.IN, whHighGranTypes));
@@ -257,22 +197,27 @@
                     Collection<String> fields = new ArrayList<String>();
                     fields.add(DataSourceTable.colName(DataSourceTable.ACCOUNT_ID));
                     fields.add(DataSourceTable.colName(DataSourceTable.TYPE));
+                    fields.add(DataSourceTable.colName(DataSourceTable.TYPE_ID));
                     fields.add(DataAvailabilityTable.colName(DataAvailabilityTable.STATUS));
+                    fields.add(SQLUtil.alias(AccountDistributionMapTable.colName(AccountDistributionMapTable.STATUS), "publisherStatus"));
                     
                     ResultSet rs = tab.select(fields, where, null, order_by);
                 
                     Integer lastAcctID = null;
                     Integer acctID = null;
                     HashMap statusMap = new HashMap();
-                    String status, type;
+                    String status;
+                    DataSourceTable.TypeValue type = null;
                     
                     int numFound = 0, numSuccess = 0;
                     
                     while(rs.next()) {
                         acctID = rs.getInt(DataSourceTable.ACCOUNT_ID);
-                        type = rs.getString(DataSourceTable.TYPE);
+                        type = DataSourceTable.TypeValue.intern(rs.getString(DataSourceTable.TYPE));
                         status = rs.getString(DataAvailabilityTable.STATUS);
                         
+                        
+                        
                         // When account ID changes, check stats
                         if (lastAcctID != null && !lastAcctID.equals(acctID)) {
                                 
@@ -297,6 +242,15 @@
                             if(status.equals(DataAvailabilityTable.StatusValue.SUCCESS.toString())) {
                                 numSuccess++;
                             }
+                            else if (status.equals(DataAvailabilityTable.StatusValue.NOT_STARTED.toString()) && DataSourceTable.TypeValue.WH_PUBLISHER == type) {
+                                String publisherStatus = rs.getString("publisherStatus");
+
+                                if (publisherStatus == null || publisherStatus.equals("INACTIVE")) {
+                                    // ignore inactive/null publisher data sources.
+                                    numFound--;
+                                    Debug.msg(Debug.TRACE, "Publisher Feed: decrementing inactive/null datasource for " + rs.getInt(DataSourceTable.TYPE_ID) + "(publisherStatus=" + publisherStatus + ")");
+                                }
+                            }
                         }
 
                         lastAcctID = acctID;
@@ -365,6 +319,23 @@
         
          Debug.debug(Debug.INFORMATION, "------------" + desc + " done");
     }
+
+
+
+    private void joinAccountDistributionMap(JoinTable aTable)
+    {
+        Collection<String> cond = new ArrayList<String>(3);
+        
+        // dataSources.type='wh_publisher' and dataSources.typeID=accountDistributionMap.distributionID and 
+        // accountDistributionMap.accountID=dataSources.accountID and accountDistributionMap.status='ACTIVE'
+        
+        cond.add(SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.TYPE), DataSourceTable.TypeValue.WH_PUBLISHER));
+        cond.add(SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.TYPE_ID), AccountDistributionMapTable.colName(AccountDistributionMapTable.DISTRIBUTION_ID)));
+        cond.add(SQLUtil.colWhere(DataSourceTable.colName(DataSourceTable.ACCOUNT_ID), AccountDistributionMapTable.colName(AccountDistributionMapTable.ACCOUNT_ID)));
+        cond.add(SQLUtil.colWhere(AccountDistributionMapTable.colName(AccountDistributionMapTable.STATUS), "ACTIVE"));
+            
+        aTable.addJoin(AccountDistributionMapTable.fullTableName(), cond, JoinTable.LEFT_JOIN);
+    }
     
     
     //----------------------------------------------------------
