import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
+import java.util.Map;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.server.activity.Activity;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.Map;
-
public class ActiveRuleChange {
public enum Type {
activity.setData("ruleKey", getKey().ruleKey().toString());
activity.setData("profileKey", getKey().qProfile());
- for (Map.Entry<String, String> param : parameters.entrySet()) {
- if (!param.getKey().isEmpty()) {
- activity.setData("param_" + param.getKey(), param.getValue());
- }
- }
+ parameters.entrySet().stream()
+ .filter(param -> !param.getKey().isEmpty())
+ .forEach(param -> activity.setData("param_" + param.getKey(), param.getValue()));
+
if (StringUtils.isNotEmpty(severity)) {
activity.setData("severity", severity);
}
*/
package org.sonar.server.qualityprofile.ws;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
+import org.sonar.api.server.ServerSide;
import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.KeyValueFormat;
WebService.NewAction activate = controller
.createAction(ACTIVATE_ACTION)
.setDescription("Activate a rule on a Quality profile")
- .setHandler(new RequestHandler() {
- @Override
- public void handle(Request request, Response response) throws Exception {
- activate(request, response);
- }
- })
+ .setHandler(this::activate)
.setPost(true)
.setSince("4.4");
WebService.NewAction deactivate = controller
.createAction(DEACTIVATE_ACTION)
.setDescription("Deactivate a rule on a Quality profile")
- .setHandler(new RequestHandler() {
- @Override
- public void handle(Request request, Response response) throws Exception {
- deactivate(request, response);
- }
- })
+ .setHandler(this::deactivate)
.setPost(true)
.setSince("4.4");
defineActiveRuleKeyParameters(deactivate);
}
- private void defineActiveRuleKeyParameters(WebService.NewAction action) {
+ private static void defineActiveRuleKeyParameters(WebService.NewAction action) {
action.createParam(PROFILE_KEY)
.setDescription("Key of Quality profile, can be obtained through <code>api/profiles/list</code>")
.setRequired(true)
service.deactivate(ActiveRuleKey.of(request.mandatoryParam(PROFILE_KEY), ruleKey));
}
- private RuleKey readRuleKey(Request request) {
+ private static RuleKey readRuleKey(Request request) {
return RuleKey.parse(request.mandatoryParam(RULE_KEY));
}
*/
package org.sonar.server.qualityprofile.ws;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.annotation.Nonnull;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.sonar.api.resources.Language;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.client.qualityprofile.SearchWsRequest;
-import static com.google.common.collect.FluentIterable.from;
import static java.lang.String.format;
import static org.sonar.server.ws.WsUtils.checkRequest;
private final QProfileFactory profileFactory;
private final DbClient dbClient;
private final ComponentFinder componentFinder;
- private final IsLanguageKnown isLanguageKnown;
public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient,
ComponentFinder componentFinder) {
this.profileFactory = profileFactory;
this.dbClient = dbClient;
this.componentFinder = componentFinder;
- this.isLanguageKnown = new IsLanguageKnown();
}
SearchData load(SearchWsRequest request) {
profiles = findAllProfiles(request);
}
- return from(profiles).toSortedList(QProfileComparator.INSTANCE);
+ return profiles.stream().sorted(QProfileComparator.INSTANCE).collect(Collectors.toList());
}
private Collection<QProfile> findDefaultProfiles(SearchWsRequest request) {
String language = request.getLanguage();
if (language == null) {
- return from(profileLookup.allProfiles()).filter(isLanguageKnown).toList();
+ return profileLookup.allProfiles().stream().filter(qProfile -> languages.get(qProfile.language()) != null).collect(Collectors.toList());
}
return profileLookup.profiles(language);
}
}
private static void addAllFromDto(Map<String, QProfile> qualityProfiles, Collection<QualityProfileDto> list) {
- for (QualityProfileDto qualityProfileDto : list) {
- qualityProfiles.put(qualityProfileDto.getLanguage(), QualityProfileDtoToQProfile.INSTANCE.apply(qualityProfileDto));
- }
+ list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), QualityProfileDtoToQProfile.INSTANCE.apply(qualityProfile)));
}
private static void addAll(Map<String, QProfile> qualityProfiles, Collection<QProfile> list) {
- for (QProfile qProfile : list) {
- qualityProfiles.put(qProfile.language(), qProfile);
- }
+ list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.language(), qualityProfile));
}
private Set<String> getLanguageKeys() {
- return from(Arrays.asList(languages.all())).transform(LanguageToKey.INSTANCE).toSet();
+ return Arrays.stream(languages.all()).map(Language::getKey).collect(Collectors.toSet());
}
private List<QProfile> findDefaultProfiles(final DbSession dbSession, Set<String> languageKeys) {
- return from(profileFactory.getDefaults(dbSession, languageKeys))
- .transform(QualityProfileDtoToQProfile.INSTANCE)
- .toList();
+ return profileFactory.getDefaults(dbSession, languageKeys).stream()
+ .map(QualityProfileDtoToQProfile.INSTANCE)
+ .collect(Collectors.toList());
}
private static void validateRequest(SearchWsRequest request) {
}
}
- private enum LanguageToKey implements Function<Language, String> {
- INSTANCE;
-
- @Override
- @Nonnull
- public String apply(@Nonnull Language input) {
- return input.getKey();
- }
- }
-
private enum QualityProfileDtoToQProfile implements Function<QualityProfileDto, QProfile> {
INSTANCE;
@Override
- @Nonnull
- public QProfile apply(@Nonnull QualityProfileDto input) {
+ public QProfile apply(QualityProfileDto input) {
return new QProfile()
.setKey(input.getKey())
.setName(input.getName())
.setDefault(input.isDefault())
.setRulesUpdatedAt(input.getRulesUpdatedAt());
}
-
- }
-
- private class IsLanguageKnown implements Predicate<QProfile> {
- @Override
- public boolean apply(@Nonnull QProfile profile) {
- return languages.get(profile.language()) != null;
- }
}
}