@@ -149,12 +149,18 @@ public class SearchAction implements ProjectAnalysesWsAction { | |||
SearchData.Builder searchResults = SearchData.builder(dbSession, request); | |||
addProject(searchResults); | |||
checkPermission(searchResults.getProject()); | |||
addManualBaseline(searchResults); | |||
addAnalyses(searchResults); | |||
addEvents(searchResults); | |||
return searchResults.build(); | |||
} | |||
} | |||
private void addManualBaseline(SearchData.Builder data) { | |||
dbClient.branchDao().selectByUuid(data.getDbSession(), data.getProject().uuid()) | |||
.ifPresent(branchDto -> data.setManualBaseline(branchDto.getManualBaseline())); | |||
} | |||
private void addAnalyses(SearchData.Builder data) { | |||
SnapshotQuery dbQuery = new SnapshotQuery() | |||
.setComponentUuid(data.getProject().uuid()) |
@@ -21,8 +21,11 @@ package org.sonar.server.projectanalysis.ws; | |||
import com.google.common.collect.ListMultimap; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import java.util.function.Predicate; | |||
import java.util.stream.Stream; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.utils.Paging; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.db.DbSession; | |||
@@ -38,6 +41,8 @@ class SearchData { | |||
final ListMultimap<String, EventDto> eventsByAnalysis; | |||
final ListMultimap<String, EventComponentChangeDto> componentChangesByEventUuid; | |||
final Paging paging; | |||
@CheckForNull | |||
private final String manualBaseline; | |||
private SearchData(Builder builder) { | |||
this.analyses = builder.analyses; | |||
@@ -47,6 +52,7 @@ class SearchData { | |||
.forPageIndex(builder.getRequest().getPage()) | |||
.withPageSize(builder.getRequest().getPageSize()) | |||
.andTotal(builder.countAnalyses); | |||
this.manualBaseline = builder.manualBaseline; | |||
} | |||
private static ListMultimap<String, EventDto> buildEvents(List<EventDto> events) { | |||
@@ -61,12 +67,17 @@ class SearchData { | |||
return new Builder(dbSession, request); | |||
} | |||
public Optional<String> getManualBaseline() { | |||
return Optional.ofNullable(manualBaseline); | |||
} | |||
static class Builder { | |||
private final DbSession dbSession; | |||
private final SearchRequest request; | |||
private ComponentDto project; | |||
private List<SnapshotDto> analyses; | |||
private int countAnalyses; | |||
private String manualBaseline; | |||
private List<EventDto> events; | |||
private List<EventComponentChangeDto> componentChanges; | |||
@@ -124,6 +135,11 @@ class SearchData { | |||
return analyses; | |||
} | |||
public Builder setManualBaseline(@Nullable String manualBaseline) { | |||
this.manualBaseline = manualBaseline; | |||
return this; | |||
} | |||
private void filterByCategory() { | |||
ListMultimap<String, String> eventCategoriesByAnalysisUuid = events.stream() | |||
.collect(MoreCollectors.index(EventDto::getAnalysisUuid, EventDto::getCategory)); |
@@ -81,9 +81,11 @@ class SearchResponseBuilder { | |||
Analysis.Builder builder = wsAnalysis.clear(); | |||
builder | |||
.setKey(dbAnalysis.getUuid()) | |||
.setDate(formatDateTime(dbAnalysis.getCreatedAt())); | |||
.setDate(formatDateTime(dbAnalysis.getCreatedAt())) | |||
.setManualNewCodePeriodBaseline(searchData.getManualBaseline().filter(dbAnalysis.getUuid()::equals).isPresent()); | |||
ofNullable(dbAnalysis.getCodePeriodVersion()).ifPresent(builder::setCodePeriodVersion); | |||
ofNullable(dbAnalysis.getProjectVersion()).ifPresent(builder::setProjectVersion); | |||
return builder; | |||
} | |||
@@ -10,6 +10,7 @@ | |||
"date": "2016-12-12T17:12:45+0100", | |||
"codePeriodVersion": "1.2.1", | |||
"projectVersion": "1.2.1.423", | |||
"manualNewCodePeriodBaseline": false, | |||
"events": [ | |||
{ | |||
"key": "E21", | |||
@@ -28,6 +29,7 @@ | |||
"date": "2016-12-11T17:12:45+0100", | |||
"codePeriodVersion": "1.2", | |||
"projectVersion": "1.2.0.322", | |||
"manualNewCodePeriodBaseline": true, | |||
"events": [ | |||
{ | |||
"key": "E11", | |||
@@ -47,6 +49,7 @@ | |||
"date": "2015-11-11T10:00:00+0100", | |||
"codePeriodVersion": "1.2", | |||
"projectVersion": "1.2.0.321", | |||
"manualNewCodePeriodBaseline": false, | |||
"events": [ | |||
{ | |||
"key": "E31", |
@@ -67,7 +67,9 @@ import static org.assertj.core.api.Assertions.tuple; | |||
import static org.sonar.api.utils.DateUtils.formatDate; | |||
import static org.sonar.api.utils.DateUtils.formatDateTime; | |||
import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
import static org.sonar.db.component.BranchType.LONG; | |||
import static org.sonar.db.component.BranchType.PULL_REQUEST; | |||
import static org.sonar.db.component.ComponentTesting.newBranchDto; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
import static org.sonar.db.event.EventComponentChangeDto.ChangeCategory.ADDED; | |||
@@ -119,6 +121,7 @@ public class SearchActionTest { | |||
public void json_example() { | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey(KEY_PROJECT_EXAMPLE_001)); | |||
userSession.addProjectPermission(UserRole.USER, project); | |||
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project) | |||
.setUuid("A1").setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime()) | |||
@@ -131,6 +134,9 @@ public class SearchActionTest { | |||
SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project) | |||
.setUuid("P1").setCreatedAt(parseDateTime("2015-11-11T10:00:00+0100").getTime()) | |||
.setCodePeriodVersion("1.2").setProjectVersion("1.2.0.321")); | |||
db.getDbClient().branchDao().insert(db.getSession(), newBranchDto(project, LONG) | |||
.setManualBaseline(a1.getUuid())); | |||
db.commit(); | |||
db.events().insertEvent(newEvent(a1).setUuid("E11") | |||
.setName("Quality Gate is Red (was Orange)") | |||
.setCategory(EventCategory.QUALITY_GATE.getLabel()) |
@@ -58,6 +58,7 @@ message Analysis { | |||
repeated Event events = 3; | |||
optional string codePeriodVersion = 4; | |||
optional string projectVersion = 5; | |||
optional bool manualNewCodePeriodBaseline = 6; | |||
} | |||
message QualityGate { |