|
24 | 24 | from typing import Any |
25 | 25 | from typing import Dict |
26 | 26 |
|
| 27 | +from anms.shared.transmogrifier import TRANSMORGIFIER |
27 | 28 | from anms.models.relational import Model |
28 | 29 | from sqlalchemy import Column |
29 | 30 | from sqlalchemy import Integer |
30 | | -from sqlalchemy import String |
| 31 | +from sqlalchemy import DateTime |
| 32 | +from sqlalchemy import ARRAY |
31 | 33 | from sqlalchemy import LargeBinary |
32 | | - |
| 34 | +from sqlalchemy import orm |
33 | 35 |
|
34 | 36 | # class for vw_ctrl_definition used for build ari |
35 | 37 | class Report(Model): |
36 | | - __tablename__ = 'ari_rptset' |
37 | | - ari_rptset_id = Column(Integer, primary_key=True) |
38 | | - nonce_cbor = Column(LargeBinary) |
39 | | - reference_time = Column(Integer) |
40 | | - report_list = Column(String) |
41 | | - report_list_cbor = Column(LargeBinary) |
42 | | - agent_id = Column(Integer) |
| 38 | + __tablename__ = 'vw_ari_rpt_set' |
| 39 | + ari_rptset_id = Column(Integer, primary_key=True) |
| 40 | + mgr_time = Column(DateTime) |
| 41 | + reference_time = Column(DateTime) |
| 42 | + nonce_cbor = Column(LargeBinary) |
| 43 | + agent_id = Column(Integer) |
| 44 | + ari_rptset_cbor = Column(LargeBinary) |
| 45 | + ari_rptlist_id = Column(Integer) |
| 46 | + agent_time = Column( DateTime) |
| 47 | + report_source = Column(LargeBinary) |
| 48 | + report_items = Column(ARRAY(LargeBinary) )#bytea[] NULL |
| 49 | + |
| 50 | + # processing the raw cbor into an ari object |
| 51 | + @orm.reconstructor |
| 52 | + def init_on_load(self): |
| 53 | + self.nonce_cbor = TRANSMORGIFIER.transcode("0x"+getattr(self, 'nonce_cbor').hex())['uri'] |
| 54 | + self.report_source = TRANSMORGIFIER.transcode("0x"+getattr(self, 'report_source').hex())['uri'] |
| 55 | + self.report_items = [TRANSMORGIFIER.transcode("0x"+x.hex())['uri'] for x in getattr(self, 'report_items')] |
| 56 | + |
43 | 57 | def __repr__(self) -> str: |
44 | 58 | return self.as_dict().__repr__() |
45 | 59 |
|
46 | 60 | def as_dict(self) -> Dict[str, Any]: |
47 | 61 | dict_obj = { |
48 | 62 | 'ari_rptset_id': getattr(self, 'ari_rptset_id'), |
49 | | - 'nonce_cbor': getattr(self, 'nonce_cbor'), |
50 | 63 | 'reference_time': getattr(self, 'reference_time'), |
51 | | - 'report_list': getattr(self, 'report_list'), |
52 | | - 'report_list_cbor': getattr(self, 'report_list_cbor'), |
53 | | - 'agent_id': getattr(self, 'agent_id') |
| 64 | + 'nonce_cbor': getattr(self, 'nonce_cbor'), |
| 65 | + 'agent_id': getattr(self, 'agent_id'), |
| 66 | + 'ari_rptlist_id': getattr(self, 'ari_rptlist_id'), |
| 67 | + 'agent_time': getattr(self, 'agent_time'), |
| 68 | + 'report_source': getattr(self, 'report_source'), |
| 69 | + 'report_items': getattr(self, 'report_items') |
54 | 70 | } |
55 | | - |
56 | 71 | return dict_obj |
0 commit comments