@@ -103,10 +103,8 @@ public class ComponentIssuesLoader { | |||
.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); | |||
} | |||
/** | |||
@@ -175,7 +173,6 @@ public class ComponentIssuesLoader { | |||
// TODO to be improved, why setOnDisabledRule(true) is not enough ? | |||
issue.setBeingClosed(true); | |||
} | |||
// FIXME | |||
issue.setSelectedAt(System.currentTimeMillis()); | |||
result.add(issue); | |||
}); | |||
@@ -264,7 +261,6 @@ public class ComponentIssuesLoader { | |||
previousIssueKey = resultObject.getKey(); | |||
DefaultIssue issue = resultObject.toDefaultIssue(); | |||
issue.setLine(line); | |||
// FIXME | |||
issue.setSelectedAt(System.currentTimeMillis()); | |||
issues.add(issue); |
@@ -25,7 +25,6 @@ import java.util.Collections; | |||
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; | |||
@@ -58,16 +57,15 @@ public class ComponentTextSearchQueryFactory { | |||
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 { |
@@ -62,20 +62,14 @@ public class State { | |||
@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) { |
@@ -20,6 +20,7 @@ | |||
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; | |||
@@ -156,15 +157,14 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert { | |||
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 |
@@ -21,14 +21,10 @@ package org.sonar.server.issue.ws; | |||
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; | |||
@@ -84,24 +80,20 @@ public class DeleteCommentAction implements IssuesWsAction { | |||
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 { |
@@ -21,8 +21,6 @@ package org.sonar.server.issue.ws; | |||
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; | |||
@@ -94,35 +92,28 @@ public class EditCommentAction implements IssuesWsAction { | |||
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 { |
@@ -19,8 +19,6 @@ | |||
*/ | |||
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; | |||
@@ -35,9 +33,9 @@ import org.sonar.server.user.UserSession; | |||
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 { | |||
@@ -74,10 +72,10 @@ 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(); | |||
} | |||
@@ -99,7 +97,4 @@ public class DeleteEventAction implements ProjectAnalysesWsAction { | |||
dbSession.commit(); | |||
} | |||
private Consumer<EventDto> checkPermissions() { | |||
return event -> userSession.checkComponentUuidPermission(UserRole.ADMIN, event.getComponentUuid()); | |||
} | |||
} |
@@ -20,6 +20,7 @@ | |||
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; | |||
@@ -100,17 +101,14 @@ public class UpdateEventAction implements ProjectAnalysesWsAction { | |||
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); | |||
} | |||
} | |||
@@ -94,13 +94,13 @@ public class SetAction implements SettingsWsAction { | |||
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( | |||
@@ -212,13 +212,16 @@ public class SetAction implements SettingsWsAction { | |||
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); | |||
} | |||
@@ -21,8 +21,8 @@ package org.sonar.server.ui; | |||
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; | |||
@@ -31,8 +31,8 @@ import org.sonar.api.web.page.Page; | |||
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; | |||
@@ -105,11 +105,12 @@ public class PageRepository implements Startable { | |||
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 |
@@ -20,6 +20,7 @@ | |||
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; | |||
@@ -510,11 +511,15 @@ public final class PropertyDefinition { | |||
} | |||
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) { |