Skip to content

Commit 63040b0

Browse files
committed
[UPD] #1 Transition from XML to UDL.
1 parent a09f933 commit 63040b0

20 files changed

+240
-2113
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25">
3-
<Class name="SQLKPI.AbstractREST">
4-
<Super>%CSP.REST</Super>
5-
<TimeCreated>64244,40123.382009</TimeCreated>
1+
Class SQLKPI.AbstractREST Extends %CSP.REST
2+
{
63

7-
<Parameter name="HandleCorsRequest">
8-
<Default>1</Default>
9-
</Parameter>
4+
Parameter HandleCorsRequest = 1;
105

11-
<Parameter name="UseSession">
12-
<Type>Integer</Type>
13-
<Default>1</Default>
14-
</Parameter>
6+
Parameter UseSession As Integer = 1;
157

16-
<Method name="outputStatus">
17-
<Description>
18-
This method takes a status, renders it as jason (if requested) and outputs the result</Description>
19-
<Internal>1</Internal>
20-
<ClassMethod>1</ClassMethod>
21-
<FormalSpec>pSC:%Status</FormalSpec>
22-
<ReturnType>%Status</ReturnType>
23-
<Implementation><![CDATA[
8+
/// This method takes a status, renders it as jason (if requested) and outputs the result
9+
ClassMethod outputStatus(pSC As %Status) As %Status [ Internal ]
10+
{
2411
#dim tSC As %Status = $$$OK
2512
#dim e As %Exception.AbstractException
2613

@@ -56,13 +43,10 @@ This method takes a status, renders it as jason (if requested) and outputs the r
5643
Set tSC = e.AsStatus()
5744
}
5845
Quit $$$OK
59-
]]></Implementation>
60-
</Method>
46+
}
6147

62-
<Method name="getDebugInfo">
63-
<ClassMethod>1</ClassMethod>
64-
<ReturnType>%ZEN.proxyObject</ReturnType>
65-
<Implementation><![CDATA[
48+
ClassMethod getDebugInfo() As %ZEN.proxyObject
49+
{
6650
set obj = ##class(%ZEN.proxyObject).%New()
6751
set obj.stack = ..getStackInfo()
6852
set obj.objlasterror = $system.Status.GetErrorText($get(%objlasterror))
@@ -72,13 +56,10 @@ This method takes a status, renders it as jason (if requested) and outputs the r
7256
set obj.user = $username
7357

7458
return obj
75-
]]></Implementation>
76-
</Method>
59+
}
7760

78-
<Method name="getStackInfo">
79-
<ClassMethod>1</ClassMethod>
80-
<ReturnType>%ListOfDataTypes</ReturnType>
81-
<Implementation><![CDATA[
61+
ClassMethod getStackInfo() As %ListOfDataTypes
62+
{
8263

8364
set ex = ##class(%Exception.SystemException).%New()
8465
do ex.StackAsArray(.stack)
@@ -92,28 +73,20 @@ This method takes a status, renders it as jason (if requested) and outputs the r
9273
}
9374

9475
return list
95-
]]></Implementation>
96-
</Method>
76+
}
9777

98-
<Method name="OnPreDispatch">
99-
<Description>
100-
This method Gets called prior to dispatch of the request. Put any common code here
101-
that you want to be executed for EVERY request. If pContinue is set to 0, the
102-
request will NOT be dispatched according to the UrlMap. If this case it's the
103-
responsibility of the user to return a response.</Description>
104-
<ClassMethod>1</ClassMethod>
105-
<FormalSpec><![CDATA[pUrl:%String,pMethod:%String,&pContinue:%Boolean]]></FormalSpec>
106-
<ReturnType>%Status</ReturnType>
107-
<Implementation><![CDATA[ Quit ..convertRequestBody()
108-
]]></Implementation>
109-
</Method>
78+
/// This method Gets called prior to dispatch of the request. Put any common code here
79+
/// that you want to be executed for EVERY request. If pContinue is set to 0, the
80+
/// request will NOT be dispatched according to the UrlMap. If this case it's the
81+
/// responsibility of the user to return a response.
82+
ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue As %Boolean) As %Status
83+
{
84+
Quit ..convertRequestBody()
85+
}
11086

111-
<Method name="convertRequestBody">
112-
<Description>
113-
Конвертируем %request.Content в UTF8 и в объект класса %ZEN.proxyObject</Description>
114-
<ClassMethod>1</ClassMethod>
115-
<ReturnType>%Status</ReturnType>
116-
<Implementation><![CDATA[
87+
/// Конвертируем %request.Content в UTF8 и в объект класса %ZEN.proxyObject
88+
ClassMethod convertRequestBody() As %Status
89+
{
11790
#dim %request As %CSP.Request
11891
#dim obj As %ZEN.proxyObject
11992

@@ -129,7 +102,7 @@ responsibility of the user to return a response.</Description>
129102

130103
set %request.Content = obj // obj это валидный UTF8 %ZEN.proxyObject
131104
return $$$OK
132-
]]></Implementation>
133-
</Method>
134-
</Class>
135-
</Export>
105+
}
106+
107+
}
108+

SQLKPI/Generator.cls.xml renamed to SQLKPI/Generator.cls

