sapiopycommons 2024.3.18a156__py3-none-any.whl → 2025.1.17a402__py3-none-any.whl

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.

Potentially problematic release.


This version of sapiopycommons might be problematic. Click here for more details.

Files changed (52) hide show
  1. sapiopycommons/callbacks/__init__.py +0 -0
  2. sapiopycommons/callbacks/callback_util.py +2041 -0
  3. sapiopycommons/callbacks/field_builder.py +545 -0
  4. sapiopycommons/chem/IndigoMolecules.py +52 -5
  5. sapiopycommons/chem/Molecules.py +114 -30
  6. sapiopycommons/customreport/__init__.py +0 -0
  7. sapiopycommons/customreport/column_builder.py +60 -0
  8. sapiopycommons/customreport/custom_report_builder.py +137 -0
  9. sapiopycommons/customreport/term_builder.py +315 -0
  10. sapiopycommons/datatype/attachment_util.py +17 -15
  11. sapiopycommons/datatype/data_fields.py +61 -0
  12. sapiopycommons/datatype/pseudo_data_types.py +440 -0
  13. sapiopycommons/eln/experiment_handler.py +390 -90
  14. sapiopycommons/eln/experiment_report_util.py +649 -0
  15. sapiopycommons/eln/plate_designer.py +152 -0
  16. sapiopycommons/files/complex_data_loader.py +31 -0
  17. sapiopycommons/files/file_bridge.py +153 -25
  18. sapiopycommons/files/file_bridge_handler.py +555 -0
  19. sapiopycommons/files/file_data_handler.py +633 -0
  20. sapiopycommons/files/file_util.py +270 -158
  21. sapiopycommons/files/file_validator.py +569 -0
  22. sapiopycommons/files/file_writer.py +377 -0
  23. sapiopycommons/flowcyto/flow_cyto.py +77 -0
  24. sapiopycommons/flowcyto/flowcyto_data.py +75 -0
  25. sapiopycommons/general/accession_service.py +375 -0
  26. sapiopycommons/general/aliases.py +259 -18
  27. sapiopycommons/general/audit_log.py +185 -0
  28. sapiopycommons/general/custom_report_util.py +252 -31
  29. sapiopycommons/general/directive_util.py +86 -0
  30. sapiopycommons/general/exceptions.py +69 -7
  31. sapiopycommons/general/popup_util.py +85 -18
  32. sapiopycommons/general/sapio_links.py +50 -0
  33. sapiopycommons/general/storage_util.py +148 -0
  34. sapiopycommons/general/time_util.py +97 -7
  35. sapiopycommons/multimodal/multimodal.py +146 -0
  36. sapiopycommons/multimodal/multimodal_data.py +490 -0
  37. sapiopycommons/processtracking/__init__.py +0 -0
  38. sapiopycommons/processtracking/custom_workflow_handler.py +406 -0
  39. sapiopycommons/processtracking/endpoints.py +192 -0
  40. sapiopycommons/recordmodel/record_handler.py +653 -149
  41. sapiopycommons/rules/eln_rule_handler.py +89 -8
  42. sapiopycommons/rules/on_save_rule_handler.py +89 -12
  43. sapiopycommons/sftpconnect/__init__.py +0 -0
  44. sapiopycommons/sftpconnect/sftp_builder.py +70 -0
  45. sapiopycommons/webhook/webhook_context.py +39 -0
  46. sapiopycommons/webhook/webhook_handlers.py +617 -69
  47. sapiopycommons/webhook/webservice_handlers.py +317 -0
  48. {sapiopycommons-2024.3.18a156.dist-info → sapiopycommons-2025.1.17a402.dist-info}/METADATA +5 -4
  49. sapiopycommons-2025.1.17a402.dist-info/RECORD +60 -0
  50. {sapiopycommons-2024.3.18a156.dist-info → sapiopycommons-2025.1.17a402.dist-info}/WHEEL +1 -1
  51. sapiopycommons-2024.3.18a156.dist-info/RECORD +0 -28
  52. {sapiopycommons-2024.3.18a156.dist-info → sapiopycommons-2025.1.17a402.dist-info}/licenses/LICENSE +0 -0
@@ -1,26 +1,88 @@
1
+ from enum import Enum
2
+
3
+
4
+ class MessageDisplayType(Enum):
5
+ """
6
+ An enum representing the different ways in which a message can be displayed to the user.
7
+ """
8
+ TOASTER_SUCCESS = 0
9
+ TOASTER_INFO = 1
10
+ TOASTER_WARNING = 2
11
+ TOASTER_ERROR = 3
12
+ OK_DIALOG = 4
13
+ DISPLAY_INFO = 5
14
+ DISPLAY_WARNING = 6
15
+ DISPLAY_ERROR = 7
16
+
17
+
1
18
  # FR-46064 - Initial port of PyWebhookUtils to sapiopycommons.
2
19
  class SapioException(Exception):
3
20
  """
4
21
  A generic exception thrown by sapiopycommons methods. Typically caused by programmer error, but may also be from
5
22
  extremely edge case user errors. For expected user errors, use SapioUserErrorException.
23
+
24
+ CommonsWebhookHandler's default behavior for this and any other exception that doesn't extend SapioException is
25
+ to return a generic toaster message saying that an unexpected error has occurred.
26
+ """
27
+ pass
28
+
29
+
30
+ class SapioUserCancelledException(SapioException):
31
+ """
32
+ An exception thrown when the user cancels a client callback.
33
+
34
+ CommonsWebhookHandler's default behavior is to simply end the webhook session with a true result without logging
35
+ the exception.
6
36
  """
7
37
  pass
8
38
 
9
39
 
10
- class SapioUserErrorException(SapioException):
40
+ class SapioDialogTimeoutException(SapioException):
41
+ """
42
+ An exception thrown when the user leaves a client callback open for too long.
43
+
44
+ CommonsWebhookHandler's default behavior is to display an OK popup notifying the user that the dialog has timed out.
45
+ """
46
+ pass
47
+
48
+
49
+ class DisplayableException(SapioException):
50
+ """
51
+ A generic exception that promises to return a user-friendly message explaining the error that should be displayed to
52
+ the user. Note that it is up to whichever class that catches this exception to actually display the message.
53
+ """
54
+ msg: str
55
+ display_type: MessageDisplayType | None
56
+ title: str | None
57
+
58
+ def __init__(self, msg: str, display_type: MessageDisplayType | None = None, title: str | None = None):
59
+ """
60
+ :param msg: The message that should be displayed to the user.
61
+ :param display_type: The manner in which the message should be displayed. If None, then the display type should
62
+ be controlled by the class that catches this exception.
63
+ :param title: If the display type is able to have a title, this is the title that will be displayed. If None,
64
+ then the title should be controlled by the class that catches this exception.
65
+ """
66
+ self.msg = msg
67
+ self.display_type = display_type
68
+ self.title = title
69
+
70
+
71
+ class SapioUserErrorException(DisplayableException):
11
72
  """
12
73
  An exception caused by user error (e.g. user provided a CSV when an XLSX was expected), which promises to return a
13
- user-friendly message explaining the error that should be displayed to the user. It is the responsibility of the
14
- programmer to catch any such exceptions and return the value in e.args[0] as text for the user to see (such as
15
- through the display text of a webhook result).
74
+ user-friendly message explaining the error that should be displayed to the user.
75
+
76
+ CommonsWebhookHandler's default behavior is to return the error message in a toaster popup.
16
77
  """
17
78
  pass
18
79
 
19
80
 
20
- class SapioCriticalErrorException(SapioException):
81
+ class SapioCriticalErrorException(DisplayableException):
21
82
  """
22
83
  A critical exception caused by user error, which promises to return a user-friendly message explaining the error
23
- that should be displayed to the user. It is the responsibility of the programmer to catch any such exceptions and
24
- return the value in e.args[0] as text for the user to see (such as through a dialog form client callback request).
84
+ that should be displayed to the user.
85
+
86
+ CommonsWebhookHandler's default behavior is to return the error message in a display_error callback.
25
87
  """
