Skip to content

updated code #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 40 additions & 49 deletions MDX2JSON/AbstractREST.cls.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Export generator="IRIS" version="26">
<Class name="MDX2JSON.AbstractREST">
<Description>
All logic related to the proceccing of http requests.</Description>
Expand All @@ -12,6 +12,10 @@ All logic related to the proceccing of http requests.</Description>
<Default>1</Default>
</Parameter>

<Parameter name="HandleCorsRequest">
<Default>1</Default>
</Parameter>

<Method name="DispatchRequest">
<Description><![CDATA[
Dispatch a REST request according to URL and Method.<br>
Expand All @@ -34,6 +38,12 @@ Add param Namespace to a request to execute MDX in desired namespace.]]></Descri
Set %response.CharSet = "utf-8"
Set %response.ContentType="application/json"

If (%request.GetCgiEnv("REQUEST_METHOD") = "OPTIONS"){
//Do %response.WriteHTTPHeader()
Return $$$OK
}


Set %session.Language=$$MatchLanguage^%occMessages(%request.GetCgiEnv("HTTP_ACCEPT_LANGUAGE"),"%CSP","+s") // Localization support
Set %response.Language=%session.Language

Expand Down Expand Up @@ -167,6 +177,7 @@ Validates incoming request body against Body Route attribute.</Description>
<Implementation><![CDATA[
#dim %request As %CSP.Request


return:(pMethod'="POST") $$$OK
return:(pBody="") $$$OK
return:'$d(%request.Content.%data(pBody)) $$$ERROR($$$PropertyRequired,pBody)
Expand Down Expand Up @@ -233,8 +244,8 @@ Called for a REST page in the event of a login being required</Description>
#; Don't want the session token
Set %response.OutputSessionToken = 0

#; We don't want Basic authentication usually
Do:$$$Debug %response.SetHeader("WWW-Authenticate","Basic")
#; We want Basic authentication
//Do %response.SetHeader("WWW-Authenticate","Basic")

#; We need to manually write out the headers here because PAGE has not been called
Do %response.WriteHTTPHeader()
Expand All @@ -254,10 +265,7 @@ Issue an '500' error and give some indication as to what occurred.<br>
// we are expecting status
#; Set the response Http status
Set %response.Status="500 Internal Server Error"

#; Skip duplicate calls
Quit:$isObject(pStatus) $$$OK


#; Return a helpful error string
Write "{""Error"":"_$$$ZENJSSTR($System.Status.GetErrorText(pStatus,%session.Language))_"}"

Expand Down Expand Up @@ -308,21 +316,15 @@ Returns OK if namespace both exists and contains MDX2JSON package.<br>
return $$$OK
}

return:('##class(%SYS.Namespace).Exists(Namespace)) $$$ERROR($$$NamespaceUnavailable, Namespace)
new $Namespace
set $Namespace = Namespace

set class = "MDX2JSON.Utils"

set exists = ##class(%Dictionary.CompiledClass).%ExistsId(class)
return:(exists=$$$NO) $$$ERROR($$$GeneralError, "MDX2JSON package is not mapped to " _ Namespace)

// If the current namespace holds unmapped MDX2JSON, include it regardless of dashboards existence
return:(##class(%RoutineMgr).IsMapped(class _ ".cls") = $$$NO) $$$OK

// Strictly speaking this can be a false-positive check
set exists = ($data(@##class(MDX2JSON.DashboardRS).#global)>0)
return:(exists=$$$NO) $$$ERROR($$$GeneralError, "No dashboards exist in " _ Namespace)
return:('##class(%SYS.Namespace).Exists(Namespace)) $$$ERROR($$$NamespaceUnavailable,Namespace)

if Namespace'=$Namespace {
set oldNS = $Namespace
zn Namespace
set exists = ##class(%Dictionary.CompiledClass).%ExistsId("MDX2JSON.Utils")
zn oldNS
return:(exists=0) $$$ERROR($$$GeneralError, "MDX2JSON package is not mapped to " _ Namespace)
}

return $$$OK
]]></Implementation>
Expand All @@ -333,10 +335,11 @@ Returns OK if namespace both exists and contains MDX2JSON package.<br>
This project creates the DispatchMethod used to dispatch the Url and Method to the associated target method</Description>
<ClassMethod>1</ClassMethod>
<CodeMode>generator</CodeMode>
<FormalSpec>pIndex:%Integer</FormalSpec>
<FormalSpec>pIndex:%String,pMethod:%String,*pResourceMatched:%Boolean,*pMatcher:%Regex.Matcher</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
#dim tSC As %Status = $$$OK

#dim e As %Exception.AbstractException

#dim tStream As %Stream.TmpCharacter
Expand Down Expand Up @@ -474,34 +477,22 @@ pArgs - additional arguments]]></Description>
<ProcedureBlock>0</ProcedureBlock>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set tOldIORedirected = ##class(%Device).ReDirectIO()
set tOldMnemonic = ##class(%Device).GetMnemonicRoutine()
set tOldIO = $io
try {
set str=""

//Redirect IO to the current routine - makes use of the labels defined below
use $io::("^"_$ZNAME)

//Enable redirection
do ##class(%Device).ReDirectIO(1)

if $isobject(pObj) {
do $Method(pObj,pMethod,pArgs...)
} elseif $$$comClassDefined(pObj) {
do $ClassMethod(pObj,pMethod,pArgs...)
}
} catch ex {
set str = ""
}
set str=""

//Redirect IO to the current routine - makes use of the labels defined below
use $io::("^"_$ZNAME)

//Return to original redirection/mnemonic routine settings
if (tOldMnemonic '= "") {
use tOldIO::("^"_tOldMnemonic)
} else {
use tOldIO
//Enable redirection
do ##class(%Device).ReDirectIO(1)

if $isobject(pObj) {
do $Method(pObj,pMethod,pArgs...)
} elseif $$$comClassDefined(pObj) {
do $ClassMethod(pObj,pMethod,pArgs...)
}
do ##class(%Device).ReDirectIO(tOldIORedirected)

//Disable redirection
do ##class(%Device).ReDirectIO(0)

quit str

Expand Down
42 changes: 21 additions & 21 deletions MDX2JSON/Dashboard.cls.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Export generator="IRIS" version="26">
<Class name="MDX2JSON.Dashboard">
<Description>
Class with methods related to DeepSee Dashboard and Widget processing.</Description>
Expand Down Expand Up @@ -87,26 +87,26 @@ Opens DeepSee dashboard by it's name. Returns status of aatempt to locate and op
<FormalSpec>DashName:%Integer,*Dashboard:%DeepSee.Dashboard.Definition</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
kill Dashboard
set id = ""
set global = ##class(MDX2JSON.DashboardRS).#global
set dashclass = ##class(MDX2JSON.DashboardRS).#dashclass
for {
set id = $order(@global@(id))
quit:id=""
/// first we check that it's a dashboard (not a pivot, etc.)
kill Dashboard
set id = ""
set global = ##class(MDX2JSON.DashboardRS).#global
set dashclass = ##class(MDX2JSON.DashboardRS).#dashclass
for {
set id = $order(@global@(id))
quit:id=""
/// first we check that it's a dashboard (not a pivot, etc.)
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
CONTINUE:class'=dashclass
/// second we check that it's the one we need
quit:$ZCVT(##class(MDX2JSON.DashboardRS).GetDashFullName(id),"L")=$ZCVT(DashName,"L")
}
return:id="" $$$ERROR($$$GeneralError,"Dashboard " _ DashName _ " does not exist")
set Dashboard = ##class(%DeepSee.Dashboard.Definition).%OpenId(id,,.st)
return st
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
CONTINUE:class'=dashclass
/// second we check that it's the one we need
quit:$ZCVT(##class(MDX2JSON.DashboardRS).GetDashFullName(id),"L")=$ZCVT(DashName,"L")
}
return:id="" $$$ERROR($$$GeneralError,"Dashboard " _ DashName _ " does not exist")
set Dashboard = ##class(%DeepSee.Dashboard.Definition).%OpenId(id,,.st)
return st
]]></Implementation>
</Method>

Expand Down Expand Up @@ -460,7 +460,7 @@ Returns name of widget's pivot source cube.</Description>
</Method>

<Storage name="Default">
<Type>%Library.CacheStorage</Type>
<Type>%Storage.Persistent</Type>
</Storage>

<Method name="DetermineWidgetDataSource">
Expand Down
2 changes: 1 addition & 1 deletion MDX2JSON/DashboardFilters.cls.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Export generator="IRIS" version="26">
<Class name="MDX2JSON.DashboardFilters">
<Description>
Class with methods related to DeepSee Dashboard and Widget processing.</Description>
Expand Down
84 changes: 42 additions & 42 deletions MDX2JSON/DashboardRS.cls.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Export generator="IRIS" version="26">
<Class name="MDX2JSON.DashboardRS">
<Description>
Custom result set to get dashboard list, visible to user in a specific folder</Description>
Expand Down Expand Up @@ -41,9 +41,9 @@ Custom result set to get dashboard list, visible to user in a specific folder</D
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
return:((folderName'="") && ('$IsObject(##class(%DeepSee.UserLibrary.Utils).%FindFolder(folderName)))) $$$ERROR($$$GeneralError,"Folder " _ folderName _ " does not exist")
set ..id = ""
set ..folder = folderName
return $$$OK
set ..id = ""
set ..folder = folderName
return $$$OK
]]></Implementation>
</Method>

Expand All @@ -52,16 +52,16 @@ Custom result set to get dashboard list, visible to user in a specific folder</D
<PlaceAfter>%Execute</PlaceAfter>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
set sc = $$$OK
do ..SetNextId()
set id = ..id
return:id="" $$$NO
set ..title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
set ..path = ..GetDashFullName(id)
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
return $$$YES
set sc = $$$OK
do ..SetNextId()
set id = ..id
return:id="" $$$NO
set ..title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
set ..path = ..GetDashFullName(id)
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
return $$$YES
]]></Implementation>
</Method>

Expand All @@ -71,11 +71,11 @@ Iterate over data global till we find dashboard definition
thet satisfies all conditions</Description>
<Implementation><![CDATA[
set ..id = $order(@..#global@(..id))
if ((..id'="") && ('..CheckConditions(..id))) {
// we are not at the last row and we failed condition check
// so we get the next id
do ..SetNextId()
}
if ((..id'="") && ('..CheckConditions(..id))) {
// we are not at the last row and we failed condition check
// so we get the next id
do ..SetNextId()
}
]]></Implementation>
</Method>

Expand All @@ -87,18 +87,18 @@ Check if element with that id satisfies our conditions</Description>
<Implementation><![CDATA[
/// first we check that it's a dashboard (not a pivot, etc.)
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
return:class'=..#dashclass $$$NO
/// second that it's not a hidden or deleted dashboard
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO

/// third we check if a dashboard is in a correct folder
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
/// fourth we check if the user has access to a dashboard
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
return:class'=..#dashclass $$$NO
/// second that it's not a hidden or deleted dashboard
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO

/// third we check if a dashboard is in a correct folder
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
/// fourth we check if the user has access to a dashboard
return:'..CheckItemResource(id) $$$NO

return $$$YES
Expand All @@ -112,8 +112,8 @@ Get dashboard full name by id</Description>
<FormalSpec>id:%String</FormalSpec>
<Implementation><![CDATA[
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
]]></Implementation>
</Method>

Expand Down Expand Up @@ -183,7 +183,7 @@ do ##class(MDX2JSON.DashboardRS).Test()</Description>

<Method name="WriteJSON">
<Description>
Execute query and output results as JSON</Description>
Execute query and output results as JSON</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>folderName:%String=""</FormalSpec>
<Implementation><![CDATA[
Expand All @@ -205,14 +205,14 @@ do ##class(MDX2JSON.DashboardRS).Test()</Description>
while rs.%Next() {
write:separator ",",$$$CRLF
write "{"
write $$$ZENJSONPAIR("title",rs.title,""),","
write $$$ZENJSONPAIR("path",rs.path,""),","
write $$$ZENJSONPAIR("Cover",rs.cover,"")
write "}"
set separator = 1
}
write "]}"
write $$$ZENJSONPAIR("title",rs.title,""),","
write $$$ZENJSONPAIR("path",rs.path,""),","
write $$$ZENJSONPAIR("Cover",rs.cover,"")
write "}"
set separator = 1
}
write "]}"
]]></Implementation>
</Method>
</Class>
Expand Down
2 changes: 1 addition & 1 deletion MDX2JSON/EmptyPortlet.cls.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Export generator="IRIS" version="26">
<Class name="MDX2JSON.EmptyPortlet">
<Super>%DeepSee.Component.Portlet.abstractPortlet</Super>
<TimeCreated>63677,67001.020851</TimeCreated>
Expand Down
Loading