Commit c44b6c70 authored by Torben Miny's avatar Torben Miny
Browse files

Merge branch fix/xml_adapter_for_current_external_schema with...

Merge branch fix/xml_adapter_for_current_external_schema with refs/heads/master into refs/merge-requests/31/train
parents 5c996f0d a8061084
Pipeline #274826 passed with stage
in 3 minutes and 15 seconds
......@@ -678,9 +678,18 @@ def _construct_entity(element: etree.Element, failsafe: bool, **_kwargs: Any) ->
asset=_failsafe_construct(element.find(NS_AAS + "assetRef"), _construct_asset_reference, failsafe),
kind=_get_modeling_kind(element)
)
for stmt in _failsafe_construct_multiple(_get_child_mandatory(element, NS_AAS + "statements"),
_construct_submodel_element, failsafe):
entity.statement.add(stmt)
# TODO: simplify this should our suggestion regarding the XML schema get accepted
# https://git.rwth-aachen.de/acplt/pyaas/-/issues/57
for statement in _get_all_children_expect_tag(
_get_child_mandatory(element, NS_AAS + "statements"), NS_AAS + "submodelElement", failsafe):
if len(statement) == 0:
raise KeyError(f"{_element_pretty_identifier(statement)} has no submodel element!")
if len(statement) > 1:
logger.warning(f"{_element_pretty_identifier(statement)} has more than one submodel element,"
"using the first one...")
constructed = _failsafe_construct(statement[0], _construct_submodel_element, failsafe)
if constructed is not None:
entity.statement.add(constructed)
_amend_abstract_attributes(entity, element, failsafe)
return entity
......@@ -802,9 +811,18 @@ def _construct_submodel_element_collection(element: etree.Element, failsafe: boo
_child_text_mandatory(element, NS_AAS + "idShort"),
kind=_get_modeling_kind(element)
)
value = _get_child_mandatory(element, NS_AAS + "value")
for se in _failsafe_construct_multiple(value, _construct_submodel_element, failsafe):
collection.value.add(se)
# TODO: simplify this should our suggestion regarding the XML schema get accepted
# https://git.rwth-aachen.de/acplt/pyaas/-/issues/57
for se in _get_all_children_expect_tag(
_get_child_mandatory(element, NS_AAS + "value"), NS_AAS + "submodelElement", failsafe):
if len(se) == 0:
raise KeyError(f"{_element_pretty_identifier(se)} has no submodel element!")
if len(se) > 1:
logger.warning(f"{_element_pretty_identifier(se)} has more than one submodel element,"
"using the first one...")
constructed = _failsafe_construct(se[0], _construct_submodel_element, failsafe)
if constructed is not None:
collection.value.add(constructed)
_amend_abstract_attributes(collection, element, failsafe)
return collection
......
......@@ -148,9 +148,10 @@ def _value_to_xml(value: model.ValueDataType,
:param tag: tag of the serialized ValueDataType object
:return: Serialized ElementTree.Element object
"""
# todo: add attributes: {NS_XSI+"type": "xs:"+model.datatypes.XSD_TYPE_NAMES[value_type]} when the schema
# gets changed to allow it
return _generate_element(tag,
text=model.datatypes.xsd_repr(value),
attributes={NS_XSI+"type": "xs:"+model.datatypes.XSD_TYPE_NAMES[value_type]})
text=model.datatypes.xsd_repr(value))
def lang_string_set_to_xml(obj: model.LangStringSet, tag: str) -> etree.Element:
......@@ -703,7 +704,9 @@ def submodel_element_collection_to_xml(obj: model.SubmodelElementCollection,
et_value = _generate_element(NS_AAS + "value")
if obj.value:
for submodel_element in obj.value:
et_value.append(submodel_element_to_xml(submodel_element))
et_submodel_element = _generate_element(NS_AAS+"submodelElement")
et_submodel_element.append(submodel_element_to_xml(submodel_element))
et_value.append(et_submodel_element)
et_submodel_element_collection.append(et_value)
return et_submodel_element_collection
......@@ -812,7 +815,10 @@ def entity_to_xml(obj: model.Entity,
et_entity.append(_generate_element(NS_AAS + "entityType", text=_generic.ENTITY_TYPES[obj.entity_type]))
et_statements = _generate_element(NS_AAS + "statements")
for statement in obj.statement:
et_statements.append(submodel_element_to_xml(statement))
# todo: remove the <submodelElement> once the proposed changes get accepted
et_submodel_element = _generate_element(NS_AAS+"submodelElement")
et_submodel_element.append(submodel_element_to_xml(statement))
et_statements.append(et_submodel_element)
et_entity.append(et_statements)
return et_entity
......
Supports Markdown
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