diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-02-26 15:44:39 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-02-29 13:26:54 +0100 |
commit | 25c379d3e6620bd94d77c8990d14640941baed00 (patch) | |
tree | e0a24692bc3de3c38571f716150ecadfa569337e /server | |
parent | 0a4969fa9f5d55f397406da18b045d64f90f6442 (diff) | |
download | sonarqube-25c379d3e6620bd94d77c8990d14640941baed00.tar.gz sonarqube-25c379d3e6620bd94d77c8990d14640941baed00.zip |
SONAR-7330 Remove Dto interface from RuleDto and ActiveRuleDto
Diffstat (limited to 'server')
5 files changed, 14 insertions, 20 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java index b53ffdd268a..03f4b64f31b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java @@ -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); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java index 0acc2497660..0ee0dd0d4a5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/RuleUpdater.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java index ae4ea2e5343..9b01137e134 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapper.java @@ -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())); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index f6be4c25a73..ae72e14747f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java index 6c8f2d5be46..684c0fd06c1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java @@ -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(); |