kuflow-robotframework 1.5.1__tar.gz → 2.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,7 @@
25
25
  from .keywords import Keywords
26
26
 
27
27
 
28
- __version__ = "1.5.1"
28
+ __version__ = "2.0.1"
29
29
  __all__ = ["KuFlow"]
30
30
 
31
31
 
@@ -0,0 +1,257 @@
1
+ #
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2022 KuFlow
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #
24
+
25
+ import json
26
+ import logging
27
+ import os
28
+ from typing import Any, Dict, Optional
29
+ from uuid import UUID
30
+
31
+ import magic
32
+ from robot.api.deco import keyword
33
+ from robot.utils import is_dict_like, is_string, type_name
34
+
35
+ from kuflow_rest import KuBotTokenCredential, KuFlowRestClient, models
36
+
37
+
38
+ class Keywords:
39
+ def __init__(self) -> None:
40
+ self.logger = logging.getLogger(__name__)
41
+ self._client: Optional[KuFlowRestClient] = None
42
+
43
+ @keyword(tags=("settings",))
44
+ def get_kuBot_token_credential(
45
+ self,
46
+ token: str,
47
+ expires_on: int,
48
+ ) -> KuBotTokenCredential:
49
+ return KuBotTokenCredential(token, expires_on)
50
+
51
+ @keyword(tags=("settings",))
52
+ def set_client_authentication(
53
+ self,
54
+ client_id: Optional[str] = None,
55
+ client_secret: Optional[str] = None,
56
+ credential: Optional[KuBotTokenCredential] = None,
57
+ endpoint: Optional[str] = None,
58
+ allow_insecure_connection: Optional[bool] = None,
59
+ ):
60
+ """Configure the client authentication in order to execute keywords against Rest API.
61
+
62
+ Before using any other KuFlow Keyword, this one must be called.
63
+
64
+ Example:
65
+ | Set Client Authentication | %{KUFLOW_CLIENT_ID} | %{KUFLOW_CLIENT_SECRET}
66
+ | Set Client Authentication | %{KUFLOW_CLIENT_ID} | %{KUFLOW_CLIENT_SECRET} | %{KUFLOW_API_ENDPOINT}
67
+ =>
68
+ | Set Client Authentication | identifier | token
69
+ | Set Client Authentication | identifier | token | https://api.kuflow.com/v1.0
70
+ """
71
+ if is_string(endpoint) and (endpoint.strip() == "" or endpoint.lower() == "none"):
72
+ endpoint = None
73
+
74
+ self._client = KuFlowRestClient(
75
+ client_id=client_id,
76
+ client_secret=client_secret,
77
+ credential=credential,
78
+ endpoint=endpoint,
79
+ allow_insecure_connection=allow_insecure_connection,
80
+ )
81
+
82
+ @keyword(tags=("settings",))
83
+ def get_client(self) -> KuFlowRestClient:
84
+ return self._client
85
+
86
+ @keyword(tags=("settings",))
87
+ def get_instance(self) -> "Keywords":
88
+ return self
89
+
90
+ @keyword(tags=("settings",))
91
+ def convert_to_dictionary_recursively(self, value: dict) -> dict:
92
+ """Converts the given ``value`` to a Python ``dict`` type.
93
+
94
+ Mainly useful for converting other mappings to normal dictionaries.
95
+ This includes converting Robot Framework's own ``DotDict`` instances.
96
+
97
+ Unlike the `Convert To Dictionary` keyword from Robotframework's Collections library,
98
+ which only converts the first level of the dictionary using "Convert To Dictionary",
99
+ this method performs nested conversion using Json's marshall and unmarshall.
100
+ """
101
+ return json.loads(json.dumps(value))
102
+
103
+ @keyword()
104
+ def retrieve_process(self, process_id: UUID) -> models.Process:
105
+ """Allow to get a process by ID.
106
+
107
+ Example:
108
+ | RETRIEVE PROCESS | ${PROCESS_ID}
109
+ =>
110
+ | RETRIEVE PROCESS | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec
111
+ """
112
+
113
+ return self._client.process.retrieve_process(process_id)
114
+
115
+ @keyword()
116
+ def retrieve_process_item(self, process_item_id: UUID) -> models.ProcessItem:
117
+ """Allow to get a process item by ID.
118
+
119
+ Example:
120
+ | RETRIEVE PROCESS ITEM | ${PROCESS_ITEM_ID}
121
+ =>
122
+ | RETRIEVE PROCESS ITEM | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec
123
+ """
124
+
125
+ return self._client.process_item.retrieve_process_item(process_item_id)
126
+
127
+ @keyword()
128
+ def append_process_item_task_log(
129
+ self,
130
+ process_item_id: UUID,
131
+ message: str,
132
+ level: models.ProcessItemTaskLogLevel = models.ProcessItemTaskLogLevel.INFO,
133
+ ) -> models.ProcessItem:
134
+ """Add a log entry to the task
135
+
136
+ If the number of log entries is reached, the oldest log entry is removed.
137
+ The level of log can be INFO, WARN or ERROR.
138
+
139
+ Example:
140
+ | Append Process Item Task Log | ${PROCESS_ITEM_ID} | ${MESSAGE}
141
+ | Append Process Item Task Log | ${PROCESS_ITEM_ID} | ${MESSAGE} | level=${LEVEL}
142
+ =>
143
+ | Append Process Item Task Log | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | My info message
144
+ | Append Process Item Task Log | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | My warning message | level=WARN
145
+ """
146
+ params = models.ProcessItemTaskAppendLogParams(message=message, level=level)
147
+
148
+ return self._client.process_item.append_process_item_task_log(process_item_id, params)
149
+
150
+ @keyword()
151
+ def claim_process_item_task(self, process_item_id: UUID) -> models.ProcessItem:
152
+ """Allow to claim a process item task
153
+
154
+ Example:
155
+ | CLAIM PROCESS ITEM TASK | ${PROCESS_ITEM_ID}
156
+ =>
157
+ | CLAIM PROCESS ITEM TASK | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec
158
+ """
159
+
160
+ return self._client.process_item.claim_process_item_task(process_item_id)
161
+
162
+ @keyword()
163
+ def update_process_item_task_data(self, process_item_id: UUID, value: Dict[str, Any]) -> models.ProcessItem:
164
+ """Save a JSON value data
165
+
166
+ Allows a JSON to be saved in the process item task.
167
+
168
+ If previous values already exist in the JSON value, they are replaced by the new values.
169
+
170
+ Server-side validations are applied on the saved JSON according to the ones you defined in the schema
171
+ in the process item task definition in KuFlow.
172
+
173
+ Example:
174
+ | Update Process Item Task Data | ${PROCESS_ITEM_ID} | ${json_data}
175
+ =>
176
+ | &{json_data}= Create Dictionary key1=value1 keu2=value2
177
+ | Update Process Item Task Data | ${PROCESS_ITEM_ID} | ${json_data}
178
+ """
179
+ if not is_dict_like(value):
180
+ raise TypeError(f"Expected argument to be a dict or dict-like, got {type_name(value)} instead.")
181
+
182
+ params = models.ProcessItemTaskDataUpdateParams(
183
+ data=models.JsonValue(value=self.convert_to_dictionary_recursively(value))
184
+ )
185
+
186
+ return self._client.process_item.update_process_item_task_data(process_item_id, params)
187
+
188
+ @keyword()
189
+ def upload_process_item_task_data_document(self, task_id: UUID, path_in_schema: str, path: str) -> str:
190
+ """Upload a JSON Forms value document
191
+
192
+ Allows you to upload a document to the referenced task and then include a reference to it
193
+ in the task's JSON Forms.
194
+
195
+ You must provide the path within the JSON schema that defines the document you wish to upload.
196
+ This schema is found in your task definition in KuFlow. For example, given this schema:
197
+
198
+ {
199
+ "type": "object",
200
+ "properties": {
201
+ "file": {
202
+ "type": "string",
203
+ "format": "kuflow-file",
204
+ "accept": "image/*,application/pdf,.pdf",
205
+ "maxSize": 20000000
206
+ }
207
+ }
208
+ }
209
+
210
+ The path is as follows: #/properties/file
211
+
212
+ Note that in RobotFramework, the hash indicates a comment, so you should escape it
213
+
214
+ Example:
215
+ | Upload Process Item Task Data Document | ${PROCESS_ITEM_ID} | ${PATH_IN_SCHEMA} | ${PATH}
216
+ =>
217
+ | ${document_reference}=
218
+ | ... Upload Json Forms Value document | ${PROCESS_ITEM_ID} | \\#/properties/file | hello.jpg
219
+ | &{json_data}= Create Dictionary my_file=${document_reference}
220
+ | Update Process Item Task Data ${KUFLOW_TASK_ID} ${json_data}
221
+ """
222
+
223
+ file_name = os.path.basename(path)
224
+ file = open(path, "rb")
225
+ content_type = magic.from_file(path, mime=True)
226
+
227
+ file = models.Document(
228
+ file_mame=file_name,
229
+ content_type=content_type,
230
+ file_content=file,
231
+ )
232
+
233
+ response = self._client.process_item.upload_process_item_task_data_document(
234
+ id=task_id, file=file, schema_path=path_in_schema
235
+ )
236
+
237
+ return response.value
238
+
239
+ @keyword()
240
+ def convert_json_string_to_object(self, json_string):
241
+ """Convert JSON String To Object
242
+
243
+ Given a JSON string as argument, return new JSON object
244
+
245
+ Example:
246
+ | ${json_object}= | Convert JSON String To Object | ${json_string} |
247
+ =>
248
+ | ${json_string}= catenate
249
+ | ... {
250
+ | ... "key1": "10",
251
+ | ... "key2": {
252
+ | ... "subkey1": "My value"
253
+ | ... }
254
+ | ... }
255
+ | ${json_object}= | Convert JSON String To Object | ${json_string} |
256
+ """
257
+ return json.loads(json_string)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kuflow-robotframework
3
- Version: 1.5.1
3
+ Version: 2.0.1
4
4
  Summary: KuFlow library for Robot Framework
