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
22_logger = logging.getLogger(__name__)
26 """Implementation of Asset Administration Shell Registry related API calls."""
28 def __init__(self, client:
"AasHttpClient"):
29 """Initializes the ShellRegistryImplementation with the given parameters."""
32 session = client.get_session()
35 "HTTP session is not initialized in the client. Call 'initialize()' method of the client before creating SubmodelRegistryImplementation instance."
38 self._session: requests.Session = session
42 """Returns a specific Asset Administration Shell Descriptor.
44 :param aas_identifier: The Asset Administration Shells unique id
45 :return: Asset Administration Shell Descriptor data or None if an error occurred
47 if not self.
_client.encoded_ids:
48 aas_identifier = encode_base_64(aas_identifier)
50 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
55 response = self._session.get(url, timeout=self.
_client.time_out)
56 _logger.debug(f
"Call REST API url '{response.url}'")
58 if response.status_code == STATUS_CODE_404:
59 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
60 _logger.debug(response.text)
63 if response.status_code != STATUS_CODE_200:
64 log_response(response)
67 except requests.exceptions.RequestException
as e:
68 _logger.error(f
"Error call REST API: {e}")
71 content = response.content.decode(
"utf-8")
72 return json.loads(content)
76 """Creates or updates an existing Asset Administration Shell Descriptor.
78 :param aas_identifier: The Asset Administration Shells unique id
79 :param request_body: Asset Administration Shell Descriptor object
80 :return: Created or updated Asset Administration Shell Descriptor data or None if an error occurred
82 if not self.
_client.encoded_ids:
83 aas_identifier = encode_base_64(aas_identifier)
85 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
90 response = self._session.put(url, json=request_body, timeout=self.
_client.time_out)
91 _logger.debug(f
"Call REST API url '{response.url}'")
93 if response.status_code == STATUS_CODE_404:
94 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
95 _logger.debug(response.text)
98 if response.status_code != STATUS_CODE_204:
99 log_response(response)
102 except requests.exceptions.RequestException
as e:
103 _logger.error(f
"Error call REST API: {e}")
110 """Deletes an Asset Administration Shell Descriptor, i.e. de-registers an AAS.
112 :param aas_identifier: The Asset Administration Shells unique id
113 :return: True if deletion was successful, False otherwise
115 if not self.
_client.encoded_ids:
116 aas_identifier = encode_base_64(aas_identifier)
118 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}"
123 response = self._session.delete(url, timeout=self.
_client.time_out)
124 _logger.debug(f
"Call REST API url '{response.url}'")
126 if response.status_code == STATUS_CODE_404:
127 _logger.warning(f
"Asset Administration Shell Descriptor with id '{aas_identifier}' not found.")
128 _logger.debug(response.text)
131 if response.status_code != STATUS_CODE_204:
132 log_response(response)
135 except requests.exceptions.RequestException
as e:
136 _logger.error(f
"Error call REST API: {e}")
143 """Returns a specific Submodel Descriptor.
145 :param aas_identifier: The Asset Administration Shells unique id
146 :param submodel_identifier: The Submodels unique id
147 :return: Submodel Descriptor data or None if an error occurred
149 if not self.
_client.encoded_ids:
150 aas_identifier = encode_base_64(aas_identifier)
151 submodel_identifier = encode_base_64(submodel_identifier)
153 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
158 response = self._session.get(url, timeout=self.
_client.time_out)
159 _logger.debug(f
"Call REST API url '{response.url}'")
161 if response.status_code == STATUS_CODE_404:
162 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
163 _logger.debug(response.text)
166 if response.status_code != STATUS_CODE_200:
167 log_response(response)
170 except requests.exceptions.RequestException
as e:
171 _logger.error(f
"Error call REST API: {e}")
174 content = response.content.decode(
"utf-8")
175 return json.loads(content)
179 """Creates or updates an existing Submodel Descriptor.
181 :param aas_identifier: The Asset Administration Shells unique id
182 :param submodel_identifier: The Submodels unique id
183 :param request_body: Submodel Descriptor object
184 :return: True if creation or update was successful, False otherwise
186 if not self.
_client.encoded_ids:
187 aas_identifier = encode_base_64(aas_identifier)
188 submodel_identifier = encode_base_64(submodel_identifier)
190 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
195 response = self._session.put(url, json=request_body, timeout=self.
_client.time_out)
196 _logger.debug(f
"Call REST API url '{response.url}'")
198 if response.status_code == STATUS_CODE_404:
199 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
200 _logger.debug(response.text)
203 if response.status_code != STATUS_CODE_204:
204 log_response(response)
207 except requests.exceptions.RequestException
as e:
208 _logger.error(f
"Error call REST API: {e}")
215 """Deletes a Submodel Descriptor, i.e. de-registers a submodel.
217 :param aas_identifier: The Asset Administration Shells unique id
218 :param submodel_identifier: The Submodels unique id
219 :return: True if deletion was successful, False otherwise
221 if not self.
_client.encoded_ids:
222 aas_identifier = encode_base_64(aas_identifier)
223 submodel_identifier = encode_base_64(submodel_identifier)
225 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors/{submodel_identifier}"
230 response = self._session.delete(url, timeout=self.
_client.time_out)
231 _logger.debug(f
"Call REST API url '{response.url}'")
233 if response.status_code == STATUS_CODE_404:
234 _logger.warning(f
"Submodel Descriptor with id '{submodel_identifier}' or submodel with id '{submodel_identifier}' not found.")
235 _logger.debug(response.text)
238 if response.status_code != STATUS_CODE_204:
239 log_response(response)
242 except requests.exceptions.RequestException
as e:
243 _logger.error(f
"Error call REST API: {e}")
250 self, limit: int = 100, cursor: str =
"", asset_kind: str =
"", asset_type: str =
""
252 """Returns all Asset Administration Shell Descriptors.
254 :param limit: Maximum number of Submodels to return
255 :param cursor: Cursor for pagination
256 :param asset_kind: The Asset's kind (Instance or Type). Available values : Instance, NotApplicable, Type
257 :param asset_type: The Asset's type (UTF8-BASE64-URL-encoded)
258 :return: Asset Administration Shell Descriptors data or None if an error occurred
260 url = f
"{self._client.base_url}/shell-descriptors"
262 params: dict[str, str] = {}
264 params[
"asset_kind"] = asset_kind
266 params[
"asset_type"] = asset_type
268 params[
"limit"] = str(limit)
270 params[
"cursor"] = cursor
275 response = self._session.get(url, params=params, timeout=self.
_client.time_out)
276 _logger.debug(f
"Call REST API url '{response.url}'")
278 if response.status_code != STATUS_CODE_200:
279 log_response(response)
282 except requests.exceptions.RequestException
as e:
283 _logger.error(f
"Error call REST API: {e}")
286 content = response.content.decode(
"utf-8")
287 return json.loads(content)
291 """Creates a new Asset Administration Shell Descriptor, i.e. registers an AAS.
293 :param request_body: Asset Administration Shell Descriptor object
294 :return: Created Asset Administration Shell Descriptor data or None if an error occurred
296 url = f
"{self._client.base_url}/shell-descriptors"
301 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
302 _logger.debug(f
"Call REST API url '{response.url}'")
304 if response.status_code != STATUS_CODE_201:
305 log_response(response)
308 except requests.exceptions.RequestException
as e:
309 _logger.error(f
"Error call REST API: {e}")
312 content = response.content.decode(
"utf-8")
313 return json.loads(content)
317 """Deletes all Asset Administration Shell Descriptors.
319 :return: True if deletion was successful, False otherwise
321 url = f
"{self._client.base_url}/shell-descriptors"
326 response = self._session.delete(url, timeout=self.
_client.time_out)
327 _logger.debug(f
"Call REST API url '{response.url}'")
329 if response.status_code != STATUS_CODE_204:
330 log_response(response)
333 except requests.exceptions.RequestException
as e:
334 _logger.error(f
"Error call REST API: {e}")
341 """Returns all Submodel Descriptors for a specific Asset Administration Shell.
343 :param aas_identifier: The Asset Administration Shells unique id
344 :return: Submodel Descriptors data or None if an error occurred
346 if not self.
_client.encoded_ids:
347 aas_identifier = encode_base_64(aas_identifier)
349 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors"
354 response = self._session.get(url, timeout=self.
_client.time_out)
355 _logger.debug(f
"Call REST API url '{response.url}'")
357 if response.status_code == STATUS_CODE_404:
358 _logger.warning(f
"Shell Descriptor with id '{aas_identifier}' not found.")
359 _logger.debug(response.text)
362 if response.status_code != STATUS_CODE_200:
363 log_response(response)
366 except requests.exceptions.RequestException
as e:
367 _logger.error(f
"Error call REST API: {e}")
370 content = response.content.decode(
"utf-8")
371 return json.loads(content)
375 """Creates a new Submodel Descriptor, i.e. registers a submodel.
377 :param aas_identifier: The Asset Administration Shells unique id
378 :param request_body: Asset Administration Shell Descriptor object
379 :return: Created Asset Administration Shell Descriptor data or None if an error occurred
381 if not self.
_client.encoded_ids:
382 aas_identifier = encode_base_64(aas_identifier)
384 url = f
"{self._client.base_url}/shell-descriptors/{aas_identifier}/submodel-descriptors"
389 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
390 _logger.debug(f
"Call REST API url '{response.url}'")
392 if response.status_code == STATUS_CODE_404:
393 _logger.warning(f
"Shell Descriptor with id '{aas_identifier}' not found.")
394 _logger.debug(response.text)
397 if response.status_code != STATUS_CODE_201:
398 log_response(response)
401 except requests.exceptions.RequestException
as e:
402 _logger.error(f
"Error call REST API: {e}")
405 content = response.content.decode(
"utf-8")
406 return json.loads(content)
409 def search(self, request_body: dict) -> dict |
None:
410 """Searches for Asset Administration Shell Descriptors based on the provided query.
412 :param request_body:query as a dictionary
413 :return: Search results as a dictionary or None if an error occurred
415 url = f
"{self._client.base_url}/search"
420 response = self._session.post(url, json=request_body, timeout=self.
_client.time_out)
421 _logger.debug(f
"Call REST API url '{response.url}'")
423 if response.status_code != STATUS_CODE_200:
424 log_response(response)
427 except requests.exceptions.RequestException
as e:
428 _logger.error(f
"Error call REST API: {e}")
431 content = response.content.decode(
"utf-8")
432 return json.loads(content)
436 """Returns the self-describing information of a network resource (ServiceDescription).
438 :return: self-describing information of a network resource
440 url = f
"{self._client.base_url}/description"
445 response = self._session.get(url, 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)
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.