logs-py 4.0.7__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.
Files changed (251) hide show
  1. LOGS/Auxiliary/CheckClassName.py +1075 -0
  2. LOGS/Auxiliary/Constants.py +99 -0
  3. LOGS/Auxiliary/CustomEntityClassGenerator.py +254 -0
  4. LOGS/Auxiliary/CustomFieldClassGenerator.py +115 -0
  5. LOGS/Auxiliary/CustomFieldValueTypeChecker.py +168 -0
  6. LOGS/Auxiliary/CustomSectionClassGenerator.py +113 -0
  7. LOGS/Auxiliary/CustomTypeClassGenerator.py +147 -0
  8. LOGS/Auxiliary/DateTimeConverter.py +66 -0
  9. LOGS/Auxiliary/Decorators.py +109 -0
  10. LOGS/Auxiliary/Exceptions.py +341 -0
  11. LOGS/Auxiliary/LOGSErrorResponse.py +89 -0
  12. LOGS/Auxiliary/MinimalModelGenerator.py +236 -0
  13. LOGS/Auxiliary/ParameterHelper.py +56 -0
  14. LOGS/Auxiliary/ReplaceMessage.py +13 -0
  15. LOGS/Auxiliary/Tools.py +432 -0
  16. LOGS/Auxiliary/__init__.py +15 -0
  17. LOGS/Converter/Conversion.py +248 -0
  18. LOGS/Converter/Converter.py +96 -0
  19. LOGS/Converter/ConverterParameter.py +88 -0
  20. LOGS/Converter/DateTimeRange.py +58 -0
  21. LOGS/Converter/ExportParameters.py +89 -0
  22. LOGS/Converter/__init__.py +13 -0
  23. LOGS/Entities/Attachment.py +84 -0
  24. LOGS/Entities/AttachmentMinimal.py +8 -0
  25. LOGS/Entities/AttachmentRequestParameter.py +42 -0
  26. LOGS/Entities/Attachments.py +53 -0
  27. LOGS/Entities/AutoloadFileInfo.py +12 -0
  28. LOGS/Entities/AutoloadStatusError.py +7 -0
  29. LOGS/Entities/AxisNaming.py +33 -0
  30. LOGS/Entities/AxisZoom.py +33 -0
  31. LOGS/Entities/Bridge.py +165 -0
  32. LOGS/Entities/BridgeClientInfo.py +93 -0
  33. LOGS/Entities/BridgeMinimal.py +8 -0
  34. LOGS/Entities/BridgeRequestParameter.py +49 -0
  35. LOGS/Entities/BridgeType.py +7 -0
  36. LOGS/Entities/Bridges.py +12 -0
  37. LOGS/Entities/CustomField.py +243 -0
  38. LOGS/Entities/CustomFieldMinimal.py +8 -0
  39. LOGS/Entities/CustomFieldModels.py +111 -0
  40. LOGS/Entities/CustomFieldRequestParameter.py +69 -0
  41. LOGS/Entities/CustomFieldSearchQuery.py +40 -0
  42. LOGS/Entities/CustomFields.py +12 -0
  43. LOGS/Entities/CustomType.py +212 -0
  44. LOGS/Entities/CustomTypeMinimal.py +8 -0
  45. LOGS/Entities/CustomTypeRequestParameter.py +60 -0
  46. LOGS/Entities/CustomTypeSection.py +63 -0
  47. LOGS/Entities/CustomTypes.py +12 -0
  48. LOGS/Entities/DataFormat.py +97 -0
  49. LOGS/Entities/DataFormatInstrument.py +18 -0
  50. LOGS/Entities/DataFormatInstrumentMinimal.py +8 -0
  51. LOGS/Entities/DataFormatInstrumentRequestParameter.py +17 -0
  52. LOGS/Entities/DataFormatInstruments.py +16 -0
  53. LOGS/Entities/DataFormatMinimal.py +18 -0
  54. LOGS/Entities/DataFormatRequestParameter.py +21 -0
  55. LOGS/Entities/DataFormats.py +12 -0
  56. LOGS/Entities/DataSource.py +218 -0
  57. LOGS/Entities/DataSourceConnectionStatus.py +12 -0
  58. LOGS/Entities/DataSourceMinimal.py +8 -0
  59. LOGS/Entities/DataSourceRequestParameter.py +57 -0
  60. LOGS/Entities/DataSourceStatus.py +108 -0
  61. LOGS/Entities/DataSourceStatusIterator.py +16 -0
  62. LOGS/Entities/DataSourceStatusRequestParameter.py +31 -0
  63. LOGS/Entities/DataSources.py +12 -0
  64. LOGS/Entities/Dataset.py +439 -0
  65. LOGS/Entities/DatasetBase.py +196 -0
  66. LOGS/Entities/DatasetCreator.py +148 -0
  67. LOGS/Entities/DatasetInfo.py +147 -0
  68. LOGS/Entities/DatasetMatchTypes.py +157 -0
  69. LOGS/Entities/DatasetMatching.py +196 -0
  70. LOGS/Entities/DatasetMinimal.py +8 -0
  71. LOGS/Entities/DatasetModels.py +33 -0
  72. LOGS/Entities/DatasetRequestParameter.py +92 -0
  73. LOGS/Entities/DatasetTemplate.py +23 -0
  74. LOGS/Entities/DatasetUploadParameter.py +14 -0
  75. LOGS/Entities/Datasets.py +142 -0
  76. LOGS/Entities/Datatrack.py +179 -0
  77. LOGS/Entities/DatatrackFormattedTable.py +25 -0
  78. LOGS/Entities/DatatrackGeneric.py +34 -0
  79. LOGS/Entities/DatatrackImage.py +25 -0
  80. LOGS/Entities/DatatrackNumericArray.py +30 -0
  81. LOGS/Entities/DatatrackNumericMatrix.py +98 -0
  82. LOGS/Entities/Entities.py +71 -0
  83. LOGS/Entities/EntitiesRequestParameter.py +18 -0
  84. LOGS/Entities/EntityOriginWriteModelWithId.py +15 -0
  85. LOGS/Entities/FileEntry.py +138 -0
  86. LOGS/Entities/FileExcludePattern.py +8 -0
  87. LOGS/Entities/FormatMetaData.py +56 -0
  88. LOGS/Entities/FormattedTable/DatatypeFormattedTable.py +135 -0
  89. LOGS/Entities/FormattedTable/DatatypeFormattedTableCell.py +108 -0
  90. LOGS/Entities/FormattedTable/DatatypeFormattedTableSettings.py +11 -0
  91. LOGS/Entities/FormattedTable/__init__.py +9 -0
  92. LOGS/Entities/HierarchyLeaf.py +15 -0
  93. LOGS/Entities/HierarchyNode.py +40 -0
  94. LOGS/Entities/ILiteraryTypedEntity.py +19 -0
  95. LOGS/Entities/InventoryItem.py +102 -0
  96. LOGS/Entities/InventoryItemMinimal.py +25 -0
  97. LOGS/Entities/InventoryItemRequestParameter.py +58 -0
  98. LOGS/Entities/InventoryItems.py +12 -0
  99. LOGS/Entities/LabNotebook.py +33 -0
  100. LOGS/Entities/LabNotebookEntries.py +16 -0
  101. LOGS/Entities/LabNotebookEntry.py +106 -0
  102. LOGS/Entities/LabNotebookEntryContent/BasicAttribute.py +15 -0
  103. LOGS/Entities/LabNotebookEntryContent/EntityAttribute.py +85 -0
  104. LOGS/Entities/LabNotebookEntryContent/EntryContentBlockquote.py +13 -0
  105. LOGS/Entities/LabNotebookEntryContent/EntryContentBulletList.py +17 -0
  106. LOGS/Entities/LabNotebookEntryContent/EntryContentCallout.py +40 -0
  107. LOGS/Entities/LabNotebookEntryContent/EntryContentContentPlaceholderNode.py +31 -0
  108. LOGS/Entities/LabNotebookEntryContent/EntryContentConverter.py +207 -0
  109. LOGS/Entities/LabNotebookEntryContent/EntryContentDocument.py +8 -0
  110. LOGS/Entities/LabNotebookEntryContent/EntryContentEntity.py +13 -0
  111. LOGS/Entities/LabNotebookEntryContent/EntryContentEntityMention.py +31 -0
  112. LOGS/Entities/LabNotebookEntryContent/EntryContentHeading.py +33 -0
  113. LOGS/Entities/LabNotebookEntryContent/EntryContentHorizontalRule.py +12 -0
  114. LOGS/Entities/LabNotebookEntryContent/EntryContentItem.py +37 -0
  115. LOGS/Entities/LabNotebookEntryContent/EntryContentListItem.py +49 -0
  116. LOGS/Entities/LabNotebookEntryContent/EntryContentOrderedList.py +31 -0
  117. LOGS/Entities/LabNotebookEntryContent/EntryContentParagraph.py +13 -0
  118. LOGS/Entities/LabNotebookEntryContent/EntryContentTable.py +17 -0
  119. LOGS/Entities/LabNotebookEntryContent/EntryContentTableCell.py +40 -0
  120. LOGS/Entities/LabNotebookEntryContent/EntryContentTableRow.py +8 -0
  121. LOGS/Entities/LabNotebookEntryContent/EntryContentTaskList.py +17 -0
  122. LOGS/Entities/LabNotebookEntryContent/EntryContentTaskListItem.py +31 -0
  123. LOGS/Entities/LabNotebookEntryContent/EntryContentText.py +33 -0
  124. LOGS/Entities/LabNotebookEntryContent/IEntryContentWithAttribute.py +23 -0
  125. LOGS/Entities/LabNotebookEntryContent/IEntryContentWithContent.py +38 -0
  126. LOGS/Entities/LabNotebookEntryContent/IEntryContentWithTextAttribute.py +16 -0
  127. LOGS/Entities/LabNotebookEntryContent/TextAttribute.py +46 -0
  128. LOGS/Entities/LabNotebookEntryContent/TextMarkAtributes.py +64 -0
  129. LOGS/Entities/LabNotebookEntryContent/TextMarkConverter.py +45 -0
  130. LOGS/Entities/LabNotebookEntryContent/TextMarks.py +71 -0
  131. LOGS/Entities/LabNotebookEntryContent/__init__.py +34 -0
  132. LOGS/Entities/LabNotebookEntryMinimal.py +8 -0
  133. LOGS/Entities/LabNotebookEntryRequestParameter.py +59 -0
  134. LOGS/Entities/LabNotebookExperiment.py +58 -0
  135. LOGS/Entities/LabNotebookExperimentMinimal.py +8 -0
  136. LOGS/Entities/LabNotebookExperimentRequestParameter.py +52 -0
  137. LOGS/Entities/LabNotebookExperiments.py +16 -0
  138. LOGS/Entities/LabNotebookMinimal.py +8 -0
  139. LOGS/Entities/LabNotebookModels.py +14 -0
  140. LOGS/Entities/LabNotebookRequestParameter.py +42 -0
  141. LOGS/Entities/LabNotebookTemplate.py +42 -0
  142. LOGS/Entities/LabNotebookTemplateMinimal.py +8 -0
  143. LOGS/Entities/LabNotebookTemplateRequestParameter.py +38 -0
  144. LOGS/Entities/LabNotebookTemplates.py +16 -0
  145. LOGS/Entities/LabNotebooks.py +12 -0
  146. LOGS/Entities/Method.py +66 -0
  147. LOGS/Entities/MethodMinimal.py +8 -0
  148. LOGS/Entities/MethodRequestParameter.py +16 -0
  149. LOGS/Entities/Methods.py +12 -0
  150. LOGS/Entities/Origin.py +53 -0
  151. LOGS/Entities/OriginMinimal.py +8 -0
  152. LOGS/Entities/OriginRequestParameter.py +28 -0
  153. LOGS/Entities/Origins.py +12 -0
  154. LOGS/Entities/ParserLog.py +49 -0
  155. LOGS/Entities/Permission.py +9 -0
  156. LOGS/Entities/Person.py +145 -0
  157. LOGS/Entities/PersonCategory.py +12 -0
  158. LOGS/Entities/PersonMinimal.py +8 -0
  159. LOGS/Entities/PersonRequestParameter.py +58 -0
  160. LOGS/Entities/Persons.py +12 -0
  161. LOGS/Entities/Project.py +52 -0
  162. LOGS/Entities/ProjectMinimal.py +8 -0
  163. LOGS/Entities/ProjectPersonPermission.py +102 -0
  164. LOGS/Entities/ProjectRequestParameter.py +58 -0
  165. LOGS/Entities/Projects.py +12 -0
  166. LOGS/Entities/Role.py +94 -0
  167. LOGS/Entities/RoleMinimal.py +8 -0
  168. LOGS/Entities/RoleRequestParameter.py +40 -0
  169. LOGS/Entities/Roles.py +12 -0
  170. LOGS/Entities/RunState.py +9 -0
  171. LOGS/Entities/Sample.py +53 -0
  172. LOGS/Entities/SampleMinimal.py +8 -0
  173. LOGS/Entities/SampleRequestParameter.py +54 -0
  174. LOGS/Entities/Samples.py +12 -0
  175. LOGS/Entities/SharedContent.py +87 -0
  176. LOGS/Entities/SharedContentMinimal.py +8 -0
  177. LOGS/Entities/SharedContentRequestParameter.py +38 -0
  178. LOGS/Entities/SharedContents.py +12 -0
  179. LOGS/Entities/Signature.py +60 -0
  180. LOGS/Entities/Track.py +93 -0
  181. LOGS/Entities/TrackData.py +20 -0
  182. LOGS/Entities/TrackImage.py +21 -0
  183. LOGS/Entities/TrackImageData.py +20 -0
  184. LOGS/Entities/TrackMatrix.py +28 -0
  185. LOGS/Entities/TrackMatrixData.py +22 -0
  186. LOGS/Entities/TrackSettings.py +55 -0
  187. LOGS/Entities/TrackTable.py +21 -0
  188. LOGS/Entities/TrackTableData.py +22 -0
  189. LOGS/Entities/TrackXY.py +40 -0
  190. LOGS/Entities/TrackXYComplex.py +51 -0
  191. LOGS/Entities/TrackXYComplexData.py +50 -0
  192. LOGS/Entities/TrackXYData.py +31 -0
  193. LOGS/Entities/Vendor.py +40 -0
  194. LOGS/Entities/VendorMinimal.py +8 -0
  195. LOGS/Entities/VendorRequestParameter.py +17 -0
  196. LOGS/Entities/Vendors.py +12 -0
  197. LOGS/Entities/__init__.py +118 -0
  198. LOGS/Entity/ConnectedEntity.py +170 -0
  199. LOGS/Entity/Entity.py +203 -0
  200. LOGS/Entity/EntityConnector.py +70 -0
  201. LOGS/Entity/EntityIterator.py +263 -0
  202. LOGS/Entity/EntityMinimal.py +141 -0
  203. LOGS/Entity/EntityMinimalWithIntId.py +36 -0
  204. LOGS/Entity/EntityMinimalWithStrId.py +36 -0
  205. LOGS/Entity/EntityMinimalWithType.py +47 -0
  206. LOGS/Entity/EntityRequestParameter.py +104 -0
  207. LOGS/Entity/EntitySortBy.py +69 -0
  208. LOGS/Entity/EntityWithIntId.py +26 -0
  209. LOGS/Entity/EntityWithStrId.py +26 -0
  210. LOGS/Entity/IGenericEntityOrderBy.py +55 -0
  211. LOGS/Entity/IdIterator.py +207 -0
  212. LOGS/Entity/SerializableContent.py +834 -0
  213. LOGS/Entity/__init__.py +23 -0
  214. LOGS/Interfaces/ICustomFieldValue.py +92 -0
  215. LOGS/Interfaces/ICustomSectionValue.py +161 -0
  216. LOGS/Interfaces/ICustomTypeValue.py +152 -0
  217. LOGS/Interfaces/ICustomValue.py +28 -0
  218. LOGS/Interfaces/IEntityInterface.py +7 -0
  219. LOGS/Interfaces/IEntryRecord.py +57 -0
  220. LOGS/Interfaces/IHierarchicalEntity.py +41 -0
  221. LOGS/Interfaces/IHierarchyType.py +63 -0
  222. LOGS/Interfaces/ILockableEntity.py +52 -0
  223. LOGS/Interfaces/IModificationRecord.py +56 -0
  224. LOGS/Interfaces/INamedEntity.py +25 -0
  225. LOGS/Interfaces/IOwnedEntity.py +27 -0
  226. LOGS/Interfaces/IPaginationRequest.py +11 -0
  227. LOGS/Interfaces/IPermissionedEntity.py +72 -0
  228. LOGS/Interfaces/IProjectBased.py +27 -0
  229. LOGS/Interfaces/ISessionedEntity.py +59 -0
  230. LOGS/Interfaces/ISignableEntity.py +49 -0
  231. LOGS/Interfaces/ISoftDeletable.py +28 -0
  232. LOGS/Interfaces/ITypedEntity.py +129 -0
  233. LOGS/Interfaces/IUniqueEntity.py +61 -0
  234. LOGS/Interfaces/IVersionedEntity.py +39 -0
  235. LOGS/Interfaces/__init__.py +7 -0
  236. LOGS/LOGS.py +1436 -0
  237. LOGS/LOGSConnection.py +647 -0
  238. LOGS/LOGSOptions.py +11 -0
  239. LOGS/Parameters/Color.py +92 -0
  240. LOGS/Parameters/ParameterBase.py +55 -0
  241. LOGS/Parameters/ParameterConverter.py +24 -0
  242. LOGS/Parameters/ParameterElement.py +99 -0
  243. LOGS/Parameters/ParameterList.py +52 -0
  244. LOGS/Parameters/ParameterTable.py +64 -0
  245. LOGS/Parameters/__init__.py +13 -0
  246. LOGS/ServerMetaData.py +120 -0
  247. LOGS/__init__.py +12 -0
  248. logs_py-4.0.7.dist-info/METADATA +51 -0
  249. logs_py-4.0.7.dist-info/RECORD +251 -0
  250. logs_py-4.0.7.dist-info/WHEEL +5 -0
  251. logs_py-4.0.7.dist-info/top_level.txt +1 -0
