@Test @RunWithCustomExecutor public void should_correctly_save_data_and_not_update_startDate_for_not_first_traceability() throws Exception { LogbookOperations logbookOperations = mock(LogbookOperations.class); GUID guid = GUIDFactory.newOperationLogbookGUID(0); LogbookOperationTraceabilityHelper helper = new LogbookOperationTraceabilityHelper(logbookOperations, guid, OPERATION_TRACEABILITY_TEMPORIZATION_DELAY); InputStream stream = getClass().getResourceAsStream(LOGBOOK_OPERATION_WITH_TOKEN); JsonNode jsonNode = JsonHandler.getFromInputStream(stream); LogbookOperation logbookOperation = new LogbookOperation(jsonNode); MongoCursor<LogbookOperation> cursor = getMongoCursorFor(logbookOperation); given(logbookOperations.selectOperationsByLastPersistenceDateInterval(any(), any())).willReturn(cursor); final MerkleTreeAlgo algo = new MerkleTreeAlgo(VitamConfiguration.getDefaultDigestType()); File zipFile = new File(folder.newFolder(), String.format(FILE_NAME)); TraceabilityFile file = new TraceabilityFile(zipFile); helper.saveDataInZip(algo, file); file.close(); assertThat(Files.size(Paths.get(zipFile.getPath()))).isEqualTo(5534L); }
@Override public void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file) throws IOException, TraceabilityException { MongoCursor<LogbookOperation> mongoCursor; try { mongoCursor = logbookOperations .selectOperationsByLastPersistenceDateInterval(traceabilityStartDate, traceabilityEndDate); } catch (LogbookDatabaseException | LogbookNotFoundException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new TraceabilityException(e); } traceabilityIterator = new LogbookTraceabilityIterator(mongoCursor); file.initStoreLog(); try { while (traceabilityIterator.hasNext()) { final LogbookOperation logbookOperation = traceabilityIterator.next(); JsonNode logbookOperationJsonNode = JsonHandler.toJsonNode(logbookOperation); byte[] logbookOperationJsonBytes = CanonicalJsonFormatter.serializeToByteArray(logbookOperationJsonNode); file.storeLog(logbookOperationJsonBytes); algo.addLeaf(logbookOperationJsonBytes); } } catch (InvalidParseOperationException e) { throw new TraceabilityException("Could not convert document to json", e); } file.closeStoreLog(); }
LogbookOperationTraceabilityHelper implements LogbookTraceabilityHelper { @Override public void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file) throws IOException, TraceabilityException { MongoCursor<LogbookOperation> mongoCursor; try { mongoCursor = logbookOperations .selectOperationsByLastPersistenceDateInterval(traceabilityStartDate, traceabilityEndDate); } catch (LogbookDatabaseException | LogbookNotFoundException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new TraceabilityException(e); } traceabilityIterator = new LogbookTraceabilityIterator(mongoCursor); file.initStoreLog(); try { while (traceabilityIterator.hasNext()) { final LogbookOperation logbookOperation = traceabilityIterator.next(); JsonNode logbookOperationJsonNode = JsonHandler.toJsonNode(logbookOperation); byte[] logbookOperationJsonBytes = CanonicalJsonFormatter.serializeToByteArray(logbookOperationJsonNode); file.storeLog(logbookOperationJsonBytes); algo.addLeaf(logbookOperationJsonBytes); } } catch (InvalidParseOperationException e) { throw new TraceabilityException("Could not convert document to json", e); } file.closeStoreLog(); } }
LogbookOperationTraceabilityHelper implements LogbookTraceabilityHelper { @Override public void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file) throws IOException, TraceabilityException { MongoCursor<LogbookOperation> mongoCursor; try { mongoCursor = logbookOperations .selectOperationsByLastPersistenceDateInterval(traceabilityStartDate, traceabilityEndDate); } catch (LogbookDatabaseException | LogbookNotFoundException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new TraceabilityException(e); } traceabilityIterator = new LogbookTraceabilityIterator(mongoCursor); file.initStoreLog(); try { while (traceabilityIterator.hasNext()) { final LogbookOperation logbookOperation = traceabilityIterator.next(); JsonNode logbookOperationJsonNode = JsonHandler.toJsonNode(logbookOperation); byte[] logbookOperationJsonBytes = CanonicalJsonFormatter.serializeToByteArray(logbookOperationJsonNode); file.storeLog(logbookOperationJsonBytes); algo.addLeaf(logbookOperationJsonBytes); } } catch (InvalidParseOperationException e) { throw new TraceabilityException("Could not convert document to json", e); } file.closeStoreLog(); } LogbookOperationTraceabilityHelper(LogbookOperations logbookOperations,
        GUID operationID, int temporizationDelayInSeconds); }
