[docs]classAASRepositoryInfrastructure:""" Class to store information about the SMIA KB infrastructure. """# Default values_AAS_HOST_IP_ADDRESS='http://192.168.186.129'# TODO DE MOMENTO ESTA LA IP DE LA MAQUINA VIRTUAL. PENSARLO SI AĆADIRLO DE FORMA QUE SEA PARAMETRIZABLE (p.e. con variable de entorno para Docker)_AAS_REPOSITORY_PORT=8081AAS_OPEN_API_VERSION='/api/v3'AAS_OPEN_API_COMMON_HEADERS={"Accept":"application/json"}
[docs]@classmethoddefset_ip_address_host(cls,ip_address):# Validate and normalize the IP address formatifip_addressandnotip_address.startswith(('http://','https://')):ip_address='http://'+ip_addresscls._AAS_HOST_IP_ADDRESS=ip_address
[docs]@classmethoddefset_ip_address(cls,ip_address):# Validate and normalize the IP address formatifip_addressandnotip_address.startswith(('http://','https://')):ip_address='http://'+ip_addressparsed=urlparse(ip_address)cls._AAS_HOST_IP_ADDRESS=f"{parsed.scheme}://{parsed.hostname}"cls._AAS_REPOSITORY_PORT=parsed.portifparsed.portelse(8080ifparsed.scheme=="http"else443)
[docs]@classmethoddefset_port(cls,port):# Validate port is a number and in valid rangetry:port_num=int(port)if1<=port_num<=65535:cls._AAS_REPOSITORY_PORT=port_numelse:raiseValueError(f"ERROR: Port must be between 1-65535, got {port}")except(ValueError,TypeError):raiseValueError(f"ERROR: Port must be a valid integer, got {port}")
# -------------------------------------------------# Methods to create URLs for the AAS Repository API# -------------------------------------------------
[docs]@classmethoddefget_aas_json_url_by_id(cls,aas_id):""" This method returns the URL to obtain the information of a specific AAS in JSON format. The AAS identifier must be added in Base64-URL-encoded. """aas_id_encoded=encode_string_in_base64_url(aas_id)returnf"{cls._AAS_HOST_IP_ADDRESS}:{cls._AAS_REPOSITORY_PORT}/shells/{aas_id_encoded}"
[docs]@classmethoddefget_submodel_json_url_by_id(cls,submodel_id):""" This method returns the URL to obtain the information of a specific Submodel in JSON format. The Submodel identifier must be added in Base64-URL-encoded. """submodel_id_encoded=encode_string_in_base64_url(submodel_id)returnf"{cls._AAS_HOST_IP_ADDRESS}:{cls._AAS_REPOSITORY_PORT}/submodels/{submodel_id_encoded}"
# -------------------------------------------# Utils methods related to the AAS Repository# -------------------------------------------
[docs]@staticmethoddefclean_aas_json_information(data):""" This method removes all the data from previous versions of the AAS meta-model so that it can be read by BaSyx SDK. For instance, the attribute 'Referable/Category' is deprecated, so it must be removed if it is defined. """# The attribute 'Referable/Category' will be removedifisinstance(data,dict):# Create a new dictionary, removing the specified key and processing each valuereturn{key:(Noneif'modelType'indata.keys()anddata['modelType']=='File'andvalue==""# else "NoneIdShort" if key == 'idShort' and value == ""elseAASRepositoryInfrastructure.clean_aas_json_information(value))forkey,valueindata.items()if(keynotin['category'])# Add old attributes to be removedandnot(key=='idShort'andvalue=="")# If idShort is not defined, it is removed}elifisinstance(data,list):# Apply recursively to each item in the listreturn[AASRepositoryInfrastructure.clean_aas_json_information(item)foritemindata]else:# If it's neither a dict nor a list, just return itreturndata