iris-pex-embedded-python 3.1.6b2__py3-none-any.whl → 3.2.0__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 iris-pex-embedded-python might be problematic. Click here for more details.

iop/_utils.py CHANGED
@@ -6,6 +6,8 @@ import inspect
6
6
  import xmltodict
7
7
  import pkg_resources
8
8
  import importlib
9
+ import json
10
+ from dc_schema import get_schema
9
11
 
10
12
  class _Utils():
11
13
  @staticmethod
@@ -33,6 +35,33 @@ class _Utils():
33
35
  if path:
34
36
  _Utils.raise_on_error(iris.cls('%SYSTEM.OBJ').LoadDir(path,'cubk',"*.cls",1))
35
37
 
38
+ @staticmethod
39
+ def register_message_schema(cls):
40
+ """
41
+ It takes a class and registers the schema
42
+
43
+ :param cls: The class to register
44
+ """
45
+ schema = get_schema(cls)
46
+ schema_name = cls.__module__ + '.' + cls.__name__
47
+ schema_str = json.dumps(schema)
48
+ categories = schema_name
49
+ _Utils.register_schema(schema_name,schema_str,categories)
50
+
51
+ @staticmethod
52
+ def register_schema(schema_name:str, schema_str:str,categories:str):
53
+ """
54
+ It takes a schema name, a schema string, and a category string, and registers the schema
55
+
56
+ :param schema_name: The name of the schema
57
+ :type schema_name: str
58
+ :param schema_str: The schema as a string
59
+ :type schema_str: str
60
+ :param categories: The categories of the schema
61
+ :type categories: str
62
+ """
63
+ _Utils.raise_on_error(iris.cls('IOP.Message.JSONSchema').Import(schema_str,categories,schema_name))
64
+
36
65
  @staticmethod
37
66
  def register_component(module:str,classname:str,path:str,overwrite:int=1,iris_classname:str='Python'):
38
67
  """
@@ -128,7 +157,7 @@ class _Utils():
128
157
  extend = klass.bases[0].id
129
158
  else:
130
159
  extend = klass.bases[0].attr
131
- if extend in ('BusinessOperation','BusinessProcess','BusinessService','DuplexService','DuplexProcess','DuplexOperation','InboundAdapter','OutboundAdapter'):
160
+ if extend in ('BusinessOperation','BusinessProcess','BusinessService','DuplexService','DuplexProcess','DuplexOperation','InboundAdapter','OutboundAdapter'):
132
161
  module = _Utils.filename_to_module(filename)
133
162
  iris_class_name = f"{iris_package_name}.{module}.{klass.name}"
134
163
  # strip "_" for iris class name
@@ -188,6 +217,8 @@ class _Utils():
188
217
  list of dictionaries:
189
218
  * key: the name of the production
190
219
  * value: a dictionary containing the settings for the production
220
+ * SCHEMAS
221
+ List of classes
191
222
  """
192
223
  path = None
193
224
  # try to load the settings file
@@ -216,6 +247,12 @@ class _Utils():
216
247
  _Utils.set_productions_settings(settings.PRODUCTIONS,path)
217
248
  except AttributeError:
218
249
  print("No productions to register")
250
+ try:
251
+ # set the schemas
252
+ for cls in settings.SCHEMAS:
253
+ _Utils.register_message_schema(cls)
254
+ except AttributeError:
255
+ print("No schemas to register")
219
256
  try:
220
257
  sys.path.remove(path)
221
258
  except ValueError:
