celonis_api_objects.py
CelonisApiObject (CelonisDataObject)
¶
Implementation of CelonisDataObject
providing the Celonis API endpoint and storing the response data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
celonis |
Celonis |
Base object to interact with Celonis Execution Management System (EMS) API. |
required |
id_or_data |
Union[str, Dict] |
ID or data of the Celonis resource object. |
required |
static |
bool |
|
False |
Source code in celonis_api/base_objects/celonis_api_objects.py
class CelonisApiObject(CelonisDataObject):
"""Implementation of [`CelonisDataObject`][celonis_api.base_objects.celonis_data_objects.CelonisDataObject]
providing the Celonis API endpoint and storing the response data.
Args:
celonis: Base object to interact with Celonis Execution Management System (EMS) API.
id_or_data: ID or data of the Celonis resource object.
static:
* `True` (static): `data` is only set once and never updated on Celonis EMS (therefore read-only).
* `False` (dynamic): Executes a `POST` request to the resource API endpoint to update the data
in Celonis EMS every time you set the `data` property.
"""
def __init__(self, celonis: 'Celonis', id_or_data: typing.Union[str, typing.Dict], static: bool = False):
self.celonis = celonis
self.static = static
self._data = None # type: ignore
if isinstance(id_or_data, (str, int)):
self.id = id_or_data
try:
self.name
except Exception:
self._name = "Unnamed"
try:
self.key
except Exception:
self._key = "Unnamed"
else:
self._process_data(id_or_data)
@property
@abc.abstractmethod
def url(self) -> str:
"""Absolut URL pointing to a Celonis resource via Celonis API."""
@property
def data(self):
"""Response data from the Celonis API.
If `static` is set to `False`, every time you set the `data` property will execute a `POST` request to
the resource API endpoint to update the remote resource in Celonis EMS.
Examples:
```py
o = celonis.<api-service>.find("<name or ID")
# This will execute a `POST` request to '<celonis_url>/<api-service>/api/...'
o.data["name"] = "New Name"
```
"""
if not self.static or self._data is None:
response = self.celonis.api_request(self.url, get_json=False)
self._data = json.loads(
response, object_hook=lambda d: CelonisApiDict(self, auto_push=not self.celonis.read_only, **d)
)
return self._data
@data.setter
def data(self, value):
temp = self.data
if value != temp:
response = self.celonis.api_request(self.url, value, method=HttpMethod.PUT)
if response == temp:
raise PyCelonisValueError(f"Setting {value} did not work.")
elif response != value and not equal_dicts(
response, value, ignore_keys=["permissions", "draftId", "changeDate"]
):
self._logger.warning("More things might have changed than requested")
def reset_state(self):
"""Resets `data = None`.
This will force a reload of the remote resource from Celonis EMS on the next property access.
"""
self._data = None
def delete(self):
"""Executes a `DELETE` request to the resource API endpoint to delete the remote resource in Celonis EMS."""
self.celonis.api_request(self.url, message=HttpMethod.DELETE)
def replace_text_in_raw_data(self, old: str, new: str):
old = ujson.dumps(old)[1:-1]
new = ujson.dumps(new)[1:-1]
data = ujson.dumps(self.data)
data = data.replace(old, new)
self.data = ujson.loads(data)
data
property
writable
¶
Response data from the Celonis API.
If static
is set to False
, every time you set the data
property will execute a POST
request to
the resource API endpoint to update the remote resource in Celonis EMS.
Examples:
url: str
property
readonly
¶
Absolut URL pointing to a Celonis resource via Celonis API.
delete(self)
¶
Executes a DELETE
request to the resource API endpoint to delete the remote resource in Celonis EMS.
reset_state(self)
¶
Resets data = None
.
This will force a reload of the remote resource from Celonis EMS on the next property access.
CelonisApiObjectChild (CelonisApiObject)
¶
Implementation of CelonisApiObject
to model hierarchical structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
Union[celonis_api.base_objects.celonis_api_objects.CelonisApiObject, str] |
The parent object. Can be an object of the class of the parent or the ID of the parent object. |
required |
id_or_data |
Union[str, Dict] |
ID or data of the Celonis resource object. |
required |
celonis |
Celonis |
Base object to interact with Celonis Execution Management System (EMS) API. |
None |
Source code in celonis_api/base_objects/celonis_api_objects.py
class CelonisApiObjectChild(CelonisApiObject):
"""Implementation of [`CelonisApiObject`][celonis_api.base_objects.celonis_api_objects.CelonisApiObject]
to model hierarchical structure.
Args:
parent: The parent object. Can be an object of the class of the parent or the ID of the parent object.
id_or_data: ID or data of the Celonis resource object.
celonis: Base object to interact with Celonis Execution Management System (EMS) API.
"""
@property
@abc.abstractmethod
def _parent_class(self):
"""Returns the parent class."""
def __init__(
self,
parent: typing.Union[CelonisApiObject, str],
id_or_data: typing.Union[str, typing.Dict],
celonis: 'Celonis' = None,
):
if isinstance(parent, self._parent_class):
self.parent = parent
celonis = self.parent.celonis
elif isinstance(parent, str):
if check_uuid(parent):
raise PyCelonisValueError("Argument 'parent' is not a valid uuid.")
if not celonis:
raise PyCelonisValueError("Argument 'celonis' must not be None if 'parent' is string.")
self.parent = self._parent_class(celonis, parent)
else:
raise PyCelonisTypeError(
"Argument 'parent' needs to be an object "
f"of type {self._parent_class.__class__.__name__} or a valid ID."
)
super().__init__(celonis, id_or_data)