Skip to content

Commit

Permalink
Merge branch 'improve/V30' into Rename/GlobalReference
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhsjdhjs committed Aug 23, 2023
2 parents 73c52b9 + 3108a22 commit 0bc0134
Show file tree
Hide file tree
Showing 16 changed files with 3,417 additions and 16 deletions.
9 changes: 9 additions & 0 deletions basyx/aas/adapter/json/aasJSONSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
"revision": {
"type": "string",
"minLength": 1
},
"creator": {
"$ref": "#/definitions/Reference"
},
"templateId": {
"type": "string",
"minLength": 1,
"maxLength": 2000,
"pattern": "^([\\t\\n\\r -\ud7ff\ue000-\ufffd]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ def _construct_administrative_information(
ret.revision = _get_ts(dct, 'revision', str)
elif 'revision' in dct:
logger.warning("Ignoring 'revision' attribute of AdministrativeInformation object due to missing 'version'")
if 'creator' in dct:
ret.creator = cls._construct_reference(_get_ts(dct, 'creator', dict))
if 'templateId' in dct:
ret.template_id = _get_ts(dct, 'templateId', str)
return ret

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions basyx/aas/adapter/json/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def _administrative_information_to_json(cls, obj: model.AdministrativeInformatio
data['version'] = obj.version
if obj.revision:
data['revision'] = obj.revision
if obj.creator:
data['creator'] = obj.creator
if obj.template_id:
data['templateId'] = obj.template_id
return data

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions basyx/aas/adapter/xml/AAS.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="creator" type="reference_t" minOccurs="0" maxOccurs="1"/>
<xs:element name="templateId" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="2000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:group>
<xs:group name="annotatedRelationshipElement">
Expand Down
6 changes: 5 additions & 1 deletion basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,12 @@ def construct_administrative_information(cls, element: etree.Element, object_cla
**_kwargs: Any) -> model.AdministrativeInformation:
administrative_information = object_class(
revision=_get_text_or_none(element.find(NS_AAS + "revision")),
version=_get_text_or_none(element.find(NS_AAS + "version"))
version=_get_text_or_none(element.find(NS_AAS + "version")),
template_id=_get_text_or_none(element.find(NS_AAS + "templateId"))
)
creator = _failsafe_construct(element.find(NS_AAS + "creator"), cls.construct_reference, cls.failsafe)
if creator is not None:
administrative_information.creator = creator
cls._amend_abstract_attributes(administrative_information, element)
return administrative_information

Expand Down
4 changes: 4 additions & 0 deletions basyx/aas/adapter/xml/xml_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ def administrative_information_to_xml(obj: model.AdministrativeInformation,
et_administration.append(_generate_element(name=NS_AAS + "version", text=obj.version))
if obj.revision:
et_administration.append(_generate_element(name=NS_AAS + "revision", text=obj.revision))
if obj.creator:
et_administration.append(reference_to_xml(obj.creator, tag=NS_AAS + "creator"))
if obj.template_id:
et_administration.append(_generate_element(name=NS_AAS + "templateId", text=obj.template_id))
return et_administration


Expand Down
39 changes: 34 additions & 5 deletions basyx/aas/examples/data/example_aas.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,14 @@ def create_example_asset_identification_submodel() -> model.Submodel:
'de': 'Ein Beispiel-Identifikations-Submodel für eine Test-Anwendung'}),
parent=None,
administration=model.AdministrativeInformation(version='9',
revision='0'),
revision='0',
creator=model.GlobalReference((
model.Key(model.KeyTypes.GLOBAL_REFERENCE,
'http://acplt.org/AdministrativeInformation/'
'TestAsset/Identification'),
)),
template_id='http://acplt.org/AdministrativeInformation'
'Templates/TestAsset/Identification'),
semantic_id=model.ModelReference((model.Key(type_=model.KeyTypes.SUBMODEL,
value='http://acplt.org/SubmodelTemplates/AssetIdentification'),),
model.Submodel),
Expand Down Expand Up @@ -316,7 +323,9 @@ def create_example_bill_of_material_submodel() -> model.Submodel:
description=model.LangStringSet({'en-US': 'An example bill of material submodel for the test application',
'de': 'Ein Beispiel-BillofMaterial-Submodel für eine Test-Anwendung'}),
parent=None,
administration=model.AdministrativeInformation(version='9'),
administration=model.AdministrativeInformation(version='9',
template_id='http://acplt.org/AdministrativeInformation'
'Templates/TestAsset/BillOfMaterial'),
semantic_id=model.ModelReference((model.Key(type_=model.KeyTypes.SUBMODEL,
value='http://acplt.org/SubmodelTemplates/BillOfMaterial'),),
model.Submodel),
Expand Down Expand Up @@ -709,7 +718,12 @@ def create_example_submodel() -> model.Submodel:
'de': 'Ein Beispiel-Teilmodell für eine Test-Anwendung'}),
parent=None,
administration=model.AdministrativeInformation(version='9',
revision='0'),
revision='0',
creator=model.ExternalReference((
model.Key(model.KeyTypes.GLOBAL_REFERENCE,
'http://acplt.org/AdministrativeInformation/'
'Test_Submodel'),
)),),
semantic_id=model.ExternalReference((model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE,
value='http://acplt.org/SubmodelTemplates/'
'ExampleSubmodel'),)),
Expand Down Expand Up @@ -738,7 +752,15 @@ def create_example_concept_description() -> model.ConceptDescription:
description=model.LangStringSet({'en-US': 'An example concept description for the test application',
'de': 'Ein Beispiel-ConceptDescription für eine Test-Anwendung'}),
parent=None,
administration=model.AdministrativeInformation(version='9', revision='0',
administration=model.AdministrativeInformation(version='9',
revision='0',
creator=model.GlobalReference((
model.Key(model.KeyTypes.GLOBAL_REFERENCE,
'http://acplt.org/AdministrativeInformation/'
'Test_ConceptDescription'),
)),
template_id='http://acplt.org/AdministrativeInformation'
'Templates/Test_ConceptDescription',
embedded_data_specifications=(
_embedded_data_specification_iec61360,
)),
Expand Down Expand Up @@ -784,7 +806,14 @@ def create_example_asset_administration_shell() -> \
'de': 'Ein Beispiel-Verwaltungsschale für eine Test-Anwendung'}),
parent=None,
administration=model.AdministrativeInformation(version='9',
revision='0'),
revision='0',
creator=model.GlobalReference((
model.Key(model.KeyTypes.GLOBAL_REFERENCE,
'http://acplt.org/AdministrativeInformation/'
'Test_AssetAdministrationShell'),
)),
template_id='http://acplt.org/AdministrativeInformation'
'Templates/Test_AssetAdministrationShell'),
submodel={model.ModelReference((model.Key(type_=model.KeyTypes.SUBMODEL,
value='https://acplt.org/Test_Submodel'),),
model.Submodel,
Expand Down
24 changes: 22 additions & 2 deletions basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ def __init__(


@_string_constraints.constrain_version_type("version")
@_string_constraints.constrain_identifier("template_id")
class AdministrativeInformation(HasDataSpecification):
"""
Administrative meta-information for an element like version information.
Expand All @@ -1103,13 +1104,26 @@ class AdministrativeInformation(HasDataSpecification):
:ivar version: Version of the element.
:ivar revision: Revision of the element.
:ivar creator: The subject ID of the subject responsible for making the element
:ivar template_id: Identifier of the template that guided the creation of the element
*Note:* In case of a submodel, the template ID is the identifier of the submodel template that guided the
creation of the submodel.
*Note:* The submodel template ID is not relevant for validation. Here, the Submodel/semanticId shall be used
*Note:* Usage of the template ID is not restricted to submodel instances.
The creation of submodel templates can also be guided by another submodel template.
:ivar embedded_data_specifications: List of Embedded data specification.
used by the element.
"""

def __init__(self,
version: Optional[VersionType] = None,
revision: Optional[RevisionType] = None,
creator: Optional[Reference] = None,
template_id: Optional[Identifier] = None,
embedded_data_specifications: Iterable[EmbeddedDataSpecification] = ()):
"""
Initializer of AdministrativeInformation
Expand All @@ -1122,6 +1136,8 @@ def __init__(self,
self.version: Optional[VersionType] = version
self._revision: Optional[RevisionType]
self.revision = revision
self.creator: Optional[Reference] = creator
self.template_id: Optional[Identifier] = template_id
self.embedded_data_specifications: List[EmbeddedDataSpecification] = list(embedded_data_specifications)

def _get_revision(self):
Expand All @@ -1140,10 +1156,14 @@ def _set_revision(self, revision: Optional[RevisionType]):
def __eq__(self, other) -> bool:
if not isinstance(other, AdministrativeInformation):
return NotImplemented
return self.version == other.version and self._revision == other._revision
return self.version == other.version \
and self._revision == other._revision \
and self.creator == other.creator \
and self.template_id == other.template_id

def __repr__(self) -> str:
return "AdministrativeInformation(version={}, revision={})".format(self.version, self.revision)
return "AdministrativeInformation(version={}, revision={}, creator={}, template_id={})".format(
self.version, self.revision, self.creator, self.template_id)


@_string_constraints.constrain_identifier("id")
Expand Down
Loading

0 comments on commit 0bc0134

Please sign in to comment.