@Test public void should_save_one_offer_log() throws Exception { service.save("containerName", "fileName", DELETE, 42); OfferLog offerLog = getFirstLogFromDb(); assertThat(offerLog.getFileName()).isEqualTo("fileName"); assertThat(offerLog.getContainer()).isEqualTo("containerName"); assertThat(offerLog.getSequence()).isEqualTo(42); assertThat(offerLog.getAction()).isEqualTo(DELETE); }
public void save(String containerName, String fileName, OfferLogAction action, long sequence) throws ContentAddressableStorageServerException, ContentAddressableStorageDatabaseException { try { OfferLog offerLog = new OfferLog(sequence, LocalDateUtil.now(), containerName, fileName, action); mongoCollection.insertOne(Document.parse(JsonHandler.writeAsString(offerLog))); } catch (MongoException e) { throw new ContentAddressableStorageDatabaseException(String.format( "Database Error while saving %s in OfferLog collection", fileName), e); } catch (InvalidParseOperationException e) { throw new ContentAddressableStorageServerException("Cannot parse storage log", e); } }
OfferLogDatabaseService { public void save(String containerName, String fileName, OfferLogAction action, long sequence) throws ContentAddressableStorageServerException, ContentAddressableStorageDatabaseException { try { OfferLog offerLog = new OfferLog(sequence, LocalDateUtil.now(), containerName, fileName, action); mongoCollection.insertOne(Document.parse(JsonHandler.writeAsString(offerLog))); } catch (MongoException e) { throw new ContentAddressableStorageDatabaseException(String.format( "Database Error while saving %s in OfferLog collection", fileName), e); } catch (InvalidParseOperationException e) { throw new ContentAddressableStorageServerException("Cannot parse storage log", e); } } }
OfferLogDatabaseService { public void save(String containerName, String fileName, OfferLogAction action, long sequence) throws ContentAddressableStorageServerException, ContentAddressableStorageDatabaseException { try { OfferLog offerLog = new OfferLog(sequence, LocalDateUtil.now(), containerName, fileName, action); mongoCollection.insertOne(Document.parse(JsonHandler.writeAsString(offerLog))); } catch (MongoException e) { throw new ContentAddressableStorageDatabaseException(String.format( "Database Error while saving %s in OfferLog collection", fileName), e); } catch (InvalidParseOperationException e) { throw new ContentAddressableStorageServerException("Cannot parse storage log", e); } } OfferLogDatabaseService(MongoCollection<Document> mongoCollection); }
OfferLogDatabaseService { public void save(String containerName, String fileName, OfferLogAction action, long sequence) throws ContentAddressableStorageServerException, ContentAddressableStorageDatabaseException { try { OfferLog offerLog = new OfferLog(sequence, LocalDateUtil.now(), containerName, fileName, action); mongoCollection.insertOne(Document.parse(JsonHandler.writeAsString(offerLog))); } catch (MongoException e) { throw new ContentAddressableStorageDatabaseException(String.format( "Database Error while saving %s in OfferLog collection", fileName), e); } catch (InvalidParseOperationException e) { throw new ContentAddressableStorageServerException("Cannot parse storage log", e); } } OfferLogDatabaseService(MongoCollection<Document> mongoCollection); void save(String containerName, String fileName, OfferLogAction action, long sequence); void bulkSave(String containerName, List<String> fileNames, OfferLogAction action, long sequence); CloseableIterable<OfferLog> getDescendingOfferLogsBy(String containerName, Long offset, int limit); CloseableIterable<OfferLog> getAscendingOfferLogsBy(String containerName, Long offset, int limit); CloseableIterable<OfferLog> getExpiredOfferLogByContainer(long expirationValue, ChronoUnit expirationUnit); }
OfferLogDatabaseService { public void save(String containerName, String fileName, OfferLogAction action, long sequence) throws ContentAddressableStorageServerException, ContentAddressableStorageDatabaseException { try { OfferLog offerLog = new OfferLog(sequence, LocalDateUtil.now(), containerName, fileName, action); mongoCollection.insertOne(Document.parse(JsonHandler.writeAsString(offerLog))); } catch (MongoException e) { throw new ContentAddressableStorageDatabaseException(String.format( "Database Error while saving %s in OfferLog collection", fileName), e); } catch (InvalidParseOperationException e) { throw new ContentAddressableStorageServerException("Cannot parse storage log", e); } } OfferLogDatabaseService(MongoCollection<Document> mongoCollection); void save(String containerName, String fileName, OfferLogAction action, long sequence); void bulkSave(String containerName, List<String> fileNames, OfferLogAction action, long sequence); CloseableIterable<OfferLog> getDescendingOfferLogsBy(String containerName, Long offset, int limit); CloseableIterable<OfferLog> getAscendingOfferLogsBy(String containerName, Long offset, int limit); CloseableIterable<OfferLog> getExpiredOfferLogByContainer(long expirationValue, ChronoUnit expirationUnit);  }