26
88
  pass
@@ -1,4 +1,4 @@
1
- from typing import Any
1
+ import warnings
2
2
 
3
3
  from sapiopylib.rest.DataMgmtService import DataMgmtServer
4
4
  from sapiopylib.rest.pojo.datatype.DataType import DataTypeDefinition
@@ -10,7 +10,7 @@ from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
10
10
  from sapiopylib.rest.pojo.webhook.WebhookResult import SapioWebhookResult
11
11
  from sapiopylib.rest.utils.FormBuilder import FormBuilder
12
12
 
13
- from sapiopycommons.general.aliases import SapioRecord, AliasUtil
13
+ from sapiopycommons.general.aliases import SapioRecord, AliasUtil, FieldMap
14
14
  from sapiopycommons.general.exceptions import SapioException
15
15
 
16
16
 
@@ -19,19 +19,25 @@ from sapiopycommons.general.exceptions import SapioException
19
19
  # and one FormEntryDialogRequest methods.)
20
20
  # CR-46332 - For any functions that use temporary data types, set the data type name, display name, and plural display
21
21
  # name in the form builder.
22
+ # FR-46716 - Add comments noting that this class is deprecated in favor of CallbackUtil.
22
23
  class PopupUtil:
23
24
  """
25
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
26
+
24
27
  Methods for creating boilerplate SapioWebhookResults with client callback requests to create popup dialogs.
25
28
  """
26
29
  @staticmethod
27
- def form_popup(title: str, msg: str, fields: list[AbstractVeloxFieldDefinition], values: dict[str, Any] = None,
30
+ def form_popup(title: str, msg: str, fields: list[AbstractVeloxFieldDefinition], values: FieldMap = None,
28
31
  column_positions: dict[str, tuple[int, int]] = None, data_type: str = "Default",
29
32
  *, display_name: str | None = None, plural_display_name: str | None = None,
30
33
  request_context: str | None = None) -> SapioWebhookResult:
31
34
  """
35
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
36
+
32
37
  Create a basic form entry dialog.
33
38
 
34
39
  The calling webhook must catch the FormEntryDialogResult that the client will send back.
40
+
35
41
  :param title: The title of the dialog.
36
42
  :param msg: The message to display at the top of the form.
37
43
  :param fields: The definitions of the fields to display in the form. Fields will be displayed in the order they
@@ -43,10 +49,11 @@ class PopupUtil:
43
49
  :param display_name: The display name for the temporary data type. If not provided, defaults to the data type
44
50
  name.
45
51
  :param plural_display_name: The plural display name for the temporary data type. If not provided, defaults to
46
- the plural display name + "s".
52
+ the display name + "s".
47
53
  :param request_context: Context that will be returned to the webhook server in the client callback result.
48
54
  :return: A SapioWebhookResult with the popup as its client callback request.
49
55
  """
56
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
50
57
  if display_name is None:
51
58
  display_name = data_type
52
59
  if plural_display_name is None:
@@ -73,11 +80,14 @@ class PopupUtil:
73
80
  column_positions: dict[str, tuple[int, int]] = None, editable: bool | None = True,
74
81
  *, request_context: str | None = None) -> SapioWebhookResult:
75
82
  """
83
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
84
+
76
85
  Create a basic form dialog for a record with displayed fields from the record data type.
77
86
 
78
87
  Makes webservice calls to get the data field and type definitions of the given data type.
79
88
  The calling webhook must catch the FormEntryDialogResult that the client will send back.
80
- :param context: The current webhook context
89
+
90
+ :param context: The current webhook context.
81
91
  :param title: The title of the dialog.
82
92
  :param msg: The message to display in the dialog.
83
93
  :param fields: The data field names of the fields from the record to display in the form. Fields will be
@@ -90,6 +100,7 @@ class PopupUtil:
90
100
  :param request_context: Context that will be returned to the webhook server in the client callback result.
91
101
  :return: A SapioWebhookResult with the popup as its client callback request.
92
102
  """
