1- <?xml version =" 1.0" encoding =" UTF-8" ?>
2- <Export generator =" Cache" version =" 25" >
3- <Class name =" MDX2JSON.AbstractREST" >
4- <Description >
5- All logic related to the proceccing of http requests.</Description >
6- <IncludeCode >MDX2JSON.MDX2JSON</IncludeCode >
7- <Super >%CSP.REST</Super >
8- <TimeCreated >63572,78432.426689</TimeCreated >
1+ Include MDX2JSON .MDX2JSON
92
10- <Parameter name =" UseSession" >
11- <Type >Integer</Type >
12- <Default >1</Default >
13- </Parameter >
3+ /// All logic related to the proceccing of http requests.
4+ Class MDX2JSON .AbstractREST Extends %CSP .REST
5+ {
146
15- <Method name =" OnPreDispatch" >
16- <Description >
17- This method gets called prior to dispatch of the request. Put any common code here
18- that you want to be executed for EVERY request. If pContinue is set to 0, the
19- request will NOT be dispatched according to the UrlMap. In this case it's the
20- responsibility of the user to return a response.</Description >
21- <ClassMethod >1</ClassMethod >
22- <FormalSpec ><![CDATA[ pUrl:%String,pMethod:%String,&pContinue:%Boolean]]> </FormalSpec >
23- <ReturnType >%Status</ReturnType >
24- <Implementation ><![CDATA[
7+ Parameter UseSession As Integer = 1 ;
8+
9+ /// This method gets called prior to dispatch of the request. Put any common code here
10+ /// that you want to be executed for EVERY request. If pContinue is set to 0, the
11+ /// request will NOT be dispatched according to the UrlMap. In this case it's the
12+ /// responsibility of the user to return a response.
13+ ClassMethod OnPreDispatch (pUrl As %String , pMethod As %String , ByRef pContinue As %Boolean ) As %Status
14+ {
2515 Set pContinue = 1
2616 #dim request As %CSP.Request
2717 Do %response .SetHeader (" Access-Control-Allow-Origin" ,..GetOrigins ())
@@ -58,15 +48,11 @@ responsibility of the user to return a response.</Description>
5848 }
5949
6050 Quit $$$OK
61- ]]> </Implementation >
62- </Method >
51+ }
6352
64- <Method name =" ConvertRequestBody" >
65- <Description >
66- Converts request into UTF8. Converts request into proxyObject. </Description >
67- <ClassMethod >1</ClassMethod >
68- <ReturnType >%Status</ReturnType >
69- <Implementation ><![CDATA[
53+ /// Converts request into UTF8. Converts request into proxyObject.
54+ ClassMethod ConvertRequestBody () As %Status
55+ {
7056 #dim %request As %CSP.Request
7157 #dim obj As %ZEN.proxyObject
7258
@@ -81,27 +67,18 @@ Converts request into UTF8. Converts request into proxyObject. </Description>
8167
8268 set %request .Content = obj // obj here is a valid UTF8 proxyObject with required property
8369 return $$$OK
84- ]]> </Implementation >
85- </Method >
70+ }
8671
87- <Method name =" GetOrigins" >
88- <Description >
89- Get Origin from %request object </Description >
90- <ClassMethod >1</ClassMethod >
91- <ReturnType >%String</ReturnType >
92- <Implementation ><![CDATA[
72+ /// Get Origin from %request object
73+ ClassMethod GetOrigins () As %String
74+ {
9375 set url = %request .GetCgiEnv (" HTTP_REFERER" )
9476 return $p (url ," /" ,1 ,3 ) // get http(s)://origin.com:port
95- ]]> </Implementation >
96- </Method >
77+ }
9778
98- <Method name =" Login" >
99- <Description >
100- Called for a REST page in the event of a login being required</Description >
101- <ClassMethod >1</ClassMethod >
102- <FormalSpec >skipheader:%Boolean=1</FormalSpec >
103- <ReturnType >%Status</ReturnType >
104- <Implementation ><![CDATA[
79+ /// Called for a REST page in the event of a login being required
80+ ClassMethod Login (skipheader As %Boolean = 1 ) As %Status
81+ {
10582 Do %response .SetHeader (" Access-Control-Allow-Origin" ,..GetOrigins ())
10683 Do %response .SetHeader (" Access-Control-Allow-Credentials" ," true" )
10784 Do %response .SetHeader (" Access-Control-Allow-Methods" ," GET, PUT, POST, DELETE, OPTIONS" )
@@ -127,17 +104,12 @@ Called for a REST page in the event of a login being required</Description>
127104 Do %response .WriteHTTPHeader ()
128105
129106 Return $$$OK
130- ]]> </Implementation >
131- </Method >
107+ }
132108
133- <Method name =" Http500" >
134- <Description ><![CDATA[
135- Issue an '500' error and give some indication as to what occurred.<br>
136- <b>pStatus</b> - %status, not %Exception.AbstractException.]]> </Description >
137- <ClassMethod >1</ClassMethod >
138- <FormalSpec >pStatus:%Exception.AbstractException</FormalSpec >
139- <ReturnType >%Status</ReturnType >
140- <Implementation ><![CDATA[
109+ /// Issue an '500' error and give some indication as to what occurred.<br>
110+ /// <b>pStatus</b> - %status, not %Exception.AbstractException.
111+ ClassMethod Http500 (pStatus As %Exception .AbstractException ) As %Status
112+ {
141113 // we are expecting status
142114 #; Set the response Http status
143115 Set %response .Status =" 500 Internal Server Error"
@@ -149,15 +121,11 @@ Issue an '500' error and give some indication as to what occurred.<br>
149121 Write " {" " Error" " :" _$$$ZENJSSTR($System .Status .GetErrorText (pStatus ,%session .Language ))_" }"
150122
151123 Quit $$$OK
152- ]]> </Implementation >
153- </Method >
124+ }
154125
155- <Method name =" GetMappings" >
156- <Description >
157- Returns info about MDX2JSON package mapping</Description >
158- <ClassMethod >1</ClassMethod >
159- <ReturnType >%ArrayOfObjects</ReturnType >
160- <Implementation ><![CDATA[
126+ /// Returns info about MDX2JSON package mapping
127+ ClassMethod GetMappings () As %ArrayOfObjects
128+ {
161129 Set result = ##class (%ArrayOfObjects ).%New ()
162130 Set mapped = ##class (%ListOfDataTypes ).%New ()
163131 Set unmapped = ##class (%ListOfDataTypes ).%New ()
@@ -179,17 +147,12 @@ Returns info about MDX2JSON package mapping</Description>
179147 do result .SetAt (mapped ," Mapped" )
180148 do result .SetAt (unmapped ," Unmapped" )
181149 return result
182- ]]> </Implementation >
183- </Method >
150+ }
184151
185- <Method name =" CheckNamespace" >
186- <Description ><![CDATA[
187- Returns OK if namespace both exists and contains MDX2JSON package.<br>
188- <b>Namespace</b> - name of namespace. Sets namespace variable to current namespace if empty or missing.]]> </Description >
189- <ClassMethod >1</ClassMethod >
190- <FormalSpec ><![CDATA[ &Namespace:%String=$Namespace]]> </FormalSpec >
191- <ReturnType >%Status</ReturnType >
192- <Implementation ><![CDATA[
152+ /// Returns OK if namespace both exists and contains MDX2JSON package.<br>
153+ /// <b>Namespace</b> - name of namespace. Sets namespace variable to current namespace if empty or missing.
154+ ClassMethod CheckNamespace (ByRef Namespace As %String = {$Namespace }) As %Status
155+ {
193156 if (Namespace = " " ) {
194157 set Namespace = $Namespace
195158 return $$$OK
@@ -212,20 +175,14 @@ Returns OK if namespace both exists and contains MDX2JSON package.<br>
212175 return :(exists =$$$NO) $$$ERROR($$$GeneralError, " No dashboards exist in " _ Namespace )
213176
214177 return $$$OK
215- ]]> </Implementation >
216- </Method >
217-
218- <Method name =" OutputToStr" >
219- <Description ><![CDATA[
220- Executes actions and returns device output <br>
221- pObj - OREF or class<br>
222- pMethod - instance or class method to execute respectively<br>
223- pArgs - additional arguments]]> </Description >
224- <ClassMethod >1</ClassMethod >
225- <FormalSpec >pObj,pMethod,pArgs...</FormalSpec >
226- <ProcedureBlock >0</ProcedureBlock >
227- <ReturnType >%String</ReturnType >
228- <Implementation ><![CDATA[
178+ }
179+
180+ /// Executes actions and returns device output <br>
181+ /// pObj - OREF or class<br>
182+ /// pMethod - instance or class method to execute respectively<br>
183+ /// pArgs - additional arguments
184+ ClassMethod OutputToStr (pObj , pMethod , pArgs ...) As %String [ ProcedureBlock = 0 ]
185+ {
229186 set tOldIORedirected = ##class (%Device ).ReDirectIO ()
230187 set tOldMnemonic = ##class (%Device ).GetMnemonicRoutine ()
231188 set tOldIO = $io
@@ -275,7 +232,6 @@ wtab(s) do output($char(9)) quit
275232 //Output label - this is where you would handle what you actually want to do.
276233 // in our case, we want to write to str
277234output (s ) set str =str _s quit
278- ]]> </Implementation >
279- </Method >
280- </Class >
281- </Export >
235+ }
236+
237+ }
0 commit comments