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.")
65 _logger.debug(response.text)
68 if response.status_code != STATUS_CODE_200:
69 log_response(response)
72 except requests.exceptions.RequestException
as e:
73 _logger.error(f
"Error call REST API: {e}")
76 content = response.content.decode(
"utf-8")
77 return json.loads(content)
81 """Creates or updates an existing Asset Administration Shell Descriptor.
83 :param aas_identifier: The Asset Administration Shells unique id
84 :param request_body: Asset Administration Shell Descriptor object
85 :return: Created or updated Asset Administration Shell Descriptor data or None if an error occurred
87 if not self.
_client.encoded_ids:
88 aas_identifier = encode_base_64(aas_identifier)
90 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
95 response = self._session.put(url, json=request_body, timeout=self.
_client.time_out)
96 _logger.debug(f
"Call REST API url '{response.url}'")
98 if response.status_code == STATUS_CODE_404:
99 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
100 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
101 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
102 _logger.debug(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
104 _logger.debug(response.text)
107 if response.status_code != STATUS_CODE_204:
108 log_response(response)
111 except requests.exceptions.RequestException
as e:
112 _logger.error(f
"Error call REST API: {e}")
119 """Deletes an Asset Administration Shell Descriptor, i.e. de-registers an AAS.
121 :param aas_identifier: The Asset Administration Shells unique id
122 :return: True if deletion was successful, False otherwise
124 if not self.
_client.encoded_ids:
125 aas_identifier = encode_base_64(aas_identifier)
127 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
132 response = self._session.delete(url, timeout=self.
_client.time_out)
133 _logger.debug(f
"Call REST API url '{response.url}'")
135 if response.status_code == STATUS_CODE_404:
136 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
137 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
138 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
139 _logger.debug(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
141 _logger.debug(response.text)
144 if response.status_code != STATUS_CODE_204:
145 log_response(response)
148 except requests.exceptions.RequestException
as e:
149 _logger.error(f
"Error call REST API: {e}")
156 """Returns a specific Submodel Descriptor.
158 :param aas_identifier: The Asset Administration Shells unique id
159 :param submodel_identifier: The Submodels unique id
160 :return: Submodel Descriptor data or None if an error occurred
162 if not self.
_client.encoded_ids:
163 aas_identifier = encode_base_64(aas_identifier)
164 submodel_identifier = encode_base_64(submodel_identifier)
166 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
171 response = self._session.get(url, timeout=self.
_client.time_out)
172 _logger.debug(f
"Call REST API url '{response.url}'")
174 if response.status_code == STATUS_CODE_404:
175 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
176 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
177 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
178 _logger.debug(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
180 _logger.debug(response.text)
183 if response.status_code != STATUS_CODE_200:
184 log_response(response)
187 except requests.exceptions.RequestException
as e:
188 _logger.error(f
"Error call REST API: {e}")
191 content = response.content.decode(
"utf-8")
192 return json.loads(content)
196 """Creates or updates an existing Submodel Descriptor.
198 :param aas_identifier: The Asset Administration Shells unique id
199 :param submodel_identifier: The Submodels unique id
200 :param request_body: Submodel Descriptor object
201 :return: True if creation or update was successful, False otherwise
203 if not self.
_client.encoded_ids:
204 aas_identifier = encode_base_64(aas_identifier)
205 submodel_identifier = encode_base_64(submodel_identifier)
207 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
212 response = self._session.put(url, json=request_body, timeout=self.
_client.time_out)
213 _logger.debug(f
"Call REST API url '{response.url}'")
215 if response.status_code == STATUS_CODE_404:
216 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
217 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
218 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
219 _logger.debug(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
221 _logger.debug(response.text)
224 if response.status_code != STATUS_CODE_204:
225 log_response(response)
228 except requests.exceptions.RequestException
as e:
229 _logger.error(f
"Error call REST API: {e}")
236 """Deletes a Submodel Descriptor, i.e. de-registers a submodel.
238 :param aas_identifier: The Asset Administration Shells unique id
239 :param submodel_identifier: The Submodels unique id
240 :return: True if deletion was successful, False otherwise
242 if not self.
_client.encoded_ids:
243 aas_identifier = encode_base_64(aas_identifier)
244 submodel_identifier = encode_base_64(submodel_identifier)
246 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
251 response = self._session.delete(url, timeout=self.
_client.time_out)
252 _logger.debug(f
"Call REST API url '{response.url}'")
254 if response.status_code == STATUS_CODE_404:
255 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
256 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
257 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
258 _logger.debug(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
260 _logger.debug(response.text)
263 if response.status_code != STATUS_CODE_204:
264 log_response(response)
267 except requests.exceptions.RequestException
as e:
268 _logger.error(f
"Error call REST API: {e}")
275 self, limit: int = 100, cursor: str =
"", asset_kind: str =
"", asset_type: str =
""
277 """Returns all Asset Administration Shell Descriptors.
279 :param limit: Maximum number of Submodels to return
280 :param cursor: Cursor for pagination
281 :param asset_kind: The Asset's kind (Instance or Type). Available values : Instance, NotApplicable, Type
282 :param asset_type: The Asset's type (UTF8-BASE64-URL-encoded)
283 :return: Asset Administration Shell Descriptors data or None if an error occurred
285 url = f
"{self._client.base_url}/shell-descriptors"
287 params: dict[str, str] = {}
289 params[
"asset_kind"] = asset_kind
291 params[
"asset_type"] = asset_type
293 params[
"limit"] = str(limit)
295 params[
"cursor"] = cursor
300 response = self._session.get(url, params=params, timeout=self.
_client.time_out)
301 _logger.debug(f
"Call REST API url '{response.url}'")
303 if response.status_code != STATUS_CODE_200:
304 log_response(response)
307 except requests.exceptions.RequestException
as e:
308 _logger.error(f
"Error call REST API: {e}")
311 content = response.content.decode(
"utf-8")
312 return json.loads(content)
316 """Creates a new Asset Administration Shell Descriptor, i.e. registers an AAS.
318 :param request_body: Asset Administration Shell Descriptor object
319 :return: Created Asset Administration Shell Descriptor data or None if an error occurred
321 url = f
"{self._client.base_url}/shell-descriptors"
326 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
327 _logger.debug(f
"Call REST API url '{response.url}'")
329 if response.status_code != STATUS_CODE_201:
330 log_response(response)
333 except requests.exceptions.RequestException
as e:
334 _logger.error(f
"Error call REST API: {e}")
337 content = response.content.decode(
"utf-8")
338 return json.loads(content)
342 """Deletes all Asset Administration Shell Descriptors.
344 :return: True if deletion was successful, False otherwise
346 url = f
"{self._client.base_url}/shell-descriptors"
351 response = self._session.delete(url, timeout=self.
_client.time_out)
352 _logger.debug(f
"Call REST API url '{response.url}'")
354 if response.status_code != STATUS_CODE_204:
355 log_response(response)
358 except requests.exceptions.RequestException
as e:
359 _logger.error(f
"Error call REST API: {e}")
366 """Returns all Submodel Descriptors for a specific Asset Administration Shell.
368 :param aas_identifier: The Asset Administration Shells unique id
369 :return: Submodel Descriptors data or None if an error occurred
371 if not self.
_client.encoded_ids:
372 aas_identifier = encode_base_64(aas_identifier)
374 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors"
379 response = self._session.get(url, timeout=self.
_client.time_out)
380 _logger.debug(f
"Call REST API url '{response.url}'")
382 if response.status_code == STATUS_CODE_404:
383 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
384 _logger.warning(f
"Shell Descriptor with id '{aas_identifier}' not found.")
385 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
386 _logger.debug(f
"Shell Descriptor with id '{aas_identifier}' not found.")
388 _logger.debug(response.text)
391 if response.status_code != STATUS_CODE_200:
392 log_response(response)
395 except requests.exceptions.RequestException
as e:
396 _logger.error(f
"Error call REST API: {e}")
399 content = response.content.decode(
"utf-8")
400 return json.loads(content)
404 """Creates a new Submodel Descriptor, i.e. registers a submodel.
406 :param aas_identifier: The Asset Administration Shells unique id
407 :param request_body: Asset Administration Shell Descriptor object
408 :return: Created Asset Administration Shell Descriptor data or None if an error occurred
410 if not self.
_client.encoded_ids:
411 aas_identifier = encode_base_64(aas_identifier)
413 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors"
418 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
419 _logger.debug(f
"Call REST API url '{response.url}'")
421 if response.status_code == STATUS_CODE_404:
422 if self.
_client.get_log_intensity() == LogIntensity.HIGH:
423 _logger.warning(f
"Shell Descriptor with id '{aas_identifier}' not found.")
424 elif self.
_client.get_log_intensity() == LogIntensity.STANDARD:
425 _logger.debug(f
"Shell Descriptor with id '{aas_identifier}' not found.")
427 _logger.debug(response.text)
430 if response.status_code != STATUS_CODE_201:
431 log_response(response)
434 except requests.exceptions.RequestException
as e:
435 _logger.error(f
"Error call REST API: {e}")
438 content = response.content.decode(
"utf-8")
439 return json.loads(content)
442 def search(self, request_body: dict) -> dict |
None:
443 """Searches for Asset Administration Shell Descriptors based on the provided query.
445 :param request_body:query as a dictionary
446 :return: Search results as a dictionary or None if an error occurred
448 url = f
"{self._client.base_url}/search"
453 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
454 _logger.debug(f
"Call REST API url '{response.url}'")
456 if response.status_code != STATUS_CODE_200:
457 log_response(response)
460 except requests.exceptions.RequestException
as e:
461 _logger.error(f
"Error call REST API: {e}")
464 content = response.content.decode(
"utf-8")
465 return json.loads(content)
469 """Returns the self-describing information of a network resource (ServiceDescription).
471 :return: self-describing information of a network resource
473 url = f
"{self._client.base_url}/description"
478 response = self._session.get(url, timeout=self.
_client.time_out)
479 _logger.debug(f
"Call REST API url '{response.url}'")
481 if response.status_code != STATUS_CODE_200:
482 log_response(response)
485 except requests.exceptions.RequestException
as e:
486 _logger.error(f
"Error call REST API: {e}")
489 content = response.content.decode(
"utf-8")
490 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.