Skip to content

Commit a0a93d1

Browse files
committed
Add ImportFromFile method to load JSON Schema from a file with error handling
1 parent fc47d87 commit a0a93d1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/iop/cls/IOP/Message/JSONSchema.cls

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ Property JSONSchema As %String(MAXLEN = "");
99

1010
Index NameIndex On Name [ IdKey, Unique ];
1111

12+
/// Import a JSON Schema from file
13+
ClassMethod ImportFromFile(
14+
pFileName As %String,
15+
pCategory As %String = "",
16+
pName As %String) As %Status
17+
{
18+
Set pStatus = $$$OK
19+
Try {
20+
If '##class(%File).Exists(pFileName) {
21+
Set pStatus = $$$ERROR($$$GeneralError, "File not found")
22+
Return pStatus
23+
}
24+
Set tFile = ##class(%File).%New(pFileName)
25+
$$$ThrowOnError(tFile.Open("R"))
26+
Set tSchema = ""
27+
While 'tFile.AtEnd {
28+
Set tSchema = tSchema _ tFile.ReadLine()
29+
}
30+
Set pStatus = ..Import(tSchema, pCategory, pName)
31+
} Catch ex {
32+
Set pStatus = ex.AsStatus()
33+
}
34+
Return pStatus
35+
}
36+
1237
/// Store the JSON Schema in this object
1338
ClassMethod Import(
1439
pSchema As %String,

0 commit comments

Comments
 (0)