use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method generateAuditLogHeaderRULE.
@Test
public void generateAuditLogHeaderRULE() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
scenarioCsvDownloadReport.generateAuditLogHeader(printer, RULE);
String retrieved = stringBuilder.toString();
commonCheckHeader(RULE_AUDIT_HEADER, retrieved);
}
use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method generateRulesCounterHeaderDMN.
@Test
public void generateRulesCounterHeaderDMN() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
scenarioCsvDownloadReport.generateRulesCounterHeader(printer, DMN);
String retrieved = stringBuilder.toString();
commonCheckHeader(DMN_COUNTER_HEADER, retrieved);
}
use of org.apache.commons.csv.CSVPrinter in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method printAuditLogLine.
@Test
public void printAuditLogLine() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
AuditLogLine auditLogLine = getAuditLogLine();
scenarioCsvDownloadReport.printAuditLogLine(auditLogLine, printer);
String retrieved = stringBuilder.toString();
List<String> data = Arrays.asList(String.valueOf(auditLogLine.getScenarioIndex()), "\"" + auditLogLine.getScenario() + "\"", String.valueOf(auditLogLine.getExecutionIndex()), "\"" + auditLogLine.getDecisionOrRuleName() + "\"", auditLogLine.getResult(), auditLogLine.getMessage().orElse(""));
commonCheckRetrievedString(retrieved, data);
}
use of org.apache.commons.csv.CSVPrinter in project webapp by elimu-ai.
the class LetterCsvExportController method handleRequest.
@RequestMapping(value = "/letters.csv", method = RequestMethod.GET)
public void handleRequest(HttpServletResponse response, OutputStream outputStream) throws IOException {
logger.info("handleRequest");
List<Letter> letters = letterDao.readAllOrderedByUsage();
logger.info("letters.size(): " + letters.size());
CSVFormat csvFormat = CSVFormat.DEFAULT.withHeader("id", "text", "diacritic", "usage_count");
StringWriter stringWriter = new StringWriter();
CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
for (Letter letter : letters) {
logger.info("letter.getText(): \"" + letter.getText() + "\"");
csvPrinter.printRecord(letter.getId(), letter.getText(), letter.isDiacritic(), letter.getUsageCount());
csvPrinter.flush();
}
String csvFileContent = stringWriter.toString();
response.setContentType("text/csv");
byte[] bytes = csvFileContent.getBytes();
response.setContentLength(bytes.length);
try {
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
} catch (IOException ex) {
logger.error(ex);
}
}
use of org.apache.commons.csv.CSVPrinter in project webapp by elimu-ai.
the class WordCsvExportController method handleRequest.
@RequestMapping(value = "/words.csv", method = RequestMethod.GET)
public void handleRequest(HttpServletResponse response, OutputStream outputStream) throws IOException {
logger.info("handleRequest");
List<Word> words = wordDao.readAllOrderedByUsage();
logger.info("words.size(): " + words.size());
CSVFormat csvFormat = CSVFormat.DEFAULT.withHeader("id", "text", "letter_sound_correspondences", "usage_count", "word_type", "spelling_consistency", "root_word_id", "root_word_text");
StringWriter stringWriter = new StringWriter();
CSVPrinter csvPrinter = new CSVPrinter(stringWriter, csvFormat);
for (Word word : words) {
logger.info("word.getText(): \"" + word.getText() + "\"");
JSONArray letterSoundCorrespondencesJsonArray = new JSONArray();
int index = 0;
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
JSONObject letterSoundCorrespondenceJsonObject = new JSONObject();
letterSoundCorrespondenceJsonObject.put("id", letterSoundCorrespondence.getId());
String[] lettersArray = new String[letterSoundCorrespondence.getLetters().size()];
for (int i = 0; i < lettersArray.length; i++) {
lettersArray[i] = letterSoundCorrespondence.getLetters().get(i).getText();
}
letterSoundCorrespondenceJsonObject.put("letters", lettersArray);
String[] soundsArray = new String[letterSoundCorrespondence.getSounds().size()];
for (int i = 0; i < soundsArray.length; i++) {
soundsArray[i] = letterSoundCorrespondence.getSounds().get(i).getValueIpa();
}
letterSoundCorrespondenceJsonObject.put("sounds", soundsArray);
letterSoundCorrespondenceJsonObject.put("usageCount", letterSoundCorrespondence.getUsageCount());
letterSoundCorrespondencesJsonArray.put(index, letterSoundCorrespondenceJsonObject);
index++;
}
Long rootWordId = null;
String rootWordText = null;
if (word.getRootWord() != null) {
rootWordId = word.getRootWord().getId();
rootWordText = word.getRootWord().getText();
}
csvPrinter.printRecord(word.getId(), word.getText(), letterSoundCorrespondencesJsonArray, word.getUsageCount(), word.getWordType(), word.getSpellingConsistency(), rootWordId, rootWordText);
csvPrinter.flush();
}
String csvFileContent = stringWriter.toString();
response.setContentType("text/csv");
byte[] bytes = csvFileContent.getBytes();
response.setContentLength(bytes.length);
try {
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
} catch (IOException ex) {
logger.error(ex);
}
}
Aggregations