+19-33
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25">
3-
<Class name="SQLKPI.Generator">
4-
<Description>
5-
Generates kpi class</Description>
6-
<Abstract>1</Abstract>
7-
<TimeCreated>64244,40301.291978</TimeCreated>
1+
/// Generates kpi class
2+
Class SQLKPI.Generator [ Abstract ]
3+
{
84

9-
<XData name="kpi">
10-
<Description>
11-
This XData definition defines the kpi.</Description>
12-
<Data><![CDATA[
5+
/// This XData definition defines the kpi.
6+
XData kpi
7+
{
138
<kpi
149
xmlns="http://www.intersystems.com/deepsee/kpi"
1510
name="!!!1!!!" sourceType="sql"
1611
sql="!!!2!!!">
17-
]]></Data>
18-
</XData>
12+
}
1913

20-
<Method name="generateKPIClass">
21-
<Description>
22-
do ##class(SQLKPI.Generator).generateKPIClass("SELECT name, type FROM Sample.Per", "KPIName", "try.kpi") </Description>
23-
<ClassMethod>1</ClassMethod>
24-
<FormalSpec>sql:%String,name:%String,class:%String</FormalSpec>
25-
<Implementation><![CDATA[
14+
/// do ##class(SQLKPI.Generator).generateKPIClass("SELECT name, type FROM Sample.Per", "KPIName", "try.kpi")
15+
ClassMethod generateKPIClass(sql As %String, name As %String, class As %String)
16+
{
2617
#dim sc As %Status = $$$OK
2718

2819
if '##class(%Dictionary.ClassDefinition).%ExistsId(class) {
@@ -65,21 +56,16 @@ do ##class(SQLKPI.Generator).generateKPIClass("SELECT name, type FROM Sample.Per
6556
set sc = classObj.%Save()
6657
return:$$$ISERR(sc) sc
6758
return $System.OBJ.Compile(class, "cuks /displaylog=0 /displayerror=0")
68-
]]></Implementation>
69-
</Method>
59+
}
7060

71-
<Method name="ReplaceRegexp">
72-
<Description>
73-
Replaces all occurances of Pattern with ReplacePattern.
74-
w $System.Status.GetErrorText(##class(SQLKPI.Generator).ReplaceRegexp(.Text))</Description>
75-
<ClassMethod>1</ClassMethod>
76-
<FormalSpec><![CDATA[&Text,Pattern:%String="",ReplacePattern:%String=""]]></FormalSpec>
77-
<ReturnType>%Status</ReturnType>
78-
<Implementation><![CDATA[
61+
/// Replaces all occurances of Pattern with ReplacePattern.
62+
/// w $System.Status.GetErrorText(##class(SQLKPI.Generator).ReplaceRegexp(.Text))
63+
ClassMethod ReplaceRegexp(ByRef Text, Pattern As %String = "", ReplacePattern As %String = "") As %Status
64+
{
7965
#Dim Matcher As %Regex.Matcher = ##class(%Regex.Matcher).%New(Pattern, Text)
8066
Set Text = Matcher.ReplaceAll(ReplacePattern)
8167
Quit Matcher.Status
82-
]]></Implementation>
83-
</Method>
84-
</Class>
85-
</Export>
68+
}
69+
70+
}
71+

SQLKPI/REST.cls

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Class SQLKPI.REST Extends SQLKPI.AbstractREST
2+
{
3+
4+
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
5+
{
6+
<Routes>
7+
<Route Url="/sql" Method="POST" Call="executeSQL"/>
8+
<Route Url="/kpi" Method="POST" Call="generateKPI"/>
9+
<Route Url="/logout" Method="GET" Call="logout"/>
10+
<Route Url="/test" Method="GET" Call="test"/>
11+
</Routes>
12+
}
13+
14+
/// Logout current session
15+
ClassMethod logout() As %Status
16+
{
17+
#dim %session As %CSP.Session
18+
set st = %session.Logout(1)
19+
set %session.EndSession = 1
20+
return st
21+
}
22+
23+
/// Test
24+
ClassMethod test() As %Status
25+
{
26+
write "{""status"": ""OK""}"
27+
return $$$OK
28+
}
29+
30+
ClassMethod executeSQL() As %Status
31+
{
32+
set sc = $$$OK
33+
set rs = ##class(%SQL.Statement).%ExecDirect(,%request.Content.query)
34+
35+
if (rs.%SQLCODE '= 0) && (rs.%SQLCODE '= 100) {
36+
quit $$$ERROR(5521,rs.%SQLCODE,rs.%Message)
37+
}
38+
39+
set obj = ##class(%ZEN.proxyObject).%New()
40+
set metadata = rs.%GetMetadata()
41+
42+
set columnNames = ##class(%ListOfDataTypes).%New()
43+
for i=1:1:metadata.columns.Count() {
44+
set tCol = metadata.columns.GetAt(i)
45+
do columnNames.Insert(tCol.colName)
46+
}
47+
48+
set obj."sql_code" = rs.%SQLCODE
49+
set obj.columns = columnNames
50+
set sc = obj.%ToJSON()
51+
52+
quit sc
53+
}
54+
55+
ClassMethod generateKPI() As %Status
56+
{
57+
set sql = %request.Content.SQL
58+
set name = %request.Content.Name
59+
set class = %request.Content.Class
60+
61+
// TODO check that it's valid
62+
63+
return ##class(SQLKPI.Generator).generateKPIClass(sql, name, class)
64+
}
65+
66+
/// Specifies the default character set for the page. This can be overriden using the
67+
/// &lt;CSP:CONTENT CHARSET=&gt; tag, or by setting the <b>%response</b>.CharSet property
68+
/// in the <method>OnPreHTTP</method> method. If this parameter is not specified, then
69+
/// for the default charset is utf-8.
70+
71+
}
72+

SQLKPI/REST.cls.xml

-71
This file was deleted.

csp/.idea/devsqlkpi.iml.xml renamed to csp/.idea/devsqlkpi.iml

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

csp/.idea/modules.xml.xml renamed to csp/.idea/modules.xml

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)