Commit 6e10b3a8 authored by TorbenD's avatar TorbenD
Browse files

merge master and pritty print of example files

parents d9be9747 fd269bd3
Pipeline #348844 passed with stages
in 1 minute and 42 seconds
......@@ -414,8 +414,9 @@ class AASFromJsonDecoder(json.JSONDecoder):
object_class=model.concept.IEC61360ConceptDescription)\
-> model.concept.IEC61360ConceptDescription:
ret = object_class(identification=cls._construct_identifier(_get_ts(dct, 'identification', dict)),
preferred_name=cls._construct_lang_string_set(_get_ts(data_spec, 'preferredName', list)),
data_type=IEC61360_DATA_TYPES_INVERSE[_get_ts(data_spec, 'dataType', str)])
preferred_name=cls._construct_lang_string_set(_get_ts(data_spec, 'preferredName', list)))
if 'dataType' in data_spec:
ret.data_type = IEC61360_DATA_TYPES_INVERSE[_get_ts(data_spec, 'dataType', str)]
if 'definition' in data_spec:
ret.definition = cls._construct_lang_string_set(_get_ts(data_spec, 'definition', list))
if 'shortName' in data_spec:
......
......@@ -275,10 +275,11 @@ def append_iec61360_concept_description_attrs(obj: model.concept.IEC61360Concept
ConceptDescription, but we want to generate compliant JSON documents. So, we fake the JSON structure of an object
with dataSpecifications.
"""
data_spec = {
'preferredName': lang_string_set_to_json(obj.preferred_name),
'dataType': _generic.IEC61360_DATA_TYPES[obj.data_type],
data_spec: Dict[str, object] = {
'preferredName': lang_string_set_to_json(obj.preferred_name)
}
if obj.data_type is not None:
data_spec['dataType'] = _generic.IEC61360_DATA_TYPES[obj.data_type]
if obj.definition is not None:
data_spec['definition'] = lang_string_set_to_json(obj.definition)
if obj.short_name is not None:
......
......@@ -929,8 +929,10 @@ def _construct_iec61360_concept_description(element: etree.Element, failsafe: bo
cd = model.IEC61360ConceptDescription(
identifier,
_child_construct_mandatory(element, NS_IEC + "preferredName", _construct_lang_string_set, namespace=NS_IEC),
_child_text_mandatory_mapped(element, NS_IEC + "dataType", IEC61360_DATA_TYPES_INVERSE)
)
data_type = _get_text_mapped_or_none(element.find(NS_IEC + "dataType"), IEC61360_DATA_TYPES_INVERSE)
if data_type is not None:
cd.data_type = data_type
definition = _failsafe_construct(element.find(NS_IEC + "definition"), _construct_lang_string_set, failsafe,
namespace=NS_IEC)
if definition is not None:
......
......@@ -134,13 +134,13 @@ def main():
with open(args.file_1, 'w', encoding='utf-8-sig') as file:
manager.set_step_status(Status.SUCCESS)
manager.add_step('Write data to file')
write_aas_json_file(file=file, data=data)
write_aas_json_file(file=file, data=data, indent=4)
manager.set_step_status(Status.SUCCESS)
elif args.xml:
with open(args.file_1, 'wb') as file:
manager.set_step_status(Status.SUCCESS)
manager.add_step('Write data to file')
write_aas_xml_file(file=file, data=data)
write_aas_xml_file(file=file, data=data, pretty_print=True)
manager.set_step_status(Status.SUCCESS)
except IOError as error:
logger.error(error)
......
......@@ -140,7 +140,7 @@ class IEC61360ConceptDescription(ConceptDescription):
def __init__(self,
identification: base.Identifier,
preferred_name: base.LangStringSet,
data_type: IEC61360DataType,
data_type: Optional[IEC61360DataType] = None,
definition: Optional[base.LangStringSet] = None,
short_name: Optional[base.LangStringSet] = None,
is_case_of: Optional[Set[base.Reference]] = None,
......@@ -190,7 +190,7 @@ class IEC61360ConceptDescription(ConceptDescription):
super().__init__(identification, is_case_of, id_short, category, description, parent, administration)
self.preferred_name: base.LangStringSet = preferred_name
self.short_name: Optional[base.LangStringSet] = short_name
self.data_type: IEC61360DataType = data_type
self.data_type: Optional[IEC61360DataType] = data_type
self.definition: Optional[base.LangStringSet] = definition
self.unit: Optional[str] = unit
self.unit_id: Optional[base.Reference] = unit_id
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment