@Test public void testBuildLogbookStatCsvFile() throws VitamException, IOException { final ByteArrayOutputStream report = JsonTransformer.buildLogbookStatCsvFile(sampleLogbookOperation); }
public static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation) throws VitamException, IOException { final ByteArrayOutputStream csvOutputStream = new ByteArrayOutputStream(); try (Writer csvWriter = new BufferedWriter(new OutputStreamWriter(csvOutputStream));) { final String startOperationTimeStr = logbookOperation.get(EVENT_DATE_TIME_FIELD).asText(); final List<JsonNode> events = IteratorUtils.toList(logbookOperation.get(EVENTS_FIELD).iterator()); final JsonNode lastEvent = events.get(events.size() - 1); final String endOperationTimeStr = lastEvent.get(EVENT_DATE_TIME_FIELD).asText(); final CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.newFormat(SEMI_COLON_SEPARATOR).withRecordSeparator(RECORD_SEPARATOR)); final List<String> header = IteratorUtils.toList(lastEvent.fieldNames()); header.add(START_EVENT_DATETIME_HEADER); header.add(END_EVENT_DATETIME_HEADER); header.add(EXECUTION_TIME_HEADER); csvPrinter.printRecord(header); for (int i = 0; i < events.size() - 1; i += 2) { final JsonNode startEvent = events.get(i); final JsonNode endEvent = events.get(i + 1); final List<String> eventReportDetails = IteratorUtils.toList(endEvent.elements()); final String startEventDateTimeStr = startEvent.get(EVENT_DATE_TIME_FIELD).asText(); final String endEventDateTimeStr = endEvent.get(EVENT_DATE_TIME_FIELD).asText(); eventReportDetails.add(startEventDateTimeStr); eventReportDetails.add(endEventDateTimeStr); eventReportDetails.add(calculateExecutionTime(startEventDateTimeStr, endEventDateTimeStr).toString()); csvPrinter.printRecord(eventReportDetails); } final List<String> lastEventDetails = IteratorUtils.toList(lastEvent.elements()); lastEventDetails.add(startOperationTimeStr); lastEventDetails.add(endOperationTimeStr); lastEventDetails.add(calculateExecutionTime(startOperationTimeStr, endOperationTimeStr).toString()); csvPrinter.printRecord(lastEventDetails); csvPrinter.flush(); csvPrinter.close(); } catch (final Exception e) { csvOutputStream.close(); throw new VitamException(UNEXPECTED_EXCEPTION_DURING_CSV_FILE_GENERATION); } return csvOutputStream; }
JsonTransformer { public static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation) throws VitamException, IOException { final ByteArrayOutputStream csvOutputStream = new ByteArrayOutputStream(); try (Writer csvWriter = new BufferedWriter(new OutputStreamWriter(csvOutputStream));) { final String startOperationTimeStr = logbookOperation.get(EVENT_DATE_TIME_FIELD).asText(); final List<JsonNode> events = IteratorUtils.toList(logbookOperation.get(EVENTS_FIELD).iterator()); final JsonNode lastEvent = events.get(events.size() - 1); final String endOperationTimeStr = lastEvent.get(EVENT_DATE_TIME_FIELD).asText(); final CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.newFormat(SEMI_COLON_SEPARATOR).withRecordSeparator(RECORD_SEPARATOR)); final List<String> header = IteratorUtils.toList(lastEvent.fieldNames()); header.add(START_EVENT_DATETIME_HEADER); header.add(END_EVENT_DATETIME_HEADER); header.add(EXECUTION_TIME_HEADER); csvPrinter.printRecord(header); for (int i = 0; i < events.size() - 1; i += 2) { final JsonNode startEvent = events.get(i); final JsonNode endEvent = events.get(i + 1); final List<String> eventReportDetails = IteratorUtils.toList(endEvent.elements()); final String startEventDateTimeStr = startEvent.get(EVENT_DATE_TIME_FIELD).asText(); final String endEventDateTimeStr = endEvent.get(EVENT_DATE_TIME_FIELD).asText(); eventReportDetails.add(startEventDateTimeStr); eventReportDetails.add(endEventDateTimeStr); eventReportDetails.add(calculateExecutionTime(startEventDateTimeStr, endEventDateTimeStr).toString()); csvPrinter.printRecord(eventReportDetails); } final List<String> lastEventDetails = IteratorUtils.toList(lastEvent.elements()); lastEventDetails.add(startOperationTimeStr); lastEventDetails.add(endOperationTimeStr); lastEventDetails.add(calculateExecutionTime(startOperationTimeStr, endOperationTimeStr).toString()); csvPrinter.printRecord(lastEventDetails); csvPrinter.flush(); csvPrinter.close(); } catch (final Exception e) { csvOutputStream.close(); throw new VitamException(UNEXPECTED_EXCEPTION_DURING_CSV_FILE_GENERATION); } return csvOutputStream; } }
JsonTransformer { public static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation) throws VitamException, IOException { final ByteArrayOutputStream csvOutputStream = new ByteArrayOutputStream(); try (Writer csvWriter = new BufferedWriter(new OutputStreamWriter(csvOutputStream));) { final String startOperationTimeStr = logbookOperation.get(EVENT_DATE_TIME_FIELD).asText(); final List<JsonNode> events = IteratorUtils.toList(logbookOperation.get(EVENTS_FIELD).iterator()); final JsonNode lastEvent = events.get(events.size() - 1); final String endOperationTimeStr = lastEvent.get(EVENT_DATE_TIME_FIELD).asText(); final CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.newFormat(SEMI_COLON_SEPARATOR).withRecordSeparator(RECORD_SEPARATOR)); final List<String> header = IteratorUtils.toList(lastEvent.fieldNames()); header.add(START_EVENT_DATETIME_HEADER); header.add(END_EVENT_DATETIME_HEADER); header.add(EXECUTION_TIME_HEADER); csvPrinter.printRecord(header); for (int i = 0; i < events.size() - 1; i += 2) { final JsonNode startEvent = events.get(i); final JsonNode endEvent = events.get(i + 1); final List<String> eventReportDetails = IteratorUtils.toList(endEvent.elements()); final String startEventDateTimeStr = startEvent.get(EVENT_DATE_TIME_FIELD).asText(); final String endEventDateTimeStr = endEvent.get(EVENT_DATE_TIME_FIELD).asText(); eventReportDetails.add(startEventDateTimeStr); eventReportDetails.add(endEventDateTimeStr); eventReportDetails.add(calculateExecutionTime(startEventDateTimeStr, endEventDateTimeStr).toString()); csvPrinter.printRecord(eventReportDetails); } final List<String> lastEventDetails = IteratorUtils.toList(lastEvent.elements()); lastEventDetails.add(startOperationTimeStr); lastEventDetails.add(endOperationTimeStr); lastEventDetails.add(calculateExecutionTime(startOperationTimeStr, endOperationTimeStr).toString()); csvPrinter.printRecord(lastEventDetails); csvPrinter.flush(); csvPrinter.close(); } catch (final Exception e) { csvOutputStream.close(); throw new VitamException(UNEXPECTED_EXCEPTION_DURING_CSV_FILE_GENERATION); } return csvOutputStream; } private  JsonTransformer(); }
JsonTransformer { public static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation) throws VitamException, IOException { final ByteArrayOutputStream csvOutputStream = new ByteArrayOutputStream(); try (Writer csvWriter = new BufferedWriter(new OutputStreamWriter(csvOutputStream));) { final String startOperationTimeStr = logbookOperation.get(EVENT_DATE_TIME_FIELD).asText(); final List<JsonNode> events = IteratorUtils.toList(logbookOperation.get(EVENTS_FIELD).iterator()); final JsonNode lastEvent = events.get(events.size() - 1); final String endOperationTimeStr = lastEvent.get(EVENT_DATE_TIME_FIELD).asText(); final CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.newFormat(SEMI_COLON_SEPARATOR).withRecordSeparator(RECORD_SEPARATOR)); final List<String> header = IteratorUtils.toList(lastEvent.fieldNames()); header.add(START_EVENT_DATETIME_HEADER); header.add(END_EVENT_DATETIME_HEADER); header.add(EXECUTION_TIME_HEADER); csvPrinter.printRecord(header); for (int i = 0; i < events.size() - 1; i += 2) { final JsonNode startEvent = events.get(i); final JsonNode endEvent = events.get(i + 1); final List<String> eventReportDetails = IteratorUtils.toList(endEvent.elements()); final String startEventDateTimeStr = startEvent.get(EVENT_DATE_TIME_FIELD).asText(); final String endEventDateTimeStr = endEvent.get(EVENT_DATE_TIME_FIELD).asText(); eventReportDetails.add(startEventDateTimeStr); eventReportDetails.add(endEventDateTimeStr); eventReportDetails.add(calculateExecutionTime(startEventDateTimeStr, endEventDateTimeStr).toString()); csvPrinter.printRecord(eventReportDetails); } final List<String> lastEventDetails = IteratorUtils.toList(lastEvent.elements()); lastEventDetails.add(startOperationTimeStr); lastEventDetails.add(endOperationTimeStr); lastEventDetails.add(calculateExecutionTime(startOperationTimeStr, endOperationTimeStr).toString()); csvPrinter.printRecord(lastEventDetails); csvPrinter.flush(); csvPrinter.close(); } catch (final Exception e) { csvOutputStream.close(); throw new VitamException(UNEXPECTED_EXCEPTION_DURING_CSV_FILE_GENERATION); } return csvOutputStream; } private  JsonTransformer(); static JsonNode transformResultObjects(JsonNode searchResult); static ObjectNode buildAllParentsRef(String unitId, JsonNode allParents); static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation); }
JsonTransformer { public static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation) throws VitamException, IOException { final ByteArrayOutputStream csvOutputStream = new ByteArrayOutputStream(); try (Writer csvWriter = new BufferedWriter(new OutputStreamWriter(csvOutputStream));) { final String startOperationTimeStr = logbookOperation.get(EVENT_DATE_TIME_FIELD).asText(); final List<JsonNode> events = IteratorUtils.toList(logbookOperation.get(EVENTS_FIELD).iterator()); final JsonNode lastEvent = events.get(events.size() - 1); final String endOperationTimeStr = lastEvent.get(EVENT_DATE_TIME_FIELD).asText(); final CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.newFormat(SEMI_COLON_SEPARATOR).withRecordSeparator(RECORD_SEPARATOR)); final List<String> header = IteratorUtils.toList(lastEvent.fieldNames()); header.add(START_EVENT_DATETIME_HEADER); header.add(END_EVENT_DATETIME_HEADER); header.add(EXECUTION_TIME_HEADER); csvPrinter.printRecord(header); for (int i = 0; i < events.size() - 1; i += 2) { final JsonNode startEvent = events.get(i); final JsonNode endEvent = events.get(i + 1); final List<String> eventReportDetails = IteratorUtils.toList(endEvent.elements()); final String startEventDateTimeStr = startEvent.get(EVENT_DATE_TIME_FIELD).asText(); final String endEventDateTimeStr = endEvent.get(EVENT_DATE_TIME_FIELD).asText(); eventReportDetails.add(startEventDateTimeStr); eventReportDetails.add(endEventDateTimeStr); eventReportDetails.add(calculateExecutionTime(startEventDateTimeStr, endEventDateTimeStr).toString()); csvPrinter.printRecord(eventReportDetails); } final List<String> lastEventDetails = IteratorUtils.toList(lastEvent.elements()); lastEventDetails.add(startOperationTimeStr); lastEventDetails.add(endOperationTimeStr); lastEventDetails.add(calculateExecutionTime(startOperationTimeStr, endOperationTimeStr).toString()); csvPrinter.printRecord(lastEventDetails); csvPrinter.flush(); csvPrinter.close(); } catch (final Exception e) { csvOutputStream.close(); throw new VitamException(UNEXPECTED_EXCEPTION_DURING_CSV_FILE_GENERATION); } return csvOutputStream; } private  JsonTransformer(); static JsonNode transformResultObjects(JsonNode searchResult); static ObjectNode buildAllParentsRef(String unitId, JsonNode allParents); static ByteArrayOutputStream buildLogbookStatCsvFile(JsonNode logbookOperation);  }