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;
.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);
private void update(DbSession session, RuleDto rule){
rule.setUpdatedAtInMs(system2.now());
- rule.setUpdatedAt(new Date(system2.now()));
dbClient.ruleDao().update(session, rule);
}
}
private void update(DbSession session, RuleDto rule) {
rule.setUpdatedAtInMs(system.now());
- rule.setUpdatedAt(new Date(system.now()));
dbClient.ruleDao().update(session, rule);
}
}
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()));
}
}
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");
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);
// 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);
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
// -> 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);
}
*/
package org.sonar.server.startup;
-import java.util.Date;
import javax.annotation.Nullable;
import org.junit.ClassRule;
import org.junit.Rule;
@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();
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();
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;
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;
/**
* @deprecated for internal use, should be private
*/
- @Deprecated
public ActiveRuleDto setKey(ActiveRuleKey key) {
this.repository = key.ruleKey().repository();
this.ruleField = key.ruleKey().rule();
return this;
}
- @Override
public ActiveRuleKey getKey() {
return ActiveRuleKey.of(profileKey, RuleKey.of(repository, ruleField));
}
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;
private long createdAtInMs;
private long updatedAtInMs;
- @Override
public RuleKey getKey() {
if (key == null) {
key = RuleKey.of(getRepositoryKey(), getRuleKey());
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>
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>
</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">
rule_id=#{ruleId},
failure_level=#{severity},
inheritance=#{inheritance},
- updated_at=#{updatedAt},
updated_at_ms=#{updatedAtInMs}
WHERE id=#{id}
</update>
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>