-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstaller.cls
129 lines (104 loc) · 4.35 KB
/
Installer.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Class App.Installer [ Abstract ]
{
ClassMethod setup(
repoRoot As %String,
namespace As %String,
appKey As %String,
strategyClass As %String,
metadataPackages As %List,
productionClass As %String,
mockAppPath As %String,
mockRestHandlerClass As %String,
mockEndpointSuffixes As %List,
mockOperationPrefix As %String) As %Status
{
new $namespace
// Install a Foundation namespace
zn "HSLIB"
$$$QuitOnError(##class(HS.Util.Installer.Foundation).Install(namespace))
zn "%SYS"
// Create web app to receive requests directed to mock-up services
kill prop
set prop("AutheEnabled") = $$$AutheUnauthenticated
set prop("NameSpace") = namespace
set prop("DispatchClass") = mockRestHandlerClass
set prop("MatchRoles") = ":%HS_DB_"_$tr(namespace, "%")
$$$QuitOnError(##class(Security.Applications).Create(mockAppPath, .prop))
// Change to the new ns
zn namespace
// Set production class
set ns = ##class(HS.Util.Installer.Foundation).%OpenId(namespace)
set ns.Production = productionClass
$$$QuitOnError(ns.%Save())
// Install elements that are required for a FHIR-enabled namespace
do ##class(HS.FHIRServer.Installer).InstallNamespace()
// Import sources
$$$QuitOnError($System.OBJ.LoadDir(repoRoot _ "/src/cls", "ck", ,1))
// Configure production auto-start
set ^Ens.Configuration("csp", "LastProduction") = productionClass
$$$QuitOnError(##class(Ens.Director).SetAutoStart(productionClass))
// Create "System Default Settings" entry for FHIREndpoint production-level setting
set ds = ##class(Ens.Config.DefaultSettings).%New()
set ds.ProductionName = productionClass
set ds.ItemName = "*"
set ds.HostClassName = "*"
set ds.SettingName = "FHIREndpoint"
set ds.SettingValue = appKey
set ds.Deployable = $$$YES
// just in case: delete existing entry
&SQL(DELETE FROM Ens_Config.DefaultSettings
WHERE ProductionName = :ds.ProductionName
AND ItemName = :ds.ItemName
AND HostClassName = :ds.HostClassName
AND SettingName = :ds.SettingName)
$$$QuitOnError(ds.%Save())
// Install an instance of a FHIR Service into the current namespace
do ##class(HS.FHIRServer.Installer).InstallInstance(appKey, strategyClass, metadataPackages)
// Configure FHIR Service instance to accept unauthenticated requests
#dim strategy As HS.FHIRServer.API.InteractionsStrategy = ##class(HS.FHIRServer.API.InteractionsStrategy).GetStrategyForEndpoint(appKey)
set config = strategy.GetServiceConfigData()
set config.DebugMode = 4
do strategy.SaveServiceConfigData(config)
// Load some FHIR data from either "fhirdata" or "data/fhir" directories
#dim dataDir As %String = repoRoot _ "/fhirdata/"
if '##class(%File).DirectoryExists(dataDir) set dataDir = repoRoot _ "/data/fhir/"
$$$QuitOnError(##class(HS.FHIRServer.Tools.DataLoader).SubmitResourceFiles(dataDir, "FHIRServer", appKey))
// Create "Service Registry" and "System Default Settings" entries for mock-up HTTP services
set sc = $$$OK
for i = 1:1:$listLength(mockEndpointSuffixes)
{
set name = $listGet(mockEndpointSuffixes, i)
// 1. create Service Registry entry for mock-up service
#dim newEntry As HS.Registry.Service.HTTP = ##class(HS.Registry.Service.HTTP).%New()
set newEntry.Type = "HTTP"
set newEntry.Name = name
set newEntry.URL = mockAppPath _ "/" _ name
set newEntry.Host = "localhost"
set newEntry.Port = ^%SYS("WebServer","Port")
set fullUrl = "http://" _ newEntry.Host _ ":" _ newEntry.Port _ newEntry.URL
do newEntry.ServiceAliases.Insert(fullUrl)
// just in case: delete existing entry
&SQL(DELETE FROM HS_Registry_Service.HTTP WHERE Name = :newEntry.Name AND Type = :newEntry.Type)
set sc = newEntry.%Save()
if $$$ISERR(sc) quit
// 2. create "System Default Settings" entry for "ServiceName" setting that belongs to business operations which call mock-up services
set ds = ##class(Ens.Config.DefaultSettings).%New()
set ds.ProductionName = productionClass
set ds.ItemName = mockOperationPrefix _ name
set ds.HostClassName = "*"
set ds.SettingName = "ServiceName"
set ds.SettingValue = name
set ds.Deployable = $$$YES
// just in case: delete existing entry
&SQL(DELETE FROM Ens_Config.DefaultSettings
WHERE ProductionName = :ds.ProductionName
AND ItemName = :ds.ItemName
AND HostClassName = :ds.HostClassName
AND SettingName = :ds.SettingName)
set sc = ds.%Save()
if $$$ISERR(sc) quit
} // for
$$$QuitOnError(sc)
quit $$$OK
}
}