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

Merge branch 'fix/aasx_file_absolute_uri' into 'master'

aasx: Fix handling of File object with absolute URI values

Closes #81

See merge request !54
parents 0ae7a41d 492ab7ef
Pipeline #339099 passed with stages
in 51 seconds
......@@ -232,6 +232,13 @@ class AASXReader:
if isinstance(element, model.File):
if element.value is None:
continue
# Only absolute-path references and relative-path URI references (see RFC 3986, sec. 4.2) are considered
# to refer to files within the AASX package. Thus, we must skip all other types of URIs (esp. absolute
# URIs and network-path references)
if element.value.startswith('//') or ':' in element.value.split('/')[0]:
logger.info("Skipping supplementary file %s, since it seems to be an absolute URI or network-path "
"URI reference", element.value)
continue
absolute_name = pyecma376_2.package_model.part_realpath(element.value, part_name)
logger.debug("Reading supplementary file {} from AASX package ...".format(absolute_name))
with self.reader.open_part(absolute_name) as p:
......@@ -408,7 +415,9 @@ class AASXWriter:
for element in traversal.walk_submodel(submodel):
if isinstance(element, model.File):
file_name = element.value
if file_name is None:
# Skip File objects with empty value URI references that are considered to be no local file (absolute
# URIs or network-path URI references)
if file_name is None or file_name.startswith('//') or ':' in file_name.split('/')[0]:
continue
try:
content_type = file_store.get_content_type(file_name)
......
......@@ -379,6 +379,23 @@ def create_example_submodel() -> model.Submodel:
qualifier=None,
kind=model.ModelingKind.INSTANCE)
submodel_element_file_uri = model.File(
id_short='ExampleFileURI',
mime_type='application/pdf',
value='https://www.plattform-i40.de/PI40/Redaktion/DE/Downloads/Publikation/Details-of-the-Asset-'
'Administration-Shell-Part1.pdf?__blob=publicationFile&v=5',
category='CONSTANT',
description={'en-us': 'Details of the Asset Administration Shell—An example for an external file reference',
'de': 'Details of the Asset Administration Shell – Ein Beispiel für eine extern referenzierte '
'Datei'},
parent=None,
semantic_id=model.Reference((model.Key(type_=model.KeyElements.GLOBAL_REFERENCE,
local=False,
value='http://acplt.org/Files/ExampleFile',
id_type=model.KeyType.IRI),)),
qualifier=None,
kind=model.ModelingKind.INSTANCE)
submodel_element_reference_element = model.ReferenceElement(
id_short='ExampleReferenceElement',
value=model.AASReference((model.Key(type_=model.KeyElements.PROPERTY,
......@@ -535,6 +552,7 @@ def create_example_submodel() -> model.Submodel:
id_short='ExampleSubmodelCollectionUnordered',
value=(submodel_element_blob,
submodel_element_file,
submodel_element_file_uri,
submodel_element_reference_element),
category='PARAMETER',
description={'en-us': 'Example SubmodelElementCollectionUnordered object',
......
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