]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5012 - Removed empty facets.
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 23 May 2014 14:26:37 +0000 (16:26 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 23 May 2014 15:39:03 +0000 (17:39 +0200)
sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml
sonar-server/src/main/java/org/sonar/server/db/Dao.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleService.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/persistence/ActiveRuleDao.java
sonar-server/src/main/java/org/sonar/server/rule2/index/RuleIndex.java
sonar-server/src/main/java/org/sonar/server/search/IndexClient.java
sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java [new file with mode: 0644]

index 45f243809316a9f4ceaedd4554057c8a5f20ab5d..bb120c7b4b0d4f514d4348674e631786e05a519c 100644 (file)
     LEFT JOIN active_rules active_rule_parent ON active_rule_parent.profile_id=profile_parent.id AND a.rule_id=active_rule_parent.rule_id
   </sql>
 
+    <select id="selectAllKeysAfterTimestamp" parameterType="Date" resultType="map">
+        SELECT
+        rule.plugin_rule_key as rule,
+        rule.plugin_name as repository,
+        profile.name as profile,
+        profile.language as language
+        FROM active_rules a
+        <include refid="activeRuleKeyJoin"/>
+        <where>
+            AND profile.name = #{profile}
+            AND profile.language = #{language}
+            AND rule.plugin_rule_key = #{rule}
+            AND rule.plugin_name = #{repository}
+        </where>
+    </select>
+
   <insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO active_rules (profile_id, rule_id, failure_level, inheritance)
     VALUES (#{profileId}, #{ruleId}, #{severity}, #{inheritance})
index b061a10f89c2e430fb5b644e0dd9af1f125ed088..86e04bfa43ab291e1a7d73db749e6a8174c7df71 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.db;
 
 import org.sonar.api.ServerComponent;
-import org.sonar.core.persistence.Dto;
 import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.Dto;
 
 import javax.annotation.CheckForNull;
 import java.io.Serializable;
@@ -49,6 +49,6 @@ public interface Dao<E extends Dto<K>, K extends Serializable> extends ServerCom
 
   void deleteByKey(K key, DbSession session);
 
-  Iterable<K> keysOfRowsUpdatedAfter(long timestamp, DbSession session);
+  void synchronizeAfter(long timestamp, DbSession session);
 
 }
index b5484164ed2264b4d0ca0f10390ef4510e73ab30..846b36531cce04937e83479c24af69227b89d35f 100644 (file)
@@ -90,12 +90,12 @@ public class ActiveRuleService implements ServerComponent {
       List<ActiveRuleChange> changes = activate(activation, dbSession);
       if (!changes.isEmpty()) {
         dbSession.commit();
-        previewCache.reportGlobalModification();
-      }
-      return changes;
-    } finally {
-      dbSession.close();
-    }
+    previewCache.reportGlobalModification();
+  }
+  return changes;
+} finally {
+  dbSession.close();
+  }
   }
 
   /**
index 1d525c512af51848bc727a8ad4fbad0f8dadc58f..daf2f7744af176aca84a3edb9f01b0712934e308 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.server.qualityprofile.persistence;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.DbSession;
@@ -33,15 +35,14 @@ import org.sonar.core.qualityprofile.db.QualityProfileDao;
 import org.sonar.core.qualityprofile.db.QualityProfileDto;
 import org.sonar.core.qualityprofile.db.QualityProfileKey;
 import org.sonar.core.rule.RuleDto;
-import org.sonar.core.rule.RuleParamDto;
 import org.sonar.server.db.BaseDao;
 import org.sonar.server.qualityprofile.QProfile;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexDefinition;
 import org.sonar.server.rule2.persistence.RuleDao;
 
+import java.util.Date;
 import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
+import java.util.Map;
 
 public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, ActiveRuleKey> {
 
@@ -61,8 +62,15 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti
   }
 
   @Override
-  public Iterable<ActiveRuleKey> keysOfRowsUpdatedAfter(long timestamp, DbSession session) {
-    throw new UnsupportedOperationException("Need to implement ActiveRuleDto.doGetByKey() method");
+  public void synchronizeAfter(long timestamp, DbSession session) {
+    session.select("selectAllKeysAfterTimestamp",new Date(timestamp), new ResultHandler() {
+      @Override
+      public void handleResult(ResultContext context) {
+        Map<String, Object> resultObject = (Map<String, Object>) context.getResultObject();
+        resultObject.get(|TOTO);
+        //session.enqueue();
+      }
+    });
   }
 
 
index af103e3446153f282acc0d16a770a5ecc2f7eec1..0b1db75a65ad8de99b91f3d72dc809b90e17e2c9 100644 (file)
@@ -332,7 +332,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
       .field(RuleNormalizer.RuleField.LANGUAGE.key())
       .order(Terms.Order.count(false))
       .size(10)
-      .minDocCount(0));
+      .minDocCount(1));
 
      /* the Tag facet */
     query.addAggregation(AggregationBuilders
@@ -340,7 +340,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
       .field(RuleNormalizer.RuleField._TAGS.key())
       .order(Terms.Order.count(false))
       .size(10)
-      .minDocCount(0));
+      .minDocCount(1));
 
      /* the Repo facet */
     query.addAggregation(AggregationBuilders
@@ -348,7 +348,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
       .field(RuleNormalizer.RuleField.REPOSITORY.key())
       .order(Terms.Order.count(false))
       .size(10)
-      .minDocCount(0));
+      .minDocCount(1));
 
   }
 
index da4da7fc17a7be053b6c38c893050810ae99d1ea..6586e37618d370fbf93199278c2a2936c84c3ef7 100644 (file)
@@ -40,6 +40,15 @@ public class IndexClient implements ServerComponent {
     }
   }
 
+  public Long getLastUpdate(String indexType){
+    for(Index<?,?,?> index:indexComponents.values()){
+      if(index.getIndexType().equals(indexType)){
+        return index.getLastSynchronization();
+      }
+    }
+    throw new IllegalStateException("no index for type '"+indexType+"' is registered");
+  }
+
   public <K extends Index> K get(Class<K> clazz){
     return (K) this.indexComponents.get(clazz);
   }
@@ -50,6 +59,6 @@ public class IndexClient implements ServerComponent {
         return (K) index;
       }
     }
-    throw new IllegalStateException("no index for tyle '"+indexType+"' is registered");
+    throw new IllegalStateException("no index for type '"+indexType+"' is registered");
   }
 }
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java b/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java
new file mode 100644 (file)
index 0000000..2bebb73
--- /dev/null
@@ -0,0 +1,17 @@
+package org.sonar.server.search;
+
+import org.sonar.server.db.DbClient;
+
+/**
+ * @since 4.4
+ */
+public class IndexSynchronizer {
+
+  private final DbClient db;
+  private final IndexClient index;
+
+  public IndexSynchronizer(DbClient db, IndexClient index) {
+    this.db = db;
+    this.index = index;
+  }
+}