Skip to content

Commit 8f13cca

Browse files
authored
Merge pull request #103 from Frisle/patch-3
Update Utils.cls
2 parents 0d32fa9 + c027f35 commit 8f13cca

1 file changed

Lines changed: 70 additions & 4 deletions

File tree

MDX2JSON/Utils.cls

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,35 @@ ClassMethod WriteJSONfromQuery(CubeKey As %String, QueryKey As %String, Timeout
8989
return $$$OK
9090
}
9191

92+
93+
/// Execute SQL query taken from KPI and extract column values by name of column
94+
/// Output array with list of values like so pValue(n) = $LB(sNameList(i)...)
95+
ClassMethod GetSQLValues(pSQL, Output pValues As %String, Output tResultSet As %SQL.Statement) As %Status
96+
{
97+
98+
set st = $$$OK
99+
Set tResultSet = ##class(%SQL.Statement).%ExecDirect(,pSQL)
100+
set tCount = 0
101+
102+
while tResultSet.%Next()
103+
{
104+
set lValue = ""
105+
for i=1:1:tResultSet.%GetMetadata().columnCount
106+
{
107+
set sNameList(i) = tResultSet.%GetMetadata().columns.GetAt(i).label
108+
set lValue = lValue _ $lb(tResultSet.%Get(sNameList(i))) // append next column to the list
109+
}
110+
111+
Set tCount = tCount + 1
112+
set pValues(tCount) = lValue
113+
}
114+
return st
115+
}
116+
117+
118+
/// This method provides listing execution for KPI.
119+
/// <b>tKPI<b> as a name of KPI class. <b>pFilters<b> not yet implemented
120+
/// as a <b>pSelection<b>. Thats for future use.
92121
ClassMethod WriteDrillthroughJSONKPI(tKPI As %String, pFilters As %String, pSelection As %String) As %Status
93122
{
94123

@@ -98,15 +127,52 @@ ClassMethod WriteDrillthroughJSONKPI(tKPI As %String, pFilters As %String, pSele
98127
set kpitype = $classmethod(tKpiClassName, "%GetSourceType")
99128

100129
if (kpitype="sql") {
101-
set pSQL = $classmethod(tKpiClassName, "%OnGetListingSQL", pFilters,pSelection) // invoke corresponding method from given kpi and get sql query
130+
set pSQL = $classmethod(tKpiClassName,"%OnGetListingSQL",pFilters,pSelection) // invoke corresponding method from given kpi and get sql query
131+
set values = ..GetSQLValues(pSQL, .pValue, .tResultSet)
132+
133+
for i=1:1:tResultSet.%GetMetadata().columnCount
134+
{
135+
set pList(i) = tResultSet.%GetMetadata().columns.GetAt(i).label
136+
set pList(i, "columnNo") = i
137+
Set tKpiPropIdx = $O(pList(""),1,tProperty)
138+
Set tKpiPropList = ""
139+
While (tKpiPropIdx'="") {
140+
Set tKpiPropList = tKpiPropList _ $LB(tProperty)
141+
Set tKpiPropArray(tKpiPropIdx) = $LB(tProperty,$G(pList(tKpiPropIdx,"name")),$G(pList(tKpiPropIdx,"columnNo")))
142+
Set tKpiPropIdx = $O(pList(tKpiPropIdx),1,tProperty)
143+
144+
}
145+
146+
}
147+
Set tKpiSC = $classmethod(tKpiClassName,"%GetKPIValueArray",tKpiClassName,,.tKpiPropList,.tFilters)
148+
149+
Set tSC = ##class(%DeepSee.REST.v1.DataServer).%CreateObjectFromArray(.pValue,tKpiPropList,.tValueObj)
150+
If $$$ISERR(tSC) Quit
151+
152+
Set tSC = ##class(%DeepSee.REST.v1.DataServer).%CreateObjectFromArray(.tKpiPropArray,$LB("name","caption","columnNo"),.tPropObj)
153+
If $$$ISERR(tSC)
154+
155+
// Use consistent objects for normalized return
156+
Set tProvider = ##class(%ZEN.Auxiliary.jsonMDXProvider).%New()
157+
Set tInfoObj = tProvider.%ConstructNewDynamicObject()
158+
Set tResultObj = tProvider.%ConstructNewDynamicObject()
159+
160+
Set:$IsObject(tPropObj.children) tResultObj.Properties = tPropObj.children
161+
Set:$IsObject(tValueObj.children) tResultObj.Series = tValueObj.children
162+
163+
Set tInfoObj.Error = tProvider.%StatusToDynamicObject(tKpiSC)
164+
Set tInfoObj.KpiName = tKpiClassName
165+
166+
Set tKpiObj = tProvider.%ConstructNewDynamicObject()
167+
Set tKpiObj.Info = tInfoObj
168+
Set tKpiObj.Result = tResultObj
169+
170+
Set tSC = tProvider.%ObjectToJSON(tKpiObj)
102171

103172
}else{
104173

105174
quit $$$ERROR($$$GeneralError, "KPI type " _ kpitype _ " not supported")
106175
}
107-
108-
set st = ##class(%ZEN.Auxiliary.altJSONSQLProvider).%WriteJSONFromSQL(,pSQL,,$$$MaxCacheInt) // receiving sql and process it
109-
return:$$$ISERR(st) st
110176

111177
return st
112178
}

0 commit comments

Comments
 (0)