5
5
  Home-page: https://kuflow.com/
6
6
  License: MIT
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3.8
13
13
  Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
- Requires-Dist: kuflow-rest (>=1.5.1,<2.0.0)
16
+ Requires-Dist: kuflow-rest (>=2.0.1,<3.0.0)
17
17
  Requires-Dist: python-magic (>=0.4.27,<0.5.0) ; sys_platform != "win32"
18
18
  Requires-Dist: python-magic-bin (>=0.4.14,<0.5.0) ; sys_platform == "win32"
19
19
  Requires-Dist: robotframework (>5.0.0)
@@ -0,0 +1 @@
1
+ 2.0.1
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "kuflow-robotframework"
3
- version = "1.5.1"
3
+ version = "2.0.1"
4
4
  description = "KuFlow library for Robot Framework"
5
5
  license = "MIT"
6
6
  authors = ["KuFlow S.L. <kuflow@kuflow.com>"]
@@ -17,15 +17,15 @@ build-backend = "poetry.core.masonry.api"
17
17
 
18
18
  [tool.poetry.dependencies]
19
19
  python = "^3.8"
20
- kuflow-rest = "^1.5.1"
20
+ kuflow-rest = "^2.0.1"
21
21
  robotframework = ">5.0.0"
22
22
  python-magic = {version = "^0.4.27", platform = "!=win32"}
