Skip to content

Commit 7899bf7

Browse files
committed
MDX2JSON translation via dynamic objects
1 parent 50de1f9 commit 7899bf7

3 files changed

Lines changed: 34 additions & 30 deletions

File tree

MDX2JSON/MDX2JSON.inc.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
#define NewDynDTList ##class(%Array).%New()
1616
#define NewDynObjList $$$NewDynDTList
1717
#define Insert(%obj,%element) do %obj.$push(%element)
18-
#define DynObjToJSON(%obj) do %obj.$toJSON()
18+
#define DynObjToJSON(%obj) w %obj.$toJSON()
1919
#define ListToJSON(%obj) $$$DynObjToJSON(%obj)
20+
#define ListSize(%obj) %obj.$size()
21+
#define ListGet(%obj,%i) %obj.$get(%i-1)
2022
#else
2123
#define NewDynObj ##class(%ZEN.proxyObject).%New()
2224
#define NewDynDTList ##class(%ListOfDataTypes).%New()
2325
#define NewDynObjList ##class(%ListOfObjects).%New()
2426
#define Insert(%obj,%element) do %obj.Insert(%element)
2527
#define DynObjToJSON(%obj) do %obj.%ToJSON()
2628
#define ListToJSON(%obj) do ##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(%obj)
29+
#define ListSize(%obj) %obj.Count()
30+
#define ListGet(%obj,%i) %obj.Get(%i)
2731
#endif
2832
2933
]]></Routine>

