@Test void testNetworkAddressBookAppend() throws Exception { byte[] fileContents = new byte[] {0b0, 0b1, 0b10}; Transaction transaction = buildTransaction(builder -> { builder.setFileAppend(FileAppendTransactionBody.newBuilder() .setFileID(ADDRESS_BOOK_FILE_ID) .setContents(ByteString.copyFrom(fileContents)) .build()); }); EntityId entityId = EntityId.of(ADDRESS_BOOK_FILE_ID); doReturn(EntityId.of(ADDRESS_BOOK_FILE_ID)).when(transactionHandler).getEntity(any()); pubSubRecordItemListener.onItem(new RecordItem(transaction.toByteArray(), DEFAULT_RECORD_BYTES)); FileData fileData = new FileData(100L, fileContents, entityId, TransactionTypeEnum.FILEAPPEND .getProtoId()); verify(addressBookService).update(fileData); }
@Override public void onItem(RecordItem recordItem) throws ImporterException { TransactionBody body = recordItem.getTransactionBody(); TransactionRecord txRecord = recordItem.getRecord(); TransactionHandler transactionHandler = transactionHandlerFactory.create(body); log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body)); long consensusTimestamp = Utility.timeStampInNanos(txRecord.getConsensusTimestamp()); EntityId entity = transactionHandler.getEntity(recordItem); PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entity, recordItem); try { sendPubSubMessage(pubSubMessage); } catch (Exception e) { throw new ParserException("Error sending transaction to pubsub", e); } log.debug("Published transaction : {}", consensusTimestamp); if (addressBookService.isAddressBook(entity)) { FileID fileID = null; byte[] fileBytes = null; if (body.hasFileAppend()) { fileID = body.getFileAppend().getFileID(); fileBytes = body.getFileAppend().getContents().toByteArray(); } else if (body.hasFileCreate()) { fileID = txRecord.getReceipt().getFileID(); fileBytes = body.getFileCreate().getContents().toByteArray(); } else if (body.hasFileUpdate()) { fileID = body.getFileUpdate().getFileID(); fileBytes = body.getFileUpdate().getContents().toByteArray(); } FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem .getTransactionType()); fileDataRepository.save(fileData); addressBookService.update(fileData); } }
PubSubRecordItemListener implements RecordItemListener { @Override public void onItem(RecordItem recordItem) throws ImporterException { TransactionBody body = recordItem.getTransactionBody(); TransactionRecord txRecord = recordItem.getRecord(); TransactionHandler transactionHandler = transactionHandlerFactory.create(body); log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body)); long consensusTimestamp = Utility.timeStampInNanos(txRecord.getConsensusTimestamp()); EntityId entity = transactionHandler.getEntity(recordItem); PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entity, recordItem); try { sendPubSubMessage(pubSubMessage); } catch (Exception e) { throw new ParserException("Error sending transaction to pubsub", e); } log.debug("Published transaction : {}", consensusTimestamp); if (addressBookService.isAddressBook(entity)) { FileID fileID = null; byte[] fileBytes = null; if (body.hasFileAppend()) { fileID = body.getFileAppend().getFileID(); fileBytes = body.getFileAppend().getContents().toByteArray(); } else if (body.hasFileCreate()) { fileID = txRecord.getReceipt().getFileID(); fileBytes = body.getFileCreate().getContents().toByteArray(); } else if (body.hasFileUpdate()) { fileID = body.getFileUpdate().getFileID(); fileBytes = body.getFileUpdate().getContents().toByteArray(); } FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem .getTransactionType()); fileDataRepository.save(fileData); addressBookService.update(fileData); } } }
PubSubRecordItemListener implements RecordItemListener { @Override public void onItem(RecordItem recordItem) throws ImporterException { TransactionBody body = recordItem.getTransactionBody(); TransactionRecord txRecord = recordItem.getRecord(); TransactionHandler transactionHandler = transactionHandlerFactory.create(body); log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body)); long consensusTimestamp = Utility.timeStampInNanos(txRecord.getConsensusTimestamp()); EntityId entity = transactionHandler.getEntity(recordItem); PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entity, recordItem); try { sendPubSubMessage(pubSubMessage); } catch (Exception e) { throw new ParserException("Error sending transaction to pubsub", e); } log.debug("Published transaction : {}", consensusTimestamp); if (addressBookService.isAddressBook(entity)) { FileID fileID = null; byte[] fileBytes = null; if (body.hasFileAppend()) { fileID = body.getFileAppend().getFileID(); fileBytes = body.getFileAppend().getContents().toByteArray(); } else if (body.hasFileCreate()) { fileID = txRecord.getReceipt().getFileID(); fileBytes = body.getFileCreate().getContents().toByteArray(); } else if (body.hasFileUpdate()) { fileID = body.getFileUpdate().getFileID(); fileBytes = body.getFileUpdate().getContents().toByteArray(); } FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem .getTransactionType()); fileDataRepository.save(fileData); addressBookService.update(fileData); } }  }
PubSubRecordItemListener implements RecordItemListener { @Override public void onItem(RecordItem recordItem) throws ImporterException { TransactionBody body = recordItem.getTransactionBody(); TransactionRecord txRecord = recordItem.getRecord(); TransactionHandler transactionHandler = transactionHandlerFactory.create(body); log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body)); long consensusTimestamp = Utility.timeStampInNanos(txRecord.getConsensusTimestamp()); EntityId entity = transactionHandler.getEntity(recordItem); PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entity, recordItem); try { sendPubSubMessage(pubSubMessage); } catch (Exception e) { throw new ParserException("Error sending transaction to pubsub", e); } log.debug("Published transaction : {}", consensusTimestamp); if (addressBookService.isAddressBook(entity)) { FileID fileID = null; byte[] fileBytes = null; if (body.hasFileAppend()) { fileID = body.getFileAppend().getFileID(); fileBytes = body.getFileAppend().getContents().toByteArray(); } else if (body.hasFileCreate()) { fileID = txRecord.getReceipt().getFileID(); fileBytes = body.getFileCreate().getContents().toByteArray(); } else if (body.hasFileUpdate()) { fileID = body.getFileUpdate().getFileID(); fileBytes = body.getFileUpdate().getContents().toByteArray(); } FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem .getTransactionType()); fileDataRepository.save(fileData); addressBookService.update(fileData); } }  @Override void onItem(RecordItem recordItem); }
PubSubRecordItemListener implements RecordItemListener { @Override public void onItem(RecordItem recordItem) throws ImporterException { TransactionBody body = recordItem.getTransactionBody(); TransactionRecord txRecord = recordItem.getRecord(); TransactionHandler transactionHandler = transactionHandlerFactory.create(body); log.trace("Storing transaction body: {}", () -> Utility.printProtoMessage(body)); long consensusTimestamp = Utility.timeStampInNanos(txRecord.getConsensusTimestamp()); EntityId entity = transactionHandler.getEntity(recordItem); PubSubMessage pubSubMessage = buildPubSubMessage(consensusTimestamp, entity, recordItem); try { sendPubSubMessage(pubSubMessage); } catch (Exception e) { throw new ParserException("Error sending transaction to pubsub", e); } log.debug("Published transaction : {}", consensusTimestamp); if (addressBookService.isAddressBook(entity)) { FileID fileID = null; byte[] fileBytes = null; if (body.hasFileAppend()) { fileID = body.getFileAppend().getFileID(); fileBytes = body.getFileAppend().getContents().toByteArray(); } else if (body.hasFileCreate()) { fileID = txRecord.getReceipt().getFileID(); fileBytes = body.getFileCreate().getContents().toByteArray(); } else if (body.hasFileUpdate()) { fileID = body.getFileUpdate().getFileID(); fileBytes = body.getFileUpdate().getContents().toByteArray(); } FileData fileData = new FileData(consensusTimestamp, fileBytes, EntityId.of(fileID), recordItem .getTransactionType()); fileDataRepository.save(fileData); addressBookService.update(fileData); } }  @Override void onItem(RecordItem recordItem);  }