54 lines
2.3 KiB
Python
54 lines
2.3 KiB
Python
from DataVaultGenerator.Components import DataVaultEntity, DataVaultEntityAttribute, ErrorCollection
|
|
|
|
|
|
class Satellite(DataVaultEntity):
|
|
def __init__(self, model, filename, definition: dict = None):
|
|
DataVaultEntity.__init__(self, model, filename, definition)
|
|
|
|
self.parent = definition.get('parent')
|
|
|
|
def get_foreign_attribute(self, name: str) -> DataVaultEntityAttribute:
|
|
return self.get_parent_key_attribute() if self.get_parent_key_attribute().name == name else None
|
|
|
|
def get_parent_entity(self) -> DataVaultEntity:
|
|
return self.model.get_entity(self.parent)
|
|
|
|
def get_parent_key_attribute(self) -> DataVaultEntityAttribute:
|
|
return self.get_parent_entity().key_attribute
|
|
|
|
@property
|
|
def hashdiff_fk_attribute(self):#FIXME: Durch config/template flexibler gestalten
|
|
return self.get_role_attribute('hashdiff').copy(self.name + "_" + self.get_role_attribute('hashdiff').name)
|
|
|
|
@property
|
|
def hash_attribute_trim(self):
|
|
return self._definition.get('hashdiff_attribute_treatment'
|
|
, self.model.config.datavault.hashdiff_attribute_treatment)\
|
|
.get('trim',
|
|
self.model.config.datavault.hashdiff_attribute_treatment.trim)
|
|
@property
|
|
def hash_attribute_case(self):
|
|
return self._definition.get('hashdiff_attribute_treatment'
|
|
, self.model.config.datavault.hashdiff_attribute_treatment)\
|
|
.get('case',
|
|
self.model.config.datavault.hashdiff_attribute_treatment.case)
|
|
|
|
def get_component_entities(self):
|
|
return [{'entity': self, 'component': c, 'type': c.type} for c in
|
|
self.get_source_entities().values()] # holt derzeit nur die Deliveries über die Mappings
|
|
|
|
def validate(self):
|
|
|
|
errors = ErrorCollection()
|
|
|
|
for attr in self.attributes.values():
|
|
spec = self.layer.sys_specification
|
|
errors.append(attr.validate(spec))
|
|
|
|
# Validating entity references:
|
|
if self.get_parent_entity() is None:
|
|
errors.add("VALIDATION ERROR",
|
|
(self.filename,"Satellite", "<" + self.name + ">"),
|
|
f'Parent <{self.parent}> not found')
|
|
|
|
return errors |