@@ -201,6 +201,16 @@ public class TrackerRawInputFactory { | |||
return issue; | |||
} | |||
private Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> convertImpacts(RuleKey ruleKey, List<ScannerReport.Impact> overridenImpactsList) { | |||
if (overridenImpactsList.isEmpty()) { | |||
return Collections.emptyMap(); | |||
} | |||
Rule rule = ruleRepository.getByKey(ruleKey); | |||
return overridenImpactsList.stream() | |||
.filter(i -> rule.getDefaultImpacts().containsKey(SoftwareQuality.valueOf(i.getSoftwareQuality()))) | |||
.collect(Collectors.toMap(i -> SoftwareQuality.valueOf(i.getSoftwareQuality()), i -> org.sonar.api.issue.impact.Severity.valueOf(i.getSeverity()))); | |||
} | |||
private DbIssues.Flow.Builder convertLocations(ScannerReport.Flow flow) { | |||
DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder(); | |||
for (ScannerReport.IssueLocation location : flow.getLocationList()) { | |||
@@ -213,6 +223,7 @@ public class TrackerRawInputFactory { | |||
return dbFlowBuilder; | |||
} | |||
private DefaultIssue toExternalIssue(LineHashSequence lineHashSeq, ScannerReport.ExternalIssue reportExternalIssue, Map<RuleKey, ScannerReport.AdHocRule> adHocRuleMap) { | |||
DefaultIssue issue = new DefaultIssue(); | |||
RuleKey ruleKey = RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + reportExternalIssue.getEngineId(), reportExternalIssue.getRuleId()); | |||
@@ -362,15 +373,6 @@ public class TrackerRawInputFactory { | |||
} | |||
private Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> convertImpacts(RuleKey ruleKey, List<ScannerReport.Impact> overridenImpactsList) { | |||
if (overridenImpactsList.isEmpty()) { | |||
return Collections.emptyMap(); | |||
} | |||
Rule rule = ruleRepository.getByKey(ruleKey); | |||
return overridenImpactsList.stream() | |||
.filter(i -> rule.getDefaultImpacts().containsKey(SoftwareQuality.valueOf(i.getSoftwareQuality()))) | |||
.collect(Collectors.toMap(i -> SoftwareQuality.valueOf(i.getSoftwareQuality()), i -> org.sonar.api.issue.impact.Severity.valueOf(i.getSeverity()))); | |||
} | |||
private static DbIssues.MessageFormattings convertMessageFormattings(List<ScannerReport.MessageFormatting> msgFormattings) { | |||
DbIssues.MessageFormattings.Builder builder = DbIssues.MessageFormattings.newBuilder(); |
@@ -242,12 +242,18 @@ public final class IndexedIssueDto { | |||
return this; | |||
} | |||
@Deprecated | |||
/** | |||
* @deprecated since 10.2 | |||
*/ | |||
@Deprecated(since = "10.2") | |||
public Integer getIssueType() { | |||
return issueType; | |||
} | |||
@Deprecated | |||
/** | |||
* @deprecated since 10.2 | |||
*/ | |||
@Deprecated(since = "10.2") | |||
public IndexedIssueDto setIssueType(Integer issueType) { | |||
this.issueType = issueType; | |||
return this; |
@@ -69,7 +69,7 @@ public class IssueTesting { | |||
.setStatus(Issue.STATUS_OPEN) | |||
.setResolution(null) | |||
.setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) | |||
//TODO map to correct impact | |||
//TODO map to correct impact. Will be fixed with persistence of impacts on issues | |||
.addImpact(new ImpactDto().setUuid(Uuids.createFast()).setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(org.sonar.api.issue.impact.Severity.HIGH)) | |||
.setEffort((long) RandomUtils.nextInt(10)) | |||
.setAssigneeUuid("assignee-uuid_" + randomAlphabetic(26)) |
@@ -24,7 +24,6 @@ import java.time.temporal.ChronoUnit; | |||
import java.util.Collection; | |||
import java.util.Date; | |||
import java.util.EnumMap; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
import java.util.Map; | |||
import java.util.Objects; |
@@ -141,7 +141,10 @@ public class IssueDoc extends BaseDoc { | |||
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_AUTHOR_LOGIN); | |||
} | |||
@Deprecated | |||
/** | |||
* @deprecated since 10.2 | |||
*/ | |||
@Deprecated(since = "10.2") | |||
public RuleType type() { | |||
return RuleType.valueOf(getField(IssueIndexDefinition.FIELD_ISSUE_TYPE)); | |||
} | |||
@@ -203,7 +206,10 @@ public class IssueDoc extends BaseDoc { | |||
return this; | |||
} | |||
@Deprecated | |||
/** | |||
* @deprecated since 10.2 | |||
*/ | |||
@Deprecated(since = "10.2") | |||
public IssueDoc setSeverity(@Nullable String s) { | |||
setField(IssueIndexDefinition.FIELD_ISSUE_SEVERITY, s); | |||
setField(IssueIndexDefinition.FIELD_ISSUE_SEVERITY_VALUE, Severity.ALL.indexOf(s)); | |||
@@ -280,7 +286,7 @@ public class IssueDoc extends BaseDoc { | |||
return this; | |||
} | |||
@Deprecated | |||
@Deprecated(since = "10.2") | |||
public IssueDoc setType(RuleType type) { | |||
setField(IssueIndexDefinition.FIELD_ISSUE_TYPE, type.toString()); | |||
return this; |
@@ -92,8 +92,8 @@ class IssueIteratorForSingleChunk implements IssueIterator { | |||
String cleanCodeAttributeCategory = Optional.ofNullable(indexedIssueDto.getCleanCodeAttribute()) | |||
.map(CleanCodeAttribute::valueOf) | |||
.map(cleanCodeAttribute -> cleanCodeAttribute.getAttributeCategory().name()) | |||
.orElse(null); | |||
//TODO:: uncomment once clean code attribute is set to not-null | |||
.orElse(null); | |||
//TODO SONAR-20073 uncomment once clean code attribute is set to not-null | |||
//.orElseThrow(() -> new IllegalStateException("Clean Code Attribute is missing for issue " + key)); | |||
doc.setCleanCodeAttributeCategory(cleanCodeAttributeCategory); | |||
doc.setStatus(indexedIssueDto.getStatus()); |
@@ -79,12 +79,20 @@ public class SearchRequestTest { | |||
assertThat(underTest.getSort()).isEqualTo("CREATION_DATE"); | |||
assertThat(underTest.getAsc()).isTrue(); | |||
assertThat(underTest.getInNewCodePeriod()).isTrue(); | |||
assertThat(underTest.getOwaspTop10For2021()).containsExactly("a2", "a3"); | |||
assertThat(underTest.getOwaspAsvs40()).containsExactly("1.1.1", "4.2.2"); | |||
assertThat(underTest.getOwaspAsvsLevel()).isEqualTo(2); | |||
assertOwasp(underTest); | |||
assertThat(underTest.getPciDss32()).containsExactly("1", "4"); | |||
assertThat(underTest.getPciDss40()).containsExactly("3", "5"); | |||
assertThat(underTest.getCodeVariants()).containsExactly("variant1", "variant2"); | |||
assertCleanCodeInformation(underTest); | |||
} | |||
private static void assertOwasp(SearchRequest underTest) { | |||
assertThat(underTest.getOwaspTop10For2021()).containsExactly("a2", "a3"); | |||
assertThat(underTest.getOwaspAsvs40()).containsExactly("1.1.1", "4.2.2"); | |||
assertThat(underTest.getOwaspAsvsLevel()).isEqualTo(2); | |||
} | |||
private static void assertCleanCodeInformation(SearchRequest underTest) { | |||
assertThat(underTest.getCleanCodeAttributesCategories()).containsExactly("ADAPTABLE"); | |||
assertThat(underTest.getImpactSeverities()).containsExactly("HIGH", "LOW"); | |||
assertThat(underTest.getImpactSoftwareQualities()).containsExactly("RELIABILITY", "SECURITY"); |
@@ -65,6 +65,7 @@ public class NewRuleCreator { | |||
} | |||
RuleDto createRuleWithSimpleFields(RulesDefinition.Rule ruleDef, String uuid, long now) { | |||
CleanCodeAttribute cleanCodeAttribute = ruleDef.cleanCodeAttribute(); | |||
RuleDto ruleDto = new RuleDto() | |||
.setUuid(uuid) | |||
.setRuleKey(RuleKey.of(ruleDef.repository().key(), ruleDef.key())) | |||
@@ -84,7 +85,7 @@ public class NewRuleCreator { | |||
.setIsAdHoc(false) | |||
.setCreatedAt(now) | |||
.setUpdatedAt(now) | |||
.setCleanCodeAttribute(ruleDef.cleanCodeAttribute() != null ? ruleDef.cleanCodeAttribute() : CleanCodeAttribute.defaultCleanCodeAttribute()) | |||
.setCleanCodeAttribute(cleanCodeAttribute != null ? cleanCodeAttribute : CleanCodeAttribute.defaultCleanCodeAttribute()) | |||
.setEducationPrinciples(ruleDef.educationPrincipleKeys()); | |||
if (isNotEmpty(ruleDef.htmlDescription())) { |
@@ -25,7 +25,6 @@ import java.util.List; | |||
import java.util.Map; | |||
import java.util.Objects; | |||
import java.util.Set; | |||
import java.util.function.Supplier; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
import org.sonar.api.rule.RuleKey; |
@@ -167,8 +167,9 @@ public class StartupRuleUpdater { | |||
private static boolean mergeCleanCodeAttribute(RulesDefinition.Rule def, RuleDto dto) { | |||
boolean changed = false; | |||
if (!Objects.equals(dto.getCleanCodeAttribute(), def.cleanCodeAttribute()) && (def.cleanCodeAttribute() != null)) { | |||
dto.setCleanCodeAttribute(def.cleanCodeAttribute()); | |||
CleanCodeAttribute defCleanCodeAttribute = def.cleanCodeAttribute(); | |||
if (!Objects.equals(dto.getCleanCodeAttribute(), defCleanCodeAttribute) && (defCleanCodeAttribute != null)) { | |||
dto.setCleanCodeAttribute(defCleanCodeAttribute); | |||
changed = true; | |||
} | |||
// apply non-nullable default | |||
@@ -205,7 +206,7 @@ public class StartupRuleUpdater { | |||
private static boolean mergeEducationPrinciples(RulesDefinition.Rule ruleDef, RuleDto dto) { | |||
boolean changed = false; | |||
if (dto.getEducationPrinciples().size() != ruleDef.educationPrincipleKeys().size() || | |||
!dto.getEducationPrinciples().containsAll(ruleDef.educationPrincipleKeys())) { | |||
!dto.getEducationPrinciples().containsAll(ruleDef.educationPrincipleKeys())) { | |||
dto.setEducationPrinciples(ruleDef.educationPrincipleKeys()); | |||
changed = true; | |||
} | |||
@@ -219,10 +220,10 @@ public class StartupRuleUpdater { | |||
dto.setSystemTags(emptySet()); | |||
changed = true; | |||
} else if (dto.getSystemTags().size() != ruleDef.tags().size() || | |||
!dto.getSystemTags().containsAll(ruleDef.tags())) { | |||
dto.setSystemTags(ruleDef.tags()); | |||
changed = true; | |||
} | |||
!dto.getSystemTags().containsAll(ruleDef.tags())) { | |||
dto.setSystemTags(ruleDef.tags()); | |||
changed = true; | |||
} | |||
return changed; | |||
} | |||
@@ -233,10 +234,10 @@ public class StartupRuleUpdater { | |||
dto.setSecurityStandards(emptySet()); | |||
changed = true; | |||
} else if (dto.getSecurityStandards().size() != ruleDef.securityStandards().size() || | |||
!dto.getSecurityStandards().containsAll(ruleDef.securityStandards())) { | |||
dto.setSecurityStandards(ruleDef.securityStandards()); | |||
changed = true; | |||
} | |||
!dto.getSecurityStandards().containsAll(ruleDef.securityStandards())) { | |||
dto.setSecurityStandards(ruleDef.securityStandards()); | |||
changed = true; | |||
} | |||
return changed; | |||
} | |||
@@ -45,8 +45,6 @@ import org.sonar.api.issue.Issue; | |||
import org.sonar.api.issue.impact.SoftwareQuality; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.Severity; | |||
import org.sonar.api.rules.CleanCodeAttribute; | |||
import org.sonar.api.rules.CleanCodeAttributeCategory; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.utils.Duration; | |||
import org.sonar.core.issue.tracking.Trackable; |
@@ -20,9 +20,7 @@ | |||
package org.sonar.api.batch.sensor.issue.internal; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.EnumMap; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Optional; |