Skip to content

Commit aeb1180

Browse files
authored
Update Utils.cls
Improved method. Now it provides complete result set with series and properties based on SQL. Part of this was taken from ##class(%DeepSee.REST.v1.DataServer).WriteJSONfromKPI
1 parent 4616b03 commit aeb1180

1 file changed

Lines changed: 71 additions & 4 deletions

File tree

MDX2JSON/Utils.cls

Lines changed: 71 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) 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,53 @@ 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 stmt = ##class(%SQL.Statement).%ExecDirect(,pSQL)
132+
set values = ..getSQLValues(pSQL, .pValue)
133+
134+
for i=1:1:stmt.%GetMetadata().columnCount
135+
{
136+
set pList(i) = stmt.%GetMetadata().columns.GetAt(i).label
137+
set pList(i, "columnNo") = i
138+
Set tKpiPropIdx = $O(pList(""),1,tProperty)
139+
Set tKpiPropList = ""
140+
While (tKpiPropIdx'="") {
141+
Set tKpiPropList = tKpiPropList _ $LB(tProperty)
142+
Set tKpiPropArray(tKpiPropIdx) = $LB(tProperty,$G(pList(tKpiPropIdx,"name")),$G(pList(tKpiPropIdx,"columnNo")))
143+
Set tKpiPropIdx = $O(pList(tKpiPropIdx),1,tProperty)
144+
145+
}
146+
147+
}
148+
Set tKpiSC = $classmethod(tKpiClassName,"%GetKPIValueArray",tKpiClassName,,.tKpiPropList,.tFilters)
149+
150+
Set tSC = ##class(%DeepSee.REST.v1.DataServer).%CreateObjectFromArray(.pValue,tKpiPropList,.tValueObj)
151+
If $$$ISERR(tSC) Quit
152+
153+
Set tSC = ##class(%DeepSee.REST.v1.DataServer).%CreateObjectFromArray(.tKpiPropArray,$LB("name","caption","columnNo"),.tPropObj)
154+
If $$$ISERR(tSC)
155+
156+
// Use consistent objects for normalized return
157+
Set tProvider = ##class(%ZEN.Auxiliary.jsonMDXProvider).%New()
158+
Set tInfoObj = tProvider.%ConstructNewDynamicObject()
159+
Set tResultObj = tProvider.%ConstructNewDynamicObject()
160+
161+
Set:$IsObject(tPropObj.children) tResultObj.Properties = tPropObj.children
162+
Set:$IsObject(tValueObj.children) tResultObj.Series = tValueObj.children
163+
164+
Set tInfoObj.Error = tProvider.%StatusToDynamicObject(tKpiSC)
165+
Set tInfoObj.KpiName = tKpiClassName
166+
167+
Set tKpiObj = tProvider.%ConstructNewDynamicObject()
168+
Set tKpiObj.Info = tInfoObj
169+
Set tKpiObj.Result = tResultObj
170+
171+
Set tSC = tProvider.%ObjectToJSON(tKpiObj)
102172

103173
}else{
104174

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

111178
return st
112179
}

0 commit comments

Comments
 (0)