MDX2JSON/ResultSet.cls.xml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Converts ResultSet to %ZEN.proxyObject.<br>
1818
set ^DeepSee.QueryLog($UserName,$I(^DeepSee.QueryLog($UserName))) = ..%GetQueryText()
1919
set status = $$$ERROR($$$GeneralError,"Error occured while executing ##class(MDX2JSON.ResultSet).ToProxyObject() method")
2020
21-
set obj=##class(%ZEN.proxyObject).%New()
21+
set obj=$$$NewDynObj
2222
2323
if (..%Query.queryType = "DRILLTHROUGH") {
2424
set pStatus = $$$ERROR($$$GeneralError, "DRILLTHROUGH queries are not supported")
@@ -68,7 +68,7 @@ Returns meta-information about ResultSet.</Description>
6868
set tAxisKeys(a) = $G($$$DeepSeeResultsGLVN(tCubeIndex,tQueryKey,"axis",a))
6969
}
7070
71-
set info=##class(%ZEN.proxyObject).%New()
71+
set info=$$$NewDynObj
7272
set info.queryKey = tQueryKey
7373
set info.rowCount = $G(tAxisSize(1))
7474
set info.colCount = $G(tAxisSize(2))
@@ -104,15 +104,15 @@ Returns array of Axes</Description>
104104
}
105105
106106
107-
set axes=##class(%ListOfObjects).%New()
107+
set axes=$$$NewDynObjList
108108
109109
for a = 1:1:tAxisCount {
110110
set tAxisSize(a) = ..%GetAxisSize(a)
111111
set tAxisKeys(a) = $G($$$DeepSeeResultsGLVN(tCubeIndex,tQueryKey,"axis",a))
112-
do axes.Insert(..ProcessOneAxis(tCubeIndex,tAxisKeys(a),a))
112+
$$$Insert(axes,..ProcessOneAxis(tCubeIndex,tAxisKeys(a),a))
113113
}
114114
115-
if (axes.Count()=0) {
115+
if ($$$ListSize(axes)=0) {
116116
set axes = ..GetDefaultAxes()
117117
}
118118
@@ -128,7 +128,7 @@ Returns array of Axes</Description>
128128
set tCubeName = $$$UPPER(..%Cube)
129129
set tQueryKey = ..%QueryKey
130130
131-
set axis=##class(%ZEN.proxyObject).%New()
131+
set axis=$$$NewDynObj
132132
set axis.tuples = ..ProcessOneAxisCell(CubeIndex, AxisKey, tCubeName, tQueryKey, AxisNumber, 1)
133133
134134
return axis
@@ -140,7 +140,7 @@ Returns array of Axes</Description>
140140
<FormalSpec>CubeIndex,AxisKey,CubeName,QueryKey,AxisNumber,Node</FormalSpec>
141141
<ReturnType>%ZEN.proxyObject</ReturnType>
142142
<Implementation><![CDATA[
143-
set cell=##class(%ZEN.proxyObject).%New()
143+
set cell=$$$NewDynObj
144144
145145
set tNode = $G($$$DeepSeeAxisGLVN(CubeIndex,AxisKey,"axes",Node))
146146
set tDimNo = $LG(tNode,9)
@@ -179,17 +179,17 @@ Returns array of Axes</Description>
179179
180180
// now we process cell children, if any exist
181181
if ($D($$$DeepSeeAxisGLVN(CubeIndex, AxisKey, "axes", Node, "ch")) = 10) {
182-
set cell.children = ##class(%ListOfObjects).%New()
182+
set cell.children = $$$NewDynObjList
183183
set key = $O($$$DeepSeeAxisGLVN(CubeIndex, AxisKey, "axes", Node, "ch", ""))
184184
while (key'="") {
185185
set children = ..ProcessOneAxisCell(CubeIndex, AxisKey, CubeName, QueryKey, AxisNumber, key)
186186
// Append children to cell
187187
if $isobject(children) {
188-
if (children.%IsA("%ZEN.proxyObject")) {
189-
do cell.children.Insert(children)
190-
} elseif (children.%IsA("%Collection.AbstractList")) {
191-
for i=1:1:children.Count() {
192-
do cell.children.Insert(children.GetAt(i))
188+
if ((children.%IsA("%ZEN.proxyObject")) || (children.%IsA("%Library.Object"))) {
189+
$$$Insert(cell.children,children)
190+
} elseif ((children.%IsA("%Collection.AbstractList")) || (children.%IsA("%Library.Array"))) {
191+
for i=1:1:$$$ListSize(children) {
192+
$$$Insert(cell.children,$$$ListGet(children,i))
193193
}
194194
}
195195
}
@@ -223,7 +223,7 @@ Determine if cell is an invisyble system cell.</Description>
223223
//return:(caption'="") 0
224224
//return:(path="") 1
225225
set children = Cell.children
226-
return:(($isobject(children)) && (children.Count()>0)) 0
226+
return:(($isobject(children)) && ($$$ListSize(children)>0)) 0
227227
228228
if (Cell.type'="lit") {
229229
set key = $O($$$DeepSeeResultsGLVN(..%CubeKey, ..%QueryKey, "leaf", AxisNumber, ""))
@@ -242,7 +242,7 @@ Determine if cell is an invisyble system cell.</Description>
242242
Returns array of cells (left-to-right, up-to-down)</Description>
243243
<ReturnType>%ListOfDataTypes</ReturnType>
244244
<Implementation><![CDATA[
245-
set data = ##class(%ListOfDataTypes).%New()
245+
set data = $$$NewDynDTList
246246
247247
set tCubeIndex = ..%CubeKey
248248
set tQueryKey = ..%QueryKey
@@ -260,12 +260,12 @@ Returns array of cells (left-to-right, up-to-down)</Description>
260260
set tNodeNo = ""
261261
262262
if (tAxisCount = 0) {
263-
do data.Insert(..%GetValue())
263+
$$$Insert(data,..%GetValue())
264264
} elseif (tAxisCount = 1) {
265265
set tRowCount = 1
266266
set c = 0
267267
while (tItemNo(1)'="") {
268-
do data.Insert(..%GetValue(tAddr(1)))
268+
$$$Insert(data,..%GetValue(tAddr(1)))
269269
set c = c + 1
270270
set tItemNo(1) = $O($$$DeepSeeResultsGLVN(tCubeIndex,tQueryKey,"leaf",1,tItemNo(1)),1,tNodeNo)
271271
set tAddr(1) = tNodeNo
@@ -277,7 +277,7 @@ Returns array of cells (left-to-right, up-to-down)</Description>
277277
set tAddr(1) = tNodeNo
278278
while (tItemNo(1)'="") {
279279
set tValue = ..%GetValue(tAddr...) // for 2 axes ..%GetValue(tAddr(1),tAddr(2))
280-
do data.Insert(tValue)
280+
$$$Insert(data,tValue)
281281
282282
set tItemNo(1) = $O($$$DeepSeeResultsGLVN(tCubeIndex,tQueryKey,"leaf",1,tItemNo(1)),1,tNodeNo)
283283
set tAddr(1) = tNodeNo
@@ -296,9 +296,9 @@ Returns array of cells (left-to-right, up-to-down)</Description>
296296
<ClassMethod>1</ClassMethod>
297297
<ReturnType>%ListOfObjects</ReturnType>
298298
<Implementation><![CDATA[
299-
set axes=##class(%ListOfObjects).%New() // all axes
299+
set axes=$$$NewDynObjList // all axes
300300
301-
set cell=##class(%ZEN.proxyObject).%New()
301+
set cell=$$$NewDynObj
302302
set cell.caption = $$$Text("Count","%DeepSee")
303303
set cell.format = ""
304304
set cell.total = "COUNT"
@@ -314,15 +314,15 @@ Returns array of cells (left-to-right, up-to-down)</Description>
314314
set cell2.caption = ""
315315
set cell2.dimension = "%Search"
316316
317-
set axis = ##class(%ZEN.proxyObject).%New() // one axis
318-
set axis.tuples = ##class(%ListOfObjects).%New() //array of cells for one axis
319-
do axis.tuples.Insert(cell)
320-
do axes.Insert(axis)
317+
set axis = $$$NewDynObj // one axis
318+
set axis.tuples = $$$NewDynObjList //array of cells for one axis
319+
$$$Insert(axis.tuples,cell)
320+
$$$Insert(axes,axis)
321321
322-
set axis2 = ##class(%ZEN.proxyObject).%New()
323-
set axis2.tuples = ##class(%ListOfObjects).%New()
324-
do axis2.tuples.Insert(cell2)
325-
do axes.Insert(axis2)
322+
set axis2 = $$$NewDynObj
323+
set axis2.tuples = $$$NewDynObjList
324+
$$$Insert(axis2.tuples,cell2)
325+
$$$Insert(axes,axis2)
326326
327327
return axes
328328
]]></Implementation>

MDX2JSON/Utils.cls.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Automatic processing of MDX query and outputting resulting JSON.<br>
3838
3939
set obj = RS.ToProxyObject(.st)
4040
return:$$$ISERR(st) st
41-
do obj.%ToJSON()
41+
$$$DynObjToJSON(obj)
4242
4343
return $$$OK
4444
]]></Implementation>

0 commit comments

Comments
 (0)