Skip to content
This repository was archived by the owner on Dec 17, 2022. It is now read-only.

Commit d211895

Browse files
committed
Added Import/Export
1 parent 1672e64 commit d211895

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

%CDEV.Server.cls

+88-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
88
<Routes>
99
<Route Url="/namespaces" Method="GET" Call="GetNamespaceList" />
1010
<Route Url="/namespaces/:namespace" Method="GET" Call="GetNamespace" />
11+
<Route Url="/namespaces/:namespace/xml" Method="PUT" Call="PutNewXML" />
1112
<Route Url="/namespaces/:namespace/files" Method="GET" Call="GetFileList" />
1213
<Route Url="/namespaces/:namespace/files" Method="PUT" Call="PutNewFile" />
1314
<Route Url="/namespaces/:namespace/files/:filename" Method="GET" Call="GetFile" />
1415
<Route Url="/namespaces/:namespace/files/:filename" Method="PUT" Call="PutFile" />
1516
<Route Url="/namespaces/:namespace/files/:filename" Method="POST" Call="FileAction" />
1617
<Route Url="/namespaces/:namespace/files/:filename/generated" Method="GET" Call="GetGenerated" />
18+
<Route Url="/namespaces/:namespace/files/:filename/xml" Method="GET" Call="GetXML" />
19+
<Route Url="/namespaces/:namespace/files/:filename/xml" Method="PUT" Call="PutXML" />
20+
<Route Url="/namespaces/:namespace/xml" Method="PUT" Call="PutNewXML" />
1721
<Route Url="/namespaces/:namespace/globals" Method="GET" Call="GetGlobalList" />
1822
<Route Url="/namespaces/:namespace/globals/:globalname" Method="GET" Call="GetGlobal" />
23+
<Route Url="/namespaces/:namespace/queries" Method="POST" Call="QueryAction" />
1924
</Routes>
2025
}
2126

@@ -24,10 +29,7 @@ ClassMethod GetNamespaceList() As %Status
2429
s rs = ..DoSQL("%SYS.Namespace::List")
2530
s results = $$$jslist
2631
while rs.%Next() {
27-
s obj = $$$jsobj
28-
s obj.name = rs.%GetData(1)
29-
s obj.id = ..CreatePath("namespaces", $zcvt(obj.name,"L"))
30-
s obj.files = obj.id _ "/files"
32+
s obj = ..NamespaceObject($zcvt(rs.%GetData(1), "L"))
3133
d results.Append(obj)
3234
}
3335

@@ -67,15 +69,24 @@ ClassMethod GetFileList(namespace As %String) As %Status
6769

6870
ClassMethod GetNamespace(namespace As %String) As %Status
6971
{
70-
s obj = $$$jsobj
71-
s obj.id = ..CreatePath("namespaces", namespace)
72-
s obj.files = ..CreatePath("namespaces", namespace, "files")
72+
s obj = ..NamespaceObject(namespace)
7373

7474
s %response.ContentType="application/json"
7575
d obj.%WriteJSON()
7676
q $$$OK
7777
}
7878

79+
ClassMethod NamespaceObject(namespace As %String) As %CDEV.JSON.Object
80+
{
81+
s obj = $$$jsobj
82+
s obj.id = ..CreatePath("namespaces", namespace)
83+
s obj.name = $zcvt(namespace, "U")
84+
s obj.files = ..CreatePath("namespaces", namespace, "files")
85+
s obj.xml = ..CreatePath("namespaces", namespace, "xml")
86+
87+
q obj
88+
}
89+
7990
ClassMethod FileObject(namespace As %String, filename As %String) As %CDEV.JSON.Object
8091
{
8192
s result = $$$jsobj
@@ -91,6 +102,7 @@ ClassMethod FileObject(namespace As %String, filename As %String) As %CDEV.JSON.
91102
q ""
92103
}
93104
} else {
105+
s systemName = filename
94106
i ##class(%Routine).Exists(filename)
95107
{
96108
s routine = ##class(%Routine).%OpenId(filename)
@@ -103,6 +115,7 @@ ClassMethod FileObject(namespace As %String, filename As %String) As %CDEV.JSON.
103115
s result.id = ..CreatePath("namespaces", namespace, "files", filename)
104116
s result.generatedfiles = result.id _ "/generated"
105117
s result.name = filename
118+
s result.xml = ..CreatePath("namespaces", namespace, "files", filename, "xml")
106119
s result.url = ..GetURLForClass(systemName)
107120
q result
108121
}
@@ -202,12 +215,66 @@ ClassMethod FileAction(namespace As %String, filename As %String) As %Status
202215
q $$$OK
203216
}
204217

