logDoc.put(LogFields.MESSAGE.field(), dto.getMessage());
logDoc.put(LogFields.EXECUTION.field(), dto.getExecutionTime());
logDoc.put(LogFields.DATE.field(), dto.getCreatedAt());
+
+ System.out.println(" KeyValueFormat.parse(dto.getData()) = " + KeyValueFormat.parse(dto.getData()));
+
logDoc.put(LogFields.DETAILS.field(), KeyValueFormat.parse(dto.getData()));
/* Creating updateRequest */
package org.sonar.server.log.ws;
import org.sonar.api.resources.Languages;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.log.Log;
import org.sonar.server.log.index.LogNormalizer;
import org.sonar.server.search.ws.BaseMapping;
import org.sonar.server.text.MacroInterpreter;
+import java.util.Map;
+
/**
* Conversion between Log and WS JSON response
*/
addIndexStringField("userLogin", LogNormalizer.LogFields.AUTHOR.field());
addIndexStringField("message", LogNormalizer.LogFields.MESSAGE.field());
addIndexStringField("executionTime", LogNormalizer.LogFields.EXECUTION.field());
+ addField("details", new DetailField());
+ }
+
+ private static class DetailField extends IndexField<Log> {
+ DetailField() {
+ super(LogNormalizer.LogFields.DETAILS.field());
+ }
+
+ @Override
+ public void write(JsonWriter json, Log log) {
+ json.name("details").beginObject();
+ for (Map.Entry<String, String> detail : log.details().entrySet()) {
+ json.prop(detail.getKey(), detail.getValue());
+ }
+ json.endObject();
+ }
}
}
private ActiveRule.Inheritance previousInheritance = null, inheritance = null;
private Map<String, String> parameters = Maps.newHashMap();
- public ActiveRuleChange() {
- type = null;
- key = null;
- }
+ private long start;
- ActiveRuleChange(Type type, ActiveRuleKey key) {
+ private ActiveRuleChange(Type type, ActiveRuleKey key) {
this.type = type;
this.key = key;
+ this.start = System.currentTimeMillis();
}
public ActiveRuleKey getKey() {
if (this.getKey() != null) {
details.put("key", this.getKey().toString());
}
-
return details.build();
}
@Override
public Integer getExecutionTime() {
- return null;
+ return (int) (System.currentTimeMillis() - start);
+ }
+
+ public static ActiveRuleChange createFor(Type type, ActiveRuleKey key) {
+ return new ActiveRuleChange(type, key);
}
}
import org.sonar.core.log.Log;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.preview.PreviewCache;
-import org.sonar.core.qualityprofile.db.*;
+import org.sonar.core.qualityprofile.db.ActiveRuleDto;
+import org.sonar.core.qualityprofile.db.ActiveRuleKey;
+import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
+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.DbClient;
import org.sonar.server.util.TypeValidations;
import javax.annotation.Nullable;
-
import java.util.Iterator;
import java.util.List;
import java.util.Map;
if (context.activeRule() == null) {
// new activation
- change = new ActiveRuleChange(ActiveRuleChange.Type.ACTIVATED, activation.getKey());
+ change = ActiveRuleChange.createFor(ActiveRuleChange.Type.ACTIVATED, activation.getKey());
if (activation.isCascade() || context.isSameAsParent(activation)) {
change.setInheritance(ActiveRule.Inheritance.INHERITED);
}
// propagating to descendants, but child profile already overrides rule -> stop propagation
return changes;
}
- change = new ActiveRuleChange(ActiveRuleChange.Type.UPDATED, activation.getKey());
+ change = ActiveRuleChange.createFor(ActiveRuleChange.Type.UPDATED, activation.getKey());
if (activation.isCascade() && context.activeRule().getInheritance() == null) {
// activate on child, then on parent -> mark child as overriding parent
change.setInheritance(ActiveRule.Inheritance.OVERRIDES);
if (!force && !isCascade && context.activeRule().getInheritance() != null) {
throw new IllegalStateException("Cannot deactivate inherited rule '" + key.ruleKey() + "'");
}
- change = new ActiveRuleChange(ActiveRuleChange.Type.DEACTIVATED, key);
+ change = ActiveRuleChange.createFor(ActiveRuleChange.Type.DEACTIVATED, key);
changes.add(change);
persist(change, context, dbSession);
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
import org.sonar.core.log.Log;
import org.sonar.core.persistence.DbSession;
+import org.sonar.core.qualityprofile.db.ActiveRuleKey;
+import org.sonar.core.qualityprofile.db.QualityProfileKey;
import org.sonar.server.db.DbClient;
import org.sonar.server.log.LogService;
import org.sonar.server.log.index.LogIndex;
@Test
public void insert_find_active_rule_change() {
- ActiveRuleChange change = new ActiveRuleChange()
+ ActiveRuleKey key = ActiveRuleKey.of(
+ QualityProfileKey.of("profile", "java"),
+ RuleKey.of("repository", "rule"));
+ ActiveRuleChange change = ActiveRuleChange
+ .createFor(ActiveRuleChange.Type.ACTIVATED, key)
.setInheritance(ActiveRule.Inheritance.INHERITED)
.setSeverity("BLOCKER")
.setParameter("param1", "value1");
Log log = Iterables.getFirst(index.findAll().getHits(), null);
assertThat(log).isNotNull();
+ assertThat(log.details().get("key")).isEqualTo(key.toString());
}
}
\ No newline at end of file