addMandatoryValuesToFacet(facets, PARAM_TYPES, RuleType.names()); | addMandatoryValuesToFacet(facets, PARAM_TYPES, RuleType.names()); | ||||
addMandatoryValuesToFacet(facets, PARAM_COMPONENT_UUIDS, request.getComponentUuids()); | addMandatoryValuesToFacet(facets, PARAM_COMPONENT_UUIDS, request.getComponentUuids()); | ||||
for (String facetName : request.getFacets()) { | |||||
LinkedHashMap<String, Long> buckets = facets.get(facetName); | |||||
if (!FACET_ASSIGNED_TO_ME.equals(facetName)) { | |||||
if (buckets != null) { | |||||
List<String> requestParams = wsRequest.paramAsStrings(facetName); | |||||
if (requestParams != null) { | |||||
for (String param : requestParams) { | |||||
if (!buckets.containsKey(param) && !IssueQueryService.LOGIN_MYSELF.equals(param)) { | |||||
// Prevent appearance of a glitch value due to dedicated parameter for this facet | |||||
buckets.put(param, 0L); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
List<String> requestedFacets = request.getFacets(); | |||||
if (requestedFacets == null) { | |||||
return; | |||||
} | } | ||||
requestedFacets.stream() | |||||
.filter(facetName -> !FACET_ASSIGNED_TO_ME.equals(facetName)) | |||||
.forEach(facetName -> { | |||||
LinkedHashMap<String, Long> buckets = facets.get(facetName); | |||||
List<String> requestParams = wsRequest.paramAsStrings(facetName); | |||||
if (buckets == null || requestParams == null) { | |||||
return; | |||||
} | |||||
requestParams.stream() | |||||
.filter(param -> !buckets.containsKey(param) && !IssueQueryService.LOGIN_MYSELF.equals(param)) | |||||
// Prevent appearance of a glitch value due to dedicated parameter for this facet | |||||
.forEach(param -> buckets.put(param, 0L)); | |||||
}); | |||||
} | } | ||||
private void addMandatoryValuesToFacet(Facets facets, String facetName, @Nullable Iterable<String> mandatoryValues) { | |||||
private static void addMandatoryValuesToFacet(Facets facets, String facetName, @Nullable Iterable<String> mandatoryValues) { | |||||
Map<String, Long> buckets = facets.get(facetName); | Map<String, Long> buckets = facets.get(facetName); | ||||
if (buckets != null && mandatoryValues != null) { | if (buckets != null && mandatoryValues != null) { | ||||
for (String mandatoryValue : mandatoryValues) { | for (String mandatoryValue : mandatoryValues) { |
*/ | */ | ||||
package org.sonar.server.qualitygate.ws; | package org.sonar.server.qualitygate.ws; | ||||
import com.google.common.base.Function; | |||||
import com.google.common.base.Joiner; | |||||
import com.google.common.base.Optional; | import com.google.common.base.Optional; | ||||
import com.google.common.collect.Lists; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import javax.annotation.Nonnull; | |||||
import java.util.stream.Collectors; | |||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.sonar.api.measures.CoreMetrics; | import org.sonar.api.measures.CoreMetrics; | ||||
import org.sonar.api.server.ws.Request; | import org.sonar.api.server.ws.Request; | ||||
import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY; | import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_PROJECT_KEY; | ||||
public class ProjectStatusAction implements QualityGatesWsAction { | public class ProjectStatusAction implements QualityGatesWsAction { | ||||
private static final String QG_STATUSES_ONE_LINE = Joiner.on(", ") | |||||
.join(Lists.transform(Arrays.asList(ProjectStatusWsResponse.Status.values()), new Function<ProjectStatusWsResponse.Status, String>() { | |||||
@Nonnull | |||||
@Override | |||||
public String apply(@Nonnull ProjectStatusWsResponse.Status input) { | |||||
return input.toString(); | |||||
} | |||||
})); | |||||
private static final String QG_STATUSES_ONE_LINE = Arrays.stream(ProjectStatusWsResponse.Status.values()) | |||||
.map(Enum::toString) | |||||
.collect(Collectors.joining(", ")); | |||||
private static final String MSG_ONE_PARAMETER_ONLY = String.format("One (and only one) of the following parameters must be provided '%s', '%s', '%s'", | private static final String MSG_ONE_PARAMETER_ONLY = String.format("One (and only one) of the following parameters must be provided '%s', '%s', '%s'", | ||||
PARAM_ANALYSIS_ID, PARAM_PROJECT_ID, PARAM_PROJECT_KEY); | PARAM_ANALYSIS_ID, PARAM_PROJECT_ID, PARAM_PROJECT_KEY); | ||||
private final Map<String, Action> actions; | private final Map<String, Action> actions; | ||||
private Controller(NewController newController) { | private Controller(NewController newController) { | ||||
checkState(!newController.actions.isEmpty(), format("At least one action must be declared in the web service '%s'", newController.path)); | |||||
checkState(!newController.actions.isEmpty(), "At least one action must be declared in the web service '%s'", newController.path); | |||||
this.path = newController.path; | this.path = newController.path; | ||||
this.description = newController.description; | this.description = newController.description; | ||||
this.since = newController.since; | this.since = newController.since; | ||||
} | } | ||||
public NewParam createParam(String paramKey) { | public NewParam createParam(String paramKey) { | ||||
checkState(!newParams.containsKey(paramKey), | |||||
format("The parameter '%s' is defined multiple times in the action '%s'", paramKey, key)); | |||||
checkState(!newParams.containsKey(paramKey), "The parameter '%s' is defined multiple times in the action '%s'", paramKey, key); | |||||
NewParam newParam = new NewParam(paramKey); | NewParam newParam = new NewParam(paramKey); | ||||
newParams.put(paramKey, newParam); | newParams.put(paramKey, newParam); | ||||
return newParam; | return newParam; | ||||
this.responseExample = newAction.responseExample; | this.responseExample = newAction.responseExample; | ||||
this.handler = newAction.handler; | this.handler = newAction.handler; | ||||
checkState(this.handler != null, "RequestHandler is not set on action " + path); | |||||
checkState(this.handler != null, "RequestHandler is not set on action %s", path); | |||||
logWarningIf(isNullOrEmpty(this.description), "Description is not set on action " + path); | logWarningIf(isNullOrEmpty(this.description), "Description is not set on action " + path); | ||||
logWarningIf(isNullOrEmpty(this.since), "Since is not set on action " + path); | logWarningIf(isNullOrEmpty(this.since), "Since is not set on action " + path); | ||||
logWarningIf(!this.post && this.responseExample == null, "The response example is not set on action " + path); | logWarningIf(!this.post && this.responseExample == null, "The response example is not set on action " + path); |
public UpdateEventRequest(String event, String name) { | public UpdateEventRequest(String event, String name) { | ||||
this.event = requireNonNull(event, "Event key is required"); | this.event = requireNonNull(event, "Event key is required"); | ||||
this.name = requireNonNull(name, "Name is required");; | |||||
this.name = requireNonNull(name, "Name is required"); | |||||
} | } | ||||
public String getEvent() { | public String getEvent() { |