103
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
93
104
  # Get the field definitions of the data type.
94
105
  data_type: str = record.data_type_name
95
106
  type_man = DataMgmtServer.get_data_type_manager(context.user)
@@ -121,15 +132,18 @@ class PopupUtil:
121
132
  return SapioWebhookResult(True, client_callback_request=callback)
122
133
 
123
134
  @staticmethod
124
- def string_field_popup(title: str, msg: str, field_name: str, default_value: str | None,
135
+ def string_field_popup(title: str, msg: str, field_name: str, default_value: str | None = None,
125
136
  max_length: int | None = None, editable: bool = True, data_type: str = "Default",
126
137
  *, display_name: str | None = None, plural_display_name: str | None = None,
127
138
  request_context: str | None = None, **kwargs) -> SapioWebhookResult:
128
139
  """
140
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
141
+
129
142
  Create a form dialog with a single string field. May take additional parameters to be passed to the string field
130
143
  definition.
131
144
 
132
145
  The calling webhook must catch the FormEntryDialogResult that the client will send back.
146
+
133
147
  :param title: The title of the dialog.
134
148
  :param msg: The message to display in the dialog.
135
149
  :param field_name: The name and display name of the string field.
@@ -141,10 +155,11 @@ class PopupUtil:
141
155
  :param display_name: The display name for the temporary data type. If not provided, defaults to the data type
142
156
  name.
143
157
  :param plural_display_name: The plural display name for the temporary data type. If not provided, defaults to
144
- the plural display name + "s".
158
+ the display name + "s".
145
159
  :param request_context: Context that will be returned to the webhook server in the client callback result.
146
160
  :return: A SapioWebhookResult with the popup as its client callback request.
147
161
  """
162
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
148
163
  if max_length is None:
149
164
  max_length = len(default_value) if default_value else 100
150
165
  string_field = VeloxStringFieldDefinition(data_type, field_name, field_name, default_value=default_value,
@@ -154,14 +169,17 @@ class PopupUtil:
154
169
 
155
170
  @staticmethod
156
171
  def integer_field_popup(title: str, msg: str, field_name: str, default_value: int = None, min_value: int = -10000,
157
- max_value: int = 10000, data_type: str = "Default",
172
+ max_value: int = 10000, data_type: str = "Default", editable: bool = True,
158
173
  *, display_name: str | None = None, plural_display_name: str | None = None,
159
174
  request_context: str | None = None, **kwargs) -> SapioWebhookResult:
160
175
  """
176
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
177
+
161
178
  Create a form dialog with a single integer field. May take additional parameters to be passed to the integer
162
179
  field definition.
163
180
 
164
181
  The calling webhook must catch the FormEntryDialogResult that the client will send back.
182
+
165
183
  :param title: The title of the dialog.
166
184
  :param msg: The message to display in the dialog.
167
185
  :param field_name: The name and display name of the integer field.
@@ -170,31 +188,37 @@ class PopupUtil:
170
188
  :param min_value: The minimum allowed value of the input.
171
189
  :param max_value: The maximum allowed value of the input.
172
190
  :param data_type: The data type name for the temporary data type that will be created for this form.
191
+ :param editable: Whether the user may edit the contents of the integer field.
173
192
  :param display_name: The display name for the temporary data type. If not provided, defaults to the data type
174
193
  name.
175
194
  :param plural_display_name: The plural display name for the temporary data type. If not provided, defaults to
176
- the plural display name + "s".
195
+ the display name + "s".
177
196
  :param request_context: Context that will be returned to the webhook server in the client callback result.
178
197
  :return: A SapioWebhookResult with the popup as its client callback request.
179
198
  """
199
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
180
200
  if default_value is None:
181
201
  default_value = max(0, min_value)
182
202
  integer_field = VeloxIntegerFieldDefinition(data_type, field_name, field_name, default_value=default_value,
183
- min_value=min_value, max_value=max_value, **kwargs)
203
+ min_value=min_value, max_value=max_value, editable=editable,
204
+ **kwargs)
184
205
  return PopupUtil.form_popup(title, msg, [integer_field], data_type=data_type, display_name=display_name,
185
206
  plural_display_name=plural_display_name, request_context=request_context)
186
207
 
187
208
  @staticmethod
188
209
  def double_field_popup(title: str, msg: str, field_name: str, default_value: float = None,
189
210
  min_value: float = -10000000, max_value: float = 100000000,
190
- data_type: str = "Default", *, display_name: str | None = None,
211
+ data_type: str = "Default", editable: bool = True, *, display_name: str | None = None,
191
212
  plural_display_name: str | None = None, request_context: str | None = None, **kwargs) \
192
213
  -> SapioWebhookResult:
193
214
  """
215
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
216
+
194
217
  Create a form dialog with a single double field. May take additional parameters to be passed to the double
195
218
  field definition.
196
219
 
197
220
  The calling webhook must catch the FormEntryDialogResult that the client will send back.
221
+
198
222
  :param title: The title of the dialog.
199
223
  :param msg: The message to display in the dialog.
200
224
  :param field_name: The name and display name of the double field.
@@ -203,28 +227,33 @@ class PopupUtil:
203
227
  :param min_value: The minimum allowed value of the input.
204
228
  :param max_value: The maximum allowed value of the input.
205
229
  :param data_type: The data type name for the temporary data type that will be created for this form.
230
+ :param editable: Whether the user may edit the contents of the double field.
206
231
  :param display_name: The display name for the temporary data type. If not provided, defaults to the data type
207
232
  name.
208
233
  :param plural_display_name: The plural display name for the temporary data type. If not provided, defaults to
209
- the plural display name + "s".
234
+ the display name + "s".
210
235
  :param request_context: Context that will be returned to the webhook server in the client callback result.
211
236
  :return: A SapioWebhookResult with the popup as its client callback request.
212
237
  """
238
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
213
239
  if default_value is None:
214
240
  default_value = min_value
215
241
  double_field = VeloxDoubleFieldDefinition(data_type, field_name, field_name, default_value=default_value,
216
- min_value=min_value, max_value=max_value, **kwargs)
242
+ min_value=min_value, max_value=max_value, editable=editable, **kwargs)
217
243
  return PopupUtil.form_popup(title, msg, [double_field], data_type=data_type, display_name=display_name,
218
244
  plural_display_name=plural_display_name, request_context=request_context)
