]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7330 Remove Dto interface from RuleDto and ActiveRuleDto
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 26 Feb 2016 14:44:39 +0000 (15:44 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 29 Feb 2016 12:26:54 +0000 (13:26 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java
server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
sonar-db/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java
sonar-db/src/main/java/org/sonar/db/rule/RuleDto.java
sonar-db/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
sonar-db/src/main/resources/org/sonar/db/rule/RuleMapper.xml

index b53ffdd268a4799c979380238dbd31a2a1978252..03f4b64f31bad9edf2c694373d74f23b83c54177 100644 (file)
@@ -28,7 +28,6 @@ import com.google.common.collect.Sets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -174,8 +173,6 @@ public class RegisterRules implements Startable {
       .setSystemTags(ruleDef.tags())
       .setCreatedAtInMs(system2.now())
       .setUpdatedAtInMs(system2.now());
-    ruleDto.setCreatedAt(new Date(system2.now()));
-    ruleDto.setUpdatedAt(new Date(system2.now()));
     if (ruleDef.htmlDescription() != null) {
       ruleDto.setDescription(ruleDef.htmlDescription());
       ruleDto.setDescriptionFormat(Format.HTML);
@@ -457,7 +454,6 @@ public class RegisterRules implements Startable {
 
   private void update(DbSession session, RuleDto rule){
     rule.setUpdatedAtInMs(system2.now());
-    rule.setUpdatedAt(new Date(system2.now()));
     dbClient.ruleDao().update(session, rule);
   }
 }
index 0acc2497660cf87361f988db123a5293754ab0b5..0ee0dd0d4a5b63e2ee72da1c4e24777e1fa62670 100644 (file)
@@ -307,7 +307,6 @@ public class RuleUpdater {
 
   private void update(DbSession session, RuleDto rule) {
     rule.setUpdatedAtInMs(system.now());
-    rule.setUpdatedAt(new Date(system.now()));
     dbClient.ruleDao().update(session, rule);
   }
 
index ae4ea2e5343e9549e11fdd10b456f239338f1aa4..9b01137e1342e9244167af8e4548b8fec88f097d 100644 (file)
@@ -170,8 +170,8 @@ public class RuleMapper {
   }
 
   private static void setCreatedAt(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
-    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.CREATED_AT) && ruleDto.getCreatedAt() != null) {
-      ruleResponse.setCreatedAt(formatDateTime(ruleDto.getCreatedAt()));
+    if (shouldReturnField(fieldsToReturn, RuleNormalizer.RuleField.CREATED_AT)) {
+      ruleResponse.setCreatedAt(formatDateTime(ruleDto.getCreatedAtInMs()));
     }
   }
 
index f6be4c25a73ca49e9fee2e7d713e53d0189f56e7..ae72e14747fd2348e1fc5a07e78744737da1e9dd 100644 (file)
@@ -104,8 +104,8 @@ public class RegisterRulesTest {
     assertThat(rule1.getSystemTags()).containsOnly("tag1", "tag2", "tag3");
     assertThat(rule1.getConfigKey()).isEqualTo("config1");
     assertThat(rule1.getStatus()).isEqualTo(RuleStatus.BETA);
-    assertThat(rule1.getCreatedAt()).isEqualTo(DATE1);
-    assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1);
+    assertThat(rule1.getCreatedAtInMs()).isEqualTo(DATE1.getTime());
+    assertThat(rule1.getUpdatedAtInMs()).isEqualTo(DATE1.getTime());
     assertThat(rule1.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
     assertThat(rule1.getDefaultRemediationCoefficient()).isEqualTo("5d");
     assertThat(rule1.getDefaultRemediationOffset()).isEqualTo("10h");
@@ -148,8 +148,8 @@ public class RegisterRulesTest {
     assertThat(rule1.getNoteData()).isEqualTo("user *note*");
     assertThat(rule1.getNoteUserLogin()).isEqualTo("marius");
     assertThat(rule1.getStatus()).isEqualTo(RuleStatus.READY);
-    assertThat(rule1.getCreatedAt()).isEqualTo(DATE1);
-    assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2);
+    assertThat(rule1.getCreatedAtInMs()).isEqualTo(DATE1.getTime());
+    assertThat(rule1.getUpdatedAtInMs()).isEqualTo(DATE2.getTime());
     // TODO check remediation function
 
     List<RuleParamDto> params = dbClient.ruleDao().selectRuleParamsByRuleKey(dbTester.getSession(), RULE_KEY1);
@@ -161,7 +161,7 @@ public class RegisterRulesTest {
     // rule2 has been removed -> status set to REMOVED but db row is not deleted
     RuleDto rule2 = dbClient.ruleDao().selectOrFailByKey(dbTester.getSession(), RULE_KEY2);
     assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED);
-    assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2);
+    assertThat(rule2.getUpdatedAtInMs()).isEqualTo(DATE2.getTime());
 
     // rule3 has been created
     RuleDto rule3 = dbClient.ruleDao().selectOrFailByKey(dbTester.getSession(), RULE_KEY3);
@@ -273,8 +273,8 @@ public class RegisterRulesTest {
     execute(new FakeRepositoryV1());
 
     RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(dbTester.getSession(), RULE_KEY1);
-    assertThat(rule1.getCreatedAt()).isEqualTo(DATE1);
-    assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1);
+    assertThat(rule1.getCreatedAtInMs()).isEqualTo(DATE1.getTime());
+    assertThat(rule1.getUpdatedAtInMs()).isEqualTo(DATE1.getTime());
   }
 
   @Test
@@ -306,7 +306,7 @@ public class RegisterRulesTest {
     // -> rule2 is still removed, but not update at DATE3
     rule2 = dbClient.ruleDao().selectOrFailByKey(dbTester.getSession(), RULE_KEY2);
     assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED);
-    assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2);
+    assertThat(rule2.getUpdatedAtInMs()).isEqualTo(DATE2.getTime());
 
     assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getIds()).containsOnly(RULE_KEY1, RULE_KEY3);
   }
