Skip to content

Commit 878948f

Browse files
committed
Project Dashboard now text rather than an image
1 parent 6eb0588 commit 878948f

File tree

4 files changed

+110
-70
lines changed

4 files changed

+110
-70
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = 'com.ldiamond'
11-
version = '6.1.0-SNAPSHOT'
11+
version = '7.0.0-SNAPSHOT'
1212
sourceCompatibility = '11'
1313
targetCompatibility = '11'
1414

samples/sonarcloud/sonarcloud.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{"title":"OWASP ZAP Proxy", "key": "zaproxy_zaproxy"}
1010
],
1111
"metrics": [
12-
{"metric":"coverage","filename":"CodeCoverage.png","title":"Code Coverage","green":"50","yellow":"1","description":"Code Coverage: More is better: What percentage of the code is covered by unit tests."},
12+
{"metric":"coverage","filename":"CodeCoverage.png","title":"Code Coverage","green":"50","yellow":"20","description":"Code Coverage: More is better: What percentage of the code is covered by unit tests."},
1313
{"metric":"CognitiveComplexityPerKLines","filename":"Complexity.png","title":"Complexity Per Thousand Lines","description":"Cognitive Complexity: Less is better: How testable and maintainable are the methods in this application?"},
1414
{"metric":"bugs","title":"Bugs","description":"Bugs: Less is better: How many Sonarqube bug code violations were found in this application?"},
1515
{"metric":"vulnerabilities","filename":"Vulnerabilities.png","title":"Vulnerabilities","description":"Vulnerabilities: Less is better: How many Sonarqube security vulnerabilities were found in this application?"},

src/main/java/com/ldiamond/sqgraph/PDFOutput.java

Lines changed: 105 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
**/
1111
package com.ldiamond.sqgraph;
1212

13+
import java.awt.Color;
1314
import java.awt.image.BufferedImage;
1415
import java.io.FileOutputStream;
1516
import java.io.IOException;
@@ -21,6 +22,7 @@
2122
import com.google.common.collect.HashBasedTable;
2223
import com.lowagie.text.Document;
2324
import com.lowagie.text.Element;
25+
import com.lowagie.text.Font;
2426
import com.lowagie.text.Image;
2527
import com.lowagie.text.Paragraph;
2628
import com.lowagie.text.Phrase;
@@ -79,7 +81,109 @@ public static void closePDF() {
7981
document.close();
8082
}
8183

82-
/*
84+
public static void addTextDashboard(final HashBasedTable<String, String, Double> dashboardData, final Config config) {
85+
try {
86+
document.add(new Phrase("")); // spacer
87+
88+
List<Integer> colWidths = new ArrayList<>();
89+
PdfPTable table = new PdfPTable(config.getMetrics().length + 1);
90+
table.setHorizontalAlignment(table.ALIGN_LEFT);
91+
table.setWidthPercentage(95);
92+
table.setSpacingBefore(2);
93+
table.setSpacingAfter(2);
94+
Phrase pphrase = new Phrase("Project");
95+
Font pfont = pphrase.getFont();
96+
pfont.setSize(20);
97+
PdfPCell cell = new PdfPCell(pphrase);
98+
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
99+
cell.setBackgroundColor(Color.LIGHT_GRAY);
100+
cell.setPaddingBottom(cell.getPaddingBottom() + 3);
101+
table.addCell(cell);
102+
colWidths.add(2);
103+
int col = 1;
104+
for (SQMetrics m : config.getMetrics()) {
105+
Phrase phrase = new Phrase(m.getTitle());
106+
Font font = phrase.getFont();
107+
font.setSize(20);
108+
cell = new PdfPCell(phrase);
109+
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
110+
cell.setBackgroundColor(Color.LIGHT_GRAY);
111+
table.addCell(cell);
112+
colWidths.add(getWidthOfString(m.getTitle()));
113+
col++;
114+
}
115+
for (Application a : config.getApplications()) {
116+
col = 0;
117+
Phrase tphrase = new Phrase(a.getTitle());
118+
Font tfont = tphrase.getFont();
119+
tfont.setSize(20);
120+
cell = new PdfPCell(tphrase);
121+
cell.setPaddingLeft(cell.getPaddingLeft() + 2);
122+
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
123+
cell.setVerticalAlignment(Element.ALIGN_CENTER);
124+
cell.setPaddingBottom(cell.getPaddingBottom() + 3);
125+
setMax(colWidths, col, a.getTitle(), 0);
126+
table.addCell(cell);
127+
for (SQMetrics m : config.getMetrics()) {
128+
String text = SqgraphApplication.standardDecimalFormatter.format(dashboardData.get(m.getTitle(), a.getTitle()));
129+
Phrase phrase = new Phrase(text);
130+
Font font = phrase.getFont();
131+
font.setSize(20);
132+
cell = new PdfPCell(phrase);
133+
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
134+
cell.setVerticalAlignment(Element.ALIGN_CENTER);
135+
cell.setPaddingLeft(cell.getPaddingLeft() + 2);
136+
cell.setPaddingRight(cell.getPaddingRight() + 5);
137+
SQMetrics metric = config.getMetrics()[col];
138+
String greenString = metric.getGreen();
139+
String yellowString = metric.getYellow();
140+
if ((greenString != null) && (yellowString != null)) {
141+
double green = Double.parseDouble(greenString);
142+
double yellow = Double.parseDouble(yellowString);
143+
boolean greenHigher = true;
144+
if (yellow > green) greenHigher = false;
145+
double cellValue = Double.parseDouble(text);
146+
if (greenHigher) {
147+
if (cellValue > green) {
148+
cell.setBackgroundColor(Color.GREEN);
149+
} else {
150+
if (cellValue > yellow) {
151+
cell.setBackgroundColor(Color.YELLOW);
152+
} else {
153+
cell.setBackgroundColor(Color.PINK);
154+
}
155+
}
156+
} else {
157+
if (cellValue < green) {
158+
cell.setBackgroundColor(Color.GREEN);
159+
} else {
160+
if (cellValue < yellow) {
161+
cell.setBackgroundColor(Color.YELLOW);
162+
} else {
163+
cell.setBackgroundColor(Color.PINK);
164+
}
165+
}
166+
}
167+
}
168+
table.addCell(cell);
169+
col++;
170+
setMax(colWidths, col, text, 4);
171+
}
172+
}
173+
174+
int[] w = new int[colWidths.size()];
175+
int colWidthsSize = colWidths.size();
176+
for (int loop = 0; loop < colWidthsSize; loop++) {
177+
w[loop] = colWidths.get(loop);
178+
}
179+
180+
table.setWidths(w);
181+
document.add(table);
182+
} catch (Exception e) {
183+
e.printStackTrace();
184+
}
185+
}
186+
83187
private static int getWidthOfString(final String s) {
84188
int width = 2;
85189

@@ -106,67 +210,4 @@ private static void setMax (List<Integer> widths, int col, String s, int plus) {
106210
widths.set (col, width);
107211
}
108212
}
109-
110-
public static void addTextDashboard(final HashBasedTable<String, String, Double> dashboardData, final Config config) {
111-
document.add(new Phrase ("")); // spacer
112-
// Phrase p = new Phrase ("blah");
113-
// Font f = p.getFont();
114-
// System.out.println ("Font " + f.getFamilyname() + " size " + f.getSize());
115-
116-
List<Integer> colWidths = new ArrayList<>();
117-
118-
PdfPTable table = new PdfPTable(config.getMetrics().length + 1);
119-
table.setWidthPercentage(100);
120-
table.setSpacingBefore(1);
121-
table.setSpacingAfter(2);
122-
PdfPCell cell = new PdfPCell(new Phrase ("Text"));
123-
table.addCell(cell);
124-
colWidths.add (2);
125-
int col = 1;
126-
for (SQMetrics m : config.getMetrics()) {
127-
cell = new PdfPCell(new Phrase (m.getTitle()));
128-
129-
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
130-
table.addCell(cell);
131-
colWidths.add(getWidthOfString (m.getTitle()));
132-
col++;
133-
}
134-
for (Application a : config.getApplications()) {
135-
col = 0;
136-
cell = new PdfPCell(new Phrase (a.getTitle()));
137-
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
138-
cell.setVerticalAlignment(Element.ALIGN_CENTER);
139-
setMax(colWidths, col, a.getTitle(), 0);
140-
table.addCell(cell);
141-
for (SQMetrics m : config.getMetrics()) {
142-
col++;
143-
String text = SqgraphApplication.standardDecimalFormatter.format (dashboardData.get(m.getTitle(),a.getTitle()));
144-
cell = new PdfPCell(new Phrase (text));
145-
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
146-
cell.setVerticalAlignment(Element.ALIGN_CENTER);
147-
cell.setPaddingLeft(cell.getPaddingLeft() + 2);
148-
cell.setPaddingRight(cell.getPaddingRight() + 2);
149-
table.addCell(cell);
150-
setMax(colWidths, col, text, 4);
151-
}
152-
}
153-
154-
int [] w = new int [colWidths.size()];
155-
int sum = 0;
156-
int colWidthsSize = colWidths.size();
157-
for (int loop = 0; loop < colWidthsSize; loop++) {
158-
// System.out.println ("width " + loop + " = " + colWidths.get(loop));
159-
w [loop] = colWidths.get(loop);
160-
sum += w [loop];
161-
}
162-
System.out.println ("Sum = " + sum);
163-
164-
165-
166-
table.setWidths(w);
167-
168-
document.add (table);
169-
}
170-
171-
/* */
172213
}

src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
178178

179179
if (config.getPdf() != null) {
180180
PDFOutput.createPDF (config);
181-
// not ready for prime time..... yet PDFOutput.addTextDashboard (dashboardData, config);
182-
if (bi != null)
183-
PDFOutput.addDashboard (bi);
181+
PDFOutput.addTextDashboard (dashboardData, config);
182+
// if (bi != null)
183+
// PDFOutput.addDashboard (bi);
184184
PDFOutput.addGraphs(config);
185185
PDFOutput.closePDF();
186186
}
@@ -333,6 +333,5 @@ public static Date getUTCDate (final Date date) {
333333
LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC).withHour(0).withMinute(0).withSecond(0).withNano(0).plusDays(1);
334334
return Date.from(localDateTime.toInstant(ZoneOffset.UTC));
335335
}
336-
337336
}
338337

0 commit comments

Comments
 (0)