219
245
 
220
246
  @staticmethod
221
- def table_popup(title: str, msg: str, fields: list[AbstractVeloxFieldDefinition], values: list[dict[str, Any]],
247
+ def table_popup(title: str, msg: str, fields: list[AbstractVeloxFieldDefinition], values: list[FieldMap],
222
248
  *, data_type: str = "Default", display_name: str | None = None,
223
249
  plural_display_name: str | None = None, request_context: str | None = None) -> SapioWebhookResult:
224
250
  """
251
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
252
+
225
253
  Create a basic table entry dialog.
226
254
 
227
- The calling webhook must catch the FormEntryDialogResult that the client will send back.
255
+ The calling webhook must catch the TableEntryDialogResult that the client will send back.
256
+
228
257
  :param title: The title of the dialog.
229
258
  :param msg: The message to display at the top of the form.
230
259
  :param fields: The definitions of the fields to display as table columns. Fields will be displayed in the order
@@ -234,10 +263,11 @@ class PopupUtil:
234
263
  :param display_name: The display name for the temporary data type. If not provided, defaults to the data type
235
264
  name.
236
265
  :param plural_display_name: The plural display name for the temporary data type. If not provided, defaults to
237
- the plural display name + "s".
266
+ the display name + "s".
238
267
  :param request_context: Context that will be returned to the webhook server in the client callback result.
239
268
  :return: A SapioWebhookResult with the popup as its client callback request.
240
269
  """
270
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
241
271
  if display_name is None:
242
272
  display_name = data_type
243
273
  if plural_display_name is None:
@@ -255,10 +285,13 @@ class PopupUtil:
255
285
  title: str, msg: str, fields: list[str], records: list[SapioRecord],
256
286
  editable: bool | None = True, *, request_context: str | None = None) -> SapioWebhookResult:
257
287
  """
288
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
289
+
258
290
  Create a table dialog for a list of record where the columns are specific fields from the record data type.
259
291
 
260
292
  Makes webservice calls to get the data field and type definitions of the given data type.
261
293
  The calling webhook must catch the TableEntryDialogResult that the client will send back.
294
+
262
295
  :param context: The current webhook context
263
296
  :param title: The title of the dialog.
264
297
  :param msg: The message to display in the dialog.
@@ -270,12 +303,15 @@ class PopupUtil:
270
303
  :param request_context: Context that will be returned to the webhook server in the client callback result.
271
304
  :return: A SapioWebhookResult with the popup as its client callback request.
272
305
  """
306
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
307
+ if not records:
308
+ raise SapioException("No records provided.")
273
309
  data_types: set[str] = {x.data_type_name for x in records}
274
310
  if len(data_types) > 1:
275
311
  raise SapioException("Multiple data type names encountered in records list for record table popup.")
276
312
  data_type: str = data_types.pop()
277
313
  # Get the field maps from the records.
278
- field_map_list: list[dict[str, Any]] = AliasUtil.to_field_map_lists(records)
314
+ field_map_list: list[FieldMap] = AliasUtil.to_field_map_lists(records)
279
315
  # Get the field definitions of the data type.
280
316
  type_man = DataMgmtServer.get_data_type_manager(context.user)
281
317
  type_def: DataTypeDefinition = type_man.get_data_type_definition(data_type)
@@ -305,11 +341,14 @@ class PopupUtil:
305
341
  msg: str, fields: list[str], records: list[SapioRecord], multi_select: bool = True,
306
342
  *, request_context: str | None = None) -> SapioWebhookResult:
307
343
  """
344
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
345
+
308
346
  Create a record selection dialog for a list of record where the columns are specific fields from the record data
309
347
  type.
310
348
 
311
349
  Makes webservice calls to get the data field and type definitions of the given data type.
312
350
  The calling webhook must catch the DataRecordSelectionResult that the client will send back.
351
+
313
352
  :param context: The current webhook context
314
353
  :param msg: The message to display in the dialog.
315
354
  :param records: The records to display as rows in the table.
@@ -319,12 +358,15 @@ class PopupUtil:
319
358
  :param request_context: Context that will be returned to the webhook server in the client callback result.
320
359
  :return: A SapioWebhookResult with the popup as its client callback request.
321
360
  """
361
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
362
+ if not records:
363
+ raise SapioException("No records provided.")
322
364
  data_types: set[str] = {x.data_type_name for x in records}
323
365
  if len(data_types) > 1:
324
366
  raise SapioException("Multiple data type names encountered in records list for record table popup.")
325
367
  data_type: str = data_types.pop()
326
368
  # Get the field maps from the records.
327
- field_map_list: list[dict[str, Any]] = AliasUtil.to_field_map_lists(records)
369
+ field_map_list: list[FieldMap] = AliasUtil.to_field_map_lists(records)
328
370
  # Get the field definitions of the data type.
329
371
  type_man = DataMgmtServer.get_data_type_manager(context.user)
330
372
  type_def: DataTypeDefinition = type_man.get_data_type_definition(data_type)
@@ -351,15 +393,19 @@ class PopupUtil:
351
393
  def list_popup(title: str, options: list[str], multi_select: bool = False,
352
394
  *, request_context: str | None = None) -> SapioWebhookResult:
