Skip to content

Commit 714fe67

Browse files
committed
[ADD] Gulp build task, Installer
1 parent 9af76a3 commit 714fe67

20 files changed

+638
-68
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
csp/.idea
1+
csp/.idea
2+
.idea
3+
node_modules
4+
build

Installer.xml

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2017.1 (Build 792U)" ts="2017-08-18 17:12:53">
3+
<Class name="SQLKPI.Installer">
4+
<TimeChanged>64513,61955.639014</TimeChanged>
5+
<TimeCreated>64513,60278.826343</TimeCreated>
6+
7+
<XData name="Install">
8+
<XMLNamespace>INSTALLER</XMLNamespace>
9+
<Data><![CDATA[
10+
<Manifest>
11+
<IfNotDef Var="Namespace">
12+
<Var Name="Namespace" Value="SQLKPI"/>
13+
<Log Text="Set namespace to ${Namespace}" Level="0"/>
14+
</IfNotDef>
15+
16+
<If Condition='(##class(Config.Namespaces).Exists("${Namespace}")=0)'>
17+
<Log Text="Creating namespace ${Namespace}" Level="0"/>
18+
<Namespace Name="${Namespace}" Create="yes" Code="${Namespace}" Ensemble="0" Data="${Namespace}">
19+
<Configuration>
20+
<Database Name="${Namespace}" Dir="${MGRDIR}${Namespace}" Create="yes"/>
21+
</Configuration>
22+
</Namespace>
23+
<Log Text="End Creating namespace ${Namespace}" Level="0"/>
24+
</If>
25+
26+
<Role Name="SQLKPIRole" Description="Role to access and use the SQLKPI" Resources="%DB_CACHESYS:RW,%Admin_Secure:U" />
27+
<Namespace Name="${Namespace}" Create="no">
28+
<RunInstall Class="SQLKPI.Installer" Method="CopyClasses"/>
29+
<RunInstall Class="SQLKPI.Installer" Method="CreateApplication"/>
30+
<CSPApplication Url="/csp/sqlkpi" Recurse="1" Directory="${CSPDIR}sqlkpi" AuthenticationMethods="64" IsNamespaceDefault="true" Grant="AppRole" />
31+
<Log Text="Copying web application files" Level="0"/>
32+
<RunInstall Class="SQLKPI.Installer" Method="CopyFiles"/>
33+
</Namespace>
34+
35+
<If Condition='(##class(Config.Namespaces).Exists("%All")=0)'>
36+
<Log Text="Creating namespace %All" Level="0"/>
37+
<Namespace Name="%All" Create="yes" Code="CACHETEMP" Data="CACHETEMP" Ensemble="0">
38+
<Configuration>
39+
<Log Text="Mapping SQLKPI package to %All namespace" Level="0"/>
40+
<ClassMapping From="${Namespace}" Package="SQLKPI"/>
41+
</Configuration>
42+
</Namespace>
43+
</If>
44+
45+
<If Condition='(##class(Config.Namespaces).Exists("%All")=1)'>
46+
<Namespace Name="%All" Create="no" Code="CACHETEMP" Data="CACHETEMP" Ensemble="0">
47+
<Configuration>
48+
<Log Text="Mapping package SQLKPI to %All namespace" Level="0"/>
49+
<ClassMapping From="${Namespace}" Package="SQLKPI"/>
50+
</Configuration>
51+
</Namespace>
52+
</If>
53+
54+
55+
<Log Text="Mapping SQLKPI package to Samples namespace" Level="0"/>
56+
<If Condition='##class(Config.Namespaces).Exists("Samples")'>
57+
<Namespace Name="Samples" Create="no" Code="SAMPLES" Data="SAMPLES" Ensemble="0">
58+
<Configuration>
59+
<ClassMapping From="${Namespace}" Package="SQLKPI"/>
60+
</Configuration>
61+
</Namespace>
62+
</If>
63+
</Manifest>
64+
]]></Data>
65+
</XData>
66+
67+
<Method name="setup">
68+
<Internal>1</Internal>
69+
<ClassMethod>1</ClassMethod>
70+
<CodeMode>objectgenerator</CodeMode>
71+
<FormalSpec><![CDATA[&pVars,pLogLevel:%Integer=0,pInstaller:%Installer.Installer]]></FormalSpec>
72+
<ReturnType>%Status</ReturnType>
73+
<Implementation><![CDATA[ Quit ##class(%Installer.Manifest).%Generate(%compiledclass, %code, "Install")
74+
]]></Implementation>
75+
</Method>
76+
77+
<Method name="CreateApplication">
78+
<ClassMethod>1</ClassMethod>
79+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
80+
<Implementation><![CDATA[
81+
set Namespace = tInstaller.Evaluate("${Namespace}")
82+
do tInstaller.PushNS("%SYS")
83+
if ('##class(Security.Applications).Exists("/sqlkpi")) {
84+
set cspProperties("NameSpace") = Namespace
85+
set cspProperties("AutheEnabled") = $$$AutheCache
86+
set cspProperties("IsNameSpaceDefault") = $$$NO
87+
set cspProperties("DispatchClass") = "SQLKPI.REST"
88+
set cspProperties("GroupById") = "sqlkpi"
89+
set cspProperties("MatchRoles") = ":SQLKPIRole"
90+
set cspProperties("CookiePath") = "/"
91+
92+
set tSC = ##class(Security.Applications).Create("/sqlkpi", .cspProperties)
93+
if $$$ISERR(tSC) throw ##class(%Installer.Exception).CreateFromStatus(tSC)
94+
kill cspProperties
95+
}
96+
97+
do tInstaller.PopNS()
98+
99+
quit $$$OK
100+
]]></Implementation>
101+
</Method>
102+
103+
<Method name="CopyClasses">
104+
<ClassMethod>1</ClassMethod>
105+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
106+
<Implementation><![CDATA[
107+
set sc = $$$OK
108+
109+
set i = 0
110+
while 1 {
111+
set id = "SQLKPI.CLSData||File" _ i
112+
if (##class(%Dictionary.CompiledXData).%ExistsId(id) = 0) Q
113+
set class = ##class(%Dictionary.CompiledXData).%OpenId(id)
114+
set data = $zconvert(class.Data.Read(class.Data.Size), "O", "UTF8")
115+
set className = "SQLKPI."_$piece(class.Description,".",1)
116+
117+
set Namespace = tInstaller.Evaluate("${Namespace}")
118+
do tInstaller.PushNS(Namespace)
119+
120+
if ('##class(%Dictionary.ClassDefinition).%ExistsId(className)) {
121+
set clsDef = ##class(%Dictionary.ClassDefinition).%New()
122+
set clsDef.Name = className
123+
set sc = clsDef.%Save()
124+
quit:$$$ISERR(sc)
125+
}
126+
set sc = ##class(%Compiler.UDL.TextServices).SetTextFromString(,className,$System.Encryption.Base64Decode(data))
127+
do $system.OBJ.Compile(className, "cuk")
128+
129+
do tInstaller.PopNS()
130+
131+
set i = i + 1
132+
}
133+
134+
quit $$$OK
135+
]]></Implementation>
136+
</Method>
137+
138+
<Method name="CopyFiles">
139+
<ClassMethod>1</ClassMethod>
140+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
141+
<Implementation><![CDATA[
142+
set csp = tInstaller.Evaluate("${CSPDIR}")
143+
set path = ##class(%File).NormalizeDirectory(csp _ "sqlkpi")
144+
145+
// Get path separator
146+
set r = ##class(%File).NormalizeDirectory("\")
147+
if ($find(r, "/") = 0) {
148+
set r = "\"
149+
} else {
150+
set r = "/"
151+
}
152+
153+
set i = 0
154+
while 1 {
155+
set id = "SQLKPI.CSPData||File" _ i
156+
if (##class(%Dictionary.CompiledXData).%ExistsId(id) = 0) Q
157+
set file = ##class(%Dictionary.CompiledXData).%OpenId(id)
158+
159+
set data = $zconvert(file.Data.Read(file.Data.Size), "O", "UTF8")
160+
set fileName = ##class(%File).NormalizeFilename(path _ file.Description)
161+
162+
163+
set fileName = $replace(fileName, "\", r)
164+
set fileName = $replace(fileName, "/", r)
165+
set dir = ##class(%File).ParentDirectoryName(fileName)
166+
if ('##class(%File).DirectoryExists(dir)) {
167+
do ##class(%File).CreateDirectory(dir)
168+
}
169+
170+
do tInstaller.Log(pLogLevel, "Creating file", fileName)
171+
172+
173+
set f = ##class(%Stream.FileBinary).%New()
174+
do f.LinkToFile(fileName)
175+
do f.Write($System.Encryption.Base64Decode(data))
176+
do f.%Save()
177+
178+
set i = i + 1
179+
}
180+
181+
quit $$$OK
182+
]]></Implementation>
183+
</Method>
184+
</Class>
185+
</Export>

SQLKPI/Installer.cls

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Class SQLKPI.Installer
2+
{
3+
4+
XData Install [ XMLNamespace = INSTALLER ]
5+
{
6+
<Manifest>
7+
<IfNotDef Var="Namespace">
8+
<Var Name="Namespace" Value="SQLKPI"/>
9+
<Log Text="Set namespace to ${Namespace}" Level="0"/>
10+
</IfNotDef>
11+
12+
<If Condition='(##class(Config.Namespaces).Exists("${Namespace}")=0)'>
13+
<Log Text="Creating namespace ${Namespace}" Level="0"/>
14+
<Namespace Name="${Namespace}" Create="yes" Code="${Namespace}" Ensemble="0" Data="${Namespace}">
15+
<Configuration>
16+
<Database Name="${Namespace}" Dir="${MGRDIR}${Namespace}" Create="yes"/>
17+
</Configuration>
18+
</Namespace>
19+
<Log Text="End Creating namespace ${Namespace}" Level="0"/>
20+
</If>
21+
22+
<Role Name="SQLKPIRole" Description="Role to access and use the SQLKPI" Resources="%DB_CACHESYS:RW,%Admin_Secure:U" />
23+
<Namespace Name="${Namespace}" Create="no">
24+
<RunInstall Class="SQLKPI.Installer" Method="CopyClasses"/>
25+
<RunInstall Class="SQLKPI.Installer" Method="CreateApplication"/>
26+
<CSPApplication Url="/csp/sqlkpi" Recurse="1" Directory="${CSPDIR}sqlkpi" AuthenticationMethods="64" IsNamespaceDefault="true" Grant="AppRole" />
27+
<Log Text="Copying web application files" Level="0"/>
28+
<RunInstall Class="SQLKPI.Installer" Method="CopyFiles"/>
29+
</Namespace>
30+
31+
<If Condition='(##class(Config.Namespaces).Exists("%All")=0)'>
32+
<Log Text="Creating namespace %All" Level="0"/>
33+
<Namespace Name="%All" Create="yes" Code="CACHETEMP" Data="CACHETEMP" Ensemble="0">
34+
<Configuration>
35+
<Log Text="Mapping SQLKPI package to %All namespace" Level="0"/>
36+
<ClassMapping From="${Namespace}" Package="SQLKPI"/>
37+
</Configuration>
38+
</Namespace>
39+
</If>
40+
41+
<If Condition='(##class(Config.Namespaces).Exists("%All")=1)'>
42+
<Namespace Name="%All" Create="no" Code="CACHETEMP" Data="CACHETEMP" Ensemble="0">
43+
<Configuration>
44+
<Log Text="Mapping package SQLKPI to %All namespace" Level="0"/>
45+
<ClassMapping From="${Namespace}" Package="SQLKPI"/>
46+
</Configuration>
47+
</Namespace>
48+
</If>
49+
50+
51+
<Log Text="Mapping SQLKPI package to Samples namespace" Level="0"/>
52+
<If Condition='##class(Config.Namespaces).Exists("Samples")'>
53+
<Namespace Name="Samples" Create="no" Code="SAMPLES" Data="SAMPLES" Ensemble="0">
54+
<Configuration>
55+
<ClassMapping From="${Namespace}" Package="SQLKPI"/>
56+
</Configuration>
57+
</Namespace>
58+
</If>
59+
</Manifest>
60+
}
61+
62+
ClassMethod setup(ByRef pVars, pLogLevel As %Integer = 0, pInstaller As %Installer.Installer) As %Status [ CodeMode = objectgenerator, Internal ]
63+
{
64+
Quit ##class(%Installer.Manifest).%Generate(%compiledclass, %code, "Install")
65+
}
66+
67+
ClassMethod CreateApplication(pVars, pLogLevel, tInstaller)
68+
{
69+
set Namespace = tInstaller.Evaluate("${Namespace}")
70+
do tInstaller.PushNS("%SYS")
71+
if ('##class(Security.Applications).Exists("/sqlkpi")) {
72+
set cspProperties("NameSpace") = Namespace
73+
set cspProperties("AutheEnabled") = $$$AutheCache
74+
set cspProperties("IsNameSpaceDefault") = $$$NO
75+
set cspProperties("DispatchClass") = "SQLKPI.REST"
76+
set cspProperties("GroupById") = "sqlkpi"
77+
set cspProperties("MatchRoles") = ":SQLKPIRole"
78+
set cspProperties("CookiePath") = "/"
79+
80+
set tSC = ##class(Security.Applications).Create("/sqlkpi", .cspProperties)
81+
if $$$ISERR(tSC) throw ##class(%Installer.Exception).CreateFromStatus(tSC)
82+
kill cspProperties
83+
}
84+
85+
do tInstaller.PopNS()
86+
87+
quit $$$OK
88+
}
89+
90+
ClassMethod CopyClasses(pVars, pLogLevel, tInstaller)
91+
{
92+
set sc = $$$OK
93+
94+
set i = 0
95+
while 1 {
96+
set id = "SQLKPI.CLSData||File" _ i
97+
if (##class(%Dictionary.CompiledXData).%ExistsId(id) = 0) Q
98+
set class = ##class(%Dictionary.CompiledXData).%OpenId(id)
99+
set data = $zconvert(class.Data.Read(class.Data.Size), "O", "UTF8")
100+
set className = "SQLKPI."_$piece(class.Description,".",1)
101+
102+
set Namespace = tInstaller.Evaluate("${Namespace}")
103+
do tInstaller.PushNS(Namespace)
104+
105+
if ('##class(%Dictionary.ClassDefinition).%ExistsId(className)) {
106+
set clsDef = ##class(%Dictionary.ClassDefinition).%New()
107+
set clsDef.Name = className
108+
set sc = clsDef.%Save()
109+
quit:$$$ISERR(sc)
110+
}
111+
set sc = ##class(%Compiler.UDL.TextServices).SetTextFromString(,className,$System.Encryption.Base64Decode(data))
112+
do $system.OBJ.Compile(className, "cuk")
113+
114+
do tInstaller.PopNS()
115+
116+
set i = i + 1
117+
}
118+
119+
quit $$$OK
120+
}
121+
122+
ClassMethod CopyFiles(pVars, pLogLevel, tInstaller)
123+
{
124+
set csp = tInstaller.Evaluate("${CSPDIR}")
125+
set path = ##class(%File).NormalizeDirectory(csp _ "sqlkpi")
126+
127+
// Get path separator
128+
set r = ##class(%File).NormalizeDirectory("\")
129+
if ($find(r, "/") = 0) {
130+
set r = "\"
131+
} else {
132+
set r = "/"
133+
}
134+
135+
set i = 0
136+
while 1 {
137+
set id = "SQLKPI.CSPData||File" _ i
138+
if (##class(%Dictionary.CompiledXData).%ExistsId(id) = 0) Q
139+
set file = ##class(%Dictionary.CompiledXData).%OpenId(id)
140+
141+
set data = $zconvert(file.Data.Read(file.Data.Size), "O", "UTF8")
142+
set fileName = ##class(%File).NormalizeFilename(path _ file.Description)
143+
144+
145+
set fileName = $replace(fileName, "\", r)
146+
set fileName = $replace(fileName, "/", r)
147+
set dir = ##class(%File).ParentDirectoryName(fileName)
148+
if ('##class(%File).DirectoryExists(dir)) {
149+
do ##class(%File).CreateDirectory(dir)
150+
}
151+
152+
do tInstaller.Log(pLogLevel, "Creating file", fileName)
153+
154+
155+
set f = ##class(%Stream.FileBinary).%New()
156+
do f.LinkToFile(fileName)
157+
do f.Write($System.Encryption.Base64Decode(data))
158+
do f.%Save()
159+
160+
set i = i + 1
161+
}
162+
163+
quit $$$OK
164+
}
165+
166+
}
167+

SQLKPI/Util.cls

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Class SQLKPI.Util
1+
Class SQLKPI.Util [ Abstract ]
22
{
33

44
ClassMethod executeSql(query As %String) As %Status

0 commit comments

Comments
 (0)