sapiopycommons 2024.11.11a364__py3-none-any.whl → 2024.11.18a366__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 (47) hide show
  1. sapiopycommons/callbacks/callback_util.py +532 -83
  2. sapiopycommons/callbacks/field_builder.py +537 -0
  3. sapiopycommons/chem/IndigoMolecules.py +2 -0
  4. sapiopycommons/chem/Molecules.py +77 -18
  5. sapiopycommons/customreport/__init__.py +0 -0
  6. sapiopycommons/customreport/column_builder.py +60 -0
  7. sapiopycommons/customreport/custom_report_builder.py +130 -0
  8. sapiopycommons/customreport/term_builder.py +299 -0
  9. sapiopycommons/datatype/attachment_util.py +11 -10
  10. sapiopycommons/datatype/data_fields.py +61 -0
  11. sapiopycommons/datatype/pseudo_data_types.py +440 -0
  12. sapiopycommons/eln/experiment_handler.py +272 -70
  13. sapiopycommons/eln/experiment_report_util.py +653 -0
  14. sapiopycommons/files/complex_data_loader.py +5 -4
  15. sapiopycommons/files/file_bridge.py +31 -24
  16. sapiopycommons/files/file_bridge_handler.py +340 -0
  17. sapiopycommons/files/file_data_handler.py +2 -5
  18. sapiopycommons/files/file_util.py +59 -9
  19. sapiopycommons/files/file_validator.py +92 -6
  20. sapiopycommons/files/file_writer.py +44 -15
  21. sapiopycommons/flowcyto/flow_cyto.py +77 -0
  22. sapiopycommons/flowcyto/flowcyto_data.py +75 -0
  23. sapiopycommons/general/accession_service.py +375 -0
  24. sapiopycommons/general/aliases.py +207 -6
  25. sapiopycommons/general/audit_log.py +189 -0
  26. sapiopycommons/general/custom_report_util.py +212 -37
  27. sapiopycommons/general/exceptions.py +21 -8
  28. sapiopycommons/general/popup_util.py +21 -0
  29. sapiopycommons/general/sapio_links.py +50 -0
  30. sapiopycommons/general/time_util.py +8 -2
  31. sapiopycommons/multimodal/multimodal.py +146 -0
  32. sapiopycommons/multimodal/multimodal_data.py +490 -0
  33. sapiopycommons/processtracking/custom_workflow_handler.py +406 -0
  34. sapiopycommons/processtracking/endpoints.py +22 -22
  35. sapiopycommons/recordmodel/record_handler.py +481 -97
  36. sapiopycommons/rules/eln_rule_handler.py +34 -25
  37. sapiopycommons/rules/on_save_rule_handler.py +34 -31
  38. sapiopycommons/sftpconnect/__init__.py +0 -0
  39. sapiopycommons/sftpconnect/sftp_builder.py +69 -0
  40. sapiopycommons/webhook/webhook_context.py +39 -0
  41. sapiopycommons/webhook/webhook_handlers.py +201 -42
  42. sapiopycommons/webhook/webservice_handlers.py +67 -0
  43. {sapiopycommons-2024.11.11a364.dist-info → sapiopycommons-2024.11.18a366.dist-info}/METADATA +5 -2
  44. sapiopycommons-2024.11.18a366.dist-info/RECORD +59 -0
  45. {sapiopycommons-2024.11.11a364.dist-info → sapiopycommons-2024.11.18a366.dist-info}/WHEEL +1 -1
  46. sapiopycommons-2024.11.11a364.dist-info/RECORD +0 -38
  47. {sapiopycommons-2024.11.11a364.dist-info → sapiopycommons-2024.11.18a366.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,406 @@
1
+ from typing import Iterable
2
+
3
+ from sapiopylib.rest.User import SapioUser
4
+ from sapiopylib.rest.pojo.CustomReport import CustomReportCriteria
5
+ from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
6
+ from sapiopylib.rest.utils.recordmodel.RecordModelWrapper import WrappedType
7
+
8
+ from sapiopycommons.customreport.custom_report_builder import CustomReportBuilder
9
+ from sapiopycommons.customreport.term_builder import TermBuilder
10
+ from sapiopycommons.datatype.data_fields import ProcessQueueItemFields, SystemFields, ProcessWorkflowTrackingFields
11
+ from sapiopycommons.general.aliases import UserIdentifier, AliasUtil, SapioRecord
12
+ from sapiopycommons.general.custom_report_util import CustomReportUtil
13
+ from sapiopycommons.general.exceptions import SapioException
14
+ from sapiopycommons.general.time_util import TimeUtil
15
+ from sapiopycommons.recordmodel.record_handler import RecordHandler
16
+ from sapiopycommons.webhook.webhook_context import ProcessQueueContext
17
+
18
+
19
+ class QueueItemReportCriteria:
20
+ """
21
+ Queue item report criteria is used to restrict the results of searches for queue item records.
22
+ """
23
+ process_names: list[str] | None
24
+ not_process_names: list[str] | None
25
+ step_names: list[str] | None
26
+ not_step_names: list[str] | None
27
+ data_type_names: list[str] | None
28
+ not_data_type_names: list[str] | None
29
+ data_record_ids: list[int] | None
30
+ not_data_record_ids: list[int] | None
31
+ assigned_to: list[str] | None
32
+ not_assigned_to: list[str] | None
33
+ launched_after: int | None
34
+ launched_before: int | None
35
+ scheduled_after: int | None
36
+ scheduled_before: int | None
37
+ shown_in_queue: bool | None
38
+ has_experiment: bool | None
39
+
40
+ def __init__(self, *,
41
+ process_names: list[str] | None = None,
42
+ not_process_names: list[str] | None = None,
43
+ step_names: list[str] | None = None,
44
+ not_step_names: list[str] | None = None,
45
+ data_type_names: list[str] | None = None,
46
+ not_data_type_names: list[str] | None = None,
47
+ data_record_ids: list[int] | None = None,
48
+ not_data_record_ids: list[int] | None = None,
49
+ assigned_to: list[str] | None = None,
50
+ not_assigned_to: list[str] | None = None,
51
+ launched_after: int | None = None,
52
+ launched_before: int | None = None,
53
+ scheduled_after: int | None = None,
54
+ scheduled_before: int | None = None,
55
+ shown_in_queue: bool | None = None,
56
+ has_experiment: bool | None = None):
57
+ """
58
+ :param process_names: The allowed process name(s).
59
+ :param not_process_names: The disallowed process name(s).
60
+ :param step_names: The allowed step name(s).
61
+ :param not_step_names: The disallowed step name(s).
62
+ :param data_type_names: The allowed data type name(s).
63
+ :param not_data_type_names: The disallowed dta type name(s).
64
+ :param data_record_ids: The allowed record ID(s).
65
+ :param not_data_record_ids: The disallowed record ID(s).
66
+ :param assigned_to: The allowed username(s) of the user(s) that the queue items are assigned to.
67
+ :param not_assigned_to: The disallowed username(s) of the user(s) that the queue items are assigned to.
68
+ :param launched_after: A timestamp after which the queue item was launched.
69
+ :param launched_before: A timestamp before which the queue item was launched.
70
+ :param scheduled_after: A timestamp after which the queue item was scheduled.
71
+ :param scheduled_before: A timestamp before which the queue item was scheduled.
72
+ :param shown_in_queue: Whether the queue item is currently being shown in a queue.
73
+ :param has_experiment: Whether the queue item is linked to an experiment record.
74
+ """
75
+ self.process_names = process_names
76
+ self.not_process_names = not_process_names
77
+ self.step_names = step_names
78
+ self.not_step_names = not_step_names
79
+ self.data_type_names = data_type_names
80
+ self.not_data_type_names = not_data_type_names
81
+ self.data_record_ids = data_record_ids
82
+ self.not_data_record_ids = not_data_record_ids
83
+ self.assigned_to = assigned_to
84
+ self.not_assigned_to = not_assigned_to
85
+ self.launched_after = launched_after
86
+ self.launched_before = launched_before
87
+ self.scheduled_after = scheduled_after
88
+ self.scheduled_before = scheduled_before
89
+ self.shown_in_queue = shown_in_queue
90
+ self.has_experiment = has_experiment
91
+
92
+
93
+ class QueueItemHandler:
94
+ """
95
+ A class used for handling the display of records in custom process queues, which are controlled in the system by
96
+ ProcessQueueItem data types.
97
+ """
98
+ user: SapioUser
99
+ context: ProcessQueueContext | None
100
+ rec_handler: RecordHandler
101
+
102
+ def __init__(self, context: UserIdentifier):
103
+ """
104
+ :param context: The current webhook context or a user object to send requests from.
105
+ """
106
+ self.user = AliasUtil.to_sapio_user(context)
107
+ self.rec_handler = RecordHandler(self.user)
108
+ if isinstance(context, SapioWebhookContext):
109
+ self.context = ProcessQueueContext(context)
110
+ else:
111
+ self.context = None
112
+
113
+ def get_process_queue_items_from_context(self, wrapper: type[WrappedType],
114
+ context: SapioWebhookContext | ProcessQueueContext | None = None) \
115
+ -> list[WrappedType]:
116
+ """
117
+ When you launch records from a custom process queue, the process queue items related to the selected records
118
+ are provided as record IDs to the process queue context. Using these record IDs, query for the queue item
119
+ records and wrap them as record models.
120
+
121
+ :param wrapper: The record model wrapper for the process queue items.
122
+ :param context: If this handler was not initialized with a context object, or you wish to retrieve
123
+ data from a different context object than the initializing context, then provide the context to retrieve the
124
+ record IDs from.
125
+ :return: The process queue items corresponding to the record IDs from the context wrapped as record models.
126
+ """
127
+ if context is None and self.context is not None:
128
+ record_ids: list[int] = self.context.process_queue_item_record_ids
129
+ elif context is not None:
130
+ if isinstance(context, SapioWebhookContext):
131
+ record_ids: list[int] = ProcessQueueContext(context).process_queue_item_record_ids
132
+ else:
133
+ record_ids: list[int] = context.process_queue_item_record_ids
134
+ else:
135
+ raise SapioException("A context object must be provided to this function call, as the handler "
136
+ "was not initialized with one.")
137
+ return self.rec_handler.query_models_by_id(wrapper, record_ids)
138
+
139
+ def map_records_to_queue_items(self, records: Iterable[SapioRecord], queue_items: Iterable[SapioRecord]) \
140
+ -> dict[SapioRecord, list[SapioRecord]]:
141
+ """
142
+ Given a list of records and a list of queue items, create a dictionary mapping the records to the queue items
143
+ that refer to them.
144
+
145
+ :param records: The records to map to the queue items.
146
+ :param queue_items: The queue items to map to the records.
147
+ :return: A dictionary of record to the queue items that refer to them. Input queue items that don't refer to
148
+ any provided records will not be in this dictionary.
149
+ """
150
+ ret_val: dict[SapioRecord, list[SapioRecord]] = {}
151
+ id_to_queue_items: dict[int, list[SapioRecord]] = self.rec_handler.map_by_field(queue_items,
152
+ ProcessQueueItemFields.DATA_RECORD_ID__FIELD)
153
+ id_to_record: dict[int, SapioRecord] = self.rec_handler.map_by_id(records)
154
+ for record_id, record in id_to_record.items():
155
+ ret_val[record] = id_to_queue_items[record_id]
156
+ return ret_val
157
+
158
+ def map_queue_items_to_records(self, queue_items: Iterable[SapioRecord], records: Iterable[SapioRecord]) \
159
+ -> dict[SapioRecord, SapioRecord]:
160
+ """
161
+ Given a list of queue items and a list of records, create a dictionary mapping the queue items to the record
162
+ that they refer to.
163
+
164
+ :param queue_items: The queue items to map to the records.
165
+ :param records: The records to map to the queue items.
166
+ :return: A dictionary of queue items to the records that the refer to. Input record that aren't referred to by
167
+ any provided queue items will not be in this dictionary.
168
+ """
169
+ ret_val: dict[SapioRecord, SapioRecord] = {}
170
+ id_to_queue_items: dict[int, list[SapioRecord]] = self.rec_handler.map_by_field(queue_items,
171
+ ProcessQueueItemFields.DATA_RECORD_ID__FIELD)
172
+ id_to_record: dict[int, SapioRecord] = self.rec_handler.map_by_id(records)
173
+ for record_id, queue_items in id_to_queue_items.items():
174
+ record: SapioRecord = id_to_record[record_id]
175
+ for queue_item in queue_items:
176
+ ret_val[queue_item] = record
177
+ return ret_val
178
+
179
+ def get_queue_items_from_report(self, wrapper: type[WrappedType], criteria: QueueItemReportCriteria) \
180
+ -> list[WrappedType]:
181
+ """
182
+ Run a custom report that retrieves every queue item in the system for the given search criteria.
183
+
184
+ :param wrapper: The record model wrapper for the process queue items.
185
+ :param criteria: The search criteria to query for queue items with.
186
+ :return: A list of every queue item in the system that matches the search criteria.
187
+ """
188
+ report = self.build_queue_item_report(criteria)
189
+ return self.rec_handler.query_models_by_report(wrapper, report)
190
+
191
+ def get_records_from_item_report(self, wrapper: type[WrappedType],
192
+ criteria: QueueItemReportCriteria = QueueItemReportCriteria()) -> list[WrappedType]:
193
+ """
194
+ Run a custom report that retrieves for queue items that match the given search criteria, then query for the
195
+ data records that those queue items refer to.
196
+
197
+ :param wrapper: The record model wrapper for the records being queried for.
198
+ :param criteria: Additional search criteria to filter the results. This function forces the data_type_names
199
+ parameter of the criteria to match the data type of the given record model wrapper.
200
+ :return: A list of all records related to the queue items in the system that match the search criteria.
201
+ """
202
+ # Don't try to query for process queue items that don't match the data type of this wrapper.
203
+ criteria.data_type_names = [wrapper.get_wrapper_data_type_name()]
204
+ criteria.not_data_type_names = None
205
+ report = self.build_queue_item_report(criteria)
206
+ record_ids: list[int] = [x[ProcessQueueItemFields.DATA_RECORD_ID__FIELD.field_name]
207
+ for x in CustomReportUtil.run_custom_report(self.user, report)]
208
+ return self.rec_handler.query_models_by_id(wrapper, record_ids)
209
+
210
+ def get_queue_items_for_records(self, records: Iterable[SapioRecord], wrapper: type[WrappedType],
211
+ criteria: QueueItemReportCriteria = QueueItemReportCriteria()) \
212
+ -> dict[SapioRecord, list[WrappedType]]:
213
+ """
214
+ Given a list of records, query the system for every process queue item that refers to those records and matches
215
+ the provided search criteria.
216
+
217
+ :param records: The queued records to query for the process queue items of.
218
+ :param wrapper: The record model wrapper for the returned process queue item records.
219
+ :param criteria: Additional search criteria to filter the results. This function forces the data_record_ids and
220
+ data_type_names parameters on the criteria to match the given records.
221
+ :return: A dictionary mapping the input records to a list of the process queue items that refer to them. If a
222
+ record does not have any queue items that refer to it that match the given search criteria, then it will
223
+ map to an empty list.
224
+ """
225
+ # Query for only those process queue items that have a record ID from the provided records.
226
+ criteria.data_record_ids = AliasUtil.to_record_ids(records)
227
+ criteria.not_data_record_ids = None
228
+ criteria.data_type_names = AliasUtil.to_data_type_names(records)
229
+ criteria.not_data_type_names = None
230
+ items: list[WrappedType] = self.get_queue_items_from_report(wrapper, criteria)
231
+ return self.map_records_to_queue_items(records, items)
232
+
233
+ def get_records_for_queue_items(self, queue_items: Iterable[SapioRecord], wrapper: type[WrappedType]) \
234
+ -> dict[SapioRecord, WrappedType]:
235
+ """
236
+ Given a list of process queue items, query the system for the records that those queue items refer to.
237
+
238
+ :param queue_items: The process queue items to query for the referenced records of.
239
+ :param wrapper: The record model wrapper for the records being queried.
240
+ :return: A dictionary mapping the input process queue items to the record tht they refer to.
241
+ """
242
+ record_ids: set[int] = {x.get_field_value(ProcessQueueItemFields.DATA_RECORD_ID__FIELD) for x in queue_items}
243
+ records: list[WrappedType] = self.rec_handler.query_models_by_id(wrapper, record_ids)
244
+ return self.map_queue_items_to_records(queue_items, records)
245
+
246
+ def queue_records_for_process(self, records: Iterable[SapioRecord], process: str, step: str,
247
+ wrapper: type[WrappedType]) -> dict[SapioRecord, WrappedType]:
248
+ """
249
+ Given a list of records, create process queue item records for them at the provided process and step names.
250
+ You must store and commit using the record model manager in order for these changes to take effect.
251
+
252
+ :param records: The records to create process queue items for.
253
+ :param wrapper: The record model wrapper for the process queue items being created.
254
+ :param process: The name of the process to queue for.
255
+ :param step: The name of the step in the above process to queue for. This is the "Workflow Name" field of the
256
+ Process Workflow record corresponding to the step you want to assign these records to. For steps that
257
+ launch an experiment, this is the name of the template that will be launched. For the other types of custom
258
+ process steps, this is the "Workflow Name" as defined in the process manager config.
259
+ :return: A dictionary mapping each input record to the newly created process queue item for that record.
260
+ """
261
+ ret_val: dict[SapioRecord, WrappedType] = {}
262
+ for record in records:
263
+ item = self.rec_handler.add_model(wrapper)
264
+ item.set_field_values({
265
+ ProcessQueueItemFields.PROCESS_HEADER_NAME__FIELD.field_name: process,
266
+ ProcessQueueItemFields.WORKFLOW_HEADER_NAME__FIELD.field_name: step,
267
+ ProcessQueueItemFields.SHOW_IN_QUEUE__FIELD.field_name: True,
268
+ ProcessQueueItemFields.SCHEDULED_DATE__FIELD.field_name: TimeUtil.now_in_millis(),
269
+ ProcessQueueItemFields.DATA_RECORD_ID__FIELD.field_name: AliasUtil.to_record_id(record),
270
+ ProcessQueueItemFields.DATA_TYPE_NAME__FIELD.field_name: AliasUtil.to_data_type_name(record)
271
+ })
272
+ ret_val[record] = item
273
+ return ret_val
274
+
275
+ def dequeue_records_for_process(self, records: Iterable[SapioRecord], wrapper: type[WrappedType],
276
+ criteria: QueueItemReportCriteria = QueueItemReportCriteria()) \
277
+ -> dict[SapioRecord, list[WrappedType]]:
278
+ """
279
+ Given a list of records, locate the process queue items that refer to them and that match the given search
280
+ criteria and remove them from the queue by setting the ShowInQueue field on the process queue items to false.
281
+ You must store and commit using the record model manager in order for these changes to take effect.
282
+
283
+ :param records: The records to remove from the queue.
284
+ :param wrapper: The record model wrapper for the process queue items being updated.
285
+ :param criteria: Additional search criteria to filter the results. This function forces the show_in_queue
286
+ parameter on the criteria to True.
287
+ :return: A dictionary mapping each input record to the queue item records that refer to that record and were
288
+ updated. If a record does not have any queue items that refer to it that match the given search criteria,
289
+ then it will map to an empty list.
290
+ """
291
+ # Only locate queue items that are currently visible in the queue.
292
+ criteria.shown_in_queue = True
293
+ dequeue: dict[SapioRecord, list[WrappedType]] = self.get_queue_items_for_records(records, wrapper, criteria)
294
+ for record, items in dequeue.items():
295
+ for item in items:
296
+ item.set_field_value(ProcessQueueItemFields.SHOW_IN_QUEUE__FIELD.field_name, False)
297
+ return dequeue
298
+
299
+ @staticmethod
300
+ def assigned_queue_items(queue_items: Iterable[SapioRecord], assign_to: list[str]) -> None:
301
+ """
302
+ Given a collection of queue items, assign them to a list of usernames or group names. Only those users in the
303
+ listed groups or those users with the matching username will be able to see these related records in the process
304
+ queue.
305
+ You must store and commit using the record model manager in order for these changes to take effect.
306
+
307
+ :param queue_items: The queue items to assign.
308
+ :param assign_to: A list of usernames and/or group names to assign these items to.
309
+ """
310
+ for item in queue_items:
311
+ item.set_field_value(ProcessQueueItemFields.ASSIGNED_TO__FIELD, ",".join(assign_to))
312
+
313
+ def get_queue_item_workflow_trackers(self, items: Iterable[SapioRecord], wrapper: type[WrappedType]) \
314
+ -> dict[SapioRecord, list[WrappedType]]:
315
+ """
316
+ When a queue item is launched into a process step, a ProcessWorkflowTracking record is created by the system
317
+ with a side link to the process queue item. This record records information about how long the record ws in
318
+ the queue, among other details.
319
+
320
+ Retrieve the workflow tracker records for the input queue items.
321
+
322
+ :param items: The queue items to load the workflow trackers of.
323
+ :param wrapper: The record model wrapper for the ProcessWorkflowTracking records.
324
+ :return: A dictionary mapping each queue item to the workflow trackers that side link to that item. If an input
325
+ queue item doesn't have any workflow trackers, then it will map to an empty list.
326
+ """
327
+ field: str = ProcessWorkflowTrackingFields.PROCESS_QUEUE_ITEM__FIELD.field_name
328
+ self.rec_handler.rel_man.load_reverse_side_links_of_type(list(items), wrapper, field)
329
+ return self.rec_handler.map_to_reverse_side_links(items, field, wrapper)
330
+
331
+ @staticmethod
332
+ def build_queue_item_report(criteria: QueueItemReportCriteria) -> CustomReportCriteria:
333
+ """
334
+ Construct a custom report using the provided QueueItemReportCriteria.
335
+
336
+ :param criteria: The criteria to construct a custom report from.
337
+ :return: A custom report that can be used to search for queue items that match the given criteria.
338
+ """
339
+ dt: str = ProcessQueueItemFields.DATA_TYPE_NAME
340
+ report_builder = CustomReportBuilder(dt)
341
+ report_builder.add_column(SystemFields.RECORD_ID__FIELD)
342
+ report_builder.add_column(ProcessQueueItemFields.DATA_RECORD_ID__FIELD)
343
+
344
+ root = TermBuilder.all_records_term(dt)
345
+
346
+ if criteria.process_names is not None:
347
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.PROCESS_HEADER_NAME__FIELD, criteria.process_names)
348
+ root = TermBuilder.and_terms(root, term)
349
+ if criteria.not_process_names is not None:
350
+ term = TermBuilder.not_term(dt, ProcessQueueItemFields.PROCESS_HEADER_NAME__FIELD, criteria.not_process_names)
351
+ root = TermBuilder.and_terms(root, term)
352
+
353
+ if criteria.step_names is not None:
354
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.WORKFLOW_HEADER_NAME__FIELD, criteria.step_names)
355
+ root = TermBuilder.and_terms(root, term)
356
+ if criteria.not_step_names is not None:
357
+ term = TermBuilder.not_term(dt, ProcessQueueItemFields.WORKFLOW_HEADER_NAME__FIELD, criteria.not_step_names)
358
+ root = TermBuilder.and_terms(root, term)
359
+
360
+ if criteria.data_type_names is not None:
361
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.DATA_TYPE_NAME__FIELD, criteria.data_type_names)
362
+ root = TermBuilder.and_terms(root, term)
363
+ if criteria.not_data_type_names is not None:
364
+ term = TermBuilder.not_term(dt, ProcessQueueItemFields.DATA_TYPE_NAME__FIELD, criteria.not_data_type_names)
365
+ root = TermBuilder.and_terms(root, term)
366
+
367
+ if criteria.data_record_ids is not None:
368
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.DATA_RECORD_ID__FIELD, criteria.data_record_ids)
369
+ root = TermBuilder.and_terms(root, term)
370
+ if criteria.not_data_record_ids is not None:
371
+ term = TermBuilder.not_term(dt, ProcessQueueItemFields.DATA_RECORD_ID__FIELD, criteria.not_data_record_ids)
372
+ root = TermBuilder.and_terms(root, term)
373
+
374
+ if criteria.assigned_to is not None:
375
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.ASSIGNED_TO__FIELD, criteria.assigned_to)
376
+ root = TermBuilder.and_terms(root, term)
377
+ if criteria.not_assigned_to is not None:
378
+ term = TermBuilder.not_term(dt, ProcessQueueItemFields.ASSIGNED_TO__FIELD, criteria.not_assigned_to)
379
+ root = TermBuilder.and_terms(root, term)
380
+
381
+ if criteria.launched_after is not None:
382
+ term = TermBuilder.gte_term(dt, ProcessQueueItemFields.LAUNCHED_DATE__FIELD, criteria.launched_after)
383
+ root = TermBuilder.and_terms(root, term)
384
+ if criteria.launched_before is not None:
385
+ term = TermBuilder.lte_term(dt, ProcessQueueItemFields.LAUNCHED_DATE__FIELD, criteria.launched_before)
386
+ root = TermBuilder.and_terms(root, term)
387
+
388
+ if criteria.scheduled_after is not None:
389
+ term = TermBuilder.gte_term(dt, ProcessQueueItemFields.LAUNCHED_DATE__FIELD, criteria.scheduled_after)
390
+ root = TermBuilder.and_terms(root, term)
391
+ if criteria.scheduled_before is not None:
392
+ term = TermBuilder.lte_term(dt, ProcessQueueItemFields.LAUNCHED_DATE__FIELD, criteria.scheduled_before)
393
+ root = TermBuilder.and_terms(root, term)
394
+
395
+ if criteria.shown_in_queue is not None:
396
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.SHOW_IN_QUEUE__FIELD, criteria.shown_in_queue)
397
+ root = TermBuilder.and_terms(root, term)
398
+ if criteria.has_experiment is not None:
399
+ if criteria.has_experiment:
400
+ term = TermBuilder.not_term(dt, ProcessQueueItemFields.EXPERIMENT__FIELD, None)
401
+ else:
402
+ term = TermBuilder.is_term(dt, ProcessQueueItemFields.EXPERIMENT__FIELD, None)
403
+ root = TermBuilder.and_terms(root, term)
404
+
405
+ report_builder.set_root_term(root)
406
+ return report_builder.build_report_criteria()
@@ -1,12 +1,12 @@
1
1
  from sapiopylib.rest.User import SapioUser
2
- from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
3
2
 
4
- from sapiopycommons.general.aliases import RecordIdentifier, AliasUtil, ExperimentIdentifier
3
+ from sapiopycommons.general.aliases import RecordIdentifier, AliasUtil, ExperimentIdentifier, DataTypeIdentifier, \
4
+ UserIdentifier
5
5
 
6
6
 
7
7
  class ProcessTracking:
8
8
  @staticmethod
9
- def assign_to_process(context: SapioWebhookContext | SapioUser, data_type: str, records: list[RecordIdentifier],
9
+ def assign_to_process(context: UserIdentifier, data_type: DataTypeIdentifier, records: list[RecordIdentifier],
10
10
  process_name: str, step_number: int | None = None, branch_id: int | None = None,
11
11
  request: RecordIdentifier | None = None) -> None:
12
12
  """
@@ -27,19 +27,19 @@ class ProcessTracking:
27
27
  """
28
28
  sub_path = '/ext/process-tracking/assign-to-process'
29
29
  payload = {
30
- "data-type-name": data_type,
30
+ "data-type-name": AliasUtil.to_data_type_name(data_type),
31
31
  "record-ids": AliasUtil.to_record_ids(records),
32
32
  "process-name": process_name,
33
33
  "step-number": step_number,
34
34
  "branch-id": branch_id,
35
35
  "request-record-id": AliasUtil.to_record_ids([request])[0] if request is not None else None
36
36
  }
37
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
37
+ user: SapioUser = AliasUtil.to_sapio_user(context)
38
38
  response = user.post(sub_path, payload=payload)
39
39
  user.raise_for_status(response)
40
40
 
41
41
  @staticmethod
42
- def begin_protocol(context: SapioWebhookContext | SapioUser, data_type: str, records: list[RecordIdentifier],
42
+ def begin_protocol(context: UserIdentifier, data_type: DataTypeIdentifier, records: list[RecordIdentifier],
43
43
  experiment: ExperimentIdentifier) -> None:
44
44
  """
45
45
  Begin the assigned processes of the given tracked records as the given experiment. This sets the status of the
@@ -54,16 +54,16 @@ class ProcessTracking:
54
54
  """
55
55
  sub_path = '/ext/process-tracking/begin-protocol'
56
56
  payload = {
57
- "data-type-name": data_type,
57
+ "data-type-name": AliasUtil.to_data_type_name(data_type),
58
58
  "record-ids": AliasUtil.to_record_ids(records),
59
59
  "experiment-id": AliasUtil.to_notebook_id(experiment),
60
60
  }
61
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
61
+ user: SapioUser = AliasUtil.to_sapio_user(context)
62
62
  response = user.post(sub_path, payload=payload)
63
63
  user.raise_for_status(response)
64
64
 
65
65
  @staticmethod
66
- def complete_protocol(context: SapioWebhookContext | SapioUser, data_type: str, records: list[RecordIdentifier],
66
+ def complete_protocol(context: UserIdentifier, data_type: DataTypeIdentifier, records: list[RecordIdentifier],
67
67
  experiment: ExperimentIdentifier) -> None:
68
68
  """
69
69
  Complete the current step that the given tracked records are at given the experiment.
@@ -80,16 +80,16 @@ class ProcessTracking:
80
80
  """
81
81
  sub_path = '/ext/process-tracking/complete-protocol'
82
82
  payload = {
83
- "data-type-name": data_type,
83
+ "data-type-name": AliasUtil.to_data_type_name(data_type),
84
84
  "record-ids": AliasUtil.to_record_ids(records),
85
85
  "experiment-id": AliasUtil.to_notebook_id(experiment),
86
86
  }
87
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
87
+ user: SapioUser = AliasUtil.to_sapio_user(context)
88
88
  response = user.post(sub_path, payload=payload)
89
89
  user.raise_for_status(response)
90
90
 
91
91
  @staticmethod
92
- def fail(context: SapioWebhookContext | SapioUser, data_type: str, records: list[RecordIdentifier],
92
+ def fail(context: UserIdentifier, data_type: DataTypeIdentifier, records: list[RecordIdentifier],
93
93
  experiment: ExperimentIdentifier) -> None:
94
94
  """
95
95
  Fail the assigned processes of the given tracked records, changing their statuses to "Failed -". The tracked
@@ -103,16 +103,16 @@ class ProcessTracking:
103
103
  """
104
104
  sub_path = '/ext/process-tracking/fail'
105
105
  payload = {
106
- "data-type-name": data_type,
106
+ "data-type-name": AliasUtil.to_data_type_name(data_type),
107
107
  "record-ids": AliasUtil.to_record_ids(records),
108
108
  "experiment-id": AliasUtil.to_notebook_id(experiment),
109
109
  }
110
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
110
+ user: SapioUser = AliasUtil.to_sapio_user(context)
111
111
  response = user.post(sub_path, payload=payload)
112
112
  user.raise_for_status(response)
113
113
 
114
114
  @staticmethod
115
- def promote_to_next_by_experiment(context: SapioWebhookContext | SapioUser, data_type: str,
115
+ def promote_to_next_by_experiment(context: UserIdentifier, data_type: DataTypeIdentifier,
116
116
  records: list[RecordIdentifier], experiment: ExperimentIdentifier) -> None:
117
117
  """
118
118
  Promote the status of the given tracked records to the next status in their process using an experiment.
@@ -129,16 +129,16 @@ class ProcessTracking:
129
129
  """
130
130
  sub_path = '/ext/process-tracking/promote-status-to-next'
131
131
  payload = {
132
- "data-type-name": data_type,
132
+ "data-type-name": AliasUtil.to_data_type_name(data_type),
133
133
  "record-ids": AliasUtil.to_record_ids(records),
134
134
  "experiment-id": AliasUtil.to_notebook_id(experiment),
135
135
  }
136
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
136
+ user: SapioUser = AliasUtil.to_sapio_user(context)
137
137
  response = user.post(sub_path, payload=payload)
138
138
  user.raise_for_status(response)
139
139
 
140
140
  @staticmethod
141
- def promote_to_next_by_step(context: SapioWebhookContext | SapioUser, data_type: str,
141
+ def promote_to_next_by_step(context: UserIdentifier, data_type: DataTypeIdentifier,
142
142
  records: list[RecordIdentifier], process_name: str, step_number: int,
143
143
  branch_id: int | None = None) -> None:
144
144
  """
@@ -159,7 +159,7 @@ class ProcessTracking:
159
159
  """
160
160
  sub_path = '/ext/process-tracking/promote-status-to-next'
161
161
  payload = {
162
- "data-type-name": data_type,
162
+ "data-type-name": AliasUtil.to_data_type_name(data_type),
163
163
  "record-ids": AliasUtil.to_record_ids(records),
164
164
  "current-process-status": {
165
165
  "process-name": process_name,
@@ -167,12 +167,12 @@ class ProcessTracking:
167
167
  "branch-id": branch_id
168
168
  }
169
169
  }
170
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
170
+ user: SapioUser = AliasUtil.to_sapio_user(context)
171
171
  response = user.post(sub_path, payload=payload)
172
172
  user.raise_for_status(response)
173
173
 
174
174
  @staticmethod
175
- def reprocess(context: SapioWebhookContext | SapioUser, records: list[RecordIdentifier]) -> None:
175
+ def reprocess(context: UserIdentifier, records: list[RecordIdentifier]) -> None:
176
176
  """
177
177
  Reprocess tracked records to a previous step in their process. Reprocessing is controlled by ReturnPoint records
178
178
  which are children of the AssignedProcess on the tracked records. Creates a new AssignedProcess record for the
@@ -187,6 +187,6 @@ class ProcessTracking:
187
187
  payload = {
188
188
  "record-ids": AliasUtil.to_record_ids(records)
189
189
  }
190
- user: SapioUser = context if isinstance(context, SapioUser) else context.user
190
+ user: SapioUser = AliasUtil.to_sapio_user(context)
191
191
  response = user.post(sub_path, payload=payload)
192
192
  user.raise_for_status(response)