.stream()
.collect(groupingBy(IssueChangeDto::getIssueKey));
- return issues
- .stream()
- .peek(i -> setChanges(changeDtoByIssueKey, i))
- .collect(toList());
+ issues.forEach(i -> setChanges(changeDtoByIssueKey, i));
+ return new ArrayList<>(issues);
}
/**
// TODO to be improved, why setOnDisabledRule(true) is not enough ?
issue.setBeingClosed(true);
}
- // FIXME
issue.setSelectedAt(System.currentTimeMillis());
result.add(issue);
});
previousIssueKey = resultObject.getKey();
DefaultIssue issue = resultObject.toDefaultIssue();
issue.setLine(line);
- // FIXME
issue.setSelectedAt(System.currentTimeMillis());
issues.add(issue);
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.sonar.server.es.textsearch.ComponentTextSearchFeature.UseCase;
private static Optional<QueryBuilder> createQuery(ComponentTextSearchQuery query, ComponentTextSearchFeature[] features, UseCase useCase) {
BoolQueryBuilder generateResults = boolQuery();
- AtomicBoolean anyFeatures = new AtomicBoolean();
Arrays.stream(features)
.filter(f -> f.getUseCase() == useCase)
- .peek(f -> anyFeatures.set(true))
.flatMap(f -> f.getQueries(query))
.forEach(generateResults::should);
- if (anyFeatures.get()) {
+ if (!generateResults.should().isEmpty()) {
return Optional.of(generateResults);
+ } else {
+ return Optional.empty();
}
- return Optional.empty();
}
public static class ComponentTextSearchQuery {
@CheckForNull
public Transition outAutomaticTransition(Issue issue) {
- final Transition[] result = new Transition[1];
- Set<String> keys = new HashSet<>();
-
- Arrays.stream(outTransitions)
+ List<Transition> transitions = Arrays.stream(outTransitions)
.filter(Transition::automatic)
- .filter(transition -> transition.supports(issue))
- .peek(transition -> result[0] = transition)
- .filter(transition -> !keys.add(transition.key()))
- .findAny()
- .ifPresent(transition -> {
- throw new IllegalArgumentException("Several automatic transitions are available for issue: " + issue);
- });
-
- return result[0];
+ .filter(t -> t.supports(issue))
+ .collect(Collectors.toList());
+ if(transitions.size() > 1){
+ throw new IllegalArgumentException("Several automatic transitions are available for issue: " + issue);
+ }
+ return transitions.size() == 1 ? transitions.get(0) : null;
}
Transition transition(String transitionKey) {
package org.sonar.server.qualityprofile;
import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.util.Collections;
Map<String, String> valuesByParamKey = activeRule.getParams()
.stream()
.collect(MoreCollectors.uniqueIndex(BuiltInQualityProfilesDefinition.OverriddenParam::key, BuiltInQualityProfilesDefinition.OverriddenParam::overriddenValue));
- return ruleRepository.getRuleParams(activeRule.getRuleKey())
+ List<ActiveRuleParamDto> rules = ruleRepository.getRuleParams(activeRule.getRuleKey())
.stream()
- .map(param -> {
- String activeRuleValue = valuesByParamKey.get(param.getName());
- return createParamDto(param, activeRuleValue == null ? param.getDefaultValue() : activeRuleValue);
- })
+ .map(param -> createParamDto(param, Optional.ofNullable(valuesByParamKey.get(param.getName())).orElse(param.getDefaultValue())))
.filter(Objects::nonNull)
- .peek(paramDto -> dbClient.activeRuleDao().insertParam(session, activeRuleDto, paramDto))
- .collect(MoreCollectors.toList());
+ .collect(Collectors.toList());
+
+ rules.forEach(paramDto -> dbClient.activeRuleDao().insertParam(session, activeRuleDto, paramDto));
+ return rules;
}
@CheckForNull
import com.google.common.io.Resources;
import java.util.Objects;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.stream.Stream;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.issue.IssueChangeDto;
public void handle(Request request, Response response) {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- IssueDto issueDto = Stream.of(request)
- .map(loadCommentData(dbSession))
- .peek(deleteComment(dbSession))
- .collect(MoreCollectors.toOneElement())
- .getIssueDto();
+ CommentData commentData = loadCommentData(dbSession, request);
+ deleteComment(dbSession, commentData);
+ IssueDto issueDto = commentData.getIssueDto();
responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response);
}
}
- private Function<Request, CommentData> loadCommentData(DbSession dbSession) {
- return request -> new CommentData(dbSession, request.mandatoryParam(PARAM_COMMENT));
+ private CommentData loadCommentData(DbSession dbSession, Request request) {
+ return new CommentData(dbSession, request.mandatoryParam(PARAM_COMMENT));
}
- private Consumer<CommentData> deleteComment(DbSession dbSession) {
- return commentData -> {
- dbClient.issueChangeDao().delete(dbSession, commentData.getIssueChangeDto().getKey());
- dbSession.commit();
- };
+ private void deleteComment(DbSession dbSession, CommentData commentData) {
+ dbClient.issueChangeDao().delete(dbSession, commentData.getIssueChangeDto().getKey());
+ dbSession.commit();
}
private class CommentData {
import com.google.common.io.Resources;
import java.util.Objects;
-import java.util.function.Consumer;
-import java.util.function.Function;
import java.util.stream.Stream;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
public void handle(Request request, Response response) {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
- IssueDto issueDto = Stream.of(request)
- .map(toWsRequest())
- .map(loadCommentData(dbSession))
- .peek(updateComment(dbSession))
- .collect(MoreCollectors.toOneElement())
- .getIssueDto();
+ CommentData commentData = loadCommentData(dbSession, toWsRequest(request));
+ updateComment(dbSession, commentData);
+ IssueDto issueDto = commentData.getIssueDto();
responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response);
}
}
- private Function<EditCommentRequest, CommentData> loadCommentData(DbSession dbSession) {
- return request -> new CommentData(dbSession, request);
+ private CommentData loadCommentData(DbSession dbSession, EditCommentRequest request) {
+ return new CommentData(dbSession, request);
}
- private Consumer<CommentData> updateComment(DbSession dbSession) {
- return commentData -> {
- commentData.getIssueChangeDto().setUpdatedAt(system2.now());
- commentData.getIssueChangeDto().setChangeData(commentData.getRequest().getText());
- dbClient.issueChangeDao().update(dbSession, commentData.getIssueChangeDto());
- dbSession.commit();
- };
+ private void updateComment(DbSession dbSession, CommentData commentData) {
+ commentData.getIssueChangeDto().setUpdatedAt(system2.now());
+ commentData.getIssueChangeDto().setChangeData(commentData.getRequest().getText());
+ dbClient.issueChangeDao().update(dbSession, commentData.getIssueChangeDto());
+ dbSession.commit();
}
- private static Function<Request, EditCommentRequest> toWsRequest() {
- return request -> {
- EditCommentRequest wsRequest = new EditCommentRequest(request.mandatoryParam(PARAM_COMMENT), request.mandatoryParam(PARAM_TEXT));
- checkArgument(!isNullOrEmpty(wsRequest.getText()), "Cannot set empty comment to an issue");
- return wsRequest;
- };
+ private static EditCommentRequest toWsRequest(Request request) {
+ EditCommentRequest wsRequest = new EditCommentRequest(request.mandatoryParam(PARAM_COMMENT), request.mandatoryParam(PARAM_TEXT));
+ checkArgument(!isNullOrEmpty(wsRequest.getText()), "Cannot set empty comment to an issue");
+ return wsRequest;
}
private class CommentData {
*/
package org.sonar.server.projectanalysis.ws;
-import java.util.function.Consumer;
-import java.util.stream.Stream;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
-import static org.sonar.server.projectanalysis.ws.EventValidator.checkModifiable;
import static org.sonar.server.projectanalysis.ws.EventCategory.OTHER;
import static org.sonar.server.projectanalysis.ws.EventCategory.VERSION;
+import static org.sonar.server.projectanalysis.ws.EventValidator.checkModifiable;
import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_EVENT;
public class DeleteEventAction implements ProjectAnalysesWsAction {
public void handle(Request request, Response response) throws Exception {
String eventP = request.mandatoryParam(PARAM_EVENT);
try (DbSession dbSession = dbClient.openSession(false)) {
- Stream.of(getEvent(dbSession, eventP))
- .peek(checkPermissions())
- .peek(checkModifiable())
- .forEach(event -> deleteEvent(dbSession, event));
+ EventDto event = getEvent(dbSession, eventP);
+ userSession.checkComponentUuidPermission(UserRole.ADMIN, event.getComponentUuid());
+ checkModifiable().accept(event);
+ deleteEvent(dbSession, event);
}
response.noContent();
}
dbSession.commit();
}
- private Consumer<EventDto> checkPermissions() {
- return event -> userSession.checkComponentUuidPermission(UserRole.ADMIN, event.getComponentUuid());
- }
}
package org.sonar.server.projectanalysis.ws;
import java.util.List;
+import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
private UpdateEventResponse doHandle(UpdateEventRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- return Stream
- .of(getDbEvent(dbSession, request))
- .peek(checkPermissions())
- .peek(checkModifiable())
- .peek(checkVersionNameLength(request))
- .map(updateNameAndDescription(request))
- .peek(checkNonConflictingOtherEvents(dbSession))
- .peek(updateInDb(dbSession))
- .map(toWsResponse())
- .findAny()
- .orElseThrow(() -> new IllegalStateException("Event not found"));
+ EventDto event = Optional.ofNullable(getDbEvent(dbSession, request)).orElseThrow(() -> new IllegalStateException("Event not found"));
+ checkPermissions().accept(event);
+ checkModifiable().accept(event);
+ checkVersionNameLength(request).accept(event);
+ event = updateNameAndDescription(request).apply(event);
+ checkNonConflictingOtherEvents(dbSession).accept(event);
+ updateInDb(dbSession).accept(event);
+ return toWsResponse().apply(event);
}
}
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("set")
.setDescription("Update a setting value.<br>" +
- "Either '%s' or '%s' must be provided.<br> " +
- "The settings defined in conf/sonar.properties are read-only and can't be changed.<br/>" +
- "Requires one of the following permissions: " +
- "<ul>" +
- "<li>'Administer System'</li>" +
- "<li>'Administer' rights on the specified component</li>" +
- "</ul>",
+ "Either '%s' or '%s' must be provided.<br> " +
+ "The settings defined in conf/sonar.properties are read-only and can't be changed.<br/>" +
+ "Requires one of the following permissions: " +
+ "<ul>" +
+ "<li>'Administer System'</li>" +
+ "<li>'Administer' rights on the specified component</li>" +
+ "</ul>",
PARAM_VALUE, PARAM_VALUES)
.setSince("6.1")
.setChangelog(
Set<String> fieldKeys = definition.fields().stream().map(PropertyFieldDefinition::key).collect(Collectors.toSet());
ListMultimap<String, String> valuesByFieldKeys = ArrayListMultimap.create(fieldKeys.size(), request.getFieldValues().size() * fieldKeys.size());
- request.getFieldValues().stream()
+ List<Map<String, String>> maps = request.getFieldValues().stream()
.map(oneFieldValues -> readOneFieldValues(oneFieldValues, request.getKey()))
- .peek(map -> checkRequest(map.values().stream().anyMatch(StringUtils::isNotBlank), MSG_NO_EMPTY_VALUE))
- .flatMap(map -> map.entrySet().stream())
- .peek(entry -> valuesByFieldKeys.put(entry.getKey(), entry.getValue()))
- .forEach(entry -> checkRequest(fieldKeys.contains(entry.getKey()), "Unknown field key '%s' for setting '%s'", entry.getKey(), request.getKey()));
+ .collect(Collectors.toList());
+ for (Map<String, String> map : maps) {
+ checkRequest(map.values().stream().anyMatch(StringUtils::isNotBlank), MSG_NO_EMPTY_VALUE);
+ }
+ List<Map.Entry<String, String>> entries = maps.stream().flatMap(map -> map.entrySet().stream()).collect(Collectors.toList());
+ entries.forEach(entry -> valuesByFieldKeys.put(entry.getKey(), entry.getValue()));
+ entries.forEach(entry -> checkRequest(fieldKeys.contains(entry.getKey()), "Unknown field key '%s' for setting '%s'", entry.getKey(), request.getKey()));
checkFieldType(request, definition, valuesByFieldKeys);
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
import java.util.List;
-import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.sonar.api.Startable;
import org.sonar.api.server.ServerSide;
import org.sonar.api.web.page.Page.Qualifier;
import org.sonar.api.web.page.Page.Scope;
import org.sonar.api.web.page.PageDefinition;
-import org.sonar.core.platform.PluginRepository;
import org.sonar.core.extension.CoreExtensionRepository;
+import org.sonar.core.platform.PluginRepository;
import org.sonar.server.ui.page.CorePageDefinition;
import static com.google.common.base.Preconditions.checkState;
corePageDefinitions.stream()
.map(CorePageDefinition::getPageDefinition)
.forEach(definition -> definition.define(coreContext));
- pages = Stream.concat(
- context.getPages().stream().peek(this::checkPluginExists),
- coreContext.getPages().stream().peek(this::checkCoreExtensionExists))
- .sorted(comparing(Page::getKey))
- .collect(toList());
+ context.getPages().forEach(this::checkPluginExists);
+ coreContext.getPages().forEach(this::checkCoreExtensionExists);
+ pages = new ArrayList<>();
+ pages.addAll(context.getPages());
+ pages.addAll(coreContext.getPages());
+ pages.sort(comparing(Page::getKey));
}
@Override
package org.sonar.api.config;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.EnumMap;
import java.util.LinkedHashSet;
import java.util.List;
}
private static void addQualifiers(List<String> target, String first, String... rest) {
- Stream.concat(Stream.of(first), stream(rest)).peek(PropertyDefinition.Builder::validateQualifier).forEach(target::add);
+ List<String> qualifiers = new ArrayList<>();
+ qualifiers.add(first);
+ qualifiers.addAll(Arrays.asList(rest));
+ addQualifiers(target, qualifiers);
}
private static void addQualifiers(List<String> target, List<String> qualifiers) {
- qualifiers.stream().peek(PropertyDefinition.Builder::validateQualifier).forEach(target::add);
+ qualifiers.forEach(PropertyDefinition.Builder::validateQualifier);
+ target.addAll(qualifiers);
}
private static void validateQualifier(@Nullable String qualifier) {