23
23
  python-magic-bin = {version = "^0.4.14", platform = "win32"}
24
24
 
25
25
  [tool.poetry.group.dev.dependencies]
26
- mypy = "^1.3.0"
26
+ mypy = "^1.11.1"
27
27
  ruff = ">=0.1.8,<1.0.0"
28
- pytest = "^7.3.1"
28
+ pytest = "^8.3.2"
29
29
  robotframework-tidy = "^3.3.3"
30
30
 
31
31
  [tool.pytest.ini_options]
@@ -8,7 +8,7 @@ package_data = \
8
8
  {'': ['*']}
9
9
 
10
10
  install_requires = \
11
- ['kuflow-rest>=1.5.1,<2.0.0', 'robotframework>5.0.0']
11
+ ['kuflow-rest>=2.0.1,<3.0.0', 'robotframework>5.0.0']
12
12
 
13
13
  extras_require = \
14
14
  {':sys_platform != "win32"': ['python-magic>=0.4.27,<0.5.0'],
@@ -16,7 +16,7 @@ extras_require = \
16
16
 
17
17
  setup_kwargs = {
18
18
  'name': 'kuflow-robotframework',
19
- 'version': '1.5.1',
19
+ 'version': '2.0.1',
20
20
  'description': 'KuFlow library for Robot Framework',
21
21
  'long_description': "[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/kuflow/kuflow-sdk-python/blob/master/LICENSE)\n[![Python](https://img.shields.io/pypi/pyversions/kuflow-robotframework.svg)](https://pypi.org/project/kuflow-robotframework)\n[![PyPI](https://img.shields.io/pypi/v/kuflow-robotframework.svg)](https://pypi.org/project/kuflow-robotframework)\n\n# KuFlow Robot Framework\n\nThis library provides keywords to interact with the KuFlow API from a Robot Framework Robot. Its purpose is to facilitate interaction from the robot logic (RPA). Its use helps to keep the manipulation of robot results by Workflow decoupled as much as possible.\n\nList of available keywords:\n\n#### Set Client Authentication\n\n> Configure the client authentication in order to execute keywords against Rest API\n\n#### Append Log Message\n\n> Add a log entry to the task\n\n#### Claim Task\n\n> Allow to claim a task\n\n#### Retrieve Process\n\n> Allow to get a process by ID\n\n#### Retrieve Task\n\n> Allow to get a task by ID\n\n#### Save Element Document\n\n> Save a element task of type document\n\n#### Delete Element Document\n\n> Allow to delete a specific document from an element of document type using its id.\n\n#### Save Element\n\n> Save a element task\n\n#### Delete Element\n\n> Allow to delete task element by specifying the item definition code.\n\n#### Convert To Principal Item\n\n> Given an Id of a Principal user, create an item that represents a reference to the Principal.\n\n#### Convert To Document Item From Uri\n\n> Given an Id of a Document or the URI reference of a Document, create an item that represents a reference to the Document elementand can be used.\n\n#### Convert JSON String To Object\n\n> Given a JSON string as argument, return new JSON object\n\n#### Save Json Forms Value Data\n\n> Allows a JSON Forms to be saved in the task.\n\n#### Upload Json Forms Value Document\n\n> Allows you to upload a document to the referenced task and then include a reference to it in the task's JSON Forms.\n\n## Documentation\n\nMore detailed docs are available in the [documentation pages](https://docs.kuflow.com/developers/).\n\n## Contributing\n\nWe are happy to receive your help and comments, together we will dance a wonderful KuFlow. Please review our [contribution guide](CONTRIBUTING.md).\n\n## License\n\n[MIT License](https://github.com/kuflow/kuflow-sdk-python/blob/master/LICENSE)\n",
22
22
  'author': 'KuFlow S.L.',
@@ -1,458 +0,0 @@
1
- #
2
- # MIT License
3
- #
4
- # Copyright (c) 2022 KuFlow
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
23
- #
24
-
25
- import json
26
- import logging
27
- import os
28
- from typing import Optional, Union
29
- from uuid import UUID
30
-
31
- import magic
32
- from robot.api.deco import keyword
33
- from robot.utils import is_dict_like, is_list_like, is_number, is_string, type_name
34
-
35
- from kuflow_rest import KuBotTokenCredential, KuFlowRestClient, models
36
-
37
-
38
- class Keywords:
39
- def __init__(self) -> None:
40
- self.logger = logging.getLogger(__name__)
41
- self._client = None
42
-
43
- @keyword(tags=("settings",))
44
- def get_kuBot_token_credential(
45
- self,
46
- token: str,
47
- expires_on: int,
48
- ) -> KuBotTokenCredential:
49
- return KuBotTokenCredential(token, expires_on)
50
-
51
- @keyword(tags=("settings",))
52
- def set_client_authentication(
53
- self,
54
- client_id: Optional[str] = None,
55
- client_secret: Optional[str] = None,
56
- credential: Optional[KuBotTokenCredential] = None,
57
- endpoint: Optional[str] = None,
58
- allow_insecure_connection: Optional[bool] = None,
59
- ):
60
- """Configure the client authentication in order to execute keywords against Rest API.
61
-
62
- Before using any other KuFlow Keyword, this one must be called.
63
-
64
- Example:
65
- | Set Client Authentication | %{KUFLOW_CLIENT_ID} | %{KUFLOW_CLIENT_SECRET}
66
- | Set Client Authentication | %{KUFLOW_CLIENT_ID} | %{KUFLOW_CLIENT_SECRET} | %{KUFLOW_API_ENDPOINT}
67
- =>
68
- | Set Client Authentication | identifier | token
69
- | Set Client Authentication | identifier | token | https://api.kuflow.com/v1.0
70
- """
71
- if is_string(endpoint) and (endpoint.strip() == "" or endpoint.lower() == "none"):
72
- endpoint = None
73
-
74
- self._client = KuFlowRestClient(
75
- client_id=client_id,
76
- client_secret=client_secret,
77
- credential=credential,
78
- endpoint=endpoint,
79
- allow_insecure_connection=allow_insecure_connection,
80
- )
81
-
82
- @keyword(tags=("settings",))
83
- def get_client(self) -> KuFlowRestClient:
84
- return self._client
85
-
86
- @keyword(tags=("settings",))
87
- def get_instance(self) -> "Keywords":
88
- return self
89
-
90
- @keyword(tags=("settings",))
91
- def convert_to_dictionary_recursively(self, value: dict) -> dict:
92
- """Converts the given ``value`` to a Python ``dict`` type.
93
-
94
- Mainly useful for converting other mappings to normal dictionaries.
95
- This includes converting Robot Framework's own ``DotDict`` instances.
96
-
97
- Unlike the `Convert To Dictionary` keyword from Robotframework's Collections library,
98
- which only converts the first level of the dictionary using "Convert To Dictionary",
99
- this method performs nested conversion using Json's marshall and unmarshall.
100
- """
101
- return json.loads(json.dumps(value))
102
-
103
- @keyword()
104
- def append_log_message(self, task_id: UUID, message: str, level=models.LogLevel.INFO) -> models.Task:
105
- """Add a log entry to the task
106
-
107
- If the number of log entries is reached, the oldest log entry is removed.
108
- The level of log can be INFO, WARN or ERROR.
109
-
110
- Example:
111
- | Append Log Message | ${TASK_ID} | ${MESSAGE}
112
- | Append Log Message | ${TASK_ID} | ${MESSAGE} | level=${LEVEL}
113
- =>
114
- | Append Log Message | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | My info message
115
- | Append Log Message | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | My warning message | level=WARN
116
- """
117
- log = models.Log(message=message, level=level)
118
-
119
- return self._client.task.actions_task_append_log(task_id, log)
120
-
121
- @keyword()
122
- def claim_task(self, task_id: UUID) -> models.Task:
123
- """Allow to claim a task
124
-
125
- Example:
126
- | CLAIM TASK | ${TASK_ID}
127
- =>
128
- | CLAIM TASK | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec
129
- """
130
-
131
- return self._client.task.actions_task_claim(task_id)
132
-
133
- @keyword()
134
- def retrieve_process(self, process_id: UUID) -> models.Task:
135
- """Allow to get a process by ID.
136
-
137
- Example:
138
- | RETRIEVE PROCESS | ${PROCESS_ID}
139
- =>
140
- | RETRIEVE PROCESS | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec
141
- """
142
-
143
- return self._client.process.retrieve_process(process_id)
144
-
145
- @keyword()
146
- def retrieve_task(self, task_id: UUID) -> models.Task:
147
- """Allow to get a task by ID.
148
-
149
- Example:
150
- | RETRIEVE TASK | ${TASK_ID}
151
- =>
152
- | RETRIEVE TASK | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec
153
- """
154
-
155
- return self._client.task.retrieve_task(task_id)
156
-
157
- @keyword()
158
- def save_element_document(self, task_id: UUID, code: str, path: str, id: UUID = None, valid=True) -> models.Task:
159
- """Save a element of type document
160
-
161
- Allow to save an element document uploading the content.
162
-
163
- If it is a multiple element, and the documentId does not exist or is empty, the document will be added to
164
- the element.
165
- If the element already exists (the id referenced in the body corresponds to an existing one), it updates it.
166
-
167
- You also can optionally mark the document as invalid.
168
-
169
- Example:
170
- | Save Element Document | ${TASK_ID} | ${CODE} | ${PATH}
171
- =>
172
- | Save Element Document | ${TASK_ID} | ELEMENT_KEY | hello.jpg
173
- | Save Element Document | ${TASK_ID} | ELEMENT_KEY | hello.jpg | ${False}
174
- | Save Element Document | ${TASK_ID} | ELEMENT_KEY | hello.jpg | a05f197f-a50a-46d5-bdec-29a0c020f0d7
175
- | Save Element Document | ${TASK_ID} | ELEMENT_KEY | hello.jpg | a05f197f-a50a-46d5-bdec-29a0c020f0d7 | ${False}
176
- """
177
-
178
- file_name = os.path.basename(path)
179
- file = open(path, "rb")
180
- content_type = magic.from_file(path, mime=True)
181
-
182
- file = models.Document(
183
- file_mame=file_name,
184
- content_type=content_type,
185
- file_content=file,
186
- )
187
- command = models.TaskSaveElementValueDocumentCommand(
188
- element_definition_code=code, element_value_id=id, element_value_valid=valid
189
- )
190
-
191
- return self._client.task.actions_task_save_element_value_document(id=task_id, file=file, command=command)
192
-
193
- @keyword()
194
- def delete_element_document(self, task_id: UUID, id: UUID):
195
- """Delete an element document value
196
-
197
- Allow to delete a specific document from an element of document type using its Id.
198
-
199
- Note: If it is a multiple item, it will only delete the specified document. If it is a single element,
200
- in addition to the document, it will also delete the element.
201
-
202
- Example:
203
- | Delete Element Document | ${TASK_ID} | ${ID}
204
- =>
205
- | Delete Element Document | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | ac951e9f-c194-445b-9eec-4a800b25fb56
206
- """
207
-
208
- command = models.TaskDeleteElementValueDocumentCommand(document_id=str(id))
209
-
210
- self._client.task.actions_task_delete_element_value_document(id=task_id, command=command)
211
-
212
- @keyword()
213
- def save_element(self, task_id: UUID, code: str, *value, valid=True) -> models.Task:
214
- """Save a element
215
-
216
- Allow to save an element i.e., a field, a decision, a form, a principal or document.
217
-
218
- If values already exist for the provided element code, it replaces them with the new ones,
219
- otherwise it creates them.
220
- The values of the previous elements that no longer exist will be deleted.
221
- To remove an element, use the appropriate API method.
222
-
223
- Type of arguments in keywords and KuFlow elements:
224
- - String:
225
- By default, plain argument in keywords are of type String.
226
-
227
- - Number:
228
- You can use the built-in keywords 'Convert To Integer', 'Convert To Number' or others
229
- to pass a numeric type element.
230
-
231
- Object Elements (aka Forms Elements in KuFlow):
232
- You must pass an argument of type dictionary. You can use the built-in keyword
233
- Create Dictionary or others as utilities.
234
-
235
- Principal Elements:
236
- The keyword 'Convert To Element Value Principal Item' will allow you to create a Principal
237
- object that you can use as an argument.
238
-
239
- Document Elements:
240
- To save a document you need to pass a document reference using the 'id' attribute.
241
- To upload a new file, please use the 'Save Element Document' keyword.
242
- The keyword 'Convert To Element Value Document Item' will allow you to create a Principal
243
- object that you can use as an argument. The identifier of the documents follows the following
244
- format: ku:task/{taskId}/element-value/{elementValueId}
245
-
246
- Multivalues elements:
247
- For those elements that have been defined as multiple, you can pass a variable list
248
- of arguments to the keyword.
249
-
250
- Valid flag for elements:
251
- When saving an element, it is possible to specify if its value is valid or not,
252
- which allows it to be shown in the KuFlow UI as a validated element or not. To do this
253
- you must use the Valid=Boolean parameter. Note that in RobotFramework format the default
254
- type of parameters is String, so you must write Valid=${False}. By default, all items
255
- are valid when saved. Similarly, for multi-evaluated elements, the value of the "valid"
256
- parameter applies to all values.
257
-
258
- Example:
259
- | Save Element | ${TASK_ID} | ${CODE} | ${VALUE}
260
- | Save Element | ${TASK_ID} | ${CODE} | ${VALUE} | ${VALID}
261
- | Save Element | ${TASK_ID} | ${CODE} | ${VALUE_1} | ${VALUE_2} | ${VALUE_3}
262
- | Save Element | ${TASK_ID} | ${CODE} | ${VALUE_1} | ${VALUE_2} | ${VALUE_3} | ${VALID}
263
- =>
264
- | Save Element | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | ELEMENT_KEY | Value
265
- | Save Element | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | ELEMENT_KEY | Value | ${False}
266
- | Save Element | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | ELEMENT_KEY | Value 1 | Value 2 | Value 3 | ${False}
267
- |
268
- | ${result} = Convert To Integer 123
269
- | Save Element | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | ELEMENT_KEY | ${result}
270
- |
271
- | ${result_one} = Convert To Integer | 123
272
- | ${result_two} = Convert To Number | 123.123
273
- | Save Element | ${TASK_ID} | FIELD | ${result_one} | ${result_two}
274
- |
275
- | ${result} = Convert To Principal Item 7dd16e94-2dac-4fca-931e-c2505baa695c
276
- | Save Element | ${TASK_ID} | FIELD | ${result}
277
- |
278
- | &{result_one} = Create Dictionary | one_key=My Example Value One | two_key=2
279
- | &{result_two} = Create Dictionary | a_key=My Example Value A | b_key=B
280
- | Save Element | ${TASK_ID} | FIELD | ${result_one} | ${result_two}
281
- |
282
- | ${result} = Convert To Document Item From Uri
283
- | ... ku:task/acdca56f-b8aa-46c8-9055-8ee52810a4a9/element-value/a05f197f-a50a-46d5-bdec-29a0c020f0d7
284
- | Save Element | ${TASK_ID} | FIELD | ${result}
285
- """
286
- if not is_list_like(value):
287
- raise TypeError("Expected argument to be a list or list-like, " "got %s instead." % (type_name(value)))
288
-
289
- target = []
290
- for v in value:
291
- element = None
292
-
293
- if is_string(v):
294
- element = models.TaskElementValueString(value=v, valid=valid)
295
- elif is_number(v):
296
- element = models.TaskElementValueNumber(value=v, valid=valid)
297
- elif isinstance(v, models.TaskElementValuePrincipalItem):
298
- element = models.TaskElementValuePrincipal(value=v, valid=valid)
299
- elif isinstance(v, models.TaskElementValueDocumentItem):
300
- element = models.TaskElementValueDocument(value=v, valid=valid)
301
- elif is_dict_like(v):
302
- element = models.TaskElementValueObject(value=self.convert_to_dictionary_recursively(v), valid=valid)
303
- else:
304
- element = models.TaskElementValueString(value=v, valid=valid)
305
-
306
- target.append(element)
307
-
308
- command = models.TaskSaveElementCommand(element_definition_code=code, element_values=target)
309
-
310
- return self._client.task.actions_task_save_element(id=task_id, command=command)
311
-
312
- @keyword()
313
- def delete_element(self, task_id: UUID, code: str) -> models.Task:
314
- """Delete an element by code
315
-
316
- Allow to delete task element by specifying the item definition code.
317
-
318
- Remove all values of the selected element.
319
-
320
- Example:
321
- | Delete Element | ${TASK_ID} | ${CODE}
322
- =>
323
- | Delete Element | d9729dc3-10ee-4ed9-91ca-c10e6a6d13ec | ELEMENT_KEY
324
- """
325
-
326
- command = models.TaskDeleteElementCommand(element_definition_code=code)
327
-
328
- return self._client.task.actions_task_delete_element(id=task_id, command=command)
329
-
330
- @keyword()
331
- def convert_to_principal_item(
332
- self, id: UUID, type: Union[str, "models.PrincipalType"]
333
- ) -> models.TaskElementValuePrincipalItem:
334
- """Convert to element value principal item
335
-
336
- Given an id of a Principal, create an item that represents a reference to the Principal. Then can be used
337
- as a value in the keyword 'Save Element'. The principal ID can be obtained through some api methods such
338
- as "Find all accessible Principals" or implicitly in some resources such as the Initiator of a process
339
- or the Owner of a task.
340
-
341
- Example:
342
- | Convert To Principal Item | ${PRINCIPAL_ID} | ${PRINCIPAL_TYPE}
343
- =>
344
- | Convert To Principal Item | 7dd16e94-2dac-4fca-931e-c2505baa695c | USER
345
- """
346
-
347
- return models.TaskElementValuePrincipalItem(id=str(id), type=type)
348
-
349
- @keyword()
350
- def convert_to_document_item_from_uri(self, uri: str) -> models.TaskElementValueDocumentItem:
351
- """Convert to element value principal item
352
-
353
- Given an id of a Document or the Reference of a Document, create an item that represents a reference to the
354
- Document element and can be used. Then can be used as a value in the keyword 'Save Element'.
355
-
356
- Example:
357
- | Convert To Document Item From Uri | ${ID}
358
- | Convert To Document Item From Uri | ${ID} | ${DOCUMENT_URI}
359
- =>
360
- | Convert To Document Item From Uri
361
- | ... ku:task/acdca56f-b8aa-46c8-9055-8ee52810a4a9/element-value/a05f197f-a50a-46d5-bdec-29a0c020f0d7
362
- """
363
-
364
- return models.TaskElementValueDocumentItem(uri=uri)
365
-
366
- @keyword()
367
- def convert_json_string_to_object(self, json_string):
368
- """Convert JSON String To Object
369
-
370
- Given a JSON string as argument, return new JSON object
371
-
372
- Example:
373
- | ${json_object}= | Convert JSON String To Object | ${json_string} |
374
- =>
375
- | ${json_string}= catenate
376
- | ... {
377
- | ... "key1": "10",
378
- | ... "key2": {
379
- | ... "subkey1": "My value"
380
- | ... }
381
- | ... }
382
- | ${json_object}= | Convert JSON String To Object | ${json_string} |
383
- """
384
- return json.loads(json_string)
385
-
386
- @keyword()
387
- def save_json_forms_value_data(self, task_id: UUID, value) -> models.Task:
388
- """Save a JSON Forms value data
389
-
390
- Allows a JSON Forms to be saved in the task.
391
-
392
- If previous values already exist in the JSON Forms value, they are replaced by the new values.
393
-
394
- Server-side validations are applied on the saved JSON Forms according to the ones you defined in the schema
395
- in the task definition in KuFlow.
396
-
397
- Example:
398
- | Save Json Forms Value Data | ${KUFLOW_TASK_ID} | ${json_form_data}
399
- =>
400
- | &{json_form_data}= Create Dictionary key1=value1 keu2=value2
401
- | Save Json Forms Value Data | ${TASK_ID} | ${json_form_data}
402
- """
403
- if not is_dict_like(value):
404
- raise TypeError("Expected argument to be a dict or dict-like, " "got %s instead." % (type_name(value)))
405
-
406
- command = models.TaskSaveJsonFormsValueDataCommand(data=self.convert_to_dictionary_recursively(value))
407
-
408
- return self._client.task.actions_task_save_json_forms_value_data(id=task_id, command=command)
409
-
410
- @keyword()
411
- def upload_json_forms_value_document(self, task_id: UUID, path_in_schema: str, path: str) -> str:
412
- """Upload a JSON Forms value document
413
-
414
- Allows you to upload a document to the referenced task and then include a reference to it
415
- in the task's JSON Forms.
416
-
417
- You must provide the path within the JSON schema that defines the document you wish to upload.
418
- This schema is found in your task definition in KuFlow. For example, given this schema:
419
-
420
- {
421
- "type": "object",
422
- "properties": {
423
- "file": {
424
- "type": "string",
425
- "format": "kuflow-file",
426
- "accept": "image/*,application/pdf,.pdf",
427
- "maxSize": 20000000
428
- }
429
- }
430
- }
431
-
432
- The path is as follows: #/properties/file
433
-
434
- Note that in RobotFramework, the hash indicates a comment, so you should escape it
435
-
436
- Example:
437
- | Upload Json Forms Value document | ${KUFLOW_TASK_ID} | ${PATH_IN_SCHEMA} | ${PATH}
438
- =>
439
- | ${document_reference}=
440
- | ... Upload Json Forms Value document | ${KUFLOW_TASK_ID} | \\#/properties/file | hello.jpg
441
- | &{json_form_data}= Create Dictionary my_file=${document_reference}
442
- | Save Json Forms Value Data ${KUFLOW_TASK_ID} ${json_form_data}
443
- """
444
-
445
- file_name = os.path.basename(path)
446
- file = open(path, "rb")
447
- content_type = magic.from_file(path, mime=True)
448
-
449
- file = models.Document(
450
- file_mame=file_name,
451
- content_type=content_type,
452
- file_content=file,
453
- )
454
- command = models.TaskSaveJsonFormsValueDocumentRequestCommand(schema_path=path_in_schema)
455
-
456
- response = self._client.task.actions_task_save_json_forms_value_document(id=task_id, file=file, command=command)
457
-
458
- return response.value
@@ -1 +0,0 @@
1
- 1.5.1