218+
ClassMethod GetXML(namespace As %String, filename As %String) As %Status
219+
{
220+
n $namespace
221+
s $namespace = namespace
222+
223+
s exportname = ..FileName(filename) _ "." _ $zcvt(..FileExtension(filename), "U")
224+
s sc = $system.OBJ.ExportToStream(exportname, .stream, "-d")
225+
226+
s result = $$$jsobj
227+
s result.id = ..CreatePath("namespaces", namespace, "files", filename, "xml")
228+
s result.content = $$$jsstream(stream)
229+
230+
s %response.ContentType="application/json"
231+
d result.%WriteJSON()
232+
q $$$OK
233+
}
234+
235+
ClassMethod PutXML(namespace As %String, filename As %String) As %Status
236+
{
237+
n $namespace
238+
s $namespace = namespace
239+
240+
s request = ..GetRequest()
241+
242+
if '$isobject(request.content) {
243+
s stream = ##class(%Stream.TmpCharacter).%New()
244+
d stream.Write(request.content)
245+
} else {
246+
s stream = request.content
247+
}
248+
s sc = $system.OBJ.LoadStream(stream, "-c-d",,.loadedlist)
249+
250+
s result = $$$jsobj
251+
if $$$ISERR(sc)
252+
{
253+
s result.success = $$$jstrue
254+
s result.errors = $$DecomposeStatus^%apiOBJ(sc)
255+
} else {
256+
s result.success = $$$jstrue
257+
s name = $o(loadedlist(""))
258+
s displayname = ..FileName(name) _ "." _ $zcvt(..FileExtension(name),"L")
259+
s result.file = ..FileObject(namespace, displayname)
260+
}
261+
s %response.ContentType="application/json"
262+
d result.%WriteJSON()
263+
q $$$OK
264+
}
265+
266+
ClassMethod PutNewXML(namespace As %String) As %Status
267+
{
268+
//This is fine, because it doesn't make use of filename, yet
269+
q ..PutXML(namespace, "")
270+
}
271+
272+
205273
ClassMethod GetGenerated(namespace As %String, filename As %String) As %Status
206274
{
207275
n $namespace
208276
s $namespace = namespace
209277

210-
s rs = ..DoSQL("")
211278
s type = $zcvt(..FileExtension(filename),"U")
212279
s file = ..FileName(filename)
213280
s results = $$$jslist
@@ -249,6 +316,19 @@ ClassMethod GetGlobalList(namespace As %String)
249316
q $$$OK
250317
}
251318

