sapiopycommons 2024.10.25a345__py3-none-any.whl → 2024.10.30a348__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/field_builder.py +537 -0
- sapiopycommons/customreport/custom_report_builder.py +9 -4
- sapiopycommons/datatype/data_fields.py +61 -0
- sapiopycommons/eln/experiment_handler.py +13 -3
- sapiopycommons/eln/experiment_report_util.py +438 -30
- sapiopycommons/general/aliases.py +16 -9
- sapiopycommons/processtracking/custom_workflow_handler.py +406 -0
- sapiopycommons/webhook/webhook_context.py +39 -0
- {sapiopycommons-2024.10.25a345.dist-info → sapiopycommons-2024.10.30a348.dist-info}/METADATA +1 -1
- {sapiopycommons-2024.10.25a345.dist-info → sapiopycommons-2024.10.30a348.dist-info}/RECORD +12 -8
- {sapiopycommons-2024.10.25a345.dist-info → sapiopycommons-2024.10.30a348.dist-info}/WHEEL +0 -0
- {sapiopycommons-2024.10.25a345.dist-info → sapiopycommons-2024.10.30a348.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,6 +6,7 @@ from sapiopylib.rest.pojo.DataRecord import DataRecord
|
|
|
6
6
|
from sapiopylib.rest.pojo.datatype.FieldDefinition import FieldType
|
|
7
7
|
from sapiopylib.rest.pojo.eln.ElnExperiment import ElnExperiment
|
|
8
8
|
from sapiopylib.rest.pojo.eln.ExperimentEntry import ExperimentEntry
|
|
9
|
+
from sapiopylib.rest.pojo.eln.SapioELNEnums import ElnBaseDataType
|
|
9
10
|
from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
|
|
10
11
|
from sapiopylib.rest.utils.Protocols import ElnExperimentProtocol, ElnEntryStep
|
|
11
12
|
from sapiopylib.rest.utils.recordmodel.PyRecordModel import PyRecordModel
|
|
@@ -89,44 +90,50 @@ class AliasUtil:
|
|
|
89
90
|
return record if isinstance(record, int) else record.record_id
|
|
90
91
|
|
|
91
92
|
@staticmethod
|
|
92
|
-
def to_data_type_name(value: DataTypeIdentifier) -> str:
|
|
93
|
+
def to_data_type_name(value: DataTypeIdentifier, convert_eln_dts: bool = True) -> str:
|
|
93
94
|
"""
|
|
94
95
|
Convert a given value to a data type name.
|
|
95
96
|
|
|
96
97
|
:param value: A value which is a string, record, or record model type.
|
|
98
|
+
:param convert_eln_dts: If true, convert ELN data types to their base data type name.
|
|
97
99
|
:return: A string of the data type name of the input value.
|
|
98
100
|
"""
|
|
99
|
-
if isinstance(value, str):
|
|
100
|
-
return value
|
|
101
101
|
if isinstance(value, SapioRecord):
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
value = value.data_type_name
|
|
103
|
+
elif not isinstance(value, str):
|
|
104
|
+
value = value.get_wrapper_data_type_name()
|
|
105
|
+
if convert_eln_dts and ElnBaseDataType.is_eln_type(value):
|
|
106
|
+
return ElnBaseDataType.get_base_type(value).data_type_name
|
|
107
|
+
return value
|
|
104
108
|
|
|
105
109
|
@staticmethod
|
|
106
|
-
def to_data_type_names(values: Iterable[DataTypeIdentifier], return_set: bool = False
|
|
110
|
+
def to_data_type_names(values: Iterable[DataTypeIdentifier], return_set: bool = False,
|
|
111
|
+
convert_eln_dts: bool = True) -> list[str] | set[str]:
|
|
107
112
|
"""
|
|
108
113
|
Convert a given iterable of values to a list or set of data type names.
|
|
109
114
|
|
|
110
115
|
:param values: An iterable of values which are strings, records, or record model types.
|
|
111
116
|
:param return_set: If true, return a set instead of a list.
|
|
117
|
+
:param convert_eln_dts: If true, convert ELN data types to their base data type name.
|
|
112
118
|
:return: A list or set of strings of the data type name of the input value.
|
|
113
119
|
"""
|
|
114
|
-
values = [AliasUtil.to_data_type_name(x) for x in values]
|
|
120
|
+
values = [AliasUtil.to_data_type_name(x, convert_eln_dts) for x in values]
|
|
115
121
|
return set(values) if return_set else values
|
|
116
122
|
|
|
117
123
|
@staticmethod
|
|
118
|
-
def to_singular_data_type_name(values: Iterable[DataTypeIdentifier]) -> str:
|
|
124
|
+
def to_singular_data_type_name(values: Iterable[DataTypeIdentifier], convert_eln_dts: bool = True) -> str:
|
|
119
125
|
"""
|
|
120
126
|
Convert a given iterable of values to a singular data type name that they share. Throws an exception if more
|
|
121
127
|
than one data type name exists in the provided list of identifiers.
|
|
122
128
|
|
|
123
129
|
:param values: An iterable of values which are strings, records, or record model types.
|
|
130
|
+
:param convert_eln_dts: If true, convert ELN data types to their base data type name.
|
|
124
131
|
:return: The single data type name that the input vales share. Returns an empty string if an empty iterable
|
|
125
132
|
was provided.
|
|
126
133
|
"""
|
|
127
134
|
if not values:
|
|
128
135
|
return ""
|
|
129
|
-
data_types: set[str] = AliasUtil.to_data_type_names(values, True)
|
|
136
|
+
data_types: set[str] = AliasUtil.to_data_type_names(values, True, convert_eln_dts)
|
|
130
137
|
if len(data_types) > 1:
|
|
131
138
|
raise SapioException(f"Provided values contain multiple data types: {data_types}. "
|
|
132
139
|
f"Only expecting a single data type.")
|
|
@@ -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()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CustomWebhookContext(SapioWebhookContext):
|
|
8
|
+
"""
|
|
9
|
+
CustomWebhookContext is a wrapper for the default SapioWebhookContext to be used by custom invocation types to
|
|
10
|
+
convert the context_data that the server sends from a JSON string to usable parameters. This class works as a
|
|
11
|
+
middleman to cleanly convert a SapioWebhookContext object into a CustomWebhookContext by copying all the parameters
|
|
12
|
+
of the given context into the custom context.
|
|
13
|
+
"""
|
|
14
|
+
def __init__(self, context: SapioWebhookContext):
|
|
15
|
+
# Use __dict__ so that we don't need t maintain this class due to future changes to SapioWebhookContext.
|
|
16
|
+
self.__dict__ = context.__dict__
|
|
17
|
+
super().__init__(self.user, self.end_point_type)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ProcessQueueContext(CustomWebhookContext):
|
|
21
|
+
"""
|
|
22
|
+
When a custom process queue endpoint is invoked, the context from the queue is sent in a context_data parameter
|
|
23
|
+
on the SapioWebhookContext object, stored as a JSON string. This class parses that JSON into fields for the
|
|
24
|
+
caller to make use of.
|
|
25
|
+
"""
|
|
26
|
+
process_name: str
|
|
27
|
+
"""The name of the process that the user invoked this webhook from."""
|
|
28
|
+
step_name: str
|
|
29
|
+
"""The name of the step in the process that the user invoked this webhook from."""
|
|
30
|
+
process_queue_item_record_ids: list[int]
|
|
31
|
+
"""The record IDs of the process queue items related to the records that were selected by the user when this
|
|
32
|
+
webhook was invoked."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, context: SapioWebhookContext):
|
|
35
|
+
super().__init__(context)
|
|
36
|
+
context_data: dict[str, Any] = json.loads(self.context_data)
|
|
37
|
+
self.process_name = context_data["processName"]
|
|
38
|
+
self.step_name = context_data["workflowName"]
|
|
39
|
+
self.process_queue_item_record_ids = context_data["processQueueItemRecordIds"]
|
{sapiopycommons-2024.10.25a345.dist-info → sapiopycommons-2024.10.30a348.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: sapiopycommons
|
|
3
|
-
Version: 2024.10.
|
|
3
|
+
Version: 2024.10.30a348
|
|
4
4
|
Summary: Official Sapio Python API Utilities Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/sapiosciences
|
|
6
6
|
Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
sapiopycommons/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
sapiopycommons/callbacks/callback_util.py,sha256=nb6cXK8yFq96gtG0Z2NiK-qdNaRh88bavUH-ZoBjh18,67953
|
|
4
|
+
sapiopycommons/callbacks/field_builder.py,sha256=8n0jcbMgtMUHjie4C1-IkpAuHz4zBxbZtWpr4y0kABU,36868
|
|
4
5
|
sapiopycommons/chem/IndigoMolecules.py,sha256=3f-aig3AJkKJhRmhlQ0cI-5G8oeaQk_3foJTDZCvoko,2040
|
|
5
6
|
sapiopycommons/chem/Molecules.py,sha256=SQKnqdZnhYj_6HGtEZmE_1DormonRR1-nBAQ__z4gms,11485
|
|
6
7
|
sapiopycommons/chem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
8
|
sapiopycommons/customreport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
9
|
sapiopycommons/customreport/column_builder.py,sha256=0RO53e9rKPZ07C--KcepN6_tpRw_FxF3O9vdG0ilKG8,3014
|
|
9
|
-
sapiopycommons/customreport/custom_report_builder.py,sha256=
|
|
10
|
+
sapiopycommons/customreport/custom_report_builder.py,sha256=Lsy8DQryb7wC9RmEVVLQ6Q74JiNxU-ywFX-m5zL5CSk,6896
|
|
10
11
|
sapiopycommons/customreport/term_builder.py,sha256=oVsr7iFPnug2TrZUCcAMhyps-b62kDodPcBxyQeneUY,16763
|
|
11
12
|
sapiopycommons/datatype/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
13
|
sapiopycommons/datatype/attachment_util.py,sha256=_l2swuP8noIGAl4bwzBUEhr6YlN_OVZl3-gi1XqFHYA,3364
|
|
14
|
+
sapiopycommons/datatype/data_fields.py,sha256=g8Ib6LH8ikNu9AzeVJs8Z2qS8A-cplACeFU7vYguNEY,4063
|
|
13
15
|
sapiopycommons/datatype/pseudo_data_types.py,sha256=Fe75Rnq5evyeJM1nC0sLkLGKAC74g2-GEeTdMeId80o,27649
|
|
14
16
|
sapiopycommons/eln/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
sapiopycommons/eln/experiment_handler.py,sha256=
|
|
16
|
-
sapiopycommons/eln/experiment_report_util.py,sha256=
|
|
17
|
+
sapiopycommons/eln/experiment_handler.py,sha256=VJPBQSP_4QmhSGDCRDOb5neOjGM6sZ9krvJEmDkpVV8,69282
|
|
18
|
+
sapiopycommons/eln/experiment_report_util.py,sha256=9wWV6oEdKtfn2rI5V0BtmuW9OJlGFd9U07FIf889Gjw,37679
|
|
17
19
|
sapiopycommons/eln/plate_designer.py,sha256=FYJfhhNq8hdfuXgDYOYHy6g0m2zNwQXZWF_MTPzElDg,7184
|
|
18
20
|
sapiopycommons/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
21
|
sapiopycommons/files/complex_data_loader.py,sha256=T39veNhvYl6j_uZjIIJ8Mk5Aa7otR5RB-g8XlAdkksA,1421
|
|
@@ -27,7 +29,7 @@ sapiopycommons/flowcyto/flow_cyto.py,sha256=YlkKJR_zEHYRuNW0bnTqlTyZeXs0lOaeSCfG
|
|
|
27
29
|
sapiopycommons/flowcyto/flowcyto_data.py,sha256=mYKFuLbtpJ-EsQxLGtu4tNHVlygTxKixgJxJqD68F58,2596
|
|
28
30
|
sapiopycommons/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
31
|
sapiopycommons/general/accession_service.py,sha256=HYgyOsH_UaoRnoury-c2yTW8SeG4OtjLemdpCzoV4R8,13484
|
|
30
|
-
sapiopycommons/general/aliases.py,sha256=
|
|
32
|
+
sapiopycommons/general/aliases.py,sha256=tdDBNWSGx6s39eHJ3n2kscc4xxW3ZYaUfDftct6FmJE,12910
|
|
31
33
|
sapiopycommons/general/audit_log.py,sha256=KQI0AGgN9WLwKqnHE4Tm0xeBCfpVBf8rIQ2HFmnyFGI,8956
|
|
32
34
|
sapiopycommons/general/custom_report_util.py,sha256=BGu9Ki0wn3m4Nk-LKM6inDSfe8ULUSG9d-HJJNOTtGc,15653
|
|
33
35
|
sapiopycommons/general/exceptions.py,sha256=GY7fe0qOgoy4kQVn_Pn3tdzHsJZyNIpa6VCChg6tzuM,1813
|
|
@@ -38,6 +40,7 @@ sapiopycommons/general/time_util.py,sha256=jUAWmQLNcLHZa4UYB4ht_I3d6uoi63VxYdo7T
|
|
|
38
40
|
sapiopycommons/multimodal/multimodal.py,sha256=A1QsC8QTPmgZyPr7KtMbPRedn2Ie4WIErodUvQ9otgU,6724
|
|
39
41
|
sapiopycommons/multimodal/multimodal_data.py,sha256=t-0uY4cVgm88uXaSOL4ZeB6zmdHufowXuLFlMk61wFg,15087
|
|
40
42
|
sapiopycommons/processtracking/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
+
sapiopycommons/processtracking/custom_workflow_handler.py,sha256=0Si5RQ1YFmqmcZWV8jNDKTffix2iZnQJ6b97fn31pbc,23859
|
|
41
44
|
sapiopycommons/processtracking/endpoints.py,sha256=w5bziI2xC7450M95rCF8JpRwkoni1kEDibyAux9B12Q,10848
|
|
42
45
|
sapiopycommons/recordmodel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
46
|
sapiopycommons/recordmodel/record_handler.py,sha256=Uxjrq6f_cWFbqi7KRLySdOvmQGtbIBrCNyStRewqzx8,64751
|
|
@@ -47,9 +50,10 @@ sapiopycommons/rules/on_save_rule_handler.py,sha256=Rkqvph20RbNq6m-RF4fbvCP-YfD2
|
|
|
47
50
|
sapiopycommons/sftpconnect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
48
51
|
sapiopycommons/sftpconnect/sftp_builder.py,sha256=eKYMiyBc10DNTfbeidQUcfZgFTwhu5ZU-nNJMCK_eos,3014
|
|
49
52
|
sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
53
|
+
sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
|
|
50
54
|
sapiopycommons/webhook/webhook_handlers.py,sha256=JTquLBln49L1pJ9txJ4oc4Hpzy9kYtMKs0m4SLaFx78,18363
|
|
51
55
|
sapiopycommons/webhook/webservice_handlers.py,sha256=1J56zFI0pWl5MHoNTznvcZumITXgAHJMluj8-2BqYEw,3315
|
|
52
|
-
sapiopycommons-2024.10.
|
|
53
|
-
sapiopycommons-2024.10.
|
|
54
|
-
sapiopycommons-2024.10.
|
|
55
|
-
sapiopycommons-2024.10.
|
|
56
|
+
sapiopycommons-2024.10.30a348.dist-info/METADATA,sha256=U8UVQE9LmFPyIDkAZka9MQcyFTd7QGBqH7TSlyx2MKE,3177
|
|
57
|
+
sapiopycommons-2024.10.30a348.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
58
|
+
sapiopycommons-2024.10.30a348.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
|
|
59
|
+
sapiopycommons-2024.10.30a348.dist-info/RECORD,,
|
|
File without changes
|
{sapiopycommons-2024.10.25a345.dist-info → sapiopycommons-2024.10.30a348.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|