sapiopycommons 2025.4.17a489__py3-none-any.whl → 2025.4.23a491__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 (51) hide show
  1. sapiopycommons/ai/__init__.py +0 -0
  2. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +123 -0
  3. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +598 -0
  4. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +24 -0
  5. sapiopycommons/ai/api/plan/proto/step_output_pb2.py +45 -0
  6. sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +42 -0
  7. sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +24 -0
  8. sapiopycommons/ai/api/plan/proto/step_pb2.py +43 -0
  9. sapiopycommons/ai/api/plan/proto/step_pb2.pyi +43 -0
  10. sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +24 -0
  11. sapiopycommons/ai/api/plan/script/proto/script_pb2.py +53 -0
  12. sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +99 -0
  13. sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +153 -0
  14. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +57 -0
  15. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +96 -0
  16. sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +24 -0
  17. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +73 -0
  18. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +242 -0
  19. sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +154 -0
  20. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +39 -0
  21. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +32 -0
  22. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +24 -0
  23. sapiopycommons/ai/tool_of_tools.py +917 -0
  24. sapiopycommons/ai/tool_service_base.py +271 -0
  25. sapiopycommons/callbacks/callback_util.py +64 -116
  26. sapiopycommons/callbacks/field_builder.py +0 -2
  27. sapiopycommons/customreport/auto_pagers.py +1 -2
  28. sapiopycommons/customreport/term_builder.py +1 -1
  29. sapiopycommons/datatype/pseudo_data_types.py +326 -349
  30. sapiopycommons/eln/experiment_handler.py +719 -336
  31. sapiopycommons/eln/plate_designer.py +2 -7
  32. sapiopycommons/files/file_util.py +4 -4
  33. sapiopycommons/general/accession_service.py +2 -2
  34. sapiopycommons/general/aliases.py +1 -4
  35. sapiopycommons/general/html_formatter.py +456 -0
  36. sapiopycommons/general/sapio_links.py +12 -4
  37. sapiopycommons/processtracking/custom_workflow_handler.py +1 -2
  38. sapiopycommons/recordmodel/record_handler.py +27 -357
  39. sapiopycommons/rules/eln_rule_handler.py +1 -8
  40. sapiopycommons/rules/on_save_rule_handler.py +1 -8
  41. sapiopycommons/webhook/webhook_handlers.py +0 -3
  42. sapiopycommons/webhook/webservice_handlers.py +2 -2
  43. {sapiopycommons-2025.4.17a489.dist-info → sapiopycommons-2025.4.23a491.dist-info}/METADATA +2 -2
  44. sapiopycommons-2025.4.23a491.dist-info/RECORD +88 -0
  45. sapiopycommons/eln/experiment_cache.py +0 -188
  46. sapiopycommons/eln/experiment_step_factory.py +0 -476
  47. sapiopycommons/eln/step_creation.py +0 -236
  48. sapiopycommons/general/data_structure_util.py +0 -115
  49. sapiopycommons-2025.4.17a489.dist-info/RECORD +0 -67
  50. {sapiopycommons-2025.4.17a489.dist-info → sapiopycommons-2025.4.23a491.dist-info}/WHEEL +0 -0
  51. {sapiopycommons-2025.4.17a489.dist-info → sapiopycommons-2025.4.23a491.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,88 @@
1
+ sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ sapiopycommons/ai/tool_of_tools.py,sha256=zYmQ4rNX-qYQnc-vNDnYZjtv9JgmQAmVVuHfVOdBF3w,46984
4
+ sapiopycommons/ai/tool_service_base.py,sha256=YJoHWTPD10TXXmZUKZIS6ryrV3Xqzt6TWNMNFaD8aQ4,10911
5
+ sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py,sha256=cPg_-vpIgsP-TAtUDT5CbvQ8mih5QRX_DE_LvJLC_Aw,20621
6
+ sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi,sha256=gVXRsuscx9XavKsTcepzXWf0LDAAyQ_J5ZjFK6kPYuo,34028
7
+ sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py,sha256=4vD4jWanaJ4uclSkFmS7JIz_lwYXDWBE3DomuPjUyII,941
8
+ sapiopycommons/ai/api/plan/proto/step_output_pb2.py,sha256=_p7ABb0wnS7G5SGmWxmlsAi38zyvoKv7uwKz7ZqD6P8,2551
9
+ sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi,sha256=4zIkURW-I_688qCtwRDbl53vRpoWHBpok5bAgopgSRE,1921
10
+ sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py,sha256=vDRY_pIIshQ4UpdW-ra1F5zBmntdsW2scySkMAA-zfc,925
11
+ sapiopycommons/ai/api/plan/proto/step_pb2.py,sha256=QxBq17NtYw7QqRRZ6bb5EQALT_z35UQQO3Vt43hliWg,2402
12
+ sapiopycommons/ai/api/plan/proto/step_pb2.pyi,sha256=LNR5iHcop9_0dwFgpHSfeuxwK0esmm1dx6fFY17SxQg,2032
13
+ sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py,sha256=DgiBYFvTNiDG_2a9Tpt5iel2fRUfePZWP41fZTC-KWk,918
14
+ sapiopycommons/ai/api/plan/script/proto/script_pb2.py,sha256=WFgdOEA-uhh24gkqnpAbYiPINQLRr8rP8CYQxeyP9XY,4147
15
+ sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi,sha256=MBrry29hBGKoo2ax-jDFUNHz9oI4X6rGRUEEKi-Cds4,5906
16
+ sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py,sha256=GPhkapVixTqBmwSQFVguQ-xGO5EyXX_wKLmxUivMgYg,6791
17
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py,sha256=rqv8pyZptfGBjb_hyHwh6j1o-xd2s2KoCcG0GofVWFQ,3891
18
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi,sha256=Zc1LyJQmj_Qkha1Wnua2Fx4vs6FEScaSX-xDb1Xi-rw,4287
19
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py,sha256=YKkX2kexERUx4asLCShufSnZhgf339Zk8Xw1FAgLfHQ,924
20
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py,sha256=q82WrKy439ICmNjzgRVfwGmR7tLKbJQcGroT8BbFflM,7332
21
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi,sha256=Z9XxKHPuaa-8m0enxs_PQnA6-BBDzVRAazO_zIWMknc,16592
22
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py,sha256=KpCu_VDynPx54coAU13LIVLMulhJiUKCZi7BaS2Gd5Y,6842
23
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py,sha256=zwGh5W7MOdQRaJbljRKQ2b_8NGPixL9rnCMicOJ7Q9g,2087
24
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi,sha256=9uHCNMVriDd72lsrWWH2irUB_5VG0mYyL_vhZWdOkns,1597
25
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py,sha256=2W0YzT4SfnGTLq98AdvkyNM0n75Tkl8DervPS1ryGao,932
26
+ sapiopycommons/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
+ sapiopycommons/callbacks/callback_util.py,sha256=sz76LzD9sVLPMcoOpmzPe1aILGXcpHfyZ-qex8oR11c,130849
28
+ sapiopycommons/callbacks/field_builder.py,sha256=p2XacN99MuKk3ite8GAqstUMpixqugul2CsC4gB83-o,38620
29
+ sapiopycommons/chem/IndigoMolecules.py,sha256=slM2y39zZFHc468c366EqR8T-GYJ24UnM9HWAqWFEwQ,3900
30
+ sapiopycommons/chem/Molecules.py,sha256=5PzRyE1s-Z3nfwh3Y4dCNdQOIJGhog08wyZvgTkKwyU,12384
31
+ sapiopycommons/chem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
+ sapiopycommons/customreport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
+ sapiopycommons/customreport/auto_pagers.py,sha256=3-XXWrP7r41a_Y-8YLPnfm0s65m4qEEUqu4azX47oPI,14828
34
+ sapiopycommons/customreport/column_builder.py,sha256=0RO53e9rKPZ07C--KcepN6_tpRw_FxF3O9vdG0ilKG8,3014
35
+ sapiopycommons/customreport/custom_report_builder.py,sha256=BlTxZ4t1sfZA2Ciur1EfYvkZxHxJ7ADwYNAe2zwiN0c,7176
36
+ sapiopycommons/customreport/term_builder.py,sha256=PNp71NF1vFxidk5v6uQNi9oQR9KJIk8WfhyntvvZN-U,18573
37
+ sapiopycommons/datatype/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
+ sapiopycommons/datatype/attachment_util.py,sha256=N-nhsJ0oxa_Ft6Y6VWeNFYLzfuQqsjhHA6_-yIt2wVw,3596
39
+ sapiopycommons/datatype/data_fields.py,sha256=pczUlEcE0TeHEDU0Gkvu7voacSLPXCB7l9UbI1Tb6V0,5656
40
+ sapiopycommons/datatype/pseudo_data_types.py,sha256=6TG7aJxgmUZ8FQkWBcgmbK5oy7AFFNtKOPpi1w1OOYA,27657
41
+ sapiopycommons/eln/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
+ sapiopycommons/eln/experiment_handler.py,sha256=FeqmjnxN5WyDDstN3_AMSo9r7nQi-5zou4m-3K5JsYM,123363
43
+ sapiopycommons/eln/experiment_report_util.py,sha256=NNNNPVD3_2ZAjoOqCMOnlnmPD0SCjDcgYi453ATSJBs,37027
44
+ sapiopycommons/eln/experiment_tags.py,sha256=7-fpOiSqrjbXmWIJhEhaxMgLsVCPAtKqH8xRzpDVKoE,356
45
+ sapiopycommons/eln/plate_designer.py,sha256=ix2cflz13PAHyu4deS3d5Qd3kQXk0C7IQxBQ2Dm9fEM,13692
46
+ sapiopycommons/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
+ sapiopycommons/files/complex_data_loader.py,sha256=T39veNhvYl6j_uZjIIJ8Mk5Aa7otR5RB-g8XlAdkksA,1421
48
+ sapiopycommons/files/file_bridge.py,sha256=vKbqxPexi15epr_-_qLrEfYoxNxB031mXN92iVtOMqE,9511
49
+ sapiopycommons/files/file_bridge_handler.py,sha256=SEYDIQhSCmjI6qyLdDJE8JVKSd0WYvF7JvAq_Ahp9Do,25503
50
+ sapiopycommons/files/file_data_handler.py,sha256=f96MlkMuQhUCi4oLnzJK5AiuElCp5jLI8_sJkZVwpws,36779
51
+ sapiopycommons/files/file_util.py,sha256=w4Q7zYJb9YaPxrecmT4RT_OOibKMRP0NI1CyoOLfAP4,31747
52
+ sapiopycommons/files/file_validator.py,sha256=ryg22-93csmRO_Pv0ZpWphNkB74xWZnHyJ23K56qLj0,28761
53
+ sapiopycommons/files/file_writer.py,sha256=hACVl0duCjP28gJ1NPljkjagNCLod0ygUlPbvUmRDNM,17605
54
+ sapiopycommons/flowcyto/flow_cyto.py,sha256=vs9WhXXKz3urpjL8QKSk56B-NSmQR3O3x_WFBKoeO10,3227
55
+ sapiopycommons/flowcyto/flowcyto_data.py,sha256=mYKFuLbtpJ-EsQxLGtu4tNHVlygTxKixgJxJqD68F58,2596
56
+ sapiopycommons/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
+ sapiopycommons/general/accession_service.py,sha256=QeNGd78Zr08ezWpThTuAkxO4bXusEcp5x9jJRZRwliA,13483
58
+ sapiopycommons/general/aliases.py,sha256=alc2R5TOSKbZif3pcGZ706y23Y9F4HQPC-Kj4xJZ_Us,14503
59
+ sapiopycommons/general/audit_log.py,sha256=KQq0PsvukUoE3l6TQb3-vpu5-MbSINpWlnQ9e7jojPg,8743
60
+ sapiopycommons/general/custom_report_util.py,sha256=NwwmejSQLwSbrndEk1gPyFNYk9GZoS7Wrp9ab9moFgw,18014
61
+ sapiopycommons/general/directive_util.py,sha256=7SeQrd2Ye5JHlXZtJZaVGgtaSLdq_Vm9EObuxf44Pz8,3905
62
+ sapiopycommons/general/exceptions.py,sha256=aPlzK1cvxeMU5UsokYlLrIBGltUfJZ7LH8zvLh9DxpI,3233
63
+ sapiopycommons/general/html_formatter.py,sha256=HE3OeGgwOw6x53zGSc4-UzP4-JoOmQIz3pX-DzNVg94,17138
64
+ sapiopycommons/general/popup_util.py,sha256=HKILegU1uCL_6abNlNL0Wn3xgX2JNa_kJeq7e5CZu6Q,31923
65
+ sapiopycommons/general/sapio_links.py,sha256=YkcVKNLrSGoM7tCCXBAsIbIxylctwdcEyhePrRMODe0,2859
66
+ sapiopycommons/general/storage_util.py,sha256=ovmK_jN7v09BoX07XxwShpBUC5WYQOM7dbKV_VeLXJU,8892
67
+ sapiopycommons/general/time_util.py,sha256=jU1urPoZRv6evNucR0-288EyT4PrsDpCr-H1-7BKq9A,12363
68
+ sapiopycommons/multimodal/multimodal.py,sha256=PFaGJPbKvW__tnxb8KkgkJZOKjQdgxF_kGfD5chet1s,6779
69
+ sapiopycommons/multimodal/multimodal_data.py,sha256=0BeVPr9HaC0hNTF1v1phTIKGruvNnwerHsD994qJKBg,15099
70
+ sapiopycommons/processtracking/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
+ sapiopycommons/processtracking/custom_workflow_handler.py,sha256=QZVRDUXpHfYIKD9LtaOcOt0Sr3RGDaeGQb-LZYAgkCc,25117
72
+ sapiopycommons/processtracking/endpoints.py,sha256=w5bziI2xC7450M95rCF8JpRwkoni1kEDibyAux9B12Q,10848
73
+ sapiopycommons/recordmodel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
+ sapiopycommons/recordmodel/record_handler.py,sha256=aPbR3OS0RlsKOGztY-LZaOmkXKUB8ZTw3qqdJKXwd6U,70872
75
+ sapiopycommons/rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
+ sapiopycommons/rules/eln_rule_handler.py,sha256=1aC88brATcjL1O0Hd2hQ0XNguKsKh8xELXComotk3mQ,10772
77
+ sapiopycommons/rules/on_save_rule_handler.py,sha256=J1YKjOGA1KUTwpnZMa7oIi5QU_4mBJrPygSHNDsMIIA,10539
78
+ sapiopycommons/samples/aliquot.py,sha256=mWOJUqaQh0t3HklNuGdmuV7D5zzXs6fpLwtDdM6_XTo,3018
79
+ sapiopycommons/sftpconnect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
80
+ sapiopycommons/sftpconnect/sftp_builder.py,sha256=lFK3FeXk-sFLefW0hqY8WGUQDeYiGaT6yDACzT_zFgQ,3015
81
+ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
+ sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
83
+ sapiopycommons/webhook/webhook_handlers.py,sha256=L0HetSm43NvA5KyW3xbLpGFh2DbAaeZJVtXIEl2fvV8,39689
84
+ sapiopycommons/webhook/webservice_handlers.py,sha256=Y5dHx_UFWFuSqaoPL6Re-fsKYRuxvCWZ8bj6KSZ3jfM,14285
85
+ sapiopycommons-2025.4.23a491.dist-info/METADATA,sha256=KrFFX1zDdrcdTieEl_-2phZAjdD7ZwLUuTPRv0QTjcE,3143
86
+ sapiopycommons-2025.4.23a491.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
87
+ sapiopycommons-2025.4.23a491.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
88
+ sapiopycommons-2025.4.23a491.dist-info/RECORD,,
@@ -1,188 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from weakref import WeakValueDictionary
4
-
5
- from sapiopylib.rest.ELNService import ElnManager
6
- from sapiopylib.rest.User import SapioUser
7
- from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition
8
- from sapiopylib.rest.pojo.eln.ElnExperiment import ElnTemplate, TemplateExperimentQuery
9
- from sapiopylib.rest.pojo.eln.SapioELNEnums import ElnBaseDataType
10
- from sapiopylib.rest.pojo.eln.field_set import ElnFieldSetInfo
11
- from sapiopylib.rest.pojo.eln.protocol_template import ProtocolTemplateInfo, ProtocolTemplateQuery
12
-
13
- from sapiopycommons.general.aliases import UserIdentifier, AliasUtil
14
- from sapiopycommons.general.exceptions import SapioException
15
-
16
-
17
- # FR-47530: Created a class that caches experiment template and predefined field information.
18
- class ExperimentCacheManager:
19
- """
20
- A class to manage the caching of experiment-related information.
21
- """
22
- user: SapioUser
23
- eln_man: ElnManager
24
-
25
- _templates: list[ElnTemplate]
26
- """A list of experiment templates. Only cached when first accessed."""
27
- _protocols: list[ProtocolTemplateInfo]
28
- """A list of protocol templates. Only cached when first accessed."""
29
- _field_sets: dict[str, ElnFieldSetInfo]
30
- """A dictionary of field set name to field set. Only cached when first accessed."""
31
- _field_set_fields: dict[int, list[AbstractVeloxFieldDefinition]]
32
- """A dictionary of field set ID to field definitions. Only cached when first accessed."""
33
- _predefined_fields: dict[str, dict[str, AbstractVeloxFieldDefinition]]
34
- """A dictionary of ELN data type name to predefined field definitions. Only cached when first accessed."""
35
-
36
- __instances: WeakValueDictionary[SapioUser, ExperimentCacheManager] = WeakValueDictionary()
37
- __initialized: bool
38
-
39
- def __new__(cls, context: UserIdentifier):
40
- """
41
- :param context: The current webhook context or a user object to send requests from.
42
- """
43
- user = AliasUtil.to_sapio_user(context)
44
- obj = cls.__instances.get(user)
45
- if not obj:
46
- obj = object.__new__(cls)
47
- obj.__initialized = False
48
- cls.__instances[user] = obj
49
- return obj
50
-
51
- def __init__(self, context: UserIdentifier):
52
- """
53
- :param context: The current webhook context or a user object to send requests from.
54
- """
55
- if self.__initialized:
56
- return
57
- self.__initialized = True
58
-
59
- self.user = AliasUtil.to_sapio_user(context)
60
- self.eln_man = ElnManager(self.user)
61
-
62
- self._field_set_fields = {}
63
- self._predefined_fields = {}
64
-
65
- def get_experiment_template(self, name: str, active: bool = True, version: int | None = None,
66
- first_match: bool = False, public: bool | None = True) -> ElnTemplate:
67
- """
68
- Get the experiment template with the given information.
69
-
70
- :param name: The name of the template.
71
- :param active: Whether the template is marked as active.
72
- :param version: The version of the template to get. If None, the latest version will be returned.
73
- :param first_match: If true, returns the first match found. If false, raises an exception.
74
- :param public: Whether the template is public. If true, only pubic templates will be queried. If false, only
75
- private templates will be queried. If None, both public and private templates will be queried. Non-public
76
- templates do not have a version number, so this will always fail if public is false and a version number is
77
- provided.
78
- :return: The experiment template with the given information.
79
- """
80
- if not hasattr(self, "_templates"):
81
- query = TemplateExperimentQuery()
82
- query.active_templates_only = False
83
- query.latest_version_only = False
84
- self._templates = self.eln_man.get_template_experiment_list(query)
85
- return self._find_template(self._templates, name, active, version, first_match, public)
86
-
87
-
88
- def get_protocol_template(self, name: str, active: bool = True, version: int | None = None,
89
- first_match: bool = False, public: bool | None = True) -> ProtocolTemplateInfo:
90
- """
91
- Get the protocol template with the given information. Will throw an exception if multiple templates match
92
- the given information.
93
-
94
- :param name: The name of the template.
95
- :param active: Whether the template is marked as active.
96
- :param version: The version of the template to get. If None, the latest version will be returned.
97
- :param first_match: If true, returns the first match found. If false, raises an exception.
98
- :param public: Whether the template is public. If true, only pubic templates will be queried. If false, only
99
- private templates will be queried. If None, both public and private templates will be queried. Non-public
100
- templates do not have a version number, so this will always fail if public is false and a version number is
101
- provided.
102
- :return: The protocol template with the given information.
103
- """
104
- if not hasattr(self, "_protocols"):
105
- query = ProtocolTemplateQuery()
106
- query.active_templates_only = False
107
- query.latest_version_only = False
108
- self._protocols = self.eln_man.get_protocol_template_info_list(query)
109
- return self._find_template(self._protocols, name, active, version, first_match, public)
110
-
111
- @staticmethod
112
- def _find_template(templates: list[ElnTemplate] | list[ProtocolTemplateInfo], name: str, active: bool,
113
- version: int, first_match: bool, public: bool | None) -> ElnTemplate | ProtocolTemplateInfo:
114
- """
115
- Find the experiment or protocol template with the given information.
116
- """
117
- matches = []
118
- for template in templates:
119
- if template.template_name != name:
120
- continue
121
- if template.active != active:
122
- continue
123
- if version is not None and template.template_version != version:
124
- continue
125
- if public is True and template.template_version is None:
126
- continue
127
- if public is False and template.template_version is not None:
128
- continue
129
- matches.append(template)
130
- if not matches:
131
- raise SapioException(f"No template with the name \"{name}\"" +
132
- ("" if version is None else f" and the version {version}") +
133
- f" found.")
134
- # Only filter for the max version number if any of the matches actually have a version number.
135
- versioned_matches = [x for x in matches if x.template_version is not None]
136
- if version is None and versioned_matches:
137
- return max(versioned_matches, key=lambda x: x.template_version)
138
- if len(matches) > 1 and not first_match:
139
- raise SapioException(f"Multiple templates with the name \"{name}\" found. Consider setting first_match to "
140
- f"true, or restrict your search criteria further.")
141
- return matches[0]
142
-
143
- def get_predefined_field(self, field_name: str, data_type: ElnBaseDataType) -> AbstractVeloxFieldDefinition:
144
- """
145
- Get the predefined field of the given name for the given ELN data type.
146
-
147
- :param field_name: The name of the field.
148
- :param data_type: The ELN data type of the field.
149
- :return: The predefined field of the given name for the given ELN data type.
150
- """
151
- return self.get_predefined_fields(data_type)[field_name]
152
-
153
- def get_predefined_fields(self, data_type: ElnBaseDataType) -> dict[str, AbstractVeloxFieldDefinition]:
154
- """
155
- Get the predefined fields for the given ELN data type.
156
-
157
- :param data_type: The ELN data type to get the predefined fields for.
158
- :return: A dictionary of field name to field definition for the given ELN data type.
159
- """
160
- if data_type.data_type_name not in self._predefined_fields:
161
- fields: list[AbstractVeloxFieldDefinition] = self.eln_man.get_predefined_fields(data_type)
162
- self._predefined_fields[data_type.data_type_name] = {x.data_field_name: x for x in fields}
163
- return self._predefined_fields[data_type.data_type_name]
164
-
165
- def get_field_set(self, name: str) -> ElnFieldSetInfo:
166
- """
167
- Get the field set with the given name.
168
-
169
- :param name: The name of the field set.
170
- :return: The field set with the given name.
171
- """
172
- if not hasattr(self, "_field_sets"):
173
- self._field_sets = {x.field_set_name: x for x in self.eln_man.get_field_set_info_list()}
174
- return self._field_sets[name]
175
-
176
- def get_field_set_fields(self, field_set: ElnFieldSetInfo | int) -> list[AbstractVeloxFieldDefinition]:
177
- """
178
- Get the fields of the given field set.
179
-
180
- :param field_set: The field set to get the fields from. Can be either an ElnFieldSetInfo object or an integer
181
- for the set ID.
182
- :return: The fields of the given field set.
183
- """
184
- field_set: int = field_set if isinstance(field_set, int) else field_set.field_set_id
185
- if field_set in self._field_set_fields:
186
- return self._field_set_fields[field_set]
187
- self._field_set_fields[field_set] = self.eln_man.get_predefined_fields_from_field_set_id(field_set)
188
- return self._field_set_fields[field_set]