Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.base: Add new attributes to class AdministrativeInformation #107

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -193,7 +193,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 @@ -313,7 +320,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 @@ -703,7 +712,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.GlobalReference((
model.Key(model.KeyTypes.GLOBAL_REFERENCE,
'http://acplt.org/AdministrativeInformation/'
'Test_Submodel'),
)),),
semantic_id=model.GlobalReference((model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE,
value='http://acplt.org/SubmodelTemplates/'
'ExampleSubmodel'),)),
Expand Down Expand Up @@ -732,7 +746,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 @@ -778,7 +800,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
48 changes: 44 additions & 4 deletions test/compliance_tool/files/test_demo_full_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
"id": "https://acplt.org/Test_AssetAdministrationShell",
"administration": {
"version": "9",
"revision": "0"
"revision": "0",
"creator": {
"type": "GlobalReference",
"keys": [
{
"type": "GlobalReference",
"value": "http://acplt.org/AdministrativeInformation/Test_AssetAdministrationShell"
}
]
},
"templateId": "http://acplt.org/AdministrativeInformationTemplates/Test_AssetAdministrationShell"
},
"derivedFrom": {
"type": "ModelReference",
Expand Down Expand Up @@ -322,7 +332,17 @@
"id": "http://acplt.org/Submodels/Assets/TestAsset/Identification",
"administration": {
"version": "9",
"revision": "0"
"revision": "0",
"creator": {
"type": "GlobalReference",
"keys": [
{
"type": "GlobalReference",
"value": "http://acplt.org/AdministrativeInformation/TestAsset/Identification"
}
]
},
"templateId": "http://acplt.org/AdministrativeInformationTemplates/TestAsset/Identification"
},
"semanticId": {
"type": "ModelReference",
Expand Down Expand Up @@ -488,7 +508,8 @@
"modelType": "Submodel",
"id": "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial",
"administration": {
"version": "9"
"version": "9",
"templateId": "http://acplt.org/AdministrativeInformationTemplates/TestAsset/BillOfMaterial"
},
"semanticId": {
"type": "ModelReference",
Expand Down Expand Up @@ -760,7 +781,16 @@
"id": "https://acplt.org/Test_Submodel",
"administration": {
"version": "9",
"revision": "0"
"revision": "0",
"creator": {
"type": "GlobalReference",
"keys": [
{
"type": "GlobalReference",
"value": "http://acplt.org/AdministrativeInformation/Test_Submodel"
}
]
}
},
"semanticId": {
"type": "GlobalReference",
Expand Down Expand Up @@ -3086,6 +3116,16 @@
"administration": {
"version": "9",
"revision": "0",
"creator": {
"type": "GlobalReference",
"keys": [
{
"type": "GlobalReference",
"value": "http://acplt.org/AdministrativeInformation/Test_ConceptDescription"
}
]
},
"templateId": "http://acplt.org/AdministrativeInformationTemplates/Test_ConceptDescription",
"embeddedDataSpecifications": [
{
"dataSpecification": {
Expand Down
40 changes: 40 additions & 0 deletions test/compliance_tool/files/test_demo_full_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
<aas:administration>
<aas:version>9</aas:version>
<aas:revision>0</aas:revision>
<aas:creator>
<aas:type>GlobalReference</aas:type>
<aas:keys>
<aas:key>
<aas:type>GlobalReference</aas:type>
<aas:value>http://acplt.org/AdministrativeInformation/Test_AssetAdministrationShell</aas:value>
</aas:key>
</aas:keys>
</aas:creator>
<aas:templateId>http://acplt.org/AdministrativeInformationTemplates/Test_AssetAdministrationShell</aas:templateId>
</aas:administration>
<aas:id>https://acplt.org/Test_AssetAdministrationShell</aas:id>
<aas:embeddedDataSpecifications>
Expand Down Expand Up @@ -308,6 +318,16 @@
<aas:administration>
<aas:version>9</aas:version>
<aas:revision>0</aas:revision>
<aas:creator>
<aas:type>GlobalReference</aas:type>
<aas:keys>
<aas:key>
<aas:type>GlobalReference</aas:type>
<aas:value>http://acplt.org/AdministrativeInformation/TestAsset/Identification</aas:value>
</aas:key>
</aas:keys>
</aas:creator>
<aas:templateId>http://acplt.org/AdministrativeInformationTemplates/TestAsset/Identification</aas:templateId>
</aas:administration>
<aas:id>http://acplt.org/Submodels/Assets/TestAsset/Identification</aas:id>
<aas:kind>Instance</aas:kind>
Expand Down Expand Up @@ -472,6 +492,7 @@
</aas:description>
<aas:administration>
<aas:version>9</aas:version>
<aas:templateId>http://acplt.org/AdministrativeInformationTemplates/TestAsset/BillOfMaterial</aas:templateId>
</aas:administration>
<aas:id>http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial</aas:id>
<aas:kind>Instance</aas:kind>
Expand Down Expand Up @@ -638,6 +659,15 @@
<aas:administration>
<aas:version>9</aas:version>
<aas:revision>0</aas:revision>
<aas:creator>
<aas:type>GlobalReference</aas:type>
<aas:keys>
<aas:key>
<aas:type>GlobalReference</aas:type>
<aas:value>http://acplt.org/AdministrativeInformation/Test_Submodel</aas:value>
</aas:key>
</aas:keys>
</aas:creator>
</aas:administration>
<aas:id>https://acplt.org/Test_Submodel</aas:id>
<aas:kind>Instance</aas:kind>
Expand Down Expand Up @@ -3031,6 +3061,16 @@
</aas:embeddedDataSpecifications>
<aas:version>9</aas:version>
<aas:revision>0</aas:revision>
<aas:creator>
<aas:type>GlobalReference</aas:type>
<aas:keys>
<aas:key>
<aas:type>GlobalReference</aas:type>
<aas:value>http://acplt.org/AdministrativeInformation/Test_ConceptDescription</aas:value>
</aas:key>
</aas:keys>
</aas:creator>
<aas:templateId>http://acplt.org/AdministrativeInformationTemplates/Test_ConceptDescription</aas:templateId>
</aas:administration>
<aas:id>https://acplt.org/Test_ConceptDescription</aas:id>
<aas:embeddedDataSpecifications>
Expand Down
Binary file modified test/compliance_tool/files/test_demo_full_example_json.aasx
Binary file not shown.
Loading
Loading