319+
ClassMethod QueryAction(namespace As %String)
320+
{
321+
n $namespace
322+
s $namespace = namespace
323+
324+
s request = ..GetRequest()
325+
i request.action = "execute"
326+
{
327+
d ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONFromSQL("",request.content)
328+
}
329+
q $$$OK
330+
}
331+
252332
ClassMethod FileExtension(filename As %String) As %String
253333
{
254334
q $zcvt($p(filename, ".", *), "L")

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ InterSystems Cache Development API
55

66
To install the server-side components, run this absurd thing:
77

8-
zn "%SYS" s b=##class(SYS.Database).%OpenId($zu(12,"cachelib")),bk=b.ReadOnly,b.ReadOnly=0 d b.%Save() s s="Github_CDEV",l="/brandonhorst/cdev-server/master/",jf="json/",jn="%CDEV.JSON.",f="base,boolean,list,null,number,object,stream",if="includes.inc",sn="%CDEV.Server",u="/csp/sys/dev" d ##class(Security.SSLConfigs).Create(s) d ##class(Security.Applications).Copy("/csp/sys",u,"CDev REST Application"),##class(Security.Applications).Get(u,.p) s p("DispatchClass")=sn d ##class(Security.Applications).Modify(u,.p) s r=##class(%Net.HttpRequest).%New(),r.Server="raw.github.com",r.Https=1,r.SSLConfiguration=s f i=1:1:$l(f,",") { s t=$p(f,",",i),tn=jn_$zcvt($e(t),"U")_$e(t,2,99) d r.Get(l_jf_t_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,tn,d) d $system.OBJ.Compile(tn,"c-d") } d r.Get(l_jf_if) s i=##class(%Routine).%New(jn_$zcvt($e(if),"U")_$e(if,2,*-3)_$zcvt($e(if,*-2,99),"U")) d i.CopyFromAndSave(r.HttpResponse.Data) d r.Get(l_$zcvt(sn,"O","URL")_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,sn,d) d $system.OBJ.Compile(sn,"c-d") s b.ReadOnly=bk d b.%Save()
8+
zn "%SYS" s b=##class(SYS.Database).%OpenId($zu(12,"cachelib")),bk=b.ReadOnly,b.ReadOnly=0 d b.%Save() s s="Github_CDEV",l="/brandonhorst/cdev-server/v0.2/",jf="json/",jn="%CDEV.JSON.",f="base,boolean,list,null,number,object,stream",if="includes.inc",sn="%CDEV.Server",u="/csp/sys/dev" d ##class(Security.SSLConfigs).Create(s) d ##class(Security.Applications).Copy("/csp/sys",u,"CDev REST Application"),##class(Security.Applications).Get(u,.p) s p("DispatchClass")=sn d ##class(Security.Applications).Modify(u,.p) s r=##class(%Net.HttpRequest).%New(),r.Server="raw.github.com",r.Https=1,r.SSLConfiguration=s f i=1:1:$l(f,",") { s t=$p(f,",",i),tn=jn_$zcvt($e(t),"U")_$e(t,2,99) d r.Get(l_jf_t_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,tn,d) d $system.OBJ.Compile(tn,"c-d") } d r.Get(l_jf_if) s i=##class(%Routine).%New(jn_$zcvt($e(if),"U")_$e(if,2,*-3)_$zcvt($e(if,*-2,99),"U")) d i.CopyFromAndSave(r.HttpResponse.Data) d r.Get(l_$zcvt(sn,"O","URL")_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,sn,d) d $system.OBJ.Compile(sn,"c-d") s b.ReadOnly=bk d b.%Save()
99

1010
Only runs on Cache 2014.1+, and only on Windows (as %Compiler.UDL.TextServices has not yet been ported).

download.mac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
zn "%SYS" s b=##class(SYS.Database).%OpenId($zu(12,"cachelib")),bk=b.ReadOnly,b.ReadOnly=0 d b.%Save() s s="Github_CDEV",l="/brandonhorst/cdev-server/master/",jf="json/",jn="%CDEV.JSON.",f="base,boolean,list,null,number,object,stream",if="includes.inc",sn="%CDEV.Server",u="/csp/sys/dev" d ##class(Security.SSLConfigs).Create(s) d ##class(Security.Applications).Copy("/csp/sys",u,"CDev REST Application"),##class(Security.Applications).Get(u,.p) s p("DispatchClass")=sn d ##class(Security.Applications).Modify(u,.p) s r=##class(%Net.HttpRequest).%New(),r.Server="raw.github.com",r.Https=1,r.SSLConfiguration=s f i=1:1:$l(f,",") { s t=$p(f,",",i),tn=jn_$zcvt($e(t),"U")_$e(t,2,99) d r.Get(l_jf_t_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,tn,d) d $system.OBJ.Compile(tn,"c-d") } d r.Get(l_jf_if) s i=##class(%Routine).%New(jn_$zcvt($e(if),"U")_$e(if,2,*-3)_$zcvt($e(if,*-2,99),"U")) d i.CopyFromAndSave(r.HttpResponse.Data) d r.Get(l_$zcvt(sn,"O","URL")_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,sn,d) d $system.OBJ.Compile(sn,"c-d") s b.ReadOnly=bk d b.%Save()
1+
zn "%SYS" s b=##class(SYS.Database).%OpenId($zu(12,"cachelib")),bk=b.ReadOnly,b.ReadOnly=0 d b.%Save() s s="Github_CDEV",l="/brandonhorst/cdev-server/v0.2/",jf="json/",jn="%CDEV.JSON.",f="base,boolean,list,null,number,object,stream",if="includes.inc",sn="%CDEV.Server",u="/csp/sys/dev" d ##class(Security.SSLConfigs).Create(s) d ##class(Security.Applications).Copy("/csp/sys",u,"CDev REST Application"),##class(Security.Applications).Get(u,.p) s p("DispatchClass")=sn d ##class(Security.Applications).Modify(u,.p) s r=##class(%Net.HttpRequest).%New(),r.Server="raw.github.com",r.Https=1,r.SSLConfiguration=s f i=1:1:$l(f,",") { s t=$p(f,",",i),tn=jn_$zcvt($e(t),"U")_$e(t,2,99) d r.Get(l_jf_t_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,tn,d) d $system.OBJ.Compile(tn,"c-d") } d r.Get(l_jf_if) s i=##class(%Routine).%New(jn_$zcvt($e(if),"U")_$e(if,2,*-3)_$zcvt($e(if,*-2,99),"U")) d i.CopyFromAndSave(r.HttpResponse.Data) d r.Get(l_$zcvt(sn,"O","URL")_".cls") s d=$replace(r.HttpResponse.Data.Read(),$c(10),$c(13,10)) d ##class(%Compiler.UDL.TextServices).SetTextFromString(,sn,d) d $system.OBJ.Compile(sn,"c-d") s b.ReadOnly=bk d b.%Save()

0 commit comments

Comments
 (0)