sapiopycommons 2025.5.7a514__py3-none-any.whl → 2025.5.12a519__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 (54) hide show
  1. sapiopycommons/ai/__init__.py +0 -0
  2. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py +43 -0
  3. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi +31 -0
  4. sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py +24 -0
  5. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py +123 -0
  6. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi +598 -0
  7. sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py +24 -0
  8. sapiopycommons/ai/api/plan/proto/step_output_pb2.py +45 -0
  9. sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +42 -0
  10. sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +24 -0
  11. sapiopycommons/ai/api/plan/proto/step_pb2.py +43 -0
  12. sapiopycommons/ai/api/plan/proto/step_pb2.pyi +43 -0
  13. sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +24 -0
  14. sapiopycommons/ai/api/plan/script/proto/script_pb2.py +53 -0
  15. sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +99 -0
  16. sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +153 -0
  17. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +57 -0
  18. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +96 -0
  19. sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +24 -0
  20. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +67 -0
  21. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +220 -0
  22. sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +154 -0
  23. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +39 -0
  24. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +32 -0
  25. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +24 -0
  26. sapiopycommons/ai/protobuf_utils.py +454 -0
  27. sapiopycommons/ai/tool_service_base.py +740 -0
  28. sapiopycommons/callbacks/callback_util.py +64 -116
  29. sapiopycommons/callbacks/field_builder.py +0 -2
  30. sapiopycommons/customreport/auto_pagers.py +1 -2
  31. sapiopycommons/customreport/term_builder.py +1 -1
  32. sapiopycommons/datatype/pseudo_data_types.py +326 -349
  33. sapiopycommons/eln/experiment_handler.py +719 -336
  34. sapiopycommons/eln/plate_designer.py +2 -7
  35. sapiopycommons/files/file_util.py +4 -4
  36. sapiopycommons/general/accession_service.py +2 -2
  37. sapiopycommons/general/aliases.py +1 -4
  38. sapiopycommons/general/html_formatter.py +456 -0
  39. sapiopycommons/general/sapio_links.py +12 -4
  40. sapiopycommons/processtracking/custom_workflow_handler.py +1 -2
  41. sapiopycommons/recordmodel/record_handler.py +27 -357
  42. sapiopycommons/rules/eln_rule_handler.py +1 -8
  43. sapiopycommons/rules/on_save_rule_handler.py +1 -8
  44. sapiopycommons/webhook/webhook_handlers.py +0 -3
  45. sapiopycommons/webhook/webservice_handlers.py +2 -2
  46. {sapiopycommons-2025.5.7a514.dist-info → sapiopycommons-2025.5.12a519.dist-info}/METADATA +2 -2
  47. sapiopycommons-2025.5.12a519.dist-info/RECORD +91 -0
  48. sapiopycommons/eln/experiment_cache.py +0 -188
  49. sapiopycommons/eln/experiment_step_factory.py +0 -476
  50. sapiopycommons/eln/step_creation.py +0 -236
  51. sapiopycommons/general/data_structure_util.py +0 -115
  52. sapiopycommons-2025.5.7a514.dist-info/RECORD +0 -67
  53. {sapiopycommons-2025.5.7a514.dist-info → sapiopycommons-2025.5.12a519.dist-info}/WHEEL +0 -0
  54. {sapiopycommons-2025.5.7a514.dist-info → sapiopycommons-2025.5.12a519.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,91 @@
1
+ sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ sapiopycommons/ai/protobuf_utils.py,sha256=aKmZtNLrrzUe_LFsdW0zYpG4VI-ZGgukyXVDFtIqfes,22656
4
+ sapiopycommons/ai/tool_service_base.py,sha256=lJRR4jX9oRs56f9ysRbIbWe5tFOYrV6DXQlS0dbGa3M,32496
5
+ sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py,sha256=YcZjb_YM-XeLErM8hEC_S7vGMVGvcXAMGs2b-u5zvOE,2377
6
+ sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi,sha256=FwtXmNAf7iYGEFm4kbqb04v77jNHbZg18ZmEDhle_bU,1444
7
+ sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py,sha256=wPImJPdCUZNVEVoUWzsba9kGIXjEKPdUkawP5SnVyiU,932
8
+ sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.py,sha256=nWC91vR2pMgMUyNOZRZ0YiuL1-8ntnjXLqt1daxsD34,20869
9
+ sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2.pyi,sha256=U5zXrbBxsWilLTsRWJd1TqjdjLKFsr3enF9OJ8GfyWw,34028
10
+ sapiopycommons/ai/api/fielddefinitions/proto/velox_field_def_pb2_grpc.py,sha256=4vD4jWanaJ4uclSkFmS7JIz_lwYXDWBE3DomuPjUyII,941
11
+ sapiopycommons/ai/api/plan/proto/step_output_pb2.py,sha256=JpBZSyoYyPTEaaXjW664PeJNK0zxV1mly_kp5re42z4,2661
12
+ sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi,sha256=yuxOYnDZ9DRuu-TLzaKOW_B4LUiYxTrNc2AbssXg4kE,2022
13
+ sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py,sha256=vDRY_pIIshQ4UpdW-ra1F5zBmntdsW2scySkMAA-zfc,925
14
+ sapiopycommons/ai/api/plan/proto/step_pb2.py,sha256=nL976oTFdX4ih4gg7_J-8eFoGB69tFvERB2gT3L2-6s,2439
15
+ sapiopycommons/ai/api/plan/proto/step_pb2.pyi,sha256=QPIcsjcUvEGQkdZMUMiVzFFNDl8yOUe_qJtf5XEp5Ck,2062
16
+ sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py,sha256=DgiBYFvTNiDG_2a9Tpt5iel2fRUfePZWP41fZTC-KWk,918
17
+ sapiopycommons/ai/api/plan/script/proto/script_pb2.py,sha256=5tmf7Wmxt42XA8g_2Qv-sxnA7AuK-A0kCT3-4i1Y2Vk,4221
18
+ sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi,sha256=mJ-JXUMUyIjPvv-glNn8FRlDfG1yGivtY0mp6dXVSjA,6061
19
+ sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py,sha256=RkShHpe_d5EJHk3qp-or1JpvSEqShb7cCiaXnJ2YSww,6931
20
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py,sha256=A-ufAWwbJ0odVXBZBQKvke6LYPijPl2dpb2IFRaXmPE,4124
21
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi,sha256=NNBrdHz5PzAuUEXuGgTU4THy9rx8Sr9iGTb65QtVH4Q,4589
22
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py,sha256=YKkX2kexERUx4asLCShufSnZhgf339Zk8Xw1FAgLfHQ,924
23
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py,sha256=jrSgsSx8mGPWuxYPxOom7l925bavWaX4NEQAkC9niJo,6854
24
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi,sha256=KzOmH-ic0anjRta4jhScMRCOI1OtO5rSZrQDr_W3eZ0,15992
25
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py,sha256=68u5E1ZKha5frP5GuY8Ad-c0c79vBhtfnj5Q4u-8xOY,6982
26
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py,sha256=WKzNi-d5dqeJbmEXUVE5qJ4Qm34HmsqRXRtXih382g8,2100
27
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi,sha256=vLYA8Tkzq2AwgVadoUp5vAg4HgGlgga0kzeS3e_XkCQ,1621
28
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py,sha256=2W0YzT4SfnGTLq98AdvkyNM0n75Tkl8DervPS1ryGao,932
29
+ sapiopycommons/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
+ sapiopycommons/callbacks/callback_util.py,sha256=sz76LzD9sVLPMcoOpmzPe1aILGXcpHfyZ-qex8oR11c,130849
31
+ sapiopycommons/callbacks/field_builder.py,sha256=p2XacN99MuKk3ite8GAqstUMpixqugul2CsC4gB83-o,38620
32
+ sapiopycommons/chem/IndigoMolecules.py,sha256=slM2y39zZFHc468c366EqR8T-GYJ24UnM9HWAqWFEwQ,3900
33
+ sapiopycommons/chem/Molecules.py,sha256=5PzRyE1s-Z3nfwh3Y4dCNdQOIJGhog08wyZvgTkKwyU,12384
34
+ sapiopycommons/chem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ sapiopycommons/customreport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ sapiopycommons/customreport/auto_pagers.py,sha256=3-XXWrP7r41a_Y-8YLPnfm0s65m4qEEUqu4azX47oPI,14828
37
+ sapiopycommons/customreport/column_builder.py,sha256=0RO53e9rKPZ07C--KcepN6_tpRw_FxF3O9vdG0ilKG8,3014
38
+ sapiopycommons/customreport/custom_report_builder.py,sha256=BlTxZ4t1sfZA2Ciur1EfYvkZxHxJ7ADwYNAe2zwiN0c,7176
39
+ sapiopycommons/customreport/term_builder.py,sha256=PNp71NF1vFxidk5v6uQNi9oQR9KJIk8WfhyntvvZN-U,18573
40
+ sapiopycommons/datatype/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
+ sapiopycommons/datatype/attachment_util.py,sha256=N-nhsJ0oxa_Ft6Y6VWeNFYLzfuQqsjhHA6_-yIt2wVw,3596
42
+ sapiopycommons/datatype/data_fields.py,sha256=pczUlEcE0TeHEDU0Gkvu7voacSLPXCB7l9UbI1Tb6V0,5656
43
+ sapiopycommons/datatype/pseudo_data_types.py,sha256=6TG7aJxgmUZ8FQkWBcgmbK5oy7AFFNtKOPpi1w1OOYA,27657
44
+ sapiopycommons/eln/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
+ sapiopycommons/eln/experiment_handler.py,sha256=FeqmjnxN5WyDDstN3_AMSo9r7nQi-5zou4m-3K5JsYM,123363
46
+ sapiopycommons/eln/experiment_report_util.py,sha256=NNNNPVD3_2ZAjoOqCMOnlnmPD0SCjDcgYi453ATSJBs,37027
47
+ sapiopycommons/eln/experiment_tags.py,sha256=7-fpOiSqrjbXmWIJhEhaxMgLsVCPAtKqH8xRzpDVKoE,356
48
+ sapiopycommons/eln/plate_designer.py,sha256=ix2cflz13PAHyu4deS3d5Qd3kQXk0C7IQxBQ2Dm9fEM,13692
49
+ sapiopycommons/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
+ sapiopycommons/files/complex_data_loader.py,sha256=T39veNhvYl6j_uZjIIJ8Mk5Aa7otR5RB-g8XlAdkksA,1421
51
+ sapiopycommons/files/file_bridge.py,sha256=vKbqxPexi15epr_-_qLrEfYoxNxB031mXN92iVtOMqE,9511
52
+ sapiopycommons/files/file_bridge_handler.py,sha256=SEYDIQhSCmjI6qyLdDJE8JVKSd0WYvF7JvAq_Ahp9Do,25503
53
+ sapiopycommons/files/file_data_handler.py,sha256=f96MlkMuQhUCi4oLnzJK5AiuElCp5jLI8_sJkZVwpws,36779
54
+ sapiopycommons/files/file_util.py,sha256=w4Q7zYJb9YaPxrecmT4RT_OOibKMRP0NI1CyoOLfAP4,31747
55
+ sapiopycommons/files/file_validator.py,sha256=ryg22-93csmRO_Pv0ZpWphNkB74xWZnHyJ23K56qLj0,28761
56
+ sapiopycommons/files/file_writer.py,sha256=hACVl0duCjP28gJ1NPljkjagNCLod0ygUlPbvUmRDNM,17605
57
+ sapiopycommons/flowcyto/flow_cyto.py,sha256=vs9WhXXKz3urpjL8QKSk56B-NSmQR3O3x_WFBKoeO10,3227
58
+ sapiopycommons/flowcyto/flowcyto_data.py,sha256=mYKFuLbtpJ-EsQxLGtu4tNHVlygTxKixgJxJqD68F58,2596
59
+ sapiopycommons/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
+ sapiopycommons/general/accession_service.py,sha256=QeNGd78Zr08ezWpThTuAkxO4bXusEcp5x9jJRZRwliA,13483
61
+ sapiopycommons/general/aliases.py,sha256=alc2R5TOSKbZif3pcGZ706y23Y9F4HQPC-Kj4xJZ_Us,14503
62
+ sapiopycommons/general/audit_log.py,sha256=KQq0PsvukUoE3l6TQb3-vpu5-MbSINpWlnQ9e7jojPg,8743
63
+ sapiopycommons/general/custom_report_util.py,sha256=NwwmejSQLwSbrndEk1gPyFNYk9GZoS7Wrp9ab9moFgw,18014
64
+ sapiopycommons/general/directive_util.py,sha256=7SeQrd2Ye5JHlXZtJZaVGgtaSLdq_Vm9EObuxf44Pz8,3905
65
+ sapiopycommons/general/exceptions.py,sha256=aPlzK1cvxeMU5UsokYlLrIBGltUfJZ7LH8zvLh9DxpI,3233
66
+ sapiopycommons/general/html_formatter.py,sha256=HE3OeGgwOw6x53zGSc4-UzP4-JoOmQIz3pX-DzNVg94,17138
67
+ sapiopycommons/general/popup_util.py,sha256=HKILegU1uCL_6abNlNL0Wn3xgX2JNa_kJeq7e5CZu6Q,31923
68
+ sapiopycommons/general/sapio_links.py,sha256=YkcVKNLrSGoM7tCCXBAsIbIxylctwdcEyhePrRMODe0,2859
69
+ sapiopycommons/general/storage_util.py,sha256=ovmK_jN7v09BoX07XxwShpBUC5WYQOM7dbKV_VeLXJU,8892
70
+ sapiopycommons/general/time_util.py,sha256=jU1urPoZRv6evNucR0-288EyT4PrsDpCr-H1-7BKq9A,12363
71
+ sapiopycommons/multimodal/multimodal.py,sha256=PFaGJPbKvW__tnxb8KkgkJZOKjQdgxF_kGfD5chet1s,6779
72
+ sapiopycommons/multimodal/multimodal_data.py,sha256=0BeVPr9HaC0hNTF1v1phTIKGruvNnwerHsD994qJKBg,15099
73
+ sapiopycommons/processtracking/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
+ sapiopycommons/processtracking/custom_workflow_handler.py,sha256=QZVRDUXpHfYIKD9LtaOcOt0Sr3RGDaeGQb-LZYAgkCc,25117
75
+ sapiopycommons/processtracking/endpoints.py,sha256=w5bziI2xC7450M95rCF8JpRwkoni1kEDibyAux9B12Q,10848
76
+ sapiopycommons/recordmodel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
+ sapiopycommons/recordmodel/record_handler.py,sha256=aPbR3OS0RlsKOGztY-LZaOmkXKUB8ZTw3qqdJKXwd6U,70872
78
+ sapiopycommons/rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
79
+ sapiopycommons/rules/eln_rule_handler.py,sha256=1aC88brATcjL1O0Hd2hQ0XNguKsKh8xELXComotk3mQ,10772
80
+ sapiopycommons/rules/on_save_rule_handler.py,sha256=J1YKjOGA1KUTwpnZMa7oIi5QU_4mBJrPygSHNDsMIIA,10539
81
+ sapiopycommons/samples/aliquot.py,sha256=mWOJUqaQh0t3HklNuGdmuV7D5zzXs6fpLwtDdM6_XTo,3018
82
+ sapiopycommons/sftpconnect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
+ sapiopycommons/sftpconnect/sftp_builder.py,sha256=lFK3FeXk-sFLefW0hqY8WGUQDeYiGaT6yDACzT_zFgQ,3015
84
+ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
85
+ sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
86
+ sapiopycommons/webhook/webhook_handlers.py,sha256=L0HetSm43NvA5KyW3xbLpGFh2DbAaeZJVtXIEl2fvV8,39689
87
+ sapiopycommons/webhook/webservice_handlers.py,sha256=Y5dHx_UFWFuSqaoPL6Re-fsKYRuxvCWZ8bj6KSZ3jfM,14285
88
+ sapiopycommons-2025.5.12a519.dist-info/METADATA,sha256=ydyu7WKWgeim8QXQl90mu2FpgluAJUDW1TnmolC5Z9U,3143
89
+ sapiopycommons-2025.5.12a519.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
90
+ sapiopycommons-2025.5.12a519.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
91
+ sapiopycommons-2025.5.12a519.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]