]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 11 Dec 2014 09:15:41 +0000 (10:15 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 11 Dec 2014 16:30:09 +0000 (17:30 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedUsersLongDates.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterFactory.java
server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java

index 5311c4285e6523133a8f9450eb5c81df45000cd7..5324120c6e3b49c66423c5e96cbd83ddee720d78 100644 (file)
@@ -40,33 +40,40 @@ public class FeedUsersLongDates extends BaseDataChange {
 
   @Override
   public void execute(Context context) throws SQLException {
-    final long now = system.now();
-
     MassUpdate massUpdate = context.prepareMassUpdate();
     massUpdate.select("SELECT u.id, u.created_at, u.updated_at FROM users u WHERE created_at_ms IS NULL");
     massUpdate.update("UPDATE users SET created_at_ms=?, updated_at_ms=? WHERE id=?");
     massUpdate.rowPluralName("users");
-    massUpdate.execute(new MassUpdate.Handler() {
-      @Override
-      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
-        Long id = row.getLong(1);
-        Date createdAt = row.getDate(2);
-        Date updatedAt = row.getDate(3);
+    massUpdate.execute(new RowHandler(system.now()));
+  }
+
+  private static class RowHandler implements MassUpdate.Handler {
+
+    private final long now;
 
-        if (createdAt == null) {
-          update.setLong(1, now);
-        } else {
-          update.setLong(1, Math.min(now, createdAt.getTime()));
-        }
-        if (updatedAt == null) {
-          update.setLong(2, now);
-        } else {
-          update.setLong(2, Math.min(now, updatedAt.getTime()));
-        }
-        update.setLong(3, id);
-        return true;
+    private RowHandler(long now) {
+      this.now = now;
+    }
+
+    @Override
+    public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+      Long id = row.getLong(1);
+      Date createdAt = row.getDate(2);
+      Date updatedAt = row.getDate(3);
+
+      if (createdAt == null) {
+        update.setLong(1, now);
+      } else {
+        update.setLong(1, Math.min(now, createdAt.getTime()));
+      }
+      if (updatedAt == null) {
+        update.setLong(2, now);
+      } else {
+        update.setLong(2, Math.min(now, updatedAt.getTime()));
       }
-    });
+      update.setLong(3, id);
+      return true;
+    }
   }
 
 }
index 7b607a8e7d42c9d9499960dce8a148c363b4bb59..2da4ffc443cc12e49adc9a383e3693d0d3c2d70e 100644 (file)
@@ -35,7 +35,6 @@ import javax.annotation.Nullable;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 
-import java.io.Serializable;
 import java.io.StringReader;
 import java.util.Collections;
 import java.util.Comparator;
@@ -104,7 +103,7 @@ public class DuplicationsParser implements ServerComponent {
   }
 
   @VisibleForTesting
-  static class DuplicationComparator implements Comparator<Duplication>, Serializable {
+  static class DuplicationComparator implements Comparator<Duplication> {
 
     private final ComponentDto component;
 
@@ -146,7 +145,7 @@ public class DuplicationsParser implements ServerComponent {
     }
   }
 
-  private static class BlockComparator implements Comparator<Block>, Serializable {
+  private static class BlockComparator implements Comparator<Block> {
     @Override
     public int compare(@Nullable Block b1,
       @Nullable Block b2) {
index d572a320bfada730895cc42bce49debaf63e91c2..f9f3df840862aae8b78720c8c9871907b6c5e0d4 100644 (file)
@@ -170,8 +170,11 @@ public class MeasureFilterFactory implements ServerComponent {
     });
     String val = "('" + Joiner.on("', '").skipNulls().join(alertLevelsUppercase) + "')";
     Metric metric = metricFinder.findByKey(CoreMetrics.ALERT_STATUS_KEY);
-    MeasureFilterCondition.Operator operator = MeasureFilterCondition.Operator.fromCode("in");
-    return new MeasureFilterCondition(metric, operator, val);
+    if (metric != null) {
+      MeasureFilterCondition.Operator operator = MeasureFilterCondition.Operator.fromCode("in");
+      return new MeasureFilterCondition(metric, operator, val);
+    }
+    return null;
   }
 
   private List<String> toList(@Nullable Object obj) {
index e21ad4f8796f91b6fdce55901256f62d9222a84c..0c823713fb5f02eccc3e0f33b6e95948baad59ae 100644 (file)
@@ -133,7 +133,7 @@ public class CreateAction implements RequestHandler {
           .setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION))
           .setSeverity(request.mandatoryParam(PARAM_SEVERITY))
           .setStatus(RuleStatus.valueOf(request.mandatoryParam(PARAM_STATUS)))
-          .setPreventReactivation(request.paramAsBoolean(PARAM_PREVENT_REACTIVATION));
+          .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION));
         String params = request.param(PARAMS);
         if (!Strings.isNullOrEmpty(params)) {
           newRule.setParameters(KeyValueFormat.parse(params));
@@ -146,7 +146,7 @@ public class CreateAction implements RequestHandler {
           .setName(request.mandatoryParam(PARAM_NAME))
           .setMarkdownDescription(request.mandatoryParam(PARAM_DESCRIPTION))
           .setSeverity(request.param(PARAM_SEVERITY))
-          .setPreventReactivation(request.paramAsBoolean(PARAM_PREVENT_REACTIVATION));
+          .setPreventReactivation(request.mandatoryParamAsBoolean(PARAM_PREVENT_REACTIVATION));
         writeResponse(response, service.create(newRule));
       }
     } catch (ReactivationException e) {