sapiopycommons 2025.4.17a488__py3-none-any.whl → 2025.4.22a490__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 (48) hide show
  1. sapiopycommons/ai/__init__.py +0 -0
  2. sapiopycommons/ai/api/plan/proto/step_output_pb2.py +45 -0
  3. sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi +42 -0
  4. sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py +24 -0
  5. sapiopycommons/ai/api/plan/proto/step_pb2.py +43 -0
  6. sapiopycommons/ai/api/plan/proto/step_pb2.pyi +43 -0
  7. sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py +24 -0
  8. sapiopycommons/ai/api/plan/script/proto/script_pb2.py +51 -0
  9. sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi +73 -0
  10. sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py +153 -0
  11. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py +57 -0
  12. sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi +96 -0
  13. sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py +24 -0
  14. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py +61 -0
  15. sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi +114 -0
  16. sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py +154 -0
  17. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py +39 -0
  18. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi +32 -0
  19. sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py +24 -0
  20. sapiopycommons/ai/tool_of_tools.py +917 -0
  21. sapiopycommons/ai/tool_service_base.py +271 -0
  22. sapiopycommons/callbacks/callback_util.py +64 -116
  23. sapiopycommons/callbacks/field_builder.py +0 -2
  24. sapiopycommons/customreport/auto_pagers.py +1 -2
  25. sapiopycommons/customreport/term_builder.py +1 -1
  26. sapiopycommons/datatype/pseudo_data_types.py +326 -349
  27. sapiopycommons/eln/experiment_handler.py +719 -336
  28. sapiopycommons/eln/plate_designer.py +2 -7
  29. sapiopycommons/files/file_util.py +4 -4
  30. sapiopycommons/general/accession_service.py +2 -2
  31. sapiopycommons/general/aliases.py +1 -4
  32. sapiopycommons/general/html_formatter.py +456 -0
  33. sapiopycommons/general/sapio_links.py +12 -4
  34. sapiopycommons/processtracking/custom_workflow_handler.py +1 -2
  35. sapiopycommons/recordmodel/record_handler.py +27 -357
  36. sapiopycommons/rules/eln_rule_handler.py +1 -8
  37. sapiopycommons/rules/on_save_rule_handler.py +1 -8
  38. sapiopycommons/webhook/webhook_handlers.py +0 -3
  39. sapiopycommons/webhook/webservice_handlers.py +2 -2
  40. {sapiopycommons-2025.4.17a488.dist-info → sapiopycommons-2025.4.22a490.dist-info}/METADATA +2 -2
  41. sapiopycommons-2025.4.22a490.dist-info/RECORD +85 -0
  42. sapiopycommons/eln/experiment_cache.py +0 -188
  43. sapiopycommons/eln/experiment_step_factory.py +0 -476
  44. sapiopycommons/eln/step_creation.py +0 -236
  45. sapiopycommons/general/data_structure_util.py +0 -115
  46. sapiopycommons-2025.4.17a488.dist-info/RECORD +0 -67
  47. {sapiopycommons-2025.4.17a488.dist-info → sapiopycommons-2025.4.22a490.dist-info}/WHEEL +0 -0
  48. {sapiopycommons-2025.4.17a488.dist-info → sapiopycommons-2025.4.22a490.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,85 @@
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/plan/proto/step_output_pb2.py,sha256=-5pyXHpDOVwM1FnbSyVKZ7UY2--DbvI1U2JxhsrCAtA,2527
6
+ sapiopycommons/ai/api/plan/proto/step_output_pb2.pyi,sha256=4zIkURW-I_688qCtwRDbl53vRpoWHBpok5bAgopgSRE,1921
7
+ sapiopycommons/ai/api/plan/proto/step_output_pb2_grpc.py,sha256=byasn9F38obmcDiMTRuLOmTHF8uzFadUciNfasaygTE,917
8
+ sapiopycommons/ai/api/plan/proto/step_pb2.py,sha256=6qjydntkqu81b9rmcB2td-jBSfhXsA1dLKJ56PBLaxM,2378
9
+ sapiopycommons/ai/api/plan/proto/step_pb2.pyi,sha256=LNR5iHcop9_0dwFgpHSfeuxwK0esmm1dx6fFY17SxQg,2032
10
+ sapiopycommons/ai/api/plan/proto/step_pb2_grpc.py,sha256=p8iIDb3GJ0Fsy_TlwivXwRz_VeejSI7IDcEc4CNRvwM,910
11
+ sapiopycommons/ai/api/plan/script/proto/script_pb2.py,sha256=MgltofGYEirWXHpUNI3bkogAq8tcMr4mLe77a2Md4hs,3575
12
+ sapiopycommons/ai/api/plan/script/proto/script_pb2.pyi,sha256=BtYJeXdAyzWPB0Woe3s5MJL_RCYc_-bkfu2xb8-0jJg,4780
13
+ sapiopycommons/ai/api/plan/script/proto/script_pb2_grpc.py,sha256=tjE-oFduGGZNuUMzRXosb2h5TaMT_Z-KKPHjm3KLoUs,6783
14
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2.py,sha256=IHZWU6JG6WUPpqHvhipcfhsTkH0lL5N6x8u78CFr3yU,3868
15
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2.pyi,sha256=Zc1LyJQmj_Qkha1Wnua2Fx4vs6FEScaSX-xDb1Xi-rw,4287
16
+ sapiopycommons/ai/api/plan/tool/proto/entry_pb2_grpc.py,sha256=nnm3JI2mwfklOWs_8qtbbzPhT-P9deitnFpfDNiOCcY,916
17
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2.py,sha256=quu96N7pDXw3cdzFrf6ykQIrOvhDFaLfRHgqSY1M1TI,4983
18
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2.pyi,sha256=SZpr7mIU1Et1uefXbBr5jG-oJM_B6Ro7ZlWnT972s94,7304
19
+ sapiopycommons/ai/api/plan/tool/proto/tool_pb2_grpc.py,sha256=InZkCC6ySInC2xZb3U61i3tClyycxv3mIO0qRZ70OGM,6834
20
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.py,sha256=LO35H0ojxcENWqDgMARqFIAmYU4iinVzdmbCcbYen4E,2063
21
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2.pyi,sha256=9uHCNMVriDd72lsrWWH2irUB_5VG0mYyL_vhZWdOkns,1597
22
+ sapiopycommons/ai/api/session/proto/sapio_conn_info_pb2_grpc.py,sha256=bXZMcjFHRAaQ3MqTz7oycWw9LaSlaBChyqW2VzZWEAk,924
23
+ sapiopycommons/callbacks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ sapiopycommons/callbacks/callback_util.py,sha256=sz76LzD9sVLPMcoOpmzPe1aILGXcpHfyZ-qex8oR11c,130849
25
+ sapiopycommons/callbacks/field_builder.py,sha256=p2XacN99MuKk3ite8GAqstUMpixqugul2CsC4gB83-o,38620
26
+ sapiopycommons/chem/IndigoMolecules.py,sha256=slM2y39zZFHc468c366EqR8T-GYJ24UnM9HWAqWFEwQ,3900
27
+ sapiopycommons/chem/Molecules.py,sha256=5PzRyE1s-Z3nfwh3Y4dCNdQOIJGhog08wyZvgTkKwyU,12384
28
+ sapiopycommons/chem/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
+ sapiopycommons/customreport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
+ sapiopycommons/customreport/auto_pagers.py,sha256=3-XXWrP7r41a_Y-8YLPnfm0s65m4qEEUqu4azX47oPI,14828
31
+ sapiopycommons/customreport/column_builder.py,sha256=0RO53e9rKPZ07C--KcepN6_tpRw_FxF3O9vdG0ilKG8,3014
32
+ sapiopycommons/customreport/custom_report_builder.py,sha256=BlTxZ4t1sfZA2Ciur1EfYvkZxHxJ7ADwYNAe2zwiN0c,7176
33
+ sapiopycommons/customreport/term_builder.py,sha256=PNp71NF1vFxidk5v6uQNi9oQR9KJIk8WfhyntvvZN-U,18573
34
+ sapiopycommons/datatype/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ sapiopycommons/datatype/attachment_util.py,sha256=N-nhsJ0oxa_Ft6Y6VWeNFYLzfuQqsjhHA6_-yIt2wVw,3596
36
+ sapiopycommons/datatype/data_fields.py,sha256=pczUlEcE0TeHEDU0Gkvu7voacSLPXCB7l9UbI1Tb6V0,5656
37
+ sapiopycommons/datatype/pseudo_data_types.py,sha256=6TG7aJxgmUZ8FQkWBcgmbK5oy7AFFNtKOPpi1w1OOYA,27657
38
+ sapiopycommons/eln/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
+ sapiopycommons/eln/experiment_handler.py,sha256=FeqmjnxN5WyDDstN3_AMSo9r7nQi-5zou4m-3K5JsYM,123363
40
+ sapiopycommons/eln/experiment_report_util.py,sha256=NNNNPVD3_2ZAjoOqCMOnlnmPD0SCjDcgYi453ATSJBs,37027
41
+ sapiopycommons/eln/experiment_tags.py,sha256=7-fpOiSqrjbXmWIJhEhaxMgLsVCPAtKqH8xRzpDVKoE,356
42
+ sapiopycommons/eln/plate_designer.py,sha256=ix2cflz13PAHyu4deS3d5Qd3kQXk0C7IQxBQ2Dm9fEM,13692
43
+ sapiopycommons/files/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
+ sapiopycommons/files/complex_data_loader.py,sha256=T39veNhvYl6j_uZjIIJ8Mk5Aa7otR5RB-g8XlAdkksA,1421
45
+ sapiopycommons/files/file_bridge.py,sha256=vKbqxPexi15epr_-_qLrEfYoxNxB031mXN92iVtOMqE,9511
46
+ sapiopycommons/files/file_bridge_handler.py,sha256=SEYDIQhSCmjI6qyLdDJE8JVKSd0WYvF7JvAq_Ahp9Do,25503
47
+ sapiopycommons/files/file_data_handler.py,sha256=f96MlkMuQhUCi4oLnzJK5AiuElCp5jLI8_sJkZVwpws,36779
48
+ sapiopycommons/files/file_util.py,sha256=w4Q7zYJb9YaPxrecmT4RT_OOibKMRP0NI1CyoOLfAP4,31747
49
+ sapiopycommons/files/file_validator.py,sha256=ryg22-93csmRO_Pv0ZpWphNkB74xWZnHyJ23K56qLj0,28761
50
+ sapiopycommons/files/file_writer.py,sha256=hACVl0duCjP28gJ1NPljkjagNCLod0ygUlPbvUmRDNM,17605
51
+ sapiopycommons/flowcyto/flow_cyto.py,sha256=vs9WhXXKz3urpjL8QKSk56B-NSmQR3O3x_WFBKoeO10,3227
52
+ sapiopycommons/flowcyto/flowcyto_data.py,sha256=mYKFuLbtpJ-EsQxLGtu4tNHVlygTxKixgJxJqD68F58,2596
53
+ sapiopycommons/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
+ sapiopycommons/general/accession_service.py,sha256=QeNGd78Zr08ezWpThTuAkxO4bXusEcp5x9jJRZRwliA,13483
55
+ sapiopycommons/general/aliases.py,sha256=alc2R5TOSKbZif3pcGZ706y23Y9F4HQPC-Kj4xJZ_Us,14503
56
+ sapiopycommons/general/audit_log.py,sha256=KQq0PsvukUoE3l6TQb3-vpu5-MbSINpWlnQ9e7jojPg,8743
57
+ sapiopycommons/general/custom_report_util.py,sha256=NwwmejSQLwSbrndEk1gPyFNYk9GZoS7Wrp9ab9moFgw,18014
58
+ sapiopycommons/general/directive_util.py,sha256=7SeQrd2Ye5JHlXZtJZaVGgtaSLdq_Vm9EObuxf44Pz8,3905
59
+ sapiopycommons/general/exceptions.py,sha256=aPlzK1cvxeMU5UsokYlLrIBGltUfJZ7LH8zvLh9DxpI,3233
60
+ sapiopycommons/general/html_formatter.py,sha256=HE3OeGgwOw6x53zGSc4-UzP4-JoOmQIz3pX-DzNVg94,17138
61
+ sapiopycommons/general/popup_util.py,sha256=HKILegU1uCL_6abNlNL0Wn3xgX2JNa_kJeq7e5CZu6Q,31923
62
+ sapiopycommons/general/sapio_links.py,sha256=YkcVKNLrSGoM7tCCXBAsIbIxylctwdcEyhePrRMODe0,2859
63
+ sapiopycommons/general/storage_util.py,sha256=ovmK_jN7v09BoX07XxwShpBUC5WYQOM7dbKV_VeLXJU,8892
64
+ sapiopycommons/general/time_util.py,sha256=jU1urPoZRv6evNucR0-288EyT4PrsDpCr-H1-7BKq9A,12363
65
+ sapiopycommons/multimodal/multimodal.py,sha256=PFaGJPbKvW__tnxb8KkgkJZOKjQdgxF_kGfD5chet1s,6779
66
+ sapiopycommons/multimodal/multimodal_data.py,sha256=0BeVPr9HaC0hNTF1v1phTIKGruvNnwerHsD994qJKBg,15099
67
+ sapiopycommons/processtracking/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
68
+ sapiopycommons/processtracking/custom_workflow_handler.py,sha256=QZVRDUXpHfYIKD9LtaOcOt0Sr3RGDaeGQb-LZYAgkCc,25117
69
+ sapiopycommons/processtracking/endpoints.py,sha256=w5bziI2xC7450M95rCF8JpRwkoni1kEDibyAux9B12Q,10848
70
+ sapiopycommons/recordmodel/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
+ sapiopycommons/recordmodel/record_handler.py,sha256=aPbR3OS0RlsKOGztY-LZaOmkXKUB8ZTw3qqdJKXwd6U,70872
72
+ sapiopycommons/rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
73
+ sapiopycommons/rules/eln_rule_handler.py,sha256=1aC88brATcjL1O0Hd2hQ0XNguKsKh8xELXComotk3mQ,10772
74
+ sapiopycommons/rules/on_save_rule_handler.py,sha256=J1YKjOGA1KUTwpnZMa7oIi5QU_4mBJrPygSHNDsMIIA,10539
75
+ sapiopycommons/samples/aliquot.py,sha256=mWOJUqaQh0t3HklNuGdmuV7D5zzXs6fpLwtDdM6_XTo,3018
76
+ sapiopycommons/sftpconnect/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
+ sapiopycommons/sftpconnect/sftp_builder.py,sha256=lFK3FeXk-sFLefW0hqY8WGUQDeYiGaT6yDACzT_zFgQ,3015
78
+ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
79
+ sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
80
+ sapiopycommons/webhook/webhook_handlers.py,sha256=L0HetSm43NvA5KyW3xbLpGFh2DbAaeZJVtXIEl2fvV8,39689
81
+ sapiopycommons/webhook/webservice_handlers.py,sha256=Y5dHx_UFWFuSqaoPL6Re-fsKYRuxvCWZ8bj6KSZ3jfM,14285
82
+ sapiopycommons-2025.4.22a490.dist-info/METADATA,sha256=zttU8KRjC2j6mRGxer76WEB_E8IPAOm_U3xENmQ-Tek,3143
83
+ sapiopycommons-2025.4.22a490.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
84
+ sapiopycommons-2025.4.22a490.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
85
+ sapiopycommons-2025.4.22a490.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]