Skip to content

Commit

Permalink
Merge pull request #261 from cnescatlab/issues-count-improvement
Browse files Browse the repository at this point in the history
Make issues count table clearer
  • Loading branch information
Sancretor authored Jun 9, 2021
2 parents 69eb319 + 1752be1 commit e18031a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 41 deletions.
14 changes: 3 additions & 11 deletions src/main/java/fr/cnes/sonar/report/exporters/MarkdownExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@

public class MarkdownExporter implements IExporter {

/**
* Start index of the sub array in the headers array for the the second table
*/
private static final int HEADER_START_INDEX = 2;
/**
* End index of the sub array in the headers array for the the second table
*/
private static final int HEADER_END_INDEX = 5;
/**
* Placeholder for issues count table
*/
Expand Down Expand Up @@ -123,9 +115,9 @@ public File export(Object data, String path, String filename) throws IOException

// Generate issue count table
final List<List<String>> types = DataAdapter.getTypes(report);
final String tableTypes = generateMDTable(
headerIssues.subList(HEADER_START_INDEX, HEADER_END_INDEX),
types);
final List<String> headerIssuesCount = DataAdapter.getReversedIssuesSeverities();
headerIssuesCount.add(0, StringManager.string("header.typeSlashSeverity"));
final String tableTypes = generateMDTable(headerIssuesCount, types);
output = output.replace(ISSUES_COUNT_PLACEHOLDER, tableTypes);

// Generate security hotspots table
Expand Down
53 changes: 34 additions & 19 deletions src/main/java/fr/cnes/sonar/report/exporters/docx/DataAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,32 +353,47 @@ public static List<List<String>> getTypes(Report report) {
final List<List<String>> results = new ArrayList<>();

final String[] types = ISSUE_TYPES;
final String[] severities = ISSUE_SEVERITIES;

final List<String> severities = getReversedIssuesSeverities();

// accumulator for the number of occurrences for each severity
LinkedHashMap<String,Integer> countPerSeverity = new LinkedHashMap<>();
for (String severity : severities) {
countPerSeverity.put(severity, 0);
}

for(String type : types) {
for (String severity : severities) {
// accumulator for the number of occurrences
long nb = 0;
//List of items for each line of the table
final List<String> item = new ArrayList<>();

// we sum all issues with a type and a severity
for(Issue issue : report.getIssues()) {
if(issue.getType().equals(type) && issue.getSeverity().equals(severity)) {
nb++;
}
//List of items for each line of the table
final List<String> row = new ArrayList<>();
for(Issue issue : report.getIssues()) {
if(issue.getType().equals(type)) {
// increment the count of the severity
countPerSeverity.put(issue.getSeverity(),
countPerSeverity.get(issue.getSeverity()) + 1);
}
// we add it to the list
item.add(type);
item.add(severity);
item.add(String.valueOf(nb));
// add the whole line to the results
results.add(item);
}
// add data to the row
row.add(type);
for (String severity : severities) {
row.add(String.valueOf(countPerSeverity.get(severity)));
// reset the count
countPerSeverity.put(severity, 0);
}
// add row to the result
results.add(row);
}
return results;
}

/**
* Getter for reversed ISSUE_SEVERITIES
* @return reversed ISSUE_SEVERITIES
*/
public static List<String> getReversedIssuesSeverities() {
List<String> issuesSeverities = new ArrayList<>(Arrays.asList(ISSUE_SEVERITIES));
Collections.reverse(issuesSeverities);
return issuesSeverities;
}

/**
* Prepare list of resources to be print in a table
* Data are lines containing the number of security hotspots by review priority and security category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ public class DocXExporter implements IExporter {
* Name of the property giving the path header's number
*/
private static final String HEADER_NUMBER = "header.number";
/**
* Start index of the sub array in the headers array for the the second table
*/
private static final int HEADER_START_INDEX = 2;
/**
* End index of the sub array in the headers array for the the second table
*/
private static final int HEADER_END_INDEX = 5;

/**
* Overridden export for docX
Expand Down Expand Up @@ -133,9 +125,9 @@ public File export(final Object data, final String path, final String filename)

// Add issues count by type and severity
final List<List<String>> types = DataAdapter.getTypes(report);
DocXTools.fillTable(document,
headerIssues.subList(HEADER_START_INDEX, HEADER_END_INDEX),
types, COUNT_TABLE_PLACEHOLDER);
final List<String> headerIssuesCount = DataAdapter.getReversedIssuesSeverities();
headerIssuesCount.add(0, StringManager.string("header.typeSlashSeverity"));
DocXTools.fillTable(document, headerIssuesCount, types, COUNT_TABLE_PLACEHOLDER);

// Add security hotspots
final List<List<String>> securityHotspots = DataAdapter.getSecurityHotspots(report);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ header.number=Number
header.category=Category
header.priority=Priority
header.count=Count
header.typeSlashSeverity=Type / Severity
header.categorySlashPriority=Category / Priority
header.metric=Metric
header.value=Value
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ header.number=Number
header.category=Category
header.priority=Priority
header.count=Count
header.typeSlashSeverity=Type / Severity
header.categorySlashPriority=Category / Priority
header.metric=Metric
header.value=Value
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_fr_FR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ header.number=Nombre
header.category=Catégorie
header.priority=Priorité
header.count=Total
header.typeSlashSeverity=Type / Criticité
header.categorySlashPriority=Catégorie / Priorité
header.metric=Métrique
header.value=Valeur
Expand Down
1 change: 1 addition & 0 deletions src/test/ut/java/fr/cnes/sonar/report/CommonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void before() {
i2.setStatus("OPEN");
i2.setType("BUG");
i2.setRule("abcd:dcba");
i4.setSeverity(MAJOR);
i4.setType("BUG");
// Adding multiple time to test comparator (DataAdapter.RuleComparator)
Issue issue;
Expand Down

0 comments on commit e18031a

Please sign in to comment.