sapiopycommons 2025.4.8a473__py3-none-any.whl → 2025.4.9a150__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.
- sapiopycommons/callbacks/callback_util.py +392 -1262
- sapiopycommons/callbacks/field_builder.py +0 -2
- sapiopycommons/chem/Molecules.py +2 -0
- sapiopycommons/customreport/term_builder.py +1 -1
- sapiopycommons/datatype/attachment_util.py +2 -4
- sapiopycommons/datatype/data_fields.py +1 -23
- sapiopycommons/eln/experiment_handler.py +279 -933
- sapiopycommons/eln/experiment_report_util.py +10 -15
- sapiopycommons/eln/plate_designer.py +59 -159
- sapiopycommons/files/file_bridge.py +0 -76
- sapiopycommons/files/file_bridge_handler.py +110 -325
- sapiopycommons/files/file_data_handler.py +2 -2
- sapiopycommons/files/file_util.py +15 -40
- sapiopycommons/files/file_validator.py +5 -6
- sapiopycommons/files/file_writer.py +1 -1
- sapiopycommons/flowcyto/flow_cyto.py +1 -1
- sapiopycommons/general/accession_service.py +3 -3
- sapiopycommons/general/aliases.py +28 -51
- sapiopycommons/general/audit_log.py +2 -2
- sapiopycommons/general/custom_report_util.py +1 -24
- sapiopycommons/general/exceptions.py +2 -41
- sapiopycommons/general/popup_util.py +2 -2
- sapiopycommons/multimodal/multimodal.py +0 -1
- sapiopycommons/processtracking/custom_workflow_handler.py +30 -46
- sapiopycommons/recordmodel/record_handler.py +159 -547
- sapiopycommons/rules/eln_rule_handler.py +30 -41
- sapiopycommons/rules/on_save_rule_handler.py +30 -41
- sapiopycommons/webhook/webhook_handlers.py +55 -448
- sapiopycommons/webhook/webservice_handlers.py +2 -2
- {sapiopycommons-2025.4.8a473.dist-info → sapiopycommons-2025.4.9a150.dist-info}/METADATA +1 -1
- sapiopycommons-2025.4.9a150.dist-info/RECORD +59 -0
- sapiopycommons/customreport/auto_pagers.py +0 -281
- sapiopycommons/eln/experiment_cache.py +0 -173
- sapiopycommons/eln/experiment_step_factory.py +0 -474
- sapiopycommons/eln/experiment_tags.py +0 -7
- sapiopycommons/eln/step_creation.py +0 -235
- sapiopycommons/general/data_structure_util.py +0 -115
- sapiopycommons/general/directive_util.py +0 -86
- sapiopycommons/samples/aliquot.py +0 -48
- sapiopycommons-2025.4.8a473.dist-info/RECORD +0 -67
- {sapiopycommons-2025.4.8a473.dist-info → sapiopycommons-2025.4.9a150.dist-info}/WHEEL +0 -0
- {sapiopycommons-2025.4.8a473.dist-info → sapiopycommons-2025.4.9a150.dist-info}/licenses/LICENSE +0 -0
|
@@ -3,13 +3,12 @@ from typing import Iterable
|
|
|
3
3
|
from sapiopylib.rest.User import SapioUser
|
|
4
4
|
from sapiopylib.rest.pojo.CustomReport import CustomReportCriteria
|
|
5
5
|
from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
|
|
6
|
-
from sapiopylib.rest.utils.recordmodel.PyRecordModel import PyRecordModel
|
|
7
6
|
from sapiopylib.rest.utils.recordmodel.RecordModelWrapper import WrappedType
|
|
8
7
|
|
|
9
|
-
from sapiopycommons.customreport.auto_pagers import CustomReportDictAutoPager, CustomReportRecordAutoPager
|
|
10
8
|
from sapiopycommons.customreport.custom_report_builder import CustomReportBuilder
|
|
11
9
|
from sapiopycommons.datatype.data_fields import ProcessQueueItemFields, SystemFields, ProcessWorkflowTrackingFields
|
|
12
10
|
from sapiopycommons.general.aliases import UserIdentifier, AliasUtil, SapioRecord
|
|
11
|
+
from sapiopycommons.general.custom_report_util import CustomReportUtil
|
|
13
12
|
from sapiopycommons.general.exceptions import SapioException
|
|
14
13
|
from sapiopycommons.general.time_util import TimeUtil
|
|
15
14
|
from sapiopycommons.recordmodel.record_handler import RecordHandler
|
|
@@ -105,28 +104,24 @@ class QueueItemHandler:
|
|
|
105
104
|
"""
|
|
106
105
|
self.user = AliasUtil.to_sapio_user(context)
|
|
107
106
|
self.rec_handler = RecordHandler(self.user)
|
|
108
|
-
|
|
109
|
-
if isinstance(context, SapioWebhookContext) and context.context_data:
|
|
107
|
+
if isinstance(context, SapioWebhookContext):
|
|
110
108
|
self.context = ProcessQueueContext(context)
|
|
111
109
|
else:
|
|
112
110
|
self.context = None
|
|
113
111
|
|
|
114
|
-
|
|
115
|
-
def get_process_queue_items_from_context(self, wrapper: type[WrappedType] | str,
|
|
112
|
+
def get_process_queue_items_from_context(self, wrapper: type[WrappedType],
|
|
116
113
|
context: SapioWebhookContext | ProcessQueueContext | None = None) \
|
|
117
|
-
-> list[WrappedType]
|
|
114
|
+
-> list[WrappedType]:
|
|
118
115
|
"""
|
|
119
116
|
When you launch records from a custom process queue, the process queue items related to the selected records
|
|
120
117
|
are provided as record IDs to the process queue context. Using these record IDs, query for the queue item
|
|
121
118
|
records and wrap them as record models.
|
|
122
119
|
|
|
123
|
-
:param wrapper: The record model wrapper
|
|
120
|
+
:param wrapper: The record model wrapper for the process queue items.
|
|
124
121
|
:param context: If this handler was not initialized with a context object, or you wish to retrieve
|
|
125
122
|
data from a different context object than the initializing context, then provide the context to retrieve the
|
|
126
123
|
record IDs from.
|
|
127
124
|
:return: The process queue items corresponding to the record IDs from the context wrapped as record models.
|
|
128
|
-
If a data type name was used instead of a model wrapper, then the returned records will be PyRecordModels
|
|
129
|
-
instead of WrappedRecordModels.
|
|
130
125
|
"""
|
|
131
126
|
if context is None and self.context is not None:
|
|
132
127
|
record_ids: list[int] = self.context.process_queue_item_record_ids
|
|
@@ -180,52 +175,46 @@ class QueueItemHandler:
|
|
|
180
175
|
ret_val[queue_item] = record
|
|
181
176
|
return ret_val
|
|
182
177
|
|
|
183
|
-
def get_queue_items_from_report(self, wrapper: type[WrappedType]
|
|
184
|
-
-> list[WrappedType]
|
|
178
|
+
def get_queue_items_from_report(self, wrapper: type[WrappedType], criteria: QueueItemReportCriteria) \
|
|
179
|
+
-> list[WrappedType]:
|
|
185
180
|
"""
|
|
186
181
|
Run a custom report that retrieves every queue item in the system for the given search criteria.
|
|
187
182
|
|
|
188
|
-
:param wrapper: The record model wrapper for the process queue items.
|
|
189
|
-
be PyRecordModels instead of WrappedRecordModels.
|
|
183
|
+
:param wrapper: The record model wrapper for the process queue items.
|
|
190
184
|
:param criteria: The search criteria to query for queue items with.
|
|
191
185
|
:return: A list of every queue item in the system that matches the search criteria.
|
|
192
186
|
"""
|
|
193
187
|
report = self.build_queue_item_report(criteria)
|
|
194
|
-
|
|
195
|
-
return CustomReportRecordAutoPager(self.user, report, dt).get_all_at_once()
|
|
188
|
+
return self.rec_handler.query_models_by_report(wrapper, report)
|
|
196
189
|
|
|
197
|
-
def get_records_from_item_report(self, wrapper: type[WrappedType]
|
|
198
|
-
criteria: QueueItemReportCriteria = QueueItemReportCriteria())
|
|
199
|
-
-> list[WrappedType] | list[PyRecordModel]:
|
|
190
|
+
def get_records_from_item_report(self, wrapper: type[WrappedType],
|
|
191
|
+
criteria: QueueItemReportCriteria = QueueItemReportCriteria()) -> list[WrappedType]:
|
|
200
192
|
"""
|
|
201
193
|
Run a custom report that retrieves for queue items that match the given search criteria, then query for the
|
|
202
194
|
data records that those queue items refer to.
|
|
203
195
|
|
|
204
|
-
:param wrapper: The record model wrapper
|
|
196
|
+
:param wrapper: The record model wrapper for the records being queried for.
|
|
205
197
|
:param criteria: Additional search criteria to filter the results. This function forces the data_type_names
|
|
206
198
|
parameter of the criteria to match the data type of the given record model wrapper.
|
|
207
199
|
:return: A list of all records related to the queue items in the system that match the search criteria.
|
|
208
|
-
If a data type name was used instead of a model wrapper, then the returned records will be PyRecordModels
|
|
209
|
-
instead of WrappedRecordModels.
|
|
210
200
|
"""
|
|
211
201
|
# Don't try to query for process queue items that don't match the data type of this wrapper.
|
|
212
|
-
criteria.data_type_names = [
|
|
202
|
+
criteria.data_type_names = [wrapper.get_wrapper_data_type_name()]
|
|
213
203
|
criteria.not_data_type_names = None
|
|
214
204
|
report = self.build_queue_item_report(criteria)
|
|
215
205
|
record_ids: list[int] = [x[ProcessQueueItemFields.DATA_RECORD_ID__FIELD.field_name]
|
|
216
|
-
for x in
|
|
206
|
+
for x in CustomReportUtil.run_custom_report(self.user, report)]
|
|
217
207
|
return self.rec_handler.query_models_by_id(wrapper, record_ids)
|
|
218
208
|
|
|
219
|
-
def get_queue_items_for_records(self, records: Iterable[SapioRecord], wrapper: type[WrappedType]
|
|
209
|
+
def get_queue_items_for_records(self, records: Iterable[SapioRecord], wrapper: type[WrappedType],
|
|
220
210
|
criteria: QueueItemReportCriteria = QueueItemReportCriteria()) \
|
|
221
|
-
-> dict[SapioRecord, list[WrappedType]
|
|
211
|
+
-> dict[SapioRecord, list[WrappedType]]:
|
|
222
212
|
"""
|
|
223
213
|
Given a list of records, query the system for every process queue item that refers to those records and matches
|
|
224
214
|
the provided search criteria.
|
|
225
215
|
|
|
226
216
|
:param records: The queued records to query for the process queue items of.
|
|
227
|
-
:param wrapper: The record model wrapper for the returned process queue item records.
|
|
228
|
-
returned records will be PyRecordModels instead of WrappedRecordModels.
|
|
217
|
+
:param wrapper: The record model wrapper for the returned process queue item records.
|
|
229
218
|
:param criteria: Additional search criteria to filter the results. This function forces the data_record_ids and
|
|
230
219
|
data_type_names parameters on the criteria to match the given records.
|
|
231
220
|
:return: A dictionary mapping the input records to a list of the process queue items that refer to them. If a
|
|
@@ -237,43 +226,40 @@ class QueueItemHandler:
|
|
|
237
226
|
criteria.not_data_record_ids = None
|
|
238
227
|
criteria.data_type_names = AliasUtil.to_data_type_names(records)
|
|
239
228
|
criteria.not_data_type_names = None
|
|
240
|
-
items: list[WrappedType]
|
|
229
|
+
items: list[WrappedType] = self.get_queue_items_from_report(wrapper, criteria)
|
|
241
230
|
return self.map_records_to_queue_items(records, items)
|
|
242
231
|
|
|
243
|
-
def get_records_for_queue_items(self, queue_items: Iterable[SapioRecord], wrapper: type[WrappedType]
|
|
244
|
-
-> dict[SapioRecord, WrappedType
|
|
232
|
+
def get_records_for_queue_items(self, queue_items: Iterable[SapioRecord], wrapper: type[WrappedType]) \
|
|
233
|
+
-> dict[SapioRecord, WrappedType]:
|
|
245
234
|
"""
|
|
246
235
|
Given a list of process queue items, query the system for the records that those queue items refer to.
|
|
247
236
|
|
|
248
237
|
:param queue_items: The process queue items to query for the referenced records of.
|
|
249
|
-
:param wrapper: The record model wrapper
|
|
250
|
-
:return: A dictionary mapping the input process queue items to the record tht they refer to.
|
|
251
|
-
name was used instead of a model wrapper, then the returned records will be PyRecordModels instead of
|
|
252
|
-
WrappedRecordModels.
|
|
238
|
+
:param wrapper: The record model wrapper for the records being queried.
|
|
239
|
+
:return: A dictionary mapping the input process queue items to the record tht they refer to.
|
|
253
240
|
"""
|
|
254
241
|
record_ids: set[int] = {x.get_field_value(ProcessQueueItemFields.DATA_RECORD_ID__FIELD) for x in queue_items}
|
|
255
|
-
records: list[WrappedType]
|
|
242
|
+
records: list[WrappedType] = self.rec_handler.query_models_by_id(wrapper, record_ids)
|
|
256
243
|
return self.map_queue_items_to_records(queue_items, records)
|
|
257
244
|
|
|
258
245
|
def queue_records_for_process(self, records: Iterable[SapioRecord], process: str, step: str,
|
|
259
|
-
wrapper: type[WrappedType]
|
|
246
|
+
wrapper: type[WrappedType]) -> dict[SapioRecord, WrappedType]:
|
|
260
247
|
"""
|
|
261
248
|
Given a list of records, create process queue item records for them at the provided process and step names.
|
|
262
249
|
You must store and commit using the record model manager in order for these changes to take effect.
|
|
263
250
|
|
|
264
251
|
:param records: The records to create process queue items for.
|
|
252
|
+
:param wrapper: The record model wrapper for the process queue items being created.
|
|
265
253
|
:param process: The name of the process to queue for.
|
|
266
254
|
:param step: The name of the step in the above process to queue for. This is the "Workflow Name" field of the
|
|
267
255
|
Process Workflow record corresponding to the step you want to assign these records to. For steps that
|
|
268
256
|
launch an experiment, this is the name of the template that will be launched. For the other types of custom
|
|
269
257
|
process steps, this is the "Workflow Name" as defined in the process manager config.
|
|
270
|
-
:param wrapper: The record model wrapper for the process queue items being created. If not provided, the
|
|
271
|
-
returned records will be PyRecordModels instead of WrappedRecordModels.
|
|
272
258
|
:return: A dictionary mapping each input record to the newly created process queue item for that record.
|
|
273
259
|
"""
|
|
274
260
|
ret_val: dict[SapioRecord, WrappedType] = {}
|
|
275
261
|
for record in records:
|
|
276
|
-
item = self.rec_handler.add_model(wrapper
|
|
262
|
+
item = self.rec_handler.add_model(wrapper)
|
|
277
263
|
item.set_field_values({
|
|
278
264
|
ProcessQueueItemFields.PROCESS_HEADER_NAME__FIELD.field_name: process,
|
|
279
265
|
ProcessQueueItemFields.WORKFLOW_HEADER_NAME__FIELD.field_name: step,
|
|
@@ -285,17 +271,16 @@ class QueueItemHandler:
|
|
|
285
271
|
ret_val[record] = item
|
|
286
272
|
return ret_val
|
|
287
273
|
|
|
288
|
-
def dequeue_records_for_process(self, records: Iterable[SapioRecord], wrapper: type[WrappedType]
|
|
274
|
+
def dequeue_records_for_process(self, records: Iterable[SapioRecord], wrapper: type[WrappedType],
|
|
289
275
|
criteria: QueueItemReportCriteria = QueueItemReportCriteria()) \
|
|
290
|
-
-> dict[SapioRecord, list[WrappedType]
|
|
276
|
+
-> dict[SapioRecord, list[WrappedType]]:
|
|
291
277
|
"""
|
|
292
278
|
Given a list of records, locate the process queue items that refer to them and that match the given search
|
|
293
279
|
criteria and remove them from the queue by setting the ShowInQueue field on the process queue items to false.
|
|
294
280
|
You must store and commit using the record model manager in order for these changes to take effect.
|
|
295
281
|
|
|
296
282
|
:param records: The records to remove from the queue.
|
|
297
|
-
:param wrapper: The record model wrapper for the process queue items being updated.
|
|
298
|
-
returned records will be PyRecordModels instead of WrappedRecordModels.
|
|
283
|
+
:param wrapper: The record model wrapper for the process queue items being updated.
|
|
299
284
|
:param criteria: Additional search criteria to filter the results. This function forces the show_in_queue
|
|
300
285
|
parameter on the criteria to True.
|
|
301
286
|
:return: A dictionary mapping each input record to the queue item records that refer to that record and were
|
|
@@ -304,8 +289,7 @@ class QueueItemHandler:
|
|
|
304
289
|
"""
|
|
305
290
|
# Only locate queue items that are currently visible in the queue.
|
|
306
291
|
criteria.shown_in_queue = True
|
|
307
|
-
dequeue: dict[SapioRecord, list[WrappedType]
|
|
308
|
-
dequeue = self.get_queue_items_for_records(records, wrapper, criteria)
|
|
292
|
+
dequeue: dict[SapioRecord, list[WrappedType]] = self.get_queue_items_for_records(records, wrapper, criteria)
|
|
309
293
|
for record, items in dequeue.items():
|
|
310
294
|
for item in items:
|
|
311
295
|
item.set_field_value(ProcessQueueItemFields.SHOW_IN_QUEUE__FIELD.field_name, False)
|