LogbookOperationTraceabilityHelper implements LogbookTraceabilityHelper { @Override public void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file) throws IOException, TraceabilityException { MongoCursor<LogbookOperation> mongoCursor; try { mongoCursor = logbookOperations .selectOperationsByLastPersistenceDateInterval(traceabilityStartDate, traceabilityEndDate); } catch (LogbookDatabaseException | LogbookNotFoundException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new TraceabilityException(e); } traceabilityIterator = new LogbookTraceabilityIterator(mongoCursor); file.initStoreLog(); try { while (traceabilityIterator.hasNext()) { final LogbookOperation logbookOperation = traceabilityIterator.next(); JsonNode logbookOperationJsonNode = JsonHandler.toJsonNode(logbookOperation); byte[] logbookOperationJsonBytes = CanonicalJsonFormatter.serializeToByteArray(logbookOperationJsonNode); file.storeLog(logbookOperationJsonBytes); algo.addLeaf(logbookOperationJsonBytes); } } catch (InvalidParseOperationException e) { throw new TraceabilityException("Could not convert document to json", e); } file.closeStoreLog(); } LogbookOperationTraceabilityHelper(LogbookOperations logbookOperations,
        GUID operationID, int temporizationDelayInSeconds); @Override void initialize(); @Override void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file); @Override String getPreviousStartDate(); @Override byte[] getPreviousTimestampToken(); @Override String getPreviousMonthStartDate(); @Override byte[] getPreviousMonthTimestampToken(); @Override String getPreviousYearStartDate(); @Override byte[] getPreviousYearTimestampToken(); @Override void createLogbookOperationStructure(); @Override void createLogbookOperationEvent(Integer tenantId, String eventType, StatusCode status,
        TraceabilityEvent event); @Override void saveEmpty(Integer tenantId); @Override void storeAndDeleteZip(Integer tenant, String strategyId, File zipFile, String fileName,
        TraceabilityEvent event); @Override String getStepName(); @Override String getTimestampStepName(); @Override String getZipName(); @Override TraceabilityType getTraceabilityType(); @Override boolean getMaxEntriesReached(); @Override TraceabilityStatistics getTraceabilityStatistics(); @Override long getDataSize(); @Override String getTraceabilityStartDate(); @Override String getTraceabilityEndDate(); }
LogbookOperationTraceabilityHelper implements LogbookTraceabilityHelper { @Override public void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file) throws IOException, TraceabilityException { MongoCursor<LogbookOperation> mongoCursor; try { mongoCursor = logbookOperations .selectOperationsByLastPersistenceDateInterval(traceabilityStartDate, traceabilityEndDate); } catch (LogbookDatabaseException | LogbookNotFoundException | InvalidParseOperationException | InvalidCreateOperationException e) { throw new TraceabilityException(e); } traceabilityIterator = new LogbookTraceabilityIterator(mongoCursor); file.initStoreLog(); try { while (traceabilityIterator.hasNext()) { final LogbookOperation logbookOperation = traceabilityIterator.next(); JsonNode logbookOperationJsonNode = JsonHandler.toJsonNode(logbookOperation); byte[] logbookOperationJsonBytes = CanonicalJsonFormatter.serializeToByteArray(logbookOperationJsonNode); file.storeLog(logbookOperationJsonBytes); algo.addLeaf(logbookOperationJsonBytes); } } catch (InvalidParseOperationException e) { throw new TraceabilityException("Could not convert document to json", e); } file.closeStoreLog(); } LogbookOperationTraceabilityHelper(LogbookOperations logbookOperations,
        GUID operationID, int temporizationDelayInSeconds); @Override void initialize(); @Override void saveDataInZip(MerkleTreeAlgo algo, TraceabilityFile file); @Override String getPreviousStartDate(); @Override byte[] getPreviousTimestampToken(); @Override String getPreviousMonthStartDate(); @Override byte[] getPreviousMonthTimestampToken(); @Override String getPreviousYearStartDate(); @Override byte[] getPreviousYearTimestampToken(); @Override void createLogbookOperationStructure(); @Override void createLogbookOperationEvent(Integer tenantId, String eventType, StatusCode status,
        TraceabilityEvent event); @Override void saveEmpty(Integer tenantId); @Override void storeAndDeleteZip(Integer tenant, String strategyId, File zipFile, String fileName,
        TraceabilityEvent event); @Override String getStepName(); @Override String getTimestampStepName(); @Override String getZipName(); @Override TraceabilityType getTraceabilityType(); @Override boolean getMaxEntriesReached(); @Override TraceabilityStatistics getTraceabilityStatistics(); @Override long getDataSize(); @Override String getTraceabilityStartDate(); @Override String getTraceabilityEndDate();  }