[docs]classACLOpenAPIServices:""" This class implements the logic of all the ACL-OpenAPI services. """# --------------------------------# Infrastructure registry services# --------------------------------
[docs]@staticmethoddefregister_smia_instance(id,asset:dict,aasID,status,startedTimeStamp,smiaVersion):""" This method registers the smia instance in the SMIA KB. """ifidisNoneorassetisNone:return"ERROR: The SMIA or asset identifier cannot be null."smia_kb_instances_url=SMIAKBInfrastructure.get_smia_instances_url()# The body JSON is built with the parameters names and values of the method (id, asset...)body_json={arg_name:arg_valueforarg_name,arg_valueinlocals().items()}smia_instances_json=send_openapi_http_post_request(smia_kb_instances_url,body=body_json)if'ERROR'incheck_and_get_response_error(smia_instances_json):return'Cannot register SMIA instance. {}'.format(check_and_get_response_error(smia_instances_json))return{'status':'success'}
[docs]@staticmethoddefregister_css_elements(capabilities:list[dict],skills:list[dict]):""" This method registers CSS elements (capabilities and skills) in the SMIA KB. """# First, the skills need to be registeredifcapabilitiesisNoneandskillsisNone:return"ERROR: Both the capabilities and skills cannot be null."ifskillsisnotNoneandlen(skills)>0:smia_kb_skills_url=SMIAKBInfrastructure.get_skills_url()forskill_jsoninskills:skill_instance_json=send_openapi_http_post_request(smia_kb_skills_url,body=skill_json)if'ERROR'incheck_and_get_response_error(skill_instance_json):return'Cannot register skill. {}'.format(check_and_get_response_error(skill_instance_json))# Then, the capabilities can be registeredifcapabilitiesisnotNoneandlen(capabilities)>0:smia_kb_capabilities_url=SMIAKBInfrastructure.get_capabilities_url()forcapability_jsonincapabilities:cap_instance_json=send_openapi_http_post_request(smia_kb_capabilities_url,body=capability_json)if'ERROR'incheck_and_get_response_error(cap_instance_json):return'Cannot register capability. {}'.format(check_and_get_response_error(cap_instance_json))return{'status':'success'}
[docs]@staticmethoddefget_smia_instance_by_asset_id(asset_id):ifasset_idisNone:return"ERROR: The asset identifier cannot be null."# First, all the registered SMIA instances are obtainedsmia_kb_instances_url=SMIAKBInfrastructure.get_smia_instances_url()smia_instances_json=send_openapi_http_get_request(smia_kb_instances_url)if'ERROR'incheck_and_get_response_error(smia_instances_json):return'Cannot obtain the SMIA instances. {}'.format(check_and_get_response_error(smia_instances_json))# Then, the associated SMIA instance is obtainedforsmia_instanceinsmia_instances_json:ifsmia_instance['asset']['id']==asset_id:returnsmia_instance['id']return"ERROR: SMIA instance for asset identifier [{}] not found.".format(asset_id)
[docs]@staticmethoddefget_asset_id_by_smia_instance(smia_instance_id):ifsmia_instance_idisNone:return"ERROR: The SMIA instance identifier cannot be null."# First, all the registered SMIA instances are obtainedsmia_kb_smia_instance_url=SMIAKBInfrastructure.get_smia_instance_url(smia_instance_id)smia_instance_json=send_openapi_http_get_request(smia_kb_smia_instance_url)if'ERROR'incheck_and_get_response_error(smia_instance_json):return'Cannot obtain the assetIDs. {}'.format(check_and_get_response_error(smia_instance_json))# Then, the associated SMIA instance is obtainedreturnsmia_instance_json['asset']['id']
[docs]@staticmethoddefget_assets_ids_of_capability(capability_iri):ifcapability_iriisNone:return"ERROR: The capability IRI identifier cannot be null."# First, the capability with the given IRI is obtainedsmia_kb_capability_url=SMIAKBInfrastructure.get_assets_of_capability_url(capability_iri)assets_json=send_openapi_http_get_request(smia_kb_capability_url)if'ERROR'incheck_and_get_response_error(assets_json):return'Cannot obtain the assetIDs. {}'.format(check_and_get_response_error(assets_json))assets_ids=[asset_data['id']forasset_datainassets_json]returnassets_ids
# AAS Repository services --->
[docs]@staticmethoddefget_asset_adminitration_shell_by_id(aas_id):""" This method gets the administration shell from the AAS Repository by its identifier. Args: aas_id (str): The AAS identifier. Returns: object: The AAS object from the AAS Repository. """ifaas_idisNone:return"ERROR: The AAS identifier cannot be null."# First, the AAS JSON object need to be obtainedaas_json=send_openapi_http_get_request(AASRepositoryInfrastructure.get_aas_json_url_by_id(aas_id))if'ERROR'incheck_and_get_response_error(aas_json):return'Cannot obtain the AAS. {}'.format(check_and_get_response_error(aas_json))aas_complete_json={'assetAdministrationShells':[aas_json],'submodels':[]}# Then, each Submodel JSON related to the AAS need to bje obtainedforsubmodel_ref_datainaas_json['submodels']:submodel_json=send_openapi_http_get_request(AASRepositoryInfrastructure.get_submodel_json_url_by_id(submodel_ref_data['keys'][0]['value']))aas_complete_json['submodels'].append(submodel_json)# Finally, the data will be cleaned to comply with the latest version of the AAS meta-model so that BaSyx SDK# does not present errorsreturnAASRepositoryInfrastructure.clean_aas_json_information(aas_complete_json)
ACLOpenAPIServicesMap={# Registry ServicesAASRelatedServicesInfo.AAS_INFRASTRUCTURE_REGISTRY_SERVICE_REGISTER_SMIA:register_smia_instance,AASRelatedServicesInfo.AAS_INFRASTRUCTURE_REGISTRY_CSS_ELEMENTS:register_css_elements,# Discovery ServicesAASRelatedServicesInfo.AAS_INFRASTRUCTURE_DISCOVERY_SERVICE_GET_SMIA_BY_ASSET:get_smia_instance_by_asset_id,AASRelatedServicesInfo.AAS_INFRASTRUCTURE_DISCOVERY_SERVICE_GET_ASSET_BY_SMIA:get_asset_id_by_smia_instance,AASRelatedServicesInfo.AAS_INFRASTRUCTURE_DISCOVERY_SERVICE_GET_ALL_ASSET_BY_CAPABILITY:get_assets_ids_of_capability,AASRelatedServicesInfo.AAS_INFRASTRUCTURE_DISCOVERY_SERVICE_GET_AAS_BY_ID:get_asset_adminitration_shell_by_id,}#: This object maps the service identifiers with its associated execution methods