@@ -0,0 +1,341 @@
1
+ from typing import TYPE_CHECKING, Any, List, Optional, Type, TypeVar, Union, cast
2
+
3
+ from LOGS.Auxiliary.Constants import Constants
4
+ from LOGS.Auxiliary.Tools import Tools
5
+
6
+ if TYPE_CHECKING:
7
+ from LOGS.Auxiliary.LOGSErrorResponse import LOGSErrorResponse
8
+ from LOGS.Converter.Conversion import Conversion
9
+ from LOGS.Entity.ConnectedEntity import ConnectedEntity
10
+ from LOGS.Entity.Entity import Entity
11
+
12
+
13
+ class LOGSException(Exception):
14
+ title: Optional[str] = None
15
+ details: Optional[str] = None
16
+ status: Optional[int] = None
17
+ # type: Optional[str] = None
18
+
19
+ def __init__(
20
+ self,
21
+ message: Optional[Union[List[str], str]] = None,
22
+ responseError: Optional["LOGSErrorResponse"] = None,
23
+ ):
24
+ responseMessage = None
25
+ if responseError:
26
+ self._fromResponse(responseError)
27
+ responseMessage = "\n" + responseError.errorString()
28
+
29
+ if message:
30
+ if isinstance(message, list):
31
+ message = self.formatErrorMessage(message)
32
+ message = cast(str, message)
33
+ super().__init__(Tools.convertToNativeNewline(message))
34
+ elif responseMessage:
35
+ super().__init__(Tools.convertToNativeNewline(cast(str, responseMessage)))
36
+ else:
37
+ super().__init__()
38
+
39
+ @classmethod
40
+ def formatErrorMessage(cls, errors: List[str], indent: str = " " * 2):
41
+ indent *= 2
42
+ if len(errors) == 1:
43
+ return errors[0]
44
+ if len(errors) > 1:
45
+ return "\n" + indent + ("\n" + indent).join(errors)
46
+ else:
47
+ return ""
48
+
49
+ def _fromResponse(self, response: "LOGSErrorResponse"):
50
+ self.title = response.title if response.title else response.header
51
+ self.status = response.status
52
+
53
+
54
+ TEntity = TypeVar("TEntity", bound="Entity")
55
+
56
+
57
+ class LOGSMultilineException(LOGSException):
58
+ def __init__(
59
+ self,
60
+ errors: Optional[List[str]] = None,
61
+ responseError: Optional["LOGSErrorResponse"] = None,
62
+ ):
63
+ if not errors and responseError:
64
+ errors = responseError.errorStringList
65
+
66
+ super().__init__(
67
+ self._createMessage(errors=errors), responseError=responseError
68
+ )
69
+
70
+ @classmethod
71
+ def _createMessage(
72
+ cls,
73
+ errors: Optional[List[str]] = None,
74
+ ):
75
+ indent = Constants.exceptionIndentation
76
+ message = ""
77
+
78
+ indent *= 2
79
+
80
+ if errors:
81
+ message = errors.pop(0)
82
+
83
+ if errors:
84
+ message += "\n" + indent + ("\n" + indent).join(errors)
85
+
86
+ return message
87
+
88
+
89
+ class EntityIncompleteException(LOGSException):
90
+ def __init__(
91
+ self,
92
+ entity: Union["Entity", "ConnectedEntity"],
93
+ errors: Optional[List[str]] = None,
94
+ parameterName: Optional[str] = None,
95
+ functionName: Optional[str] = None,
96
+ responseError: Optional["LOGSErrorResponse"] = None,
97
+ hasFetchFull: bool = True,
98
+ ):
99
+ if not errors and responseError:
100
+ errors = responseError.errorStringList
101
+
102
+ super().__init__(
103
+ self._createMessage(
104
+ entity=entity,
105
+ errors=errors,
106
+ functionName=functionName,
107
+ parameterName=parameterName,
108
+ hasFetchFull=hasFetchFull,
109
+ ),
110
+ responseError=responseError,
111
+ )
112
+
113
+ def _createMessage(
114
+ self,
115
+ entity: Union["Entity", "ConnectedEntity"],
116
+ errors: Optional[List[str]] = None,
117
+ parameterName: Optional[str] = None,
118
+ functionName: Optional[str] = None,
119
+ hasFetchFull: bool = True,
120
+ ):
121
+ indent = Constants.exceptionIndentation
122
+ message = ""
123
+
124
+ name = f" '{parameterName}' " if parameterName else " "
125
+ func = []
126
+ if functionName:
127
+ func.append(f"'{functionName}'")
128
+
129
+ if hasFetchFull:
130
+ func.append(f"'fetchFull()'")
131
+
132
+ message = f"Additional field{name}of entity {entity.identifier} was not fetched for efficiency reasons. Use {' or '.join(func)} method to fetch this parameter"
133
+
134
+ indent *= 2
135
+ if errors:
136
+ message += self.formatErrorMessage(errors=errors, indent=indent)
137
+ # lines = errors.split("\n")
138
+ # if len(lines) > 1:
139
+ # message += ":\n" + indent + ("\n" + indent).join(lines)
140
+ # else:
141
+ # message += ": " + errors
142
+ else:
143
+ message += "."
144
+
145
+ return message
146
+
147
+
148
+ class EntityAPIException(LOGSException):
149
+ _action = "communicate"
150
+
151
+ def __init__(
152
+ self,
153
+ entity: Optional[Union[TEntity, List[TEntity]]] = None,
154
+ errors: Optional[List[str]] = None,
155
+ responseError: Optional["LOGSErrorResponse"] = None,
156
+ ):
157
+ if not errors and responseError:
158
+ errors = responseError.errorStringList
159
+
160
+ super().__init__(
161
+ self._createMessage(entity=entity, errors=errors),
162
+ responseError=responseError,
163
+ )
164
+
165
+ def _createMessage(
166
+ self,
167
+ entity: Optional[Union[TEntity, List[TEntity]]],
168
+ errors: Optional[List[str]] = None,
169
+ ):
170
+ from LOGS.Entity.Entity import Entity
171
+
172
+ indent = Constants.exceptionIndentation
173
+ message = ""
174
+ if isinstance(entity, list):
175
+ message = "%sCould not %s %s %a" % (
176
+ "\n" + indent if errors and len(errors) > 1 else "",
177
+ self._action,
178
+ Tools.plural("entity", entity),
179
+ Tools.eclipsesJoin(", ", [e.identifier for e in entity]),
180
+ )
181
+ elif isinstance(entity, Entity):
182
+ message = "Could not %s entity %a" % (self._action, entity.identifier)
183
+ else:
184
+ message = "%s entity failed" % Tools.gerundVerb(self._action.capitalize())
185
+
186
+ # indent *= 2
187
+ if errors:
188
+ message += ": " + self.formatErrorMessage(errors=errors, indent=indent)
189
+ # lines = error.split("\n")
190
+ # if len(lines) > 1:
191
+ # message += ":\n" + indent + ("\n" + indent).join(lines)
192
+ # else:
193
+ # message += ": " + error
194
+ else:
195
+ message += "."
196
+
197
+ return message
198
+
199
+
200
+ class EntityFetchingException(EntityAPIException):
201
+ _action = "fetch"
202
+
203
+
204
+ class EntityUpdatingException(EntityAPIException):
205
+ _action = "update"
206
+
207
+
208
+ class EntityCreatingException(EntityAPIException):
209
+ _action = "create"
210
+
211
+
212
+ class EntityDeletingException(LOGSException):
213
+ _action = "delete"
214
+
215
+ def __init__(
216
+ self,
217
+ entityIds: Optional[Union[Constants.ID_TYPE, List[Constants.ID_TYPE]]] = None,
218
+ errors: Optional[List[str]] = None,
219
+ responseError: Optional["LOGSErrorResponse"] = None,
220
+ ):
221
+ if not errors and responseError:
222
+ errors = responseError.errorStringList
223
+
224
+ super().__init__(
225
+ self._createMessage(entityIds=entityIds, errors=errors),
226
+ responseError=responseError,
227
+ )
228
+
229
+ def _createMessage(
230
+ self,
231
+ entityIds: Optional[Union[Constants.ID_TYPE, List[Constants.ID_TYPE]]],
232
+ errors: Optional[List[str]] = None,
233
+ ):
234
+ from LOGS.Entity.Entity import Entity
235
+
236
+ indent = Constants.exceptionIndentation
237
+ message = ""
238
+ if isinstance(entityIds, list):
239
+ message = "%sCould not %s %s %a" % (
240
+ "\n" + indent if errors and len(errors) > 1 else "",
241
+ self._action,
242
+ Tools.plural("entity", entityIds),
243
+ Tools.eclipsesJoin(", ", [str(id) for id in entityIds]),
244
+ )
245
+ elif isinstance(entityIds, Entity):
246
+ message = "Could not %s entity %a" % (self._action, entityIds.identifier)
247
+ else:
248
+ message = "%s entity failed" % (Tools.gerundVerb(self._action.capitalize()))
249
+
250
+ indent *= 2
251
+ if errors:
252
+ message += ": " + self.formatErrorMessage(errors=errors, indent=indent)
253
+ # lines = error.split("\n")
254
+ # if len(lines) > 1:
255
+ # message += ":\n" + indent + ("\n" + indent).join(lines)
256
+ # else:
257
+ # message += ": " + error
258
+ else:
259
+ message += "."
260
+
261
+ return message
262
+
263
+
264
+ class EntityNotFoundException(LOGSException):
265
+ def __init__(self, entity=None):
266
+ ident = ""
267
+ if entity:
268
+ ident = " " + str(entity.id)
269
+ name = entity.name
270
+ if name:
271
+ ident += " " + name
272
+ ident += " (id:%s)" % str(entity.id)
273
+
274
+ super().__init__("%s%s is not connected." % (type(entity).__name__, ident))
275
+
276
+
277
+ class NotConnectedException(LOGSException):
278
+ def __init__(self, message: Optional[str] = None):
279
+ if message:
280
+ super().__init__(message=message)
281
+ else:
282
+ super().__init__("Not connected.")
283
+
284
+
285
+ class EntityNotConnectedException(NotConnectedException):
286
+ def __init__(
287
+ self,
288
+ entity: Optional["ConnectedEntity"] = None,
289
+ identifier: Optional[str] = None,
290
+ ):
291
+ if entity:
292
+ super().__init__(
293
+ "Entity %a is not connected to a LOGS instance." % (entity.identifier)
294
+ )
295
+ elif identifier:
296
+ super().__init__(
297
+ "Entity %a is not connected to a LOGS instance." % (identifier)
298
+ )
299
+ else:
300
+ super().__init__("Entity is not connected to a LOGS instance.")
301
+
302
+
303
+ class TypedEntityNotConnectedException(NotConnectedException):
304
+ def __init__(
305
+ self,
306
+ entity: Union[Type["ConnectedEntity"], "ConnectedEntity"],
307
+ ):
308
+ from LOGS import LOGS
309
+
310
+ t = entity if isinstance(entity, type) else type(entity)
311
+
312
+ super().__init__(
313
+ f"Typed entity '{t.__name__}' is not connected to a LOGS instance. Please use {LOGS.__name__}().getEntityClass()."
314
+ )
315
+
316
+
317
+ class IllegalFieldValueException(LOGSException):
318
+
319
+ def __init__(
320
+ self,
321
+ entityType: Any,
322
+ fieldName: str,
323
+ value: Any,
324
+ errorMessage: Optional[str] = None,
325
+ ):
326
+ if isinstance(entityType, object):
327
+ t = type(entityType).__name__
328
+ elif isinstance(entityType, type) and issubclass(entityType, Entity):
329
+ t = entityType.__name__
330
+
331
+ m = f"Illegal value for field '{t}.{fieldName} = {value}'"
332
+ if errorMessage:
333
+ m += ":" + errorMessage
334
+ super().__init__(m)
335
+
336
+
337
+ class UnfinishedConversionException(LOGSException):
338
+ def __init__(self, conversion: "Conversion"):
339
+ super().__init__(
340
+ f"Conversion for dataset {conversion.datasetId} from format '{conversion.datasetFormat}' to format '{conversion.exportFormat}' is not finished yet."
341
+ )
@@ -0,0 +1,89 @@
1
+ from enum import Enum
2
+ from typing import Dict, Generic, List, Optional, Union
3
+
4
+ from typing_extensions import TypeVar
5
+
6
+ from LOGS.Auxiliary.Tools import Tools
7
+ from LOGS.Entity.SerializableContent import SerializableClass
8
+
9
+
10
+ class LogsErrorType(Enum):
11
+ EntityList = "EntityList"
12
+ ParameterValidation = "ParameterValidation"
13
+
14
+
15
+ class ILogsErrorClass(SerializableClass):
16
+ pass
17
+
18
+
19
+ _T = TypeVar("_T", bound=ILogsErrorClass)
20
+ _idType = TypeVar("_idType", bound=Union[int, str])
21
+
22
+
23
+ class EntityListErrorClass(Generic[_idType], ILogsErrorClass):
24
+ ids: List[_idType] = []
25
+ errors: List[str] = []
26
+
27
+
28
+ class LOGSErrorResponse(Generic[_T], SerializableClass):
29
+ _noSerialize = ["errorStringList", "details"]
30
+
31
+ header: Optional[str] = None
32
+ title: Optional[str] = None
33
+ status: Optional[int] = None
34
+ errorsType: Optional[LogsErrorType] = None
35
+ errorsClass: Optional[Dict] = None
36
+ errors: Optional[Union[Dict, List]] = None
37
+ details: Optional[str] = None
38
+
39
+ def _fieldToStr(self, d: Union[Dict, List], indentation: int = 0) -> List[str]:
40
+ tab = self._indentationString * indentation
41
+
42
+ if isinstance(d, list):
43
+ s = []
44
+ for v in d:
45
+ s.extend(self._fieldToStr(v, indentation))
46
+ return s
47
+ elif isinstance(d, dict):
48
+ s = []
49
+ nextTab = tab + self._indentationString
50
+ for k, v in d.items():
51
+ l = self._fieldToStr(v)
52
+ if l is None:
53
+ continue
54
+ if len(l) < 1:
55
+ s.append(f"{tab}{k}: <empty>")
56
+ if len(l) > 1:
57
+ s.append(f"{tab}{k}:")
58
+ s.extend([f"{nextTab}{i}" for i in l])
59
+ else:
60
+ s.append(f"{tab}{k}: {l[0]}")
61
+
62
+ return s
63
+
64
+ if d is None:
65
+ return None
66
+ return [str(d)]
67
+
68
+ def __str__(self):
69
+ s1 = f":{self.status}" if self.status else ""
70
+ s2 = f"'{Tools.truncString(self.title, 50)}'" if self.title else ""
71
+ return f"<{type(self).__name__}{s1} {s2}>"
72
+
73
+ def errorString(self, prefix: str = "") -> str:
74
+ return "\n".join(f"{prefix}{f}" for f in self.errorStringList)
75
+
76
+ @property
77
+ def errorStringList(self) -> List[str]:
78
+ errors: List[str] = []
79
+
80
+ if self.title:
81
+ errors.append(str(self.title))
82
+ elif self.header:
83
+ errors.append(str(self.header))
84
+
85
+ if self.errors:
86
+ errors.append(f"{self._indentationString}Details:")
87
+ errors.extend(self._fieldToStr(self.errors, 2))
88
+
89
+ return errors
@@ -0,0 +1,236 @@
1
+ from typing import TYPE_CHECKING, Any, Optional, Type
2
+
3
+ if TYPE_CHECKING:
4
+ from LOGS.LOGSConnection import LOGSConnection
5
+
6
+
7
+ class MinimalModelGenerator:
8
+ _entities = [
9
+ "Attachment",
10
+ "Bridge",
11
+ "Dataset",
12
+ "DataFormatInstrument",
13
+ "Method",
14
+ "DataFormat",
15
+ "Vendor",
16
+ "Notebook",
17
+ "NotebookExperiment",
18
+ "NotebookEntry",
19
+ "NotebookTemplate",
20
+ "LabNotebook",
21
+ "LabNotebookExperiment",
22
+ "LabNotebookEntry",
23
+ "Origin",
24
+ "Person",
25
+ "Project",
26
+ "Sample",
27
+ "SharedContent",
28
+ "InventoryItem",
29
+ "CustomType",
30
+ "CustomField",
31
+ ]
32
+
33
+ @classmethod
34
+ def createMapper(cls):
35
+ cls._mapper = {e: getattr(cls, f"get{e}MinimalClass")() for e in cls._entities}
36
+ cls._mapper.update({f"{e}Minimal": cls._mapper[e] for e in cls._entities})
37
+
38
+ @classmethod
39
+ def _typeByTypename(cls, typeName: str, fieldName: Optional[str]) -> Type:
40
+ if not hasattr(cls, "_mapper"):
41
+ cls.createMapper()
42
+
43
+ t = cls._mapper.get(typeName, None)
44
+ if not t:
45
+ raise ValueError(f"Unknown type '{typeName}' for field '{fieldName}'")
46
+ return t
47
+
48
+ @classmethod
49
+ def MinimalFromSingle(
50
+ cls,
51
+ value: Any,
52
+ fieldType: str,
53
+ fieldName: Optional[str],
54
+ connection: Optional["LOGSConnection"],
55
+ ) -> Any:
56
+ from LOGS.Entity.ConnectedEntity import ConnectedEntity
57
+
58
+ result = ConnectedEntity.checkAndConvertWithConnection(
59
+ value,
60
+ fieldType=cls._typeByTypename(fieldType, fieldName),
61
+ fieldName=fieldName,
62
+ allowNone=True,
63
+ connection=connection,
64
+ )
65
+
66
+ return result
67
+
68
+ @classmethod
69
+ def MinimalFromList(
70
+ cls,
71
+ value: Any,
72
+ fieldType: str,
73
+ fieldName: Optional[str],
74
+ connection: Optional["LOGSConnection"],
75
+ ) -> Any:
76
+ from LOGS.Entity.ConnectedEntity import ConnectedEntity
77
+
78
+ if isinstance(value, (int, str)):
79
+ value = {"id": value}
80
+
81
+ if isinstance(value, list):
82
+ l = []
83
+ for v in value:
84
+ if isinstance(v, (int, str)):
85
+ l.append({"id": v})
86
+ else:
87
+ l.append(v)
88
+ value = l
89
+
90
+ l = ConnectedEntity.checkListAndConvertWithConnection(
91
+ value,
92
+ fieldType=cls._typeByTypename(fieldType, fieldName),
93
+ fieldName=fieldName,
94
+ allowNone=True,
95
+ connection=connection,
96
+ )
97
+ result = [a for a in l if a]
98
+
99
+ if len(result) < 1:
100
+ return None
101
+
102
+ return result
103
+
104
+ @classmethod
105
+ def getAttachmentMinimalClass(cls):
106
+ from LOGS.Entities.AttachmentMinimal import AttachmentMinimal
107
+
108
+ return AttachmentMinimal
109
+
110
+ @classmethod
111
+ def getBridgeMinimalClass(cls):
112
+ from LOGS.Entities.BridgeMinimal import BridgeMinimal
113
+
114
+ return BridgeMinimal
115
+
116
+ @classmethod
117
+ def getDatasetMinimalClass(cls):
118
+ from LOGS.Entities.DatasetMinimal import DatasetMinimal
119
+
120
+ return DatasetMinimal
121
+
122
+ @classmethod
123
+ def getDataFormatInstrumentMinimalClass(cls):
124
+ from LOGS.Entities.DataFormatInstrumentMinimal import (
125
+ DataFormatInstrumentMinimal,
126
+ )
127
+
128
+ return DataFormatInstrumentMinimal
129
+
130
+ @classmethod
131
+ def getMethodMinimalClass(cls):
132
+ from LOGS.Entities.MethodMinimal import MethodMinimal
133
+
134
+ return MethodMinimal
135
+
136
+ @classmethod
137
+ def getDataFormatMinimalClass(cls):
138
+ from LOGS.Entities.DataFormatMinimal import DataFormatMinimal
139
+
140
+ return DataFormatMinimal
141
+
142
+ @classmethod
143
+ def getVendorMinimalClass(cls):
144
+ from LOGS.Entities.VendorMinimal import VendorMinimal
145
+
146
+ return VendorMinimal
147
+
148
+ @classmethod
149
+ def getNotebookMinimalClass(cls):
150
+ return cls.getLabNotebookMinimalClass()
151
+
152
+ @classmethod
153
+ def getLabNotebookMinimalClass(cls):
154
+ from LOGS.Entities.LabNotebookMinimal import LabNotebookMinimal
155
+
156
+ return LabNotebookMinimal
157
+
158
+ @classmethod
159
+ def getNotebookExperimentMinimalClass(cls):
160
+ return cls.getLabNotebookExperimentMinimalClass()
161
+
162
+ @classmethod
163
+ def getLabNotebookExperimentMinimalClass(cls):
164
+ from LOGS.Entities.LabNotebookExperimentMinimal import (
165
+ LabNotebookExperimentMinimal,
166
+ )
167
+
168
+ return LabNotebookExperimentMinimal
169
+
170
+ @classmethod
171
+ def getNotebookEntryMinimalClass(cls):
172
+ return cls.getLabNotebookEntryMinimalClass()
173
+
174
+ @classmethod
175
+ def getLabNotebookEntryMinimalClass(cls):
176
+ from LOGS.Entities.LabNotebookEntryMinimal import LabNotebookEntryMinimal
177
+
178
+ return LabNotebookEntryMinimal
179
+
180
+ @classmethod
181
+ def getNotebookTemplateMinimalClass(cls):
182
+ return cls.getLabNotebookTemplateMinimalClass()
183
+
184
+ @classmethod
185
+ def getLabNotebookTemplateMinimalClass(cls):
186
+ from LOGS.Entities.LabNotebookTemplateMinimal import LabNotebookTemplateMinimal
187
+
188
+ return LabNotebookTemplateMinimal
189
+
190
+ @classmethod
191
+ def getOriginMinimalClass(cls):
192
+ from LOGS.Entities.OriginMinimal import OriginMinimal
193
+
194
+ return OriginMinimal
195
+
196
+ @classmethod
197
+ def getPersonMinimalClass(cls):
198
+ from LOGS.Entities.PersonMinimal import PersonMinimal
199
+
200
+ return PersonMinimal
201
+
202
+ @classmethod
203
+ def getProjectMinimalClass(cls):
204
+ from LOGS.Entities.ProjectMinimal import ProjectMinimal
205
+
206
+ return ProjectMinimal
207
+
208
+ @classmethod
209
+ def getSampleMinimalClass(cls):
210
+ from LOGS.Entities.SampleMinimal import SampleMinimal
211
+
212
+ return SampleMinimal
213
+
214
+ @classmethod
215
+ def getSharedContentMinimalClass(cls):
216
+ from LOGS.Entities.SharedContentMinimal import SharedContentMinimal
217
+
218
+ return SharedContentMinimal
219
+
220
+ @classmethod
221
+ def getInventoryItemMinimalClass(cls):
222
+ from LOGS.Entities.InventoryItemMinimal import InventoryItemMinimal
223
+
224
+ return InventoryItemMinimal
225
+
226
+ @classmethod
227
+ def getCustomTypeMinimalClass(cls):
228
+ from LOGS.Entities.CustomTypeMinimal import CustomTypeMinimal
229
+
230
+ return CustomTypeMinimal
231
+
232
+ @classmethod
233
+ def getCustomFieldMinimalClass(cls):
234
+ from LOGS.Entities.CustomFieldMinimal import CustomFieldMinimal
235
+
236
+ return CustomFieldMinimal