index 6c8f2d5be46a985eaa3d3826bbb3d7169ff92b8e..684c0fd06c11c1de3d68da911e5d1d6ff519ca44 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.startup;
 
-import java.util.Date;
 import javax.annotation.Nullable;
 import org.junit.ClassRule;
 import org.junit.Rule;
@@ -91,12 +90,12 @@ public class ClearRulesOverloadedDebtTest {
   @Test
   public void not_update_rule_debt_not_overridden() throws Exception {
     RuleDto rule = insertRuleDto(RULE_KEY_1, null, null, null, null);
-    Date updateAt = rule.getUpdatedAt();
+    long updateAt = rule.getUpdatedAtInMs();
 
     underTest.start();
 
     RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
-    assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
+    assertThat(reloaded.getUpdatedAtInMs()).isEqualTo(updateAt);
     verifyRuleHasNotOverriddenDebt(RULE_KEY_1);
 
     verifyTaskRegistered();
@@ -107,12 +106,12 @@ public class ClearRulesOverloadedDebtTest {
   public void not_update_rule_debt_when_sqale_is_installed() throws Exception {
     insertSqaleProperty();
     RuleDto rule = insertRuleDto(RULE_KEY_1, SUB_CHARACTERISTIC_ID, "LINEAR", null, "1d");
-    Date updateAt = rule.getUpdatedAt();
+    long updateAt = rule.getUpdatedAtInMs();
 
     underTest.start();
 
     RuleDto reloaded = ruleDao.selectOrFailByKey(dbSession, RULE_KEY_1);
-    assertThat(reloaded.getUpdatedAt()).isEqualTo(updateAt);
+    assertThat(reloaded.getUpdatedAtInMs()).isEqualTo(updateAt);
 
     verifyTaskRegistered();
     verifyEmptyLog();
index 2f6328e413da5c2502273e52b9b17ab18a45a8c3..0112420c6c799b0453965c75e832574da4f33b83 100644 (file)
@@ -27,11 +27,10 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.ActiveRule;
-import org.sonar.db.rule.SeverityUtil;
-import org.sonar.db.Dto;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.SeverityUtil;
 
-public class ActiveRuleDto extends Dto<ActiveRuleKey> {
+public class ActiveRuleDto {
 
   public static final String INHERITED = ActiveRule.INHERITED;
   public static final String OVERRIDES = ActiveRule.OVERRIDES;
@@ -45,7 +44,7 @@ public class ActiveRuleDto extends Dto<ActiveRuleKey> {
   private long createdAtInMs;
   private long updatedAtInMs;
 
-  //These fields do not exists in db, it's only retrieve by joins
+  // These fields do not exists in db, it's only retrieve by joins
   private Integer parentId;
   private String repository;
   private String ruleField;
@@ -54,7 +53,6 @@ public class ActiveRuleDto extends Dto<ActiveRuleKey> {
   /**
    * @deprecated for internal use, should be private
    */
-  @Deprecated
   public ActiveRuleDto setKey(ActiveRuleKey key) {
     this.repository = key.ruleKey().repository();
     this.ruleField = key.ruleKey().rule();
@@ -62,7 +60,6 @@ public class ActiveRuleDto extends Dto<ActiveRuleKey> {
     return this;
   }
 
-  @Override
   public ActiveRuleKey getKey() {
     return ActiveRuleKey.of(profileKey, RuleKey.of(repository, ruleField));
   }
index 11e38b067c9eac78df751eced4f078de9c9029b3..3bf350b777c93c8cd069ffae277ac8f4e9c93b6d 100644 (file)
@@ -33,12 +33,10 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
-import org.sonar.db.Dto;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
-// TODO remove extends Dto
-public class RuleDto extends Dto<RuleKey> {
+public class RuleDto {
 
   public static final int DISABLED_CHARACTERISTIC_ID = -1;
 
@@ -79,7 +77,6 @@ public class RuleDto extends Dto<RuleKey> {
   private long createdAtInMs;
   private long updatedAtInMs;
 
-  @Override
   public RuleKey getKey() {
     if (key == null) {
       key = RuleKey.of(getRepositoryKey(), getRuleKey());
index ebeecc1030dcf562a142a167184036630aabba82..a79f5e4103e1bac9b985ef5fb63019ecaa720681 100644 (file)
@@ -12,8 +12,6 @@
     r.plugin_rule_key as "rulefield",
     r.plugin_name as "repository",
     qp.kee as "profileKey",
-    a.created_at as "createdAt",
-    a.updated_at as "updatedAt",
     a.created_at_ms as "createdAtInMs",
     a.updated_at_ms as "updatedAtInMs"
   </sql>
@@ -31,8 +29,6 @@
     a.failure_level as severity,
     a.inheritance as inheritance,
     active_rule_parent.id as parentId,
-    a.created_at as "createdAt",
-    a.updated_at as "updatedAt",
     a.created_at_ms as "createdAtInMs",
     a.updated_at_ms as "updatedAtInMs"
   </sql>
@@ -58,8 +54,8 @@
   </select>
 
   <insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO active_rules (profile_id, rule_id, failure_level, inheritance, created_at, updated_at, created_at_ms, updated_at_ms)
-    VALUES (#{profileId}, #{ruleId}, #{severity}, #{inheritance}, #{createdAt}, #{updatedAt}, #{createdAtInMs}, #{updatedAtInMs})
+    INSERT INTO active_rules (profile_id, rule_id, failure_level, inheritance, created_at_ms, updated_at_ms)
+    VALUES (#{profileId}, #{ruleId}, #{severity}, #{inheritance}, #{createdAtInMs}, #{updatedAtInMs})
   </insert>
 
   <update id="update" parameterType="ActiveRule">
@@ -68,7 +64,6 @@
     rule_id=#{ruleId},
     failure_level=#{severity},
     inheritance=#{inheritance},
-    updated_at=#{updatedAt},
     updated_at_ms=#{updatedAtInMs}
     WHERE id=#{id}
   </update>
index 3673dc55619bc3e47e42b0bdb9fb58ca48803553..4d98081a923d333c2c49c1cf8b27aef283cdd218 100644 (file)
@@ -31,8 +31,6 @@
     r.effort_to_fix_description as "effortToFixDescription",
     r.tags as "tagsField",
     r.system_tags as "systemTagsField",
-    r.created_at as "createdAt",
-    r.updated_at as "updatedAt",
     r.created_at_ms as "createdAtInMs",
     r.updated_at_ms as "updatedAtInMs"
   </sql>
     effort_to_fix_description=#{effortToFixDescription},
     tags=#{tagsField},
     system_tags=#{systemTagsField},
-    updated_at=#{updatedAt},
     updated_at_ms=#{updatedAtInMs}
     WHERE id=#{id}
   </update>
     characteristic_id, default_characteristic_id, remediation_function, default_remediation_function,
     remediation_coeff, default_remediation_coeff, remediation_offset, default_remediation_offset,
     effort_to_fix_description, tags, system_tags, note_data, note_user_login, note_created_at, note_updated_at,
-    created_at, updated_at, created_at_ms, updated_at_ms)
+    created_at_ms, updated_at_ms)
   </sql>
 
   <insert id="insert" parameterType="Rule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     #{subCharacteristicId}, #{defaultSubCharacteristicId}, #{remediationFunction}, #{defaultRemediationFunction},
     #{remediationCoefficient}, #{defaultRemediationCoefficient}, #{remediationOffset}, #{defaultRemediationOffset},
     #{effortToFixDescription}, #{tagsField}, #{systemTagsField}, #{noteData}, #{noteUserLogin}, #{noteCreatedAt},
-    #{noteUpdatedAt}, #{createdAt}, #{updatedAt}, #{createdAtInMs}, #{updatedAtInMs})
+    #{noteUpdatedAt}, #{createdAtInMs}, #{updatedAtInMs})
   </insert>
 
   <insert id="batchInsert" parameterType="Rule" useGeneratedKeys="false">
     #{remediationOffset,jdbcType=VARCHAR}, #{defaultRemediationOffset,jdbcType=VARCHAR},
     #{effortToFixDescription}, #{tagsField}, #{systemTagsField}, #{noteData}, #{noteUserLogin}, #{noteCreatedAt},
     #{noteUpdatedAt,jdbcType=TIMESTAMP},
-    #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
     #{createdAtInMs,jdbcType=BIGINT}, #{updatedAtInMs,jdbcType=BIGINT}
     )
   </insert>