@@ -0,0 +1,125 @@
1
+ Class IOP.Message.JSONSchema Extends %Persistent
2
+ {
3
+
4
+ Property Name As %String;
5
+
6
+ Property Category As %String;
7
+
8
+ Property JSONSchema As %String(MAXLEN = "");
9
+
10
+ Index NameIndex On Name [ IdKey, Unique ];
11
+
12
+ /// Import a JSON Schema from file
13
+ ClassMethod ImportFromFile(
14
+ pFileName As %String,
15
+ pCategory As %String = "",
16
+ pName As %String) As %Status
17
+ {
18
+ Set pStatus = $$$OK
19
+ Try {
20
+ If '##class(%File).Exists(pFileName) {
21
+ Set pStatus = $$$ERROR($$$GeneralError, "File not found")
22
+ Return pStatus
23
+ }
24
+ Set tFile = ##class(%File).%New(pFileName)
25
+ $$$ThrowOnError(tFile.Open("R"))
26
+ Set tSchema = ""
27
+ While 'tFile.AtEnd {
28
+ Set tSchema = tSchema _ tFile.ReadLine()
29
+ }
30
+ Set pStatus = ..Import(tSchema, pCategory, pName)
31
+ } Catch ex {
32
+ Set pStatus = ex.AsStatus()
33
+ }
34
+ Return pStatus
35
+ }
36
+
37
+ /// Store the JSON Schema in this object
38
+ ClassMethod Import(
39
+ pSchema As %String,
40
+ pCategory As %String = "",
41
+ pName As %String) As %Status
42
+ {
43
+ Set pStatus = $$$OK
44
+ Try {
45
+ if ##class(IOP.Message.JSONSchema).%ExistsId(pName) {
46
+ Set tThis = ##class(IOP.Message.JSONSchema).%OpenId(pName)
47
+ Set tThis.Category = pCategory
48
+ Set tThis.JSONSchema = pSchema
49
+ $$$ThrowOnError(tThis.%Save())
50
+ } Else {
51
+ Set tThis = ##class(IOP.Message.JSONSchema).%New()
52
+ Set tThis.Name = pName
53
+ Set tThis.Category = pCategory
54
+ Set tThis.JSONSchema = pSchema
55
+ $$$ThrowOnError(tThis.%Save())
56
+ }
57
+ } Catch ex {
58
+ Set pStatus = ex.AsStatus()
59
+ }
60
+ Quit pStatus
61
+ }
62
+
63
+ /// Get a stored schema by category and name
64
+ ClassMethod GetSchema(
65
+ pName As %String = "",
66
+ Output pSchema As %String) As %Status
67
+ {
68
+ Set pStatus = $$$OK
69
+ Try {
70
+ Set tSql = "SELECT JSONSchema FROM IOP_Message.JSONSchema WHERE Name = ?"
71
+ Set tStatement = ##class(%SQL.Statement).%New()
72
+ Do tStatement.%Prepare(tSql)
73
+ set rs = tStatement.%Execute(pName)
74
+ If rs.%Next() {
75
+ Set pSchema = rs.%Get("JSONSchema")
76
+ } Else {
77
+ Set pStatus = $$$ERROR($$$GeneralError, "Schema not found")
78
+ }
79
+ } Catch ex {
80
+ Set pStatus = ex.AsStatus()
81
+ }
82
+ Return pStatus
83
+ }
84
+
85
+ /// Validate JSON data against a stored schema
86
+ ClassMethod ValidateJSONSchema(
87
+ pJSON As %String,
88
+ pName As %String) As %Status
89
+ {
90
+ Set tSC = $$$OK
91
+ Try {
92
+ Set tSchema = ""
93
+ Set tSC = ..GetSchema(pName, .tSchema)
94
+ If $$$ISERR(tSC) Return tSC
95
+ // Validate JSON data against schema
96
+ // To be implemented
97
+ Set tSC = $$$OK
98
+ } Catch ex {
99
+ Set tSC = ex.AsStatus()
100
+ }
101
+ Return tSC
102
+ }
103
+
104
+ Storage Default
105
+ {
106
+ <Data name="JSONSchemaDefaultData">
107
+ <Value name="1">
108
+ <Value>%%CLASSNAME</Value>
109
+ </Value>
110
+ <Value name="2">
111
+ <Value>JSONSchema</Value>
112
+ </Value>
113
+ <Value name="3">
114
+ <Value>Category</Value>
115
+ </Value>
116
+ </Data>
117
+ <DataLocation>^IOP.Message.JSONSchemaD</DataLocation>
118
+ <DefaultData>JSONSchemaDefaultData</DefaultData>
119
+ <IdLocation>^IOP.Message.JSONSchemaD</IdLocation>
120
+ <IndexLocation>^IOP.Message.JSONSchemaI</IndexLocation>
121
+ <StreamLocation>^IOP.Message.JSONSchemaS</StreamLocation>
122
+ <Type>%Storage.Persistent</Type>
123
+ }
124
+
125
+ }
iop/cls/IOP/Message.cls CHANGED
@@ -1,6 +1,12 @@
1
- Class IOP.Message Extends (Ens.MessageBody, %CSP.Page, %XML.Adaptor)
1
+ Class IOP.Message Extends (Ens.MessageBody, %CSP.Page, Ens.VDoc.Interface)
2
2
  {
3
3
 
4
+ Parameter DOCCLASSNAME = "JSON Document";
5
+
6
+ Parameter DOCCLASSFULLNAME = "JSON Virtual Document";
7
+
8
+ Parameter DOCSHORTNAME = "JSON";
9
+
4
10
  Parameter BUFFER = 1000000;
5
11
 
6
12
  Property buffer As %String(MAXLEN = "") [ Calculated, Transient ];
@@ -21,6 +27,511 @@ Property jstr As %Stream.GlobalCharacter [ Internal, Private ];
21
27
 
22
28
  Property type As %String(MAXLEN = 6) [ ReadOnly ];
23
29
 
30
+ /// Gets the next index in an array
31
+ Method GetNextIndex(
32
+ pPath As %String,
33
+ pIndex As %String,
34
+ ByRef pStatus As %Status = {$$$OK}) As %String
35
+ {
36
+ Set f=$F(pPath,"()") If 'f Set pStatus=$$$ERROR($$$EnsErrGeneral,"Can't iterate on no-array type '"_pPath_"'") Quit ""
37
+ if pIndex="" Set pIndex=0
38
+ Set tValue = ..GetValueAt($EXTRACT(pPath, 1, $LENGTH(pPath)-2))
39
+ Set builtins = ##class(%SYS.Python).Builtins()
40
+ if pIndex>=builtins.len(tValue) Quit ""
41
+ Quit pIndex+1
42
+ }
43
+
44
+ Method GetValueAt(
45
+ pPropertyPath As %String = "",
46
+ pFormat As %String,
47
+ Output pStatus As %Status,
48
+ pDummy As %Boolean) As %String
49
+ {
50
+ Set pStatus = $$$OK
51
+ Try {
52
+ // Handle standard path queries
53
+ If pPropertyPath = "" Return ""
54
+
55
+ // pPropertyPath is formatted as :
56
+ // 1. "property1.property2.property3" for nested properties
57
+ // 2. "property1()" for all elements of an array or property1(*)
58
+ // 3. "property1(index).property2" for nested properties within an array
59
+ // 4. "property1(index)" for a specific element of an array
60
+
61
+ // Convert pPropertyPath to a a jsonpath
62
+ Set tPath = ..ConvertPath(pPropertyPath)
63
+
64
+ Set pyjson = ##class(%SYS.Python).Import("json")
65
+ Set jp = ##class(%SYS.Python).Import("jsonpath_ng")
66
+ Set builtins = ##class(%SYS.Python).Builtins()
67
+
68
+ Set tJSON = pyjson.loads(..json)
69
+ Set parser = jp.parse(tPath)
70
+ Set matches = parser.find(tJSON)
71
+
72
+ Set tResult = ""
73
+ // Return the first match
74
+ if matches."__len__"() = 1 {
75
+ Set match = matches."__getitem__"(0)
76
+ Set tResult = match."value"
77
+ }
78
+ ElseIf matches."__len__"() > 1 {
79
+ Set tResult = builtins.list()
80
+ For i=0:1:matches."__len__"()-1 {
81
+ Set match = matches."__getitem__"(i)
82
+ Do tResult.append(match."value")
83
+ }
84
+ }
85
+
86
+ Return tResult
87
+
88
+ } Catch ex {
89
+ Set pStatus = ex.AsStatus()
90
+ Return ""
91
+ }
92
+ }
93
+
94
+ ClassMethod ConvertPath(pPropertyPath As %String) As %String
95
+ {
96
+ // Convert pPropertyPath to a jsonpath just by replacing
97
+ // - '()' with '[*]'
98
+ // - '(index)' with '[index]'
99
+ // - '(' with '[' and ')' with ']'
100
+ // - if index is an integer, replace it with [index-1]
101
+ Set tPath = pPropertyPath
102
+ Set tPath = $Replace(tPath, "()", "[*]")
103
+ Set tPath = $Replace(tPath, "(", "[")
104
+ Set tPath = $Replace(tPath, ")", "]")
105
+ // Process each [] occurrence in the path
106
+ Set tPath = ..ProcessBrackets(tPath)
107
+
108
+ Return tPath
109
+ }
110
+
111
+ ClassMethod ProcessBrackets(pPath As %String) As %String
112
+ {
113
+ Set tPath = pPath
114
+ Set start = $Find(tPath, "[")
115
+ While start {
116
+ Set end = $Find(tPath, "]", start)
117
+ If 'end Quit // No matching closing bracket
118
+
119
+ // Extract the index between [ and ]
120
+ Set tIndex = $Extract(tPath, start, end-2)
121
+
122
+ // If index is numeric, decrease by 1 (0-based indexing)
123
+ If +tIndex {
124
+ Set newPath = $Extract(tPath, 1, start-1)
125
+ Set newPath = newPath _ (tIndex-1)
126
+ Set newPath = newPath _ $Extract(tPath, end-1, *)
127
+ Set tPath = newPath
128
+ }
129
+
130
+ // Move past this [] pair for next iteration
131
+ Set start = $Find(tPath, "[", end)
132
+ }
133
+ Return tPath
134
+ }
135
+
136
+ Method CopyValues(
137
+ pSource As Ens.VDoc.Interface,
138
+ pSourcePath As %String,
139
+ pTargetPath As %String,
140
+ pAction As %String,
141
+ pKey As %String,
142
+ pEmptyFieldAsNull As %Boolean = 0,
143
+ pIgnoreMissingSource As %Boolean = 0,
144
+ pGenerateEmptySegments As %Boolean = 0) As %Status
145
+ {
146
+ Set tSC = $$$OK
147
+ Try {
148
+ // Get source value
149
+ Set tValue = pSource.GetValueAt(pSourcePath, "String", .tSC, 0)
150
+ Return:$$$ISERR(tSC) tSC
151
+
152
+ // Set target value
153
+ Set tSC = ..SetValueAt(tValue, pTargetPath, pAction, pKey)
154
+ } Catch ex {
155
+ Set tSC = ex.AsStatus()
156
+ }
157
+ Return tSC
158
+ }
159
+
160
+ /// Sets a value at the specified property path in the JSON document
161
+ /// @param pValue Value to set
162
+ /// @param pPropertyPath Path to the property (e.g. "property1.property2" or "array()")
163
+ /// @param pAction Action to perform ("set", "append", "remove", "insert")
164
+ /// @param pKey Optional key for specialized operations, required for insert
165
+ /// @returns %Status
166
+ Method SetValueAt(
167
+ pValue As %String = "",
168
+ pPropertyPath As %String = "",
169
+ pAction As %String = "set",
170
+ pKey As %String = "") As %Status
171
+ {
172
+ Set tSC = $$$OK
173
+ Try {
174
+ // Validate input parameters
175
+ If pPropertyPath = "" Return $$$ERROR($$$GeneralError, "Property path cannot be empty")
176
+ If '$LISTFIND($LISTBUILD("set","append","remove","insert"), pAction) Return $$$ERROR($$$GeneralError, "Invalid action: "_pAction)
177
+ If (pAction = "insert") && (pKey = "") Return $$$ERROR($$$GeneralError, "Key is required for insert action")
178
+
179
+ // Initialize Python objects
180
+ Set pyjson = ##class(%SYS.Python).Import("json")
181
+ Set jp = ##class(%SYS.Python).Import("jsonpath_ng")
182
+ Set builtins = ##class(%SYS.Python).Builtins()
183
+
184
+ // Handle append operations
185
+ Set tAppend = (pAction = "append")
186
+ If tAppend, $EXTRACT(pPropertyPath, *-1, *) = "()" {
187
+ Set pPropertyPath = $EXTRACT(pPropertyPath, 1, *-2)
188
+ }
189
+
190
+ // Initialize empty JSON if needed
191
+ Set:..json="" ..json = "{}"
192
+
193
+ // Parse JSON and prepare path
194
+ Set tJSON = pyjson.loads(..json)
195
+ Set tPath = ..ConvertPath(pPropertyPath)
196
+ Set parser = jp.parse(tPath)
197
+
198
+ If pAction = "set" {
199
+ // Simple set operation
200
+ Set tJSON = parser."update_or_create"(tJSON, pValue)
201
+ }
202
+ ElseIf pAction = "remove" {
203
+ // Remove operation
204
+ Set matches = parser.find(tJSON)
205
+ If matches."__len__"() > 0 {
206
+ // Not yet implemented
207
+ Set tSC = $$$ERROR($$$GeneralError, "Remove operation not yet implemented")
208
+ }
209
+ }
210
+ ElseIf pAction = "insert" {
211
+ // Handle dictionary insert/update
212
+ Set matches = parser.find(tJSON)
213
+ If matches."__len__"() = 0 {
214
+ // Create new dictionary if path doesn't exist
215
+ Set tDict = builtins.dict()
216
+ Do tDict."__setitem__"(pKey, pValue)
217
+ Set tJSON = parser."update_or_create"(tJSON, tDict)
218
+ }
219
+ Else {
220
+ // Update existing dictionary
221
+ Set tDict = matches."__getitem__"(0)."value"
222
+ Do tDict."__setitem__"(pKey, pValue)
223
+ Set tJSON = parser."update"(tJSON, tDict)
224
+ }
225
+ }
226
+ ElseIf tAppend {
227
+ // Handle append operation
228
+ Set tFindValue = parser."find"(tJSON)
229
+ If tFindValue."__len__"() = 0 {
230
+ // Create new array if path doesn't exist
231
+ Set:(tAppend) tValue = builtins.list()
232
+ Do:tAppend tValue.append(pValue)
233
+ Set tJSON = parser."update_or_create"(tJSON, $Select(tAppend: tValue, 1: pValue))
234
+ }
235
+ Else {
236
+ // Append to existing array
237
+ Do tFindValue."__getitem__"(0)."value".append(pValue)
238
+ Set tJSON = parser."update"(tJSON, tFindValue."__getitem__"(0)."value")
239
+ }
240
+ }
241
+
242
+ // Update JSON storage
243
+ Set ..json = pyjson.dumps(tJSON)
244
+ Set ..classname = ..DocType
245
+
246
+ }
247
+ Catch ex {
248
+ Set tSC = ex.AsStatus()
249
+ // Log error details
250
+ $$$LOGWARNING("Error in SetValueAt: "_$System.Status.GetErrorText(tSC))
251
+ }
252
+
253
+ Return tSC
254
+ }
255
+
256
+ Method IsValid() As %Status
257
+ {
258
+ Return $$$OK
259
+ }
260
+
261
+ Method Validate(pValidationSpec As %String = "") As %Status
262
+ {
263
+ If ..DocType = "" Return $$$ERROR($$$GeneralError, "No DocType specified")
264
+
265
+ // Validate against stored schema
266
+ Return ##class(IOP.Message.JSONSchema).ValidateJSON(tJSON, ..DocTypeCategory, ..DocTypeName)
267
+ }
268
+
269
+ Method ParentMany(Output pParentsList) As %Integer
270
+ {
271
+ Return 0
272
+ }
273
+
274
+ /// Returns a list of available DocTypes by querying the JSONSchema storage.
275
+ Query EnumerateDocTypes(
276
+ Category As %String = "",
277
+ IncludeBase As %Boolean = 0) As %Query(CONTAINID = 0, ROWSPEC = "Type:%String")
278
+ {
279
+ }
280
+
281
+ ClassMethod EnumerateDocTypesExecute(
282
+ ByRef qHandle As %Binary,
283
+ pName As %String = "",
284
+ IncludeBase As %Boolean) As %Status
285
+ {
286
+ Kill qHandle
287
+ Set qHandle = 0
288
+ Set sql = "SELECT Name FROM IOP_Message.JSONSchema"
289
+ If pName '= "" {
290
+ Set sql = sql _ " WHERE Name = ?"
291
+ }
292
+
293
+ Set stmt = ##class(%SQL.Statement).%New()
294
+ Set tSC = stmt.%Prepare(sql)
295
+ Quit:$$$ISERR(tSC) tSC
296
+
297
+ If pName '= "" {
298
+ Set rs = stmt.%Execute(pName)
299
+ } Else {
300
+ Set rs = stmt.%Execute()
301
+ }
302
+ While rs.%Next() {
303
+ Set qHandle($I(qHandle)) = rs.%Get("Name")
304
+ }
305
+ set qHandle = 0
306
+ Quit $$$OK
307
+ }
308
+
309
+ ClassMethod EnumerateDocTypesFetch(
310
+ ByRef qHandle As %Binary,
311
+ ByRef qRow As %List,
312
+ ByRef AtEnd As %Integer = 0) As %Status
313
+ {
314
+ Set qHandle = $O(qHandle(qHandle))
315
+ If qHandle = "" {
316
+ Set qRow = "", AtEnd = 1
317
+ Quit $$$OK
318
+ }
319
+ Set qRow = $LB(qHandle(qHandle))
320
+ Quit $$$OK
321
+ }
322
+
323
+ ClassMethod EnumerateDocTypesClose(ByRef qHandle As %Binary) As %Status
324
+ {
325
+ Kill qHandle
326
+ Quit $$$OK
327
+ }
328
+
329
+ /// Returns a list of schema categories from the JSONSchema storage.
330
+ Query EnumerateTypeCategories(Standard As %String = "") As %Query(CONTAINID = 0, ROWSPEC = "Category:%String,Description:%String,IsStandard:%Boolean,Base:%String")
331
+ {
332
+ }
333
+
334
+ ClassMethod EnumerateTypeCategoriesExecute(
335
+ ByRef qHandle As %Binary,
336
+ pStandard As %String = "") As %Status
337
+ {
338
+ Kill qHandle
339
+ Set qHandle = 0
340
+ Set sql = "SELECT Category, Name FROM IOP_Message.JSONSchema"
341
+
342
+ Set stmt = ##class(%SQL.Statement).%New()
343
+ Set tSC = stmt.%Prepare(sql)
344
+ Quit:$$$ISERR(tSC) tSC
345
+
346
+ Set rs = stmt.%Execute()
347
+
348
+ While rs.%Next() {
349
+ Set category = rs.%Get(1)
350
+ // Format: Category, Description, IsStandard, Base
351
+ Set qHandle($I(qHandle)) = $LB(category, "JSON Schema category", "IsStandard", "Base")
352
+ }
353
+ Set qHandle = 0
354
+ Quit $$$OK
355
+ }
356
+
357
+ ClassMethod EnumerateTypeCategoriesFetch(
358
+ ByRef qHandle As %Binary,
359
+ ByRef Row As %List,
360
+ ByRef AtEnd As %Integer = 0) As %Status
361
+ {
362
+ Set qHandle = $O(qHandle(qHandle))
363
+ If qHandle = "" {
364
+ Set Row = "", AtEnd = 1
365
+ Quit $$$OK
366
+ }
367
+ Set Row = qHandle(qHandle)
368
+ Quit $$$OK
369
+ }
370
+
371
+ ClassMethod EnumerateTypeCategoriesClose(ByRef qHandle As %Binary) As %Status
372
+ {
373
+ Kill qHandle
374
+ Quit $$$OK
375
+ }
376
+
377
+ /// Returns array of properties that make up the <i>contents</i>
378
+ /// of this object.<br>
379
+ /// This method in implemented within the document class.<br>
380
+ /// The content array is in the form:<br>
381
+ /// pContents(n,"type")="%String"<br>
382
+ /// pContents(n,"name")="Field"<br>
383
+ /// pContents(n,"alias")=alias code<br>
384
+ /// If pContents(n) is non-zero then the property is a composite type with<br>
385
+ /// sub-properties. The sub-properties are indexed with a similar structure under<br>
386
+ /// pContents(n,m) where m is the index of the subtype property.<br>
387
+ ClassMethod GetContentArray(
388
+ Output pContents,
389
+ pMode As %String,
390
+ pDocType As %String = "MESSAGE",
391
+ pLevel As %Integer,
392
+ pIncludeBase As %Boolean = 0) As %Status
393
+ {
394
+ Set tSC = $$$OK
395
+ Try {
396
+ // Get schema structure
397
+ Set tName = pDocType
398
+ #; Set tName = $Piece(pDocType, ":", 2)
399
+
400
+ Set tSC = ##class(IOP.Message.JSONSchema).GetSchema(tName, .json)
401
+ If $$$ISERR(tSC) Return tSC
402
+ set schema = {}.%FromJSON(json)
403
+
404
+ $$$ThrowOnError(##class(IOP.Message).SchemaToContents(schema, .tContents))
405
+
406
+ Merge @pContents = tContents
407
+ }
408
+ Catch ex {
409
+ Set tSC = ex.AsStatus()
410
+ }
411
+ Return $$$OK
412
+ }
413
+
414
+ /// Convert a JSON schema structure into a contents array format
415
+ /// schema: Dynamic object containing the JSON schema
416
+ /// Output pContents: Array to store the contents structure
417
+ /// Returns: %Status
418
+ ClassMethod SchemaToContents(
419
+ schema As %DynamicObject,
420
+ Output pContents) As %Status
421
+ {
422
+ Set tSC = $$$OK
423
+ Try {
424
+ Set idx = 0
425
+ Do ..ProcessProperties(schema.properties, .idx, .pContents, schema)
426
+ }
427
+ Catch ex {
428
+ Set tSC = ex.AsStatus()
429
+ }
430
+ Return tSC
431
+ }
432
+
433
+ ClassMethod ProcessProperties(
434
+ properties As %DynamicObject,
435
+ ByRef idx As %Integer,
436
+ Output pContents,
437
+ schema As %DynamicObject) As %Status
438
+ {
439
+ Set iterator = properties.%GetIterator()
440
+ While iterator.%GetNext(.key, .value) {
441
+ Set idx = idx + 1
442
+ Do ..HandleProperty(value, .key, idx, .pContents, schema)
443
+ }
444
+ Return $$$OK
445
+ }
446
+
447
+ ClassMethod HandleProperty(
448
+ value As %DynamicObject,
449
+ ByRef key As %String,
450
+ idx As %Integer,
451
+ Output pContents,
452
+ schema As %DynamicObject)
453
+ {
454
+ Set type = value.type
455
+
456
+ If type = "string" || type = "number" || type = "boolean" {
457
+ Do ..HandlePrimitiveType(type, idx, .pContents)
458
+ }
459
+ ElseIf type = "array" {
460
+ Do ..HandleArrayType(value, .key, idx, .pContents, schema)
461
+ }
462
+ ElseIf type = "object" {
463
+ Do ..HandleObjectType(value, idx, .pContents)
464
+ }
465
+ ElseIf $IsObject(value.allOf) {
466
+ Do ..HandleAllOfType(value, key, idx, .pContents, schema)
467
+ }
468
+
469
+ If type = "array" Set key = key_"()"
470
+ Set pContents(idx,"name") = key
471
+ Set pContents(idx,"alias") = key
472
+ }
473
+
474
+ ClassMethod HandlePrimitiveType(
475
+ type As %String,
476
+ idx As %Integer,
477
+ Output pContents)
478
+ {
479
+ Set pContents(idx,"type") = $Case(type,
480
+ "string": "%String",
481
+ "number": "%Numeric",
482
+ "boolean": "%Boolean")
483
+ }
484
+
485
+ ClassMethod HandleArrayType(
486
+ value As %DynamicObject,
487
+ ByRef key As %String,
488
+ idx As %Integer,
489
+ Output pContents,
490
+ schema As %DynamicObject)
491
+ {
492
+ Set pContents(idx,"type") = "()"
493
+ If $IsObject(value.items) && $IsObject(value.items.allOf) {
494
+ Do ..HandleAllOfType(value.items, key, idx, .pContents, schema)
495
+ }
496
+ }
497
+
498
+ ClassMethod HandleObjectType(
499
+ value As %DynamicObject,
500
+ idx As %Integer,
501
+ Output pContents)
502
+ {
503
+ Set pContents(idx,"type") = "object"
504
+ If $IsObject(value.properties) {
505
+ Do ..SchemaToContents(value, .subContents)
506
+ Merge @pContents(idx) = subContents
507
+ }
508
+ }
509
+
510
+ ClassMethod HandleAllOfType(
511
+ value As %DynamicObject,
512
+ key As %String,
513
+ idx As %Integer,
514
+ Output pContents,
515
+ schema As %DynamicObject)
516
+ {
517
+ Set pContents(idx) = 1 //TODO size of subContents
518
+ Set pContents(idx,"type") = "object"
519
+ Set pContents(idx,"name") = key
520
+ Set pContents(idx,"alias") = key
521
+
522
+ Set allOfIterator = value.allOf.%GetIterator()
523
+ While allOfIterator.%GetNext(.allOfKey, .allOfValue) {
524
+ If $IsObject(allOfValue."$ref") {
525
+ Do ..SchemaToContents(allOfValue."$ref", .subContents)
526
+ }
527
+ Else {
528
+ Set tDef = schema."$defs".%Get($Piece(allOfValue."$ref","/",*))
529
+ Do ..SchemaToContents(tDef, .subContents)
530
+ }
531
+ Merge pContents(idx) = subContents
532
+ }
533
+ }
534
+
24
535
  Method bufferGet()
25
536
  {
26
537
  Quit ..#BUFFER
@@ -185,6 +696,26 @@ Storage Default
185
696
  <Value name="6">
186
697
  <Value>jsonString</Value>
187
698
  </Value>
699
+ <Value name="7">
700
+ <Value>DocType</Value>
701
+ </Value>
702
+ <Value name="8">
703
+ <Value>TimeCreated</Value>
704
+ </Value>
705
+ <Value name="9">
706
+ <Value>Source</Value>
707
+ </Value>
708
+ <Value name="10">
709
+ <Value>IsMutable</Value>
710
+ </Value>
711
+ <Value name="11">
712
+ <Value>OriginalDocId</Value>
713
+ </Value>
714
+ </Data>
715
+ <Data name="UserValues">
716
+ <Attribute>UserValues</Attribute>
717
+ <Structure>subnode</Structure>
718
+ <Subscript>"IOP.Message.UserValues"</Subscript>
188
719
  </Data>
189
720
  <Data name="jsonObject">
190
721
  <Attribute>jsonObject</Attribute>
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: iris_pex_embedded_python
3
- Version: 3.1.6b2
3
+ Version: 3.2.0
4
4
  Summary: Iris Interoperability based on Embedded Python
5
5
  Author-email: grongier <guillaume.rongier@intersystems.com>
6
6
  License: MIT License
@@ -48,6 +48,8 @@ Requires-Dist: dacite>=1.6.0
48
48
  Requires-Dist: xmltodict>=0.12.0
49
49
  Requires-Dist: iris-embedded-python-wrapper>=0.0.6
50
50
  Requires-Dist: setuptools>=40.8.0
51
+ Requires-Dist: dc-schema>=0.0.8
52
+ Requires-Dist: jsonpath-ng>=1.7.0
51
53
 
52
54
  # IoP (Interoperability On Python)
53
55
 
@@ -105,14 +105,14 @@ iop/_outbound_adapter.py,sha256=YTAhLrRf9chEAd53mV6KKbpaHOKNOKJHoGgj5wakRR0,726
105
105
  iop/_pickle_message.py,sha256=noKfc2VkXufV3fqjKvNHN_oANQ1YN9ffCaSV0XSTAIE,331
106
106
  iop/_private_session_duplex.py,sha256=36OwAGlasbPtfwq2KgMFcr3a33RsNSqohJx243XcDWI,5153
107
107
  iop/_private_session_process.py,sha256=pGjWFOQhWpQxUVpTtvNKTPvDxgzjfw0VC4Aqj3KUq8w,1704
108
- iop/_utils.py,sha256=b1vFnAXbcNV4uN9zojIeSeLgr0CuSt9bBgguZra0ve8,18105
108
+ iop/_utils.py,sha256=c59QrgQgrk528V_n6RInnq_N6RzIGAAEmaTGRwanTSI,19404
109
109
  iop/cls/IOP/BusinessOperation.cls,sha256=lrymqZ8wHl5kJjXwdjbQVs5sScV__yIWGh-oGbiB_X0,914
110
110
  iop/cls/IOP/BusinessProcess.cls,sha256=s3t38w1ykHqM26ETcbCYLt0ocjZyVVahm-_USZkuJ1E,2855
111
111
  iop/cls/IOP/BusinessService.cls,sha256=7ebn32J9PiZXUgXuh5Xxm_7X6zHBiqkJr9c_dWxbPO8,1021
112
112
  iop/cls/IOP/Common.cls,sha256=4f4ZpLj8fsj8IKJDNb9pKoCokzo522JHWX0OqpAaC5g,11192
113
113
  iop/cls/IOP/Director.cls,sha256=M43LoTb6lwSr0J81RFxi1YLW1mwda09wQ7Xqr3nBtxo,2008
114
114
  iop/cls/IOP/InboundAdapter.cls,sha256=GeoCm6q5HcLJ5e4VxgqXiErJXqolBbpKwpunaNzpvjU,610
115
- iop/cls/IOP/Message.cls,sha256=_-RZ4AxyZ97M8Guvm5eFg_-rH1VbNtnFE3x_G4eMZFg,9719
115
+ iop/cls/IOP/Message.cls,sha256=EJWt0ifN3v-QxFit-xvU4Brodx58_jWeYZDoiyHuHa8,25156
116
116
  iop/cls/IOP/OutboundAdapter.cls,sha256=9eOwy5ojwcTzwrHs6LNrFQvUD8aqcoNCZrILN1ycdDM,958
117
117
  iop/cls/IOP/PickleMessage.cls,sha256=S3y7AClQ8mAILjxPuHdCjGosBZYzGbUQ5WTv4mYPNMQ,1673
118
118
  iop/cls/IOP/Test.cls,sha256=gAC9PEfMZsvAEWIa241-ug2FWAhITbN1SOispZzJPnI,2094
@@ -120,6 +120,7 @@ iop/cls/IOP/Utils.cls,sha256=ZTBr02spm4ppxVBfhnUwb08BmhTjG5-ZbItRshYHs1I,13746
120
120
  iop/cls/IOP/Duplex/Operation.cls,sha256=K_fmgeLjPZQbHgNrc0kd6DUQoW0fDn1VHQjJxHo95Zk,525
121
121
  iop/cls/IOP/Duplex/Process.cls,sha256=xbefZ4z84a_IUhavWN6P_gZBzqkdJ5XRTXxro6iDvAg,6986
122
122
  iop/cls/IOP/Duplex/Service.cls,sha256=sTMOQUCMBgVitmQkM8bbsrmrRtCdj91VlctJ3I7b8WU,161
123
+ iop/cls/IOP/Message/JSONSchema.cls,sha256=SL26n8Z0D81SAGL2NthI10NFdT4Oe1x_GQiaTYPwkoo,3252
123
124
  iop/cls/IOP/PrivateSession/Duplex.cls,sha256=8a_dO7E2RTzuxzoufryjlS41l-99NmTtOcmFXOnSwA8,7957
124
125
  iop/cls/IOP/PrivateSession/Message/Ack.cls,sha256=y6-5uSVod36bxeQuT2ytPN4TUAfM1mvGGJuTbWbpNv4,941
125
126
  iop/cls/IOP/PrivateSession/Message/Poll.cls,sha256=z3ALYmGYQasTcyYNyBeoHzJdNXI4nBO_N8Cqo9l4sQY,942
@@ -129,9 +130,9 @@ iop/cls/IOP/Service/WSGI.cls,sha256=VLNCXEwmHW9dBnE51uGE1nvGX6T4HjhqePT3LVhsjAE,
129
130
  iop/wsgi/handlers.py,sha256=NrFLo_YbAh-x_PlWhAiWkQnUUN2Ss9HoEm63dDWCBpQ,2947
130
131
  irisnative/_IRISNative.py,sha256=HQ4nBhc8t8_5OtxdMG-kx1aa-T1znf2I8obZOPLOPzg,665
131
132
  irisnative/__init__.py,sha256=6YmvBLQSURsCPKaNg7LK-xpo4ipDjrlhKuwdfdNb3Kg,341
132
- iris_pex_embedded_python-3.1.6b2.dist-info/LICENSE,sha256=rZSiBFId_sfbJ6RL0GjjPX-InNLkNS9ou7eQsikciI8,1089
133
- iris_pex_embedded_python-3.1.6b2.dist-info/METADATA,sha256=EDJ5HbzThJvVGWatjDaa7blCaD2mI5n6HdclkhGjjbQ,4361
134
- iris_pex_embedded_python-3.1.6b2.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
135
- iris_pex_embedded_python-3.1.6b2.dist-info/entry_points.txt,sha256=pj-i4LSDyiSP6xpHlVjMCbg1Pik7dC3_sdGY3Yp9Vhk,38
136
- iris_pex_embedded_python-3.1.6b2.dist-info/top_level.txt,sha256=VWDlX4YF4qFVRGrG3-Gs0kgREol02i8gIpsHNbhfFPw,42
137
- iris_pex_embedded_python-3.1.6b2.dist-info/RECORD,,
133
+ iris_pex_embedded_python-3.2.0.dist-info/LICENSE,sha256=rZSiBFId_sfbJ6RL0GjjPX-InNLkNS9ou7eQsikciI8,1089
134
+ iris_pex_embedded_python-3.2.0.dist-info/METADATA,sha256=pccc6u5ZCNCsCR_WmN8skwon3__mAcaeGXxcmW2gDuk,4425
135
+ iris_pex_embedded_python-3.2.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
136
+ iris_pex_embedded_python-3.2.0.dist-info/entry_points.txt,sha256=pj-i4LSDyiSP6xpHlVjMCbg1Pik7dC3_sdGY3Yp9Vhk,38
137
+ iris_pex_embedded_python-3.2.0.dist-info/top_level.txt,sha256=VWDlX4YF4qFVRGrG3-Gs0kgREol02i8gIpsHNbhfFPw,42
138
+ iris_pex_embedded_python-3.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.7.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5