diff options
5 files changed, 34 insertions, 30 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java b/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java index 98111b30275..78180abc505 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualitygate/db/QualityGateConditionDto.java @@ -143,7 +143,7 @@ public class QualityGateConditionDto { return warningThreshold; } - public QualityGateConditionDto setWarningThreshold(String warningThreshold) { + public QualityGateConditionDto setWarningThreshold(@Nullable String warningThreshold) { this.warningThreshold = warningThreshold; return this; } @@ -152,7 +152,7 @@ public class QualityGateConditionDto { return errorThreshold; } - public QualityGateConditionDto setErrorThreshold(String errorThreshold) { + public QualityGateConditionDto setErrorThreshold(@Nullable String errorThreshold) { this.errorThreshold = errorThreshold; return this; } @@ -180,25 +180,29 @@ public class QualityGateConditionDto { } public static Collection<String> getOperatorsForType(ValueType metricType) { - if (metricType == null) { - return Collections.emptySet(); - } else { + Collection<String> operators = Collections.emptySet(); + if (metricType != null) { switch(metricType) { case BOOL: - return BOOLEAN_OPERATORS; + operators = BOOLEAN_OPERATORS; + break; case LEVEL: - return LEVEL_OPERATORS; + operators = LEVEL_OPERATORS; + break; case STRING: - return STRING_OPERATORS; + operators = STRING_OPERATORS; + break; case INT: case FLOAT: case PERCENT: case MILLISEC: case RATING: - return NUMERIC_OPERATORS; + operators = NUMERIC_OPERATORS; + break; default: - return Collections.emptySet(); + operators = Collections.emptySet(); } } + return operators; } } diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java index 599a13976e9..fc15784b0f6 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java +++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGates.java @@ -20,10 +20,8 @@ package org.sonar.server.qualitygate; import com.google.common.base.Predicate; - -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; import com.google.common.base.Strings; +import com.google.common.collect.Collections2; import org.apache.commons.lang.StringUtils; import org.elasticsearch.common.collect.Lists; import org.sonar.api.measures.CoreMetrics; @@ -195,7 +193,7 @@ public class QualityGates { }); } - private void validateCondition(Metric metric, String operator, String warningThreshold, String errorThreshold, Integer period) { + private void validateCondition(Metric metric, String operator, @Nullable String warningThreshold, @Nullable String errorThreshold, @Nullable Integer period) { List<Message> validationMessages = Lists.newArrayList(); validateMetric(metric, validationMessages); validateOperator(metric, operator, validationMessages); @@ -206,7 +204,7 @@ public class QualityGates { } } - private void validatePeriod(Metric metric, Integer period, List<Message> validationMessages) { + private void validatePeriod(Metric metric, @Nullable Integer period, List<Message> validationMessages) { if (period == null) { if (metric.getKey().startsWith("new_")) { validationMessages.add(Message.of("A period must be selected for differential metrics.")); @@ -216,7 +214,7 @@ public class QualityGates { } } - private void validateThresholds(String warningThreshold, String errorThreshold, List<Message> validationMessages) { + private void validateThresholds(@Nullable String warningThreshold, @Nullable String errorThreshold, List<Message> validationMessages) { if (warningThreshold == null && errorThreshold == null) { validationMessages.add(Message.of("At least one threshold (warning, error) must be set.")); } diff --git a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java index 87069137dde..e71f697ce93 100644 --- a/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java +++ b/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWs.java @@ -20,7 +20,6 @@ package org.sonar.server.qualitygate.ws; import org.sonar.api.measures.Metric; - import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.RequestHandler; import org.sonar.api.server.ws.Response; @@ -39,6 +38,10 @@ import java.util.Collection; public class QualityGatesWs implements WebService { + private static final String PARAM_PAGE_SIZE = "pageSize"; + private static final String PARAM_PAGE = "page"; + private static final String PARAM_QUERY = "query"; + private static final String PARAM_SELECTED = "selected"; private static final String PARAM_NAME = "name"; private static final String PARAM_ERROR = "error"; private static final String PARAM_WARNING = "warning"; @@ -204,10 +207,10 @@ public class QualityGatesWs implements WebService { } }); search.newParam(PARAM_GATE_ID).setDescription("The numerical ID of the quality gate."); - search.newParam("selected").setDescription("Optionally, to search for projects associated (selected=selected) or not (selected=deselected)."); - search.newParam("query").setDescription("Optionally, part of the name of the projects to search for."); - search.newParam("page"); - search.newParam("pageSize"); + search.newParam(PARAM_SELECTED).setDescription("Optionally, to search for projects associated (selected=selected) or not (selected=deselected)."); + search.newParam(PARAM_QUERY).setDescription("Optionally, part of the name of the projects to search for."); + search.newParam(PARAM_PAGE); + search.newParam(PARAM_PAGE_SIZE); NewAction select = controller.newAction("select") .setPost(true) @@ -259,16 +262,16 @@ public class QualityGatesWs implements WebService { protected void search(Request request, Response response) { Association associations = projectFinder.find(ProjectQgateAssociationQuery.builder() .gateId(request.requiredParam(PARAM_GATE_ID)) - .membership(request.param("selected")) - .projectSearch(request.param("query")) - .pageIndex(request.intParam("page")) - .pageSize(request.intParam("pageSize")) + .membership(request.param(PARAM_SELECTED)) + .projectSearch(request.param(PARAM_QUERY)) + .pageIndex(request.intParam(PARAM_PAGE)) + .pageSize(request.intParam(PARAM_PAGE_SIZE)) .build()); JsonWriter writer = response.newJsonWriter(); writer.beginObject().prop("more", associations.hasMoreResults()); writer.name("results").beginArray(); for (ProjectQgateAssociation project: associations.projects()) { - writer.beginObject().prop("id", project.id()).prop("name", project.name()).prop("selected", project.isMember()).endObject(); + writer.beginObject().prop("id", project.id()).prop("name", project.name()).prop(PARAM_SELECTED, project.isMember()).endObject(); } writer.endArray().endObject().close(); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGate.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGate.java index 3a2279e7467..eb336235449 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGate.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/QualityGate.java @@ -24,7 +24,7 @@ package org.sonar.wsclient.qualitygate; */ public interface QualityGate { - long id(); + Long id(); String name(); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGate.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGate.java index 0d86d899206..c964877238f 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGate.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/qualitygate/internal/DefaultQualityGate.java @@ -19,12 +19,11 @@ */ package org.sonar.wsclient.qualitygate.internal; +import org.sonar.wsclient.qualitygate.QualityGate; import org.sonar.wsclient.unmarshallers.JsonUtils; import java.util.Map; -import org.sonar.wsclient.qualitygate.QualityGate; - public class DefaultQualityGate implements QualityGate { private Map<String, String> json; @@ -34,7 +33,7 @@ public class DefaultQualityGate implements QualityGate { } @Override - public long id() { + public Long id() { return JsonUtils.getLong(json, "id"); } |