Skip to content

Commit

Permalink
#4378 Add reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Jan 7, 2025
1 parent a9553a0 commit 385b9e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import stroom.dashboard.impl.SampleGenerator;
import stroom.dashboard.impl.download.DelimitedTarget;
import stroom.dashboard.impl.download.ExcelTarget;
import stroom.dashboard.impl.download.ExcelTarget.KV;
import stroom.dashboard.impl.download.SearchResultWriter;
import stroom.dashboard.shared.DownloadSearchResultFileType;
import stroom.data.shared.StreamTypeNames;
Expand Down Expand Up @@ -215,6 +216,7 @@ boolean process(final ReportDoc reportDoc,
// Create the output file.
file = createFile(
reportDoc,
executionTime,
effectiveExecutionTime,
modifiedRequest.getDateTimeSettings(),
dataStore,
Expand Down Expand Up @@ -296,14 +298,13 @@ boolean process(final ReportDoc reportDoc,
}

private Path createFile(final ReportDoc reportDoc,
final Instant executionTime,
final Instant effectiveExecutionTime,
final DateTimeSettings dateTimeSettings,
final DataStore dataStore,
final ResultRequest resultRequest) throws IOException {
long totalRowCount = 0;
final DownloadSearchResultFileType fileType = reportDoc.getReportSettings().getFileType();

// Import file.
final String dateTime = DateUtil.createFileDateTimeString(effectiveExecutionTime);
final String fileName = getFileName(reportDoc.getName() + "_" + dateTime,
fileType.getExtension());
Expand Down Expand Up @@ -333,8 +334,7 @@ private Path createFile(final ReportDoc reportDoc,
target.start();

try {
target.startTable("Report " +
DateUtil.createFileDateTimeString(effectiveExecutionTime));
target.startTable("Report");

final SampleGenerator sampleGenerator =
new SampleGenerator(false, 100);
Expand All @@ -358,6 +358,22 @@ public TableResultBuilder createTableResultBuilder() {
} finally {
target.endTable();
}

// Write report info sheet if this is an Excel target.
if (target instanceof final ExcelTarget excelTarget) {
final List<ExcelTarget.KV> info = new ArrayList<>();
info.add(new KV("Report Name", reportDoc.getName()));
info.add(new KV("Report Description",
reportDoc.getDescription() != null
? reportDoc.getDescription().replaceAll("\n", "")
: ""));
info.add(new KV("Execution Time",
DateUtil.createNormalDateTimeString(executionTime)));
info.add(new KV("Effective Execution Time",
DateUtil.createNormalDateTimeString(effectiveExecutionTime)));
excelTarget.writeInfo(info);
}

} catch (final Exception e) {
LOGGER.debug(e::getMessage, e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

Expand All @@ -39,6 +40,7 @@
import java.time.format.DateTimeParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -316,4 +318,29 @@ private Optional<CellStyle> getFieldStyle(final Column key) {
return Optional.ofNullable(cellStyle);
});
}

public void writeInfo(final List<KV> info) {
if (workbook != null) {
int rowNum = 0;
final SXSSFSheet sheet = workbook.createSheet("Info");
for (final KV kv : info) {
final SXSSFRow row = sheet.createRow(rowNum++);
final Cell keyCell = row.createCell(0);
keyCell.setCellValue(kv.key);
keyCell.setCellStyle(headingStyle);

final Cell valueCell = row.createCell(1);
valueCell.setCellValue(kv.value);
}

// Auto-size tracked columns
for (var columnIndex : sheet.getTrackedColumnsForAutoSizing()) {
sheet.autoSizeColumn(columnIndex);
}
}
}

public record KV(String key, String value) {

}
}

0 comments on commit 385b9e7

Please sign in to comment.