import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.utils.KeyValueFormat;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventComponentChangeDto;
import org.sonar.db.event.EventDto;
import org.sonarqube.ws.ProjectAnalyses.Analysis;
import org.sonarqube.ws.ProjectAnalyses.Event;
import org.sonarqube.ws.ProjectAnalyses.QualityGate;
+import org.sonarqube.ws.ProjectAnalyses.QualityProfile;
import org.sonarqube.ws.ProjectAnalyses.SearchResponse;
import static java.lang.String.format;
private final Event.Builder wsEvent;
private final SearchData searchData;
private final QualityGate.Builder wsQualityGate;
+ private final QualityProfile.Builder wsQualityProfile;
private final ProjectAnalyses.DefinitionChange.Builder wsDefinitionChange;
SearchResponseBuilder(SearchData searchData) {
this.wsAnalysis = Analysis.newBuilder();
this.wsEvent = Event.newBuilder();
this.wsQualityGate = QualityGate.newBuilder();
+ this.wsQualityProfile = QualityProfile.newBuilder();
this.wsDefinitionChange = ProjectAnalyses.DefinitionChange.newBuilder();
this.searchData = searchData;
}
wsEvent.clear().setKey(dbEvent.getUuid());
ofNullable(dbEvent.getName()).ifPresent(wsEvent::setName);
ofNullable(dbEvent.getDescription()).ifPresent(wsEvent::setDescription);
- ofNullable(dbEvent.getCategory()).ifPresent(cat -> wsEvent.setCategory(fromLabel(cat).name()));
- if (dbEvent.getCategory() != null) {
- switch (EventCategory.fromLabel(dbEvent.getCategory())) {
- case DEFINITION_CHANGE:
- addDefinitionChange(dbEvent);
- break;
- case QUALITY_GATE:
- addQualityGateInformation(dbEvent);
- break;
- default:
- break;
- }
- }
+ ofNullable(dbEvent.getCategory())
+ .ifPresent(cat -> {
+ wsEvent.setCategory(fromLabel(cat).name());
+ switch (fromLabel(cat)) {
+ case DEFINITION_CHANGE -> addDefinitionChange(dbEvent);
+ case QUALITY_GATE -> addQualityGateInformation(dbEvent);
+ case QUALITY_PROFILE -> addQualityProfileInformation(dbEvent);
+ default -> {
+ //Nothing to do if not one of the previous cases
+ }
+ }
+ });
return wsEvent;
}
+ private void addQualityProfileInformation(EventDto event) {
+ wsQualityProfile.clear();
+
+ Map<String, String> data = KeyValueFormat.parse(event.getData());
+
+ Optional.ofNullable(data.get("key")).ifPresent(wsQualityProfile::setKey);
+ Optional.ofNullable(data.get("name")).ifPresent(wsQualityProfile::setName);
+ Optional.ofNullable(data.get("languageKey")).ifPresent(wsQualityProfile::setLanguageKey);
+
+ wsEvent.setQualityProfile(wsQualityProfile.build());
+ }
+
private void addQualityGateInformation(EventDto event) {
wsQualityGate.clear();
List<EventComponentChangeDto> eventComponentChangeDtos = searchData.componentChangesByEventUuid.get(event.getUuid());