use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReport method getReport.
/**
* @param simulationRunMetadata the <code>SimulationRunMetadata</code> to print out
* @param modelType
* @return
* @throws IOException
*/
public String getReport(SimulationRunMetadata simulationRunMetadata, ScenarioSimulationModel.Type modelType) {
StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter printer = new CSVPrinter(stringBuilder, CSVFormat.DEFAULT.withNullString(""))) {
generateOverallStatsHeader(printer, modelType);
printOverallStatsLine(printer, simulationRunMetadata.getAvailable(), simulationRunMetadata.getExecuted(), simulationRunMetadata.getCoveragePercentage());
Map<String, Integer> outputCounter = simulationRunMetadata.getOutputCounter();
if (outputCounter != null && !outputCounter.isEmpty()) {
printer.println();
generateRulesCounterHeader(printer, modelType);
for (Map.Entry<String, Integer> entry : outputCounter.entrySet()) {
printRulesCounterLine(printer, entry.getKey(), entry.getValue());
}
}
List<AuditLogLine> auditLogLines = simulationRunMetadata.getAuditLog().getAuditLogLines();
if (auditLogLines != null && !auditLogLines.isEmpty()) {
printer.println();
generateAuditLogHeader(printer, modelType);
for (AuditLogLine auditLogLine : auditLogLines) {
printAuditLogLine(auditLogLine, printer);
}
}
} catch (IOException e) {
throw ExceptionUtilities.handleException(e);
}
return stringBuilder.toString();
}
use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvImportExport method exportData.
public String exportData(AbstractScesimModel<? extends AbstractScesimData> scesimModel) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
List<FactMapping> factMappings = scesimModel.getScesimModelDescriptor().getUnmodifiableFactMappings();
CSVPrinter printer = new CSVPrinter(stringBuilder, CSVFormat.DEFAULT);
generateHeader(factMappings, printer);
for (AbstractScesimData scesimData : scesimModel.getUnmodifiableData()) {
List<Object> values = new ArrayList<>();
for (FactMapping factMapping : factMappings) {
Optional<FactMappingValue> factMappingValue = scesimData.getFactMappingValue(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier());
values.add(factMappingValue.map(FactMappingValue::getRawValue).orElse(""));
}
printer.printRecord(values.toArray());
}
printer.close();
return stringBuilder.toString();
}
use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method printOverallStatsLine.
@Test
public void printOverallStatsLine() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
AuditLog auditLog = new AuditLog();
auditLog.addAuditLogLine(getAuditLogLine());
SimulationRunMetadata simulationRunMetadata = getSimulationRunMetadata(auditLog);
scenarioCsvDownloadReport.printOverallStatsLine(printer, simulationRunMetadata.getAvailable(), simulationRunMetadata.getExecuted(), simulationRunMetadata.getCoveragePercentage());
String retrieved = stringBuilder.toString();
List<String> data = Arrays.asList(String.valueOf(simulationRunMetadata.getAvailable()), String.valueOf(simulationRunMetadata.getExecuted()), String.valueOf(simulationRunMetadata.getCoveragePercentage()));
commonCheckRetrievedString(retrieved, data);
}
use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method generateOverallStatsHeaderDMN.
@Test
public void generateOverallStatsHeaderDMN() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
scenarioCsvDownloadReport.generateOverallStatsHeader(printer, DMN);
String retrieved = stringBuilder.toString();
commonCheckHeader(DMN_OVERALL_STATS_HEADER, retrieved);
}
use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method generateRulesCounterHeaderRULE.
@Test
public void generateRulesCounterHeaderRULE() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
scenarioCsvDownloadReport.generateRulesCounterHeader(printer, ScenarioSimulationModel.Type.RULE);
String retrieved = stringBuilder.toString();
commonCheckHeader(RULE_COUNTER_HEADER, retrieved);
}
Aggregations