public abstract K getKey();
- public void setCreatedAt(Date datetime){
+ public final void setCreatedAt(Date datetime) {
this.createdAt = datetime;
}
- public void setUpdatedAt(Date datetime){
+ public final void setUpdatedAt(Date datetime) {
this.updatedAt = datetime;
}
- public Date getCreatedAt(){
+ public final Date getCreatedAt() {
return this.createdAt;
}
- public Date getUpdatedAt(){
+ public final Date getUpdatedAt() {
return this.updatedAt;
}
}
private String name;
private String language;
private String parentKee;
- private Date createdAt, updatedAt;
private String rulesUpdatedAt;
/**
return this;
}
- public Date getCreatedAt() {
- return createdAt;
- }
-
- public void setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- }
-
- public Date getUpdatedAt() {
- return updatedAt;
- }
-
- public void setUpdatedAt(Date updatedAt) {
- this.updatedAt = updatedAt;
- }
-
public String getRulesUpdatedAt() {
return rulesUpdatedAt;
}
a.inheritance as "inheritance",
r.plugin_rule_key as "rulefield",
r.plugin_name as "repository",
- qp.kee as "profileKey"
+ qp.kee as "profileKey",
+ a.created_at as "createdAt",
+ a.updated_at as "updatedAt"
</sql>
<sql id="activeRuleKeyJoin">
a.rule_id as ruleId,
a.failure_level as severity,
a.inheritance as inheritance,
- active_rule_parent.id as parentId
+ active_rule_parent.id as parentId,
+ a.created_at as "createdAt",
+ a.updated_at as "updatedAt"
</sql>
<sql id="activeRuleJoin">
</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})
+ INSERT INTO active_rules (profile_id, rule_id, failure_level, inheritance, created_at, updated_at)
+ VALUES (#{profileId}, #{ruleId}, #{severity}, #{inheritance}, #{createdAt}, #{updatedAt})
</insert>
<update id="update" parameterType="ActiveRule">
profile_id=#{profileId},
rule_id=#{ruleId},
failure_level=#{severity},
- inheritance=#{inheritance}
+ inheritance=#{inheritance},
+ updated_at=#{updatedAt}
WHERE id=#{id}
</update>
</select>
<select id="selectById" parameterType="int" resultType="ActiveRule">
- SELECT <include refid="activeRuleColumns"/>
+ SELECT
+ <include refid="activeRuleColumns"/>
FROM active_rules a
<include refid="activeRuleJoin"/>
WHERE a.id=#{id}
FROM active_rules a
<include refid="activeRuleKeyJoin"/>
WHERE
- qp.kee = #{profileKey}
- AND r.plugin_rule_key = #{rule}
- AND r.plugin_name = #{repository}
+ qp.kee = #{profileKey}
+ AND r.plugin_rule_key = #{rule}
+ AND r.plugin_name = #{repository}
</select>
<select id="selectByProfileKey" parameterType="string" resultType="ActiveRule">
- SELECT <include refid="activeRuleKeyColumns"/>
+ SELECT
+ <include refid="activeRuleKeyColumns"/>
FROM active_rules a
<include refid="activeRuleKeyJoin"/>
where qp.kee=#{id}
</select>
<select id="selectParamByActiveRuleAndKey" parameterType="map" resultType="ActiveRuleParam">
- SELECT <include refid="activeRuleParamColumns"/>
+ SELECT
+ <include refid="activeRuleParamColumns"/>
FROM active_rule_parameters p
<where>
AND p.active_rule_id=#{activeRuleId}
return doGetNullableByKey(session, key);
}
- public E getByKey(DbSession session, K key) {
+ public final E getByKey(DbSession session, K key) {
E value = doGetNullableByKey(session, key);
if (value == null) {
throw new NotFoundException(String.format("Key '%s' not found", key));
}
@Override
- public E update(DbSession session, E item) {
+ public final E update(DbSession session, E item) {
Date now = new Date(system2.now());
update(session, item, now);
return item;
}
@Override
- public E update(DbSession session, E item, E... others) {
+ public final E update(DbSession session, E item, E... others) {
Date now = new Date(system2.now());
update(session, item, now);
for (E other : others) {
}
@Override
- public Collection<E> update(DbSession session, Collection<E> items) {
+ public final Collection<E> update(DbSession session, Collection<E> items) {
Date now = new Date(system2.now());
for (E item : items) {
update(session, item, now);
}
@Override
- public E insert(DbSession session, E item) {
+ public final E insert(DbSession session, E item) {
insert(session, item, new Date(system2.now()));
return item;
}
@Override
- public Collection<E> insert(DbSession session, Collection<E> items) {
+ public final Collection<E> insert(DbSession session, Collection<E> items) {
Date now = new Date(system2.now());
for (E item : items) {
insert(session, item, now);
}
@Override
- public E insert(DbSession session, E item, E... others) {
+ public final E insert(DbSession session, E item, E... others) {
Date now = new Date(system2.now());
insert(session, item, now);
for (E other : others) {
}
@Override
- public void delete(DbSession session, E item) {
+ public final void delete(DbSession session, E item) {
deleteByKey(session, item.getKey());
}
@Override
- public void delete(DbSession session, E item, E... others) {
+ public final void delete(DbSession session, E item, E... others) {
delete(session, item);
for (E e : others) {
delete(session, e);
}
@Override
- public void delete(DbSession session, Collection<E> items) {
+ public final void delete(DbSession session, Collection<E> items) {
for (E item : items) {
delete(session, item);
}
}
@Override
- public void deleteByKey(DbSession session, K key) {
+ public final void deleteByKey(DbSession session, K key) {
Preconditions.checkNotNull(key, "Missing key");
doDeleteByKey(session, key);
if (hasIndex()) {
}
}
- protected void enqueueUpdate(Object nestedItem, K key, DbSession session) {
+ protected final void enqueueUpdate(Object nestedItem, K key, DbSession session) {
if (hasIndex()) {
session.enqueue(new EmbeddedIndexAction<K>(
this.getIndexType(), IndexAction.Method.UPSERT, key, nestedItem));
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import javax.annotation.CheckForNull;
+import java.util.Date;
import java.util.List;
import java.util.Map;
public static final List<Inheritance> ALL = ImmutableList.of(NONE, OVERRIDES, INHERITED);
}
+ Date createdAt();
+
+ Date updatedAt();
+
ActiveRuleKey key();
String severity();
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.search.BaseDoc;
+import org.sonar.server.search.IndexUtils;
import javax.annotation.CheckForNull;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Preconditions.checkArgument(key!=null, "Invalid ActiveRuleKey!");
}
+ @Override
+ public Date createdAt() {
+ return IndexUtils.parseDateTime((String) getNullableField(ActiveRuleNormalizer.ActiveRuleField.CREATED_AT.field()));
+ }
+
+ @Override
+ public Date updatedAt() {
+ return IndexUtils.parseDateTime((String) getNullableField(ActiveRuleNormalizer.ActiveRuleField.UPDATED_AT.field()));
+ }
+
@Override
public ActiveRuleKey key() {
return this.key;
import org.sonar.server.search.es.ListUpdate;
import java.lang.reflect.Field;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRuleKey> {
public static final IndexField RULE_KEY = add(IndexField.Type.STRING, "ruleKey");
public static final IndexField PARAMS = addEmbedded("params", ActiveRuleParamField.ALL_FIELDS);
+ public static final IndexField CREATED_AT = addSortable(IndexField.Type.DATE, "createdAt");
+ public static final IndexField UPDATED_AT = addSortable(IndexField.Type.DATE, UPDATED_AT_FIELD);
+
public static Set<IndexField> ALL_FIELDS = getAllFields();
private static Set<IndexField> getAllFields() {
activeRuleDto.getInheritance() :
ActiveRule.Inheritance.NONE.name());
newRule.put(ActiveRuleField.SEVERITY.field(), activeRuleDto.getSeverityString());
+ newRule.put(ActiveRuleField.KEY.field(), key.toString());
+
+ newRule.put(ActiveRuleField.CREATED_AT.field(), activeRuleDto.getCreatedAt());
+ newRule.put(ActiveRuleField.UPDATED_AT.field(), activeRuleDto.getUpdatedAt());
DbSession session = db.openSession(false);
try {
package org.sonar.server.qualityprofile;
import com.google.common.collect.ImmutableMap;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.server.tester.ServerTester;
import javax.annotation.Nullable;
-
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.fest.assertions.Fail.fail;
import static org.sonar.server.qualityprofile.QProfileTesting.*;
-@Ignore
public class RuleActivatorMediumTest {
static final RuleKey MANUAL_RULE_KEY = RuleKey.of(RuleKey.MANUAL_REPOSITORY_KEY, "m1");
assertThat(activeRule.severity()).isEqualTo(expectedSeverity);
assertThat(activeRule.inheritance()).isEqualTo(expectedInheritance == null ? ActiveRule.Inheritance.NONE : ActiveRule.Inheritance.valueOf(expectedInheritance));
+ // Dates should be set
+ assertThat(activeRule.createdAt()).isNotNull();
+ assertThat(activeRule.updatedAt()).isNotNull();
+
// verify parameters in es
assertThat(activeRule.params()).hasSize(expectedParams.size());
for (Map.Entry<String, String> entry : expectedParams.entrySet()) {