1"""Shell Registry Implementation Module."""
5from typing
import TYPE_CHECKING
8from pydantic
import BaseModel
11 from aas_http_client.classes.client.aas_client
import AasHttpClient
23_logger = logging.getLogger(__name__)
27 """Implementation of Asset Administration Shell Registry related API calls."""
29 def __init__(self, client:
"AasHttpClient"):
30 """Initializes the ShellRegistryImplementation with the given parameters."""
33 session = client.get_session()
36 "HTTP session is not initialized in the client. Call 'initialize()' method of the client before creating SubmodelRegistryImplementation instance."
39 self._session: requests.Session = session
43 """Returns a specific Asset Administration Shell Descriptor.
45 :param aas_identifier: The Asset Administration Shells unique id
46 :return: Asset Administration Shell Descriptor data or None if an error occurred
48 if not self.
_client.encoded_ids:
49 aas_identifier = encode_base_64(aas_identifier)
51 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
56 response = self._session.get(url, timeout=self.
_client.time_out)
57 _logger.debug(f
"Call REST API url '{response.url}'")
59 if response.status_code == STATUS_CODE_404:
60 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
61 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
62 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
63 _logger.debug(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
67 if response.status_code != STATUS_CODE_200:
68 log_response(response)
71 except requests.exceptions.RequestException
as e:
72 _logger.error(f
"Error call REST API: {e}")
75 content = response.content.decode(
"utf-8")
76 return json.loads(content)
80 """Creates or updates an existing Asset Administration Shell Descriptor.
82 :param aas_identifier: The Asset Administration Shells unique id
83 :param request_body: Asset Administration Shell Descriptor object
84 :return: Created or updated Asset Administration Shell Descriptor data or None if an error occurred
86 if not self.
_client.encoded_ids:
87 aas_identifier = encode_base_64(aas_identifier)
89 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
94 response = self._session.put(url, json=request_body, timeout=self.
_client.time_out)
95 _logger.debug(f
"Call REST API url '{response.url}'")
97 if response.status_code == STATUS_CODE_404:
98 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
99 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
100 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
101 _logger.debug(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
105 if response.status_code != STATUS_CODE_204:
106 log_response(response)
109 except requests.exceptions.RequestException
as e:
110 _logger.error(f
"Error call REST API: {e}")
117 """Deletes an Asset Administration Shell Descriptor, i.e. de-registers an AAS.
119 :param aas_identifier: The Asset Administration Shells unique id
120 :return: True if deletion was successful, False otherwise
122 if not self.
_client.encoded_ids:
123 aas_identifier = encode_base_64(aas_identifier)
125 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
130 response = self._session.delete(url, timeout=self.
_client.time_out)
131 _logger.debug(f
"Call REST API url '{response.url}'")
133 if response.status_code == STATUS_CODE_404:
134 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
135 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
136 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
137 _logger.debug(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
141 if response.status_code != STATUS_CODE_204:
142 log_response(response)
145 except requests.exceptions.RequestException
as e:
146 _logger.error(f
"Error call REST API: {e}")
153 """Returns a specific Submodel Descriptor.
155 :param aas_identifier: The Asset Administration Shells unique id
156 :param submodel_identifier: The Submodels unique id
157 :return: Submodel Descriptor data or None if an error occurred
159 if not self.
_client.encoded_ids:
160 aas_identifier = encode_base_64(aas_identifier)
161 submodel_identifier = encode_base_64(submodel_identifier)
163 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
168 response = self._session.get(url, timeout=self.
_client.time_out)
169 _logger.debug(f
"Call REST API url '{response.url}'")
171 if response.status_code == STATUS_CODE_404:
172 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
173 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
174 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
175 _logger.debug(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
179 if response.status_code != STATUS_CODE_200:
180 log_response(response)
183 except requests.exceptions.RequestException
as e:
184 _logger.error(f
"Error call REST API: {e}")
187 content = response.content.decode(
"utf-8")
188 return json.loads(content)
192 """Creates or updates an existing Submodel Descriptor.
194 :param aas_identifier: The Asset Administration Shells unique id
195 :param submodel_identifier: The Submodels unique id
196 :param request_body: Submodel Descriptor object
197 :return: True if creation or update was successful, False otherwise
199 if not self.
_client.encoded_ids:
200 aas_identifier = encode_base_64(aas_identifier)
201 submodel_identifier = encode_base_64(submodel_identifier)
203 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
208 response = self._session.put(url, json=request_body, timeout=self.
_client.time_out)
209 _logger.debug(f
"Call REST API url '{response.url}'")
211 if response.status_code == STATUS_CODE_404:
212 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
213 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
214 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
215 _logger.debug(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
219 if response.status_code != STATUS_CODE_204:
220 log_response(response)
223 except requests.exceptions.RequestException
as e:
224 _logger.error(f
"Error call REST API: {e}")
231 """Deletes a Submodel Descriptor, i.e. de-registers a submodel.
233 :param aas_identifier: The Asset Administration Shells unique id
234 :param submodel_identifier: The Submodels unique id
235 :return: True if deletion was successful, False otherwise
237 if not self.
_client.encoded_ids:
238 aas_identifier = encode_base_64(aas_identifier)
239 submodel_identifier = encode_base_64(submodel_identifier)
241 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
246 response = self._session.delete(url, timeout=self.
_client.time_out)
247 _logger.debug(f
"Call REST API url '{response.url}'")
249 if response.status_code == STATUS_CODE_404:
250 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
251 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
252 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
253 _logger.debug(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
257 if response.status_code != STATUS_CODE_204:
258 log_response(response)
261 except requests.exceptions.RequestException
as e:
262 _logger.error(f
"Error call REST API: {e}")
269 self, limit: int = 100, cursor: str =
"", asset_kind: str =
"", asset_type: str =
""
271 """Returns all Asset Administration Shell Descriptors.
273 :param limit: Maximum number of Submodels to return
274 :param cursor: Cursor for pagination
275 :param asset_kind: The Asset's kind (Instance or Type). Available values : Instance, NotApplicable, Type
276 :param asset_type: The Asset's type (UTF8-BASE64-URL-encoded)
277 :return: Asset Administration Shell Descriptors data or None if an error occurred
279 url = f
"{self._client.base_url}/shell-descriptors"
281 params: dict[str, str] = {}
283 params[
"asset_kind"] = asset_kind
285 params[
"asset_type"] = asset_type
287 params[
"limit"] = str(limit)
289 params[
"cursor"] = cursor
294 response = self._session.get(url, params=params, timeout=self.
_client.time_out)
295 _logger.debug(f
"Call REST API url '{response.url}'")
297 if response.status_code != STATUS_CODE_200:
298 log_response(response)
301 except requests.exceptions.RequestException
as e:
302 _logger.error(f
"Error call REST API: {e}")
305 content = response.content.decode(
"utf-8")
306 return json.loads(content)
310 """Creates a new Asset Administration Shell Descriptor, i.e. registers an AAS.
312 :param request_body: Asset Administration Shell Descriptor object
313 :return: Created Asset Administration Shell Descriptor data or None if an error occurred
315 url = f
"{self._client.base_url}/shell-descriptors"
320 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
321 _logger.debug(f
"Call REST API url '{response.url}'")
323 if response.status_code != STATUS_CODE_201:
324 log_response(response)
327 except requests.exceptions.RequestException
as e:
328 _logger.error(f
"Error call REST API: {e}")
331 content = response.content.decode(
"utf-8")
332 return json.loads(content)
336 """Deletes all Asset Administration Shell Descriptors.
338 :return: True if deletion was successful, False otherwise
340 url = f
"{self._client.base_url}/shell-descriptors"
345 response = self._session.delete(url, timeout=self.
_client.time_out)
346 _logger.debug(f
"Call REST API url '{response.url}'")
348 if response.status_code != STATUS_CODE_204:
349 log_response(response)
352 except requests.exceptions.RequestException
as e:
353 _logger.error(f
"Error call REST API: {e}")
360 """Returns all Submodel Descriptors for a specific Asset Administration Shell.
362 :param aas_identifier: The Asset Administration Shells unique id
363 :return: Submodel Descriptors data or None if an error occurred
365 if not self.
_client.encoded_ids:
366 aas_identifier = encode_base_64(aas_identifier)
368 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors"
373 response = self._session.get(url, timeout=self.
_client.time_out)
374 _logger.debug(f
"Call REST API url '{response.url}'")
376 if response.status_code == STATUS_CODE_404:
377 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
378 _logger.warning(f
"Shell Descriptor with id '{aas_identifier}' not found.")
379 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
380 _logger.debug(f
"Shell Descriptor with id '{aas_identifier}' not found.")
384 if response.status_code != STATUS_CODE_200:
385 log_response(response)
388 except requests.exceptions.RequestException
as e:
389 _logger.error(f
"Error call REST API: {e}")
392 content = response.content.decode(
"utf-8")
393 return json.loads(content)
397 """Creates a new Submodel Descriptor, i.e. registers a submodel.
399 :param aas_identifier: The Asset Administration Shells unique id
400 :param request_body: Asset Administration Shell Descriptor object
401 :return: Created Asset Administration Shell Descriptor data or None if an error occurred
403 if not self.
_client.encoded_ids:
404 aas_identifier = encode_base_64(aas_identifier)
406 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors"
411 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
412 _logger.debug(f
"Call REST API url '{response.url}'")
414 if response.status_code == STATUS_CODE_404:
415 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
416 _logger.warning(f
"Shell Descriptor with id '{aas_identifier}' not found.")
417 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
418 _logger.debug(f
"Shell Descriptor with id '{aas_identifier}' not found.")
422 if response.status_code != STATUS_CODE_201:
423 log_response(response)
426 except requests.exceptions.RequestException
as e:
427 _logger.error(f
"Error call REST API: {e}")
430 content = response.content.decode(
"utf-8")
431 return json.loads(content)
434 def search(self, request_body: dict) -> dict |
None:
435 """Searches for Asset Administration Shell Descriptors based on the provided query.
437 :param request_body:query as a dictionary
438 :return: Search results as a dictionary or None if an error occurred
440 url = f
"{self._client.base_url}/search"
445 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
446 _logger.debug(f
"Call REST API url '{response.url}'")
448 if response.status_code != STATUS_CODE_200:
449 log_response(response)
452 except requests.exceptions.RequestException
as e:
453 _logger.error(f
"Error call REST API: {e}")
456 content = response.content.decode(
"utf-8")
457 return json.loads(content)
461 """Returns the self-describing information of a network resource (ServiceDescription).
463 :return: self-describing information of a network resource
465 url = f
"{self._client.base_url}/description"
470 response = self._session.get(url, timeout=self.
_client.time_out)
471 _logger.debug(f
"Call REST API url '{response.url}'")
473 if response.status_code != STATUS_CODE_200:
474 log_response(response)
477 except requests.exceptions.RequestException
as e:
478 _logger.error(f
"Error call REST API: {e}")
481 content = response.content.decode(
"utf-8")
482 return json.loads(content)
Implementation of Asset Administration Shell Registry related API calls.
dict|None get_submodel_descriptor_by_id_through_superpath(self, str aas_identifier, str submodel_identifier)
Returns a specific Submodel Descriptor.
dict|None post_submodel_descriptor_through_superpath(self, str aas_identifier, dict request_body)
Creates a new Submodel Descriptor, i.e.
dict|None post_asset_administration_shell_descriptor(self, dict request_body)
Creates a new Asset Administration Shell Descriptor, i.e.
dict|None search(self, dict request_body)
Searches for Asset Administration Shell Descriptors based on the provided query.
bool delete_asset_administration_shell_descriptor_by_id(self, str aas_identifier)
Deletes an Asset Administration Shell Descriptor, i.e.
bool put_asset_administration_shell_descriptor_by_id(self, str aas_identifier, dict request_body)
Creates or updates an existing Asset Administration Shell Descriptor.
bool delete_submodel_descriptor_by_id_through_superpath(self, str aas_identifier, str submodel_identifier)
Deletes a Submodel Descriptor, i.e.
dict|None get_all_submodel_descriptors_through_superpath(self, str aas_identifier)
Returns all Submodel Descriptors for a specific Asset Administration Shell.
dict|None get_self_description(self)
Returns the self-describing information of a network resource (ServiceDescription).
bool delete_all_asset_administration_shell_descriptors(self)
Deletes all Asset Administration Shell Descriptors.
bool put_submodel_descriptor_by_id_through_superpath(self, str aas_identifier, str submodel_identifier, dict request_body)
Creates or updates an existing Submodel Descriptor.
__init__(self, "AasHttpClient" client)
Initializes the ShellRegistryImplementation with the given parameters.
dict|None get_asset_administration_shell_descriptor_by_id(self, str aas_identifier)
Returns a specific Asset Administration Shell Descriptor.
dict|None get_all_asset_administration_shell_descriptors(self, int limit=100, str cursor="", str asset_kind="", str asset_type="")
Returns all Asset Administration Shell Descriptors.