Skip to content

Commit a4b5bfc

Browse files
committed
Fixes for Template.cls
1 parent 9b63d10 commit a4b5bfc

2 files changed

Lines changed: 98 additions & 51 deletions

File tree

Serialization/OPNLib/Serialize/Template.cls

Lines changed: 93 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ClassMethod Export(pObject as %RegisteredObject, pInObject As %RegisteredObject
7070
do %code.WriteLine(" do tArr.%Push(tKeyValue)")
7171
do %code.WriteLine(" set tValue = "_$case(tConvert,"":"pObject."_tIdx_".GetNext(.tKey)",:".."_tConvert_"(pObject."_tIdx_".GetNext(.tKey))"))
7272
do %code.WriteLine(" }")
73-
do %code.WriteLine(" do tObj."_TargetProp_" = tArr")
73+
do %code.WriteLine(" set tObj."_tTargetProp_" = tArr")
7474
set tIdx = $order(^MAPS(tClassTarget,tMapName,tGroup,tIdx))
7575
}
7676
do %code.WriteLine(" ")
@@ -90,16 +90,25 @@ ClassMethod Export(pObject as %RegisteredObject, pInObject As %RegisteredObject
9090
do %code.WriteLine(" {")
9191
do %code.WriteLine(" set tDrillDown = "_tPropMAPDrillDown)
9292
do %code.WriteLine(" }")
93-
do %code.WriteLine(" set tJSONRef="""" ")
94-
do %code.WriteLine(" if tDrillDown > 0 ")
95-
do %code.WriteLine(" {")
96-
do %code.WriteLine(" set tJSONRef = pObject."_tIdx_".Export("""_tMAPClass_""","""_tMAP_""",,,(tDrillDown-1))")
97-
do %code.WriteLine(" }")
98-
do %code.WriteLine(" //elseif // here in default JSON we have an option to export OREFs...")
99-
do %code.WriteLine(" //{")
100-
do %code.WriteLine(" // set tJSONRef={""objref"":("" ""_$property(pObject,tIdx))}")
101-
do %code.WriteLine(" //}")
102-
do %code.WriteLine(" set tObj."_tTargetProp_" = tJSONRef")
93+
if (tClassRef '= "")
94+
{
95+
do %code.WriteLine(" set tJSONRef="""" ")
96+
do %code.WriteLine(" if (tDrillDown > 0)&&(##class(%Dictionary.CompiledClass).%OpenId("""_tClassRef_""").Super[""OPNLib.Serialize.Adaptor"")")
97+
do %code.WriteLine(" {")
98+
do %code.WriteLine(" set tJSONRef = pObject."_tIdx_".Export("""_tMAPClass_""","""_tMAP_""",,,(tDrillDown-1))")
99+
do %code.WriteLine(" }")
100+
do %code.WriteLine(" //elseif // here in default JSON we have an option to export OREFs...")
101+
do %code.WriteLine(" //{")
102+
do %code.WriteLine(" // set tJSONRef={""objref"":("" ""_$property(pObject,tIdx))}")
103+
do %code.WriteLine(" //}")
104+
do %code.WriteLine(" set tObj."_tTargetProp_" = tJSONRef")
105+
}
106+
else
107+
{
108+
do %code.WriteLine(" //Classname of Referenced Object was not indicated in MAP - No auto-generated import code included")
109+
110+
}
111+
103112
do %code.WriteLine(" }")
104113
set tIdx = $order(^MAPS(tClassTarget,tMapName,tGroup,tIdx))
105114
}
@@ -125,15 +134,23 @@ ClassMethod Export(pObject as %RegisteredObject, pInObject As %RegisteredObject
125134
do %code.WriteLine(" while (tKey'="""")")
126135
do %code.WriteLine(" { ")
127136
do %code.WriteLine(" set tJSONRef = """" ")
128-
do %code.WriteLine(" if tDrillDown > 0")
129-
do %code.WriteLine(" {")
130-
do %code.WriteLine(" set tJSONRef = tObjChildMany.Export("""_tMAPClass_""","""_tMAP_""",,,(tDrillDown-1))")
131-
do %code.WriteLine(" }")
137+
if (tClassRef '= "")
138+
{
139+
do %code.WriteLine(" if (tDrillDown > 0)&&(##class(%Dictionary.CompiledClass).%OpenId("""_tClassRef_""").Super[""OPNLib.Serialize.Adaptor"")")
140+
do %code.WriteLine(" {")
141+
do %code.WriteLine(" set tJSONRef = tObjChildMany.Export("""_tMAPClass_""","""_tMAP_""",,,(tDrillDown-1))")
142+
do %code.WriteLine(" }")
143+
}
144+
else
145+
{
146+
do %code.WriteLine(" //Classname of Referenced Object was not indicated in MAP - No auto-generated import code included")
147+
148+
}
132149
do %code.WriteLine(" set tArrElem = {""key"":(tKey),""value"":(tJSONRef)}")
133150
do %code.WriteLine(" do tArr.%Push(tArrElem)")
134151
do %code.WriteLine(" set tObjChildMany = pObject."_tIdx_".GetNext(.tKey)")
135152
do %code.WriteLine(" }")
136-
do %code.WriteLine(" set tObj."_tTargetProp_" = tArr)")
153+
do %code.WriteLine(" set tObj."_tTargetProp_" = tArr")
137154
do %code.WriteLine(" }")
138155
set tIdx = $order(^MAPS(tClassTarget,tMapName,tGroup,tIdx))
139156
}
@@ -152,21 +169,28 @@ ClassMethod Export(pObject as %RegisteredObject, pInObject As %RegisteredObject
152169
do %code.WriteLine(" set tDrillDown = pDrillDown")
153170
do %code.WriteLine(" if (pDrillDown < 0)||("_(tPropMAPDrillDown'>0)_")")
154171
do %code.WriteLine(" {")
155-
do %code.WriteLine(" set tDrillDown = tPropMAPDrillDown")
172+
do %code.WriteLine(" set tDrillDown = "_tPropMAPDrillDown)
156173
do %code.WriteLine(" }")
157174
do %code.WriteLine(" set tArr = []")
158175
do %code.WriteLine(" set tObjChildMany = pObject."_tIdx_".GetNext(.tKey)")
159176
do %code.WriteLine(" while (tKey'="""")")
160177
do %code.WriteLine(" { ")
161178
do %code.WriteLine(" set tJSONRef = """" ")
162-
do %code.WriteLine(" if tDrillDown > 0")
163-
do %code.WriteLine(" {")
164-
do %code.WriteLine(" set tJSONRef = tObjChildMany.Export("""_tMAPClass_""","""_tMAP_""",,,(tDrillDown-1))")
165-
do %code.WriteLine(" }")
179+
if (tClassRef '= "")
180+
{
181+
do %code.WriteLine(" if (tDrillDown > 0)&&(##class(%Dictionary.CompiledClass).%OpenId("""_tClassRef_""").Super[""OPNLib.Serialize.Adaptor"")")
182+
do %code.WriteLine(" {")
183+
do %code.WriteLine(" set tJSONRef = tObjChildMany.Export("""_tMAPClass_""","""_tMAP_""",,,(tDrillDown-1))")
184+
do %code.WriteLine(" }")
185+
}
186+
else
187+
{
188+
do %code.WriteLine(" //Classname of Referenced Object was not indicated in MAP - No auto-generated import code included")
189+
}
166190
do %code.WriteLine(" do tArr.%Push(tJSONRef)")
167191
do %code.WriteLine(" set tObjChildMany = pObject."_tIdx_".GetNext(.tKey)")
168192
do %code.WriteLine(" }")
169-
do %code.WriteLine(" set tObj."_tTargetProp_" = tArr)")
193+
do %code.WriteLine(" set tObj."_tTargetProp_" = tArr")
170194
do %code.WriteLine(" }")
171195
set tIdx = $order(^MAPS(tClassTarget,tMapName,tGroup,tIdx))
172196
}
@@ -195,7 +219,7 @@ ClassMethod Export(pObject as %RegisteredObject, pInObject As %RegisteredObject
195219
do %code.WriteLine(" }")
196220
do %code.WriteLine(" set tContent = $system.Encryption.Base64Encode(tContent)")
197221
}
198-
do %code.WriteLine(" set tObj."_tTargetProp_" = tContent)")
222+
do %code.WriteLine(" set tObj."_tTargetProp_" = tContent")
199223
do %code.WriteLine(" }")
200224
set tIdx = $order(^MAPS(tClassTarget,tMapName,tGroup,tIdx))
201225
}
@@ -242,7 +266,7 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
242266
do %code.WriteLine(" {")
243267
do %code.WriteLine(" set pInObject = {}.%FromJSON(pInObject)")
244268
do %code.WriteLine(" }")
245-
do %code.WriteLine(" elseif pInObject'=""%Library.DynamicObject""")
269+
do %code.WriteLine(" elseif pInObject.%ClassName(1)'=""%Library.DynamicObject""")
246270
do %code.WriteLine(" {")
247271
do %code.WriteLine(" return $$$ERROR(5001,""Valid input data should be a %Stream.* or a %DynamicObject (JSON)"")")
248272
do %code.WriteLine(" }")
@@ -304,15 +328,23 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
304328
do %code.WriteLine(" {")
305329
do %code.WriteLine(" set tDrillDown = "_tPropMAPDrillDown)
306330
do %code.WriteLine(" }")
307-
do %code.WriteLine(" //Only if there is a json object we'll try to import")
308-
do %code.WriteLine(" //By default we'll assume that referenced object it'll be a new one. ")
309-
do %code.WriteLine(" //This could be improved to allow import references to existing objects")
310-
do %code.WriteLine(" if (tDrillDown > 0)&&(pInObject.%GetTypeOf("""_tIdx_""") = ""object"")")
311-
do %code.WriteLine(" {")
312-
do %code.WriteLine(" set tRefObject = $classmethod("""_tClassRef_""",""%New"")")
313-
do %code.WriteLine(" do tRefObject.Import("""_tMAPClass_""","""_tMAP_""",pInObject."_tIdx_",(tDrillDown-1))")
314-
do %code.WriteLine(" set pObject."_tTargetProp_" = tRefObject")
315-
do %code.WriteLine(" }")
331+
if (tClassRef'="")
332+
{
333+
do %code.WriteLine(" //Only if there is a json object we'll try to import")
334+
do %code.WriteLine(" //By default we'll assume that referenced object it'll be a new one. ")
335+
do %code.WriteLine(" //This could be improved to allow import references to existing objects")
336+
do %code.WriteLine(" if (tDrillDown > 0)&&(pInObject.%GetTypeOf("""_tIdx_""") = ""object"")&&(##class(%Dictionary.CompiledClass).%OpenId("""_tClassRef_""").Super[""OPNLib.Serialize.Adaptor"")")
337+
do %code.WriteLine(" {")
338+
do %code.WriteLine(" set tRefObject = $classmethod("""_tClassRef_""",""%New"")")
339+
do %code.WriteLine(" do tRefObject.Import("""_tMAPClass_""","""_tMAP_""",pInObject."_tIdx_",(tDrillDown-1))")
340+
do %code.WriteLine(" set pObject."_tTargetProp_" = tRefObject")
341+
do %code.WriteLine(" }")
342+
}
343+
else
344+
{
345+
do %code.WriteLine(" //Classname of Referenced Object was not indicated in MAP - No auto-generated import code included")
346+
347+
}
316348
set tIdx = $order(^MAPSREV(tClassTarget,tMapName,tGroup,tIdx))
317349
}
318350
do %code.WriteLine(" ")
@@ -325,7 +357,6 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
325357
set $ListBuild(tTargetProp,tConvert,tPropMAPDrillDown,tClassRef,tMAPClass,tMAP)=$Get(^MAPSREV(tClassTarget,tMapName,tGroup,tIdx))
326358
do %code.WriteLine(" //If drilldown of this property it's not prohibited by MAP (=0), then we'll apply")
327359
do %code.WriteLine(" //the level by default or the level of deep requested in the method call")
328-
do %code.WriteLine(" set tPropMAPDrillDown = $ListGet(^MAPSREV("""_%compiledclass.Name_""",tMapName,"_tGroup_",tIdx),3)")
329360
do %code.WriteLine(" set tDrillDown = pDrillDown")
330361
do %code.WriteLine(" if (pDrillDown < 0)||("_(tPropMAPDrillDown'>0)_")")
331362
do %code.WriteLine(" {")
@@ -334,20 +365,28 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
334365
do %code.WriteLine(" //Only if there is a json object we'll try to import")
335366
do %code.WriteLine(" //By default we'll assume that referenced object it'll be a new one. ")
336367
do %code.WriteLine(" //ROOM to improve - This perhaps could be improved to allow import references to existing objects")
337-
do %code.WriteLine(" if (tClassRef'="""")&&(tDrillDown > 0)&&(pInObject.%GetTypeOf("""_tIdx_""") = ""array"")")
338-
do %code.WriteLine(" {")
339-
do %code.WriteLine(" set tIterator = pInObject."_tIdx_".%GetIterator()")
340-
do %code.WriteLine(" while tIterator.%GetNext(.tKey,.tValue)")
341-
do %code.WriteLine(" {")
342-
do %code.WriteLine(" //Each array element will be of type {""key"":<key>,""value"":<JSON object>")
343-
do %code.WriteLine(" set tElemObj = $classmethod("""_tClassRef_""",""%New"")")
344-
do %code.WriteLine(" do tElemObj.Import("""_tMAPClass_""","""_tMAP_""",tValue.value,(tDrillDown-1))")
345-
do %code.WriteLine(" if $IsObject(tElemObj)")
346-
do %code.WriteLine(" {")
347-
do %code.WriteLine(" set tSC = pObject."_tTargetProp_".SetAt(tElemObj,tValue.key)")
348-
do %code.WriteLine(" }")
349-
do %code.WriteLine(" }")
350-
do %code.WriteLine(" }")
368+
if (tClassRef'="")
369+
{
370+
do %code.WriteLine(" if (tDrillDown > 0)&&(pInObject.%GetTypeOf("""_tIdx_""") = ""array"")")
371+
do %code.WriteLine(" {")
372+
do %code.WriteLine(" set tIterator = pInObject."_tIdx_".%GetIterator()")
373+
do %code.WriteLine(" while tIterator.%GetNext(.tKey,.tValue)")
374+
do %code.WriteLine(" {")
375+
do %code.WriteLine(" //Each array element will be of type {""key"":<key>,""value"":<JSON object>")
376+
do %code.WriteLine(" set tElemObj = $classmethod("""_tClassRef_""",""%New"")")
377+
do %code.WriteLine(" do tElemObj.Import("""_tMAPClass_""","""_tMAP_""",tValue.value,(tDrillDown-1))")
378+
do %code.WriteLine(" if $IsObject(tElemObj)")
379+
do %code.WriteLine(" {")
380+
do %code.WriteLine(" set tSC = pObject."_tTargetProp_".SetAt(tElemObj,tValue.key)")
381+
do %code.WriteLine(" }")
382+
do %code.WriteLine(" }")
383+
do %code.WriteLine(" }")
384+
}
385+
else
386+
{
387+
do %code.WriteLine(" //Classname of Referenced Object was not indicated in MAP - No auto-generated import code included")
388+
389+
}
351390
set tIdx = $order(^MAPSREV(tClassTarget,tMapName,tGroup,tIdx))
352391
}
353392
do %code.WriteLine(" ")
@@ -385,6 +424,11 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
385424
do %code.WriteLine(" }")
386425
do %code.WriteLine(" }")
387426
}
427+
else
428+
{
429+
do %code.WriteLine(" //Classname of Referenced Object was not indicated in MAP - No auto-generated import code included")
430+
431+
}
388432
set tIdx = $order(^MAPSREV(tClassTarget,tMapName,tGroup,tIdx))
389433
}
390434
do %code.WriteLine(" ")
@@ -395,8 +439,6 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
395439
while (tIdx'="")
396440
{
397441
set $ListBuild(tTargetProp,tConvert,tPropMAPDrillDown,tClassRef,tMAPClass,tMAP)=$Get(^MAPSREV(tClassTarget,tMapName,tGroup,tIdx))
398-
do %code.WriteLine(" set:tConvert="""" tConvert=""importBase64Stream""")
399-
do %code.WriteLine(" set tValue = $case(tConvert,"""":pInObject.%Get(tIdx),:$method(pObject,tConvert,pInObject.%Get(tIdx)))")
400442
if tConvert'=""
401443
{
402444
do %code.WriteLine(" set tValue = .."_tConvert_"(pInObject."_tIdx_")")
@@ -408,7 +450,7 @@ ClassMethod Import(ByRef pObject as %RegisteredObject,pInObject as %RegisteredOb
408450
do %code.WriteLine(" do tValue.Write(tContent)")
409451
}
410452

411-
do %code.WriteLine(" set tSC = pObject."_tTargeProp_".CopyFrom(tValue)")
453+
do %code.WriteLine(" set tSC = pObject."_tTargetProp_".CopyFrom(tValue)")
412454
set tIdx = $order(^MAPSREV(tClassTarget,tMapName,tGroup,tIdx))
413455
}
414456
do %code.WriteLine(" ")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Class SampleApps.Serialize.MapTesting.generatedMAP1 Extends OPNLib.Serialize.Template
2+
{
3+
Parameter EXPTASSOCIATEDCLASS = "SampleApps.Serialize.MapTesting";
4+
Parameter EXPTMAP = "MAP0";
5+
}

0 commit comments

Comments
 (0)