def save_document(self, document: str or BufferedReader or provmodel.ProvDocument) -> list:
"""
Write a document into BigchainDB
:param document: Document as JSON/XML/PROVN
:type document: str or BufferedReader or ProvDocument
:return: List of transaction ids
:rtype: list
"""
log.info("Save document...")
document_tx_ids = []
prov_document = utils.to_prov_document(content=document)
elements = GraphConceptClient.calculate_account_data(prov_document)
id_mapping = {}
log.info("Create and Save instances")
for prov_element, prov_relations, namespaces in elements:
for rel in prov_relations['with_id']:
id_mapping[rel.identifier] = ''
for prov_element, prov_relations, namespaces in elements:
account = accounts.GraphConceptAccount(prov_element, prov_relations, id_mapping, namespaces, self.store)
self.accounts.append(account)
tx_id = account.save_instance_asset(self._get_bigchain_connection())
document_tx_ids.append(tx_id)
log.info("Save relations with ids")
for account in filter(lambda acc: acc.has_relations_with_id, self.accounts):
document_tx_ids += account.save_relations_with_ids(self._get_bigchain_connection())
log.info("Save relations without ids")
for account in filter(lambda acc: acc.has_relations_without_id, self.accounts):
document_tx_ids += account.save_relations_without_ids(self._get_bigchain_connection())
log.info("Saved document in %s Tx", len(document_tx_ids))
return document_tx_ids
评论列表
文章目录