353
395
  """
396
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
397
+
354
398
  Create a list dialog with the given options for the user to choose from.
355
399
 
356
400
  The calling webhook must catch the ListDialogResult that the client will send back.
401
+
357
402
  :param title: The title of the dialog.
358
403
  :param options: The list options that the user has to choose from.
359
404
  :param multi_select: Whether the user is able to select multiple options from the list.
360
405
  :param request_context: Context that will be returned to the webhook server in the client callback result.
361
406
  :return: A SapioWebhookResult with the popup as its client callback request.
362
407
  """
408
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
363
409
  callback = ListDialogRequest(title, multi_select, options,
364
410
  callback_context_data=request_context)
365
411
  return SapioWebhookResult(True, client_callback_request=callback)
@@ -368,9 +414,12 @@ class PopupUtil:
368
414
  def option_popup(title: str, msg: str, options: list[str], default_option: int = 0, user_can_cancel: bool = False,
369
415
  *, request_context: str | None = None) -> SapioWebhookResult:
370
416
  """
417
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
418
+
371
419
  Create an option dialog with the given options for the user to choose from.
372
420
 
373
421
  The calling webhook must catch the OptionDialogResult that the client will send back.
422
+
374
423
  :param title: The title of the dialog.
375
424
  :param msg: The message to display in the dialog.
376
425
  :param options: The button options that the user has to choose from.
@@ -381,6 +430,7 @@ class PopupUtil:
381
430
  :param request_context: Context that will be returned to the webhook server in the client callback result.
382
431
  :return: A SapioWebhookResult with the popup as its client callback request.
383
432
  """
433
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
384
434
  callback = OptionDialogRequest(title, msg, options, default_option, user_can_cancel,
385
435
  callback_context_data=request_context)
386
436
  return SapioWebhookResult(True, client_callback_request=callback)
@@ -389,9 +439,12 @@ class PopupUtil:
389
439
  def ok_popup(title: str, msg: str, user_can_cancel: bool = False, *, request_context: str | None = None) \
390
440
  -> SapioWebhookResult:
391
441
  """
442
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
443
+
392
444
  Create an option dialog where the only option is "OK".
393
445
 
394
446
  The calling webhook must catch the OptionDialogResult that the client will send back.
447
+
395
448
  :param title: The title of the dialog.
396
449
  :param msg: The message to display in the dialog.
397
450
  :param user_can_cancel: True if the user is able to click the X to close the dialog, returning
@@ -400,15 +453,19 @@ class PopupUtil:
400
453
  :param request_context: Context that will be returned to the webhook server in the client callback result.
401
454
  :return: A SapioWebhookResult with the popup as its client callback request.
402
455
  """
456
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
403
457
  return PopupUtil.option_popup(title, msg, ["OK"], 0, user_can_cancel, request_context=request_context)
404
458
 
405
459
  @staticmethod
406
460
  def yes_no_popup(title: str, msg: str, default_yes: bool = True, user_can_cancel: bool = False,
407
461
  *, request_context: str | None = None) -> SapioWebhookResult:
408
462
  """
463
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
464
+
409
465
  Create an option dialog where the only options are "Yes" and "No".
410
466
 
411
467
  The calling webhook must catch the OptionDialogResult that the client will send back.
468
+
412
469
  :param title: The title of the dialog.
413
470
  :param msg: The message to display in the dialog.
414
471
  :param default_yes: If true, "Yes" is the default choice. Otherwise, the default choice is "No".
@@ -418,6 +475,7 @@ class PopupUtil:
418
475
  :param request_context: Context that will be returned to the webhook server in the client callback result.
419
476
  :return: A SapioWebhookResult with the popup as its client callback request.
420
477
  """
478
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
421
479
  return PopupUtil.option_popup(title, msg, ["Yes", "No"], 0 if default_yes else 1, user_can_cancel,
422
480
  request_context=request_context)
423
481
 
@@ -426,8 +484,11 @@ class PopupUtil:
426
484
  def display_form_popup(title: str, field_name: str, msg: str, data_type: str = "Popup",
427
485
  request_context: str | None = None) -> SapioWebhookResult:
428
486
  """
487
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
488
+
429
489
  Deprecated for PopupUtil.text_field_popup.
430
490
  """
491
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
431
492
  return PopupUtil.string_field_popup(title, "", field_name, msg, len(msg), False, data_type,
432
493
  request_context=request_context, auto_size=True)
433
494
 
@@ -435,13 +496,19 @@ class PopupUtil:
435
496
  def display_option_popup(title: str, msg: str, options: list[str], user_can_cancel: bool = False,
436
497
  request_context: str | None = None) -> SapioWebhookResult:
437
498
  """
499
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
500
+
438
501
  Deprecated for PopupUtil.option_popup.
439
502
  """
503
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
440
504
  return PopupUtil.option_popup(title, msg, options, 0, user_can_cancel, request_context=request_context)
441
505
 
442
506
  @staticmethod
443
507
  def display_ok_popup(title: str, msg: str, request_context: str | None = None) -> SapioWebhookResult:
444
508
  """
509
+ DEPRECATED: Make use of CallbackUtil as of 24.5.
510
+
445
511
  Deprecated for PopupUtil.ok_popup.
446
512
  """
513
+ warnings.warn("PopupUtil is deprecated as of 24.5+. Use CallbackUtil instead.", DeprecationWarning)
447
514
  return PopupUtil.ok_popup(title, msg, False, request_context=request_context)
@@ -0,0 +1,50 @@
1
+ from sapiopylib.rest.User import SapioUser
2
+ from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
3
+
4
+ from sapiopycommons.general.aliases import RecordIdentifier, ExperimentIdentifier, AliasUtil, DataTypeIdentifier
5
+ from sapiopycommons.general.exceptions import SapioException
6
+
7
+
8
+ class SapioNavigationLinker:
9
+ """
10
+ Given a URL to a system's webservice API (example: https://company.exemplareln.com/webservice/api), construct
11
+ URLs for navigation links to various locations in the system.
12
+ """
13
+ base_url: str
14
+
15
+ def __init__(self, url: str | SapioUser | SapioWebhookContext):
16
+ """
17
+ :param url: A user or context object that is being used to send requests to a Sapio system, or a URL to a
18
+ system's webservice API.
19
+ """
20
+ if isinstance(url, SapioWebhookContext):
21
+ url = url.user.url
22
+ elif isinstance(url, SapioUser):
23
+ url = url.url
24
+ self.base_url = url.rstrip("/").replace('webservice/api', 'veloxClient')
25
+
26
+ def data_record(self, record_identifier: RecordIdentifier, data_type_name: DataTypeIdentifier | None = None) -> str:
27
+ """
28
+ :param record_identifier: An object that can be used to identify a record in the system, be that a record ID,
29
+ a data record, or a record model.
30
+ :param data_type_name: If the provided record identifier is a record ID, then the data type name of the record
31
+ must be provided in this parameter. Otherwise, this parameter is ignored.
32
+ :return: A URL for navigating to the input record.
33
+ """
34
+ record_id: int = AliasUtil.to_record_id(record_identifier)
35
+ if data_type_name:
36
+ data_type_name = AliasUtil.to_data_type_name(data_type_name)
37
+ if not isinstance(record_identifier, int):
38
+ data_type_name = AliasUtil.to_data_type_name(record_identifier)
39
+ if not data_type_name:
40
+ raise SapioException("Unable to create a data record link without a data type name. "
41
+ "Only a record ID was provided.")
42
+ return self.base_url + f"/#dataType={data_type_name};recordId={record_id};view=dataRecord"
43
+
44
+ def experiment(self, experiment: ExperimentIdentifier) -> str:
45
+ """
46
+ :param experiment: An object that can be used to identify an experiment in the system, be that an experiment
47
+ object, experiment protocol, or a notebook ID.
48
+ :return: A URL for navigating to the input experiment.
49
+ """
50
+ return self.base_url + f"/#notebookExperimentId={AliasUtil.to_notebook_id(experiment)};view=eln"