def wrap_message_for_system_of_record(self, message): # validate the message title_validator.validate(message) # put the message in an envelope signed = unicoded({ 'object' : { "data": base64.b64encode(json.dumps(message)), "object_id": message['title_number'], "initial_request_timestamp": unixts(), "chains": [ { "chain_name": "type", "chain_value": "title" }, { "chain_name": "history", "chain_value": message["title_number"] } ] # optional: # created_by # reason_for_change } }) # validate the envelope system_of_record_request_validator.validate(signed) app.logger.info("Submitting %s to the system or record" % signed) self.writer.send_to_system_of_record(signed)
def wrap_message_for_system_of_record(self, message): # validate the message title_validator.validate(message) # put the message in an envelope signed = unicoded({ 'object': { "data": base64.b64encode(json.dumps(message)), "object_id": message['title_number'], "initial_request_timestamp": unixts(), "chains": [{ "chain_name": "type", "chain_value": "title" }, { "chain_name": "history", "chain_value": message["title_number"] }] # optional: # created_by # reason_for_change } }) # validate the envelope system_of_record_request_validator.validate(signed) app.logger.info("Submitting %s to the system or record" % signed) self.writer.send_to_system_of_record(signed)
def enqueue(self, message): try: system_of_record_request_validator.validate(message) ingest_queue.add_to_queue(system_of_record_request_validator.to_canonical_form(message)) except Exception as e: self.logger.error("Could not enqueue message: [message: %s] [exception: %s]" % (message, e)) # TODO: Store failures somewhere. Possible data loss! raise e
def store_object(self, object_id, message): system_of_record_request_validator.validate(message) if object_id != message['object']['object_id']: raise Exception("Object ID does not match message ID") ingest_queue_producer.enqueue(message) return make_response('OK', 201)
def enqueue(self, message): try: system_of_record_request_validator.validate(message) ingest_queue.add_to_queue( system_of_record_request_validator.to_canonical_form(message)) except Exception as e: self.logger.error( "Could not enqueue message: [message: %s] [exception: %s]" % (message, e)) # TODO: Store failures somewhere. Possible data loss! raise e
def ingest(self, message): self.logger.debug("Beginning blockchain append for: [%s]" % str(message)) if message is not None: system_of_record_request_validator.validate(message) object_id = message['object']['object_id'] self.logger.debug("Beginning blockchain append for: [%s]" % object_id) loaded_object_from_head_of_blockchain = self.store_in_database(object_id, message) if loaded_object_from_head_of_blockchain: self.send_chain_messages(loaded_object_from_head_of_blockchain, object_id) else: self.logger.error( "Could not find object with ID [%s] so can't send message [%s]" % (object_id, repr(message))) self.logger.info("Finished blockchain append for object [%s]" % object_id) else: self.logger.warn("Attempted to ingest null message")
def test_can_validate_system_of_record_request(self): try: system_of_record_request_validator.validate(valid_system_of_record_input_message_with_two_tags) except DataDoesNotMatchSchemaException as e: self.fail("Should not have thrown " + repr(e))
def store_object(self, object_id, data): system_of_record_request_validator.validate(data) self.logger.info("Storing object %s" % object_id) db.session.add(BlockchainObject.create(object_id, data)) db.session.commit()
def check_loaded_object(self, loaded_data): self.assertIsNotNone(loaded_data) system_of_record_request_validator.validate(loaded_data) self.assertEquals(loaded_data['object']['object_id'], test_object_id)