Skip to content

Commit 2ed2e88

Browse files
committed
CRLF fix
1 parent a9fbd01 commit 2ed2e88

1 file changed

Lines changed: 163 additions & 163 deletions

File tree

MDX2JSON/DashboardRS.cls

Lines changed: 163 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,163 @@
1-
/// Custom result set to get dashboard list, visible to user in a specific folder
2-
Class MDX2JSON.DashboardRS Extends %SQL.CustomResultSet
3-
{
4-
5-
Parameter global = "^DeepSee.FolderItemD";
6-
7-
Parameter dashclass = "%DeepSee.Dashboard.Definition";
8-
9-
Property title As %String;
10-
11-
Property path As %String;
12-
13-
Property cover As %String;
14-
15-
Property id As %String [ Private ];
16-
17-
Property folder As %String [ Private ];
18-
19-
Method %OpenCursor(folderName As %String = "") As %Status
20-
{
21-
return:((folderName'="") && ('$IsObject(##class(%DeepSee.UserLibrary.Utils).%FindFolder(folderName)))) $$$ERROR($$$GeneralError,"Folder " _ folderName _ " does not exist")
22-
set ..id = ""
23-
set ..folder = folderName
24-
return $$$OK
25-
}
26-
27-
Method %Next(ByRef sc As %Library.Status) As %Integer [ PlaceAfter = %Execute ]
28-
{
29-
set sc = $$$OK
30-
do ..SetNextId()
31-
set id = ..id
32-
return:id="" $$$NO
33-
34-
set title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
35-
// While empty Title use Name instead
36-
set:(title="") title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id))
37-
38-
set ..title = title
39-
set ..path = ..GetDashFullName(id)
40-
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
41-
42-
return $$$YES
43-
}
44-
45-
/// Iterate over data global till we find dashboard definition
46-
/// thet satisfies all conditions
47-
Method SetNextId()
48-
{
49-
set ..id = $order(@..#global@(..id))
50-
if ((..id'="") && ('..CheckConditions(..id))) {
51-
// we are not at the last row and we failed condition check
52-
// so we get the next id
53-
do ..SetNextId()
54-
}
55-
}
56-
57-
/// Check if element with that id satisfies our conditions
58-
Method CheckConditions(id) As %Boolean
59-
{
60-
/// first we check that it's a dashboard (not a pivot, etc.)
61-
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
62-
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
63-
return:class'=..#dashclass $$$NO
64-
65-
/// second that it's not a hidden or deleted dashboard
66-
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
67-
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
68-
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO
69-
70-
/// third we check if a dashboard is in a correct folder
71-
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
72-
73-
/// fourth we check if the user has access to a dashboard
74-
return:'..CheckItemResource(id) $$$NO
75-
76-
return $$$YES
77-
}
78-
79-
/// Get dashboard full name by id
80-
ClassMethod GetDashFullName(id As %String)
81-
{
82-
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
83-
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
84-
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
85-
}
86-
87-
/// Test if the current user has access to this item.
88-
ClassMethod CheckItemResource(id As %String, privilege As %String = "USE") As %Boolean
89-
{
90-
set access = $$$NO
91-
set resource = ..GetItemResource(id)
92-
if ((resource="")||($System.Security.Check(resource, privilege))) {
93-
set access = $$$YES
94-
}
95-
return access
96-
}
97-
98-
/// Get the resource value for this item.
99-
ClassMethod GetItemResource(id As %String) As %String
100-
{
101-
set resource = ##class(%DeepSee.UserLibrary.FolderItem).resourceGetStored(id)
102-
if (resource="") {
103-
// inherit from folder
104-
if ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)'="" {
105-
set resource = ..GetFolderResource(##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id))
106-
}
107-
}
108-
return resource
109-
}
110-
111-
/// Get the resource value for this folder.
112-
ClassMethod GetFolderResource(folderId As %String) As %String
113-
{
114-
if (##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)'="") {
115-
return ##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)
116-
} elseif (##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId)'="") {
117-
return ..GetFolderResource(##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId))
118-
}
119-
return ""
120-
}
121-
122-
/// Get all dashes from SAMPLES namespace
123-
/// do ##class(MDX2JSON.DashboardRS).Test()
124-
ClassMethod Test(folderName As %String = "")
125-
{
126-
new $namespace
127-
set $namespace = "Samples"
128-
set rs = ..%New(,folderName)
129-
do rs.%Display()
130-
}
131-
132-
/// Execute query and output results as JSON
133-
ClassMethod WriteJSON(folderName As %String = "")
134-
{
135-
#define CRLF $c(13,10)
136-
#define ZENJSISNUM(%val) ($IsValidNum(%val)&&(%val=+(%val)))
137-
#define ZENJSNUM(%num) $fnumber(%num,"LON")
138-
#; JSON utility macros that use the JSON translation table instead of the JS translation table
139-
#define ZENJSTABLE(%format) ("JS"_$S(%format["u":"ML",1:""))
140-
#define ZENJSONTABLE(%format) ("JSON"_$S((%format["u"):"ML",1:""))
141-
#define ZENJSONESCAPE(%str,%format) $S(%format["s":$ZCVT(%str,"O",$$$ZENJSONTABLE(%format)),1:$Replace($ZCVT(%str,"O",$$$ZENJSTABLE(%format)),"\'","'"))
142-
#define ZENJSONSTR(%str,%format) (""""_$$$ZENJSONESCAPE(%str,%format)_"""")
143-
#define ZENJSONPROP(%prop,%format) $$$ZENJSONSTR(%prop,%format)
144-
#define ZENJSONVALUE(%val,%format) $S($$$ZENJSISNUM(%val):$$$ZENJSNUM(%val),$C(0)=(%val)||$ListValid(%val):"""""",1:$$$ZENJSONSTR(%val,%format))
145-
#define ZENJSONPAIR(%pr,%val,%format) $$$ZENJSONPROP(%pr,%format)_":"_$$$ZENJSONVALUE(%val,%format)
146-
147-
set rs = ..%New(,folderName)
148-
write "{ ""children"":["
149-
set separator=0
150-
while rs.%Next() {
151-
write:separator ",",$$$CRLF
152-
write "{"
153-
write $$$ZENJSONPAIR("title",rs.title,""),","
154-
write $$$ZENJSONPAIR("path",rs.path,""),","
155-
write $$$ZENJSONPAIR("Cover",rs.cover,"")
156-
write "}"
157-
158-
set separator = 1
159-
}
160-
write "]}"
161-
}
162-
163-
}
1+
/// Custom result set to get dashboard list, visible to user in a specific folder
2+
Class MDX2JSON.DashboardRS Extends %SQL.CustomResultSet
3+
{
4+
5+
Parameter global = "^DeepSee.FolderItemD";
6+
7+
Parameter dashclass = "%DeepSee.Dashboard.Definition";
8+
9+
Property title As %String;
10+
11+
Property path As %String;
12+
13+
Property cover As %String;
14+
15+
Property id As %String [ Private ];
16+
17+
Property folder As %String [ Private ];
18+
19+
Method %OpenCursor(folderName As %String = "") As %Status
20+
{
21+
return:((folderName'="") && ('$IsObject(##class(%DeepSee.UserLibrary.Utils).%FindFolder(folderName)))) $$$ERROR($$$GeneralError,"Folder " _ folderName _ " does not exist")
22+
set ..id = ""
23+
set ..folder = folderName
24+
return $$$OK
25+
}
26+
27+
Method %Next(ByRef sc As %Library.Status) As %Integer [ PlaceAfter = %Execute ]
28+
{
29+
set sc = $$$OK
30+
do ..SetNextId()
31+
set id = ..id
32+
return:id="" $$$NO
33+
34+
set title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
35+
// While empty Title use Name instead
36+
set:(title="") title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id))
37+
38+
set ..title = title
39+
set ..path = ..GetDashFullName(id)
40+
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
41+
42+
return $$$YES
43+
}
44+
45+
/// Iterate over data global till we find dashboard definition
46+
/// thet satisfies all conditions
47+
Method SetNextId()
48+
{
49+
set ..id = $order(@..#global@(..id))
50+
if ((..id'="") && ('..CheckConditions(..id))) {
51+
// we are not at the last row and we failed condition check
52+
// so we get the next id
53+
do ..SetNextId()
54+
}
55+
}
56+
57+
/// Check if element with that id satisfies our conditions
58+
Method CheckConditions(id) As %Boolean
59+
{
60+
/// first we check that it's a dashboard (not a pivot, etc.)
61+
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
62+
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
63+
return:class'=..#dashclass $$$NO
64+
65+
/// second that it's not a hidden or deleted dashboard
66+
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
67+
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
68+
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO
69+
70+
/// third we check if a dashboard is in a correct folder
71+
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
72+
73+
/// fourth we check if the user has access to a dashboard
74+
return:'..CheckItemResource(id) $$$NO
75+
76+
return $$$YES
77+
}
78+
79+
/// Get dashboard full name by id
80+
ClassMethod GetDashFullName(id As %String)
81+
{
82+
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
83+
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
84+
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
85+
}
86+
87+
/// Test if the current user has access to this item.
88+
ClassMethod CheckItemResource(id As %String, privilege As %String = "USE") As %Boolean
89+
{
90+
set access = $$$NO
91+
set resource = ..GetItemResource(id)
92+
if ((resource="")||($System.Security.Check(resource, privilege))) {
93+
set access = $$$YES
94+
}
95+
return access
96+
}
97+
98+
/// Get the resource value for this item.
99+
ClassMethod GetItemResource(id As %String) As %String
100+
{
101+
set resource = ##class(%DeepSee.UserLibrary.FolderItem).resourceGetStored(id)
102+
if (resource="") {
103+
// inherit from folder
104+
if ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)'="" {
105+
set resource = ..GetFolderResource(##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id))
106+
}
107+
}
108+
return resource
109+
}
110+
111+
/// Get the resource value for this folder.
112+
ClassMethod GetFolderResource(folderId As %String) As %String
113+
{
114+
if (##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)'="") {
115+
return ##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)
116+
} elseif (##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId)'="") {
117+
return ..GetFolderResource(##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId))
118+
}
119+
return ""
120+
}
121+
122+
/// Get all dashes from SAMPLES namespace
123+
/// do ##class(MDX2JSON.DashboardRS).Test()
124+
ClassMethod Test(folderName As %String = "")
125+
{
126+
new $namespace
127+
set $namespace = "Samples"
128+
set rs = ..%New(,folderName)
129+
do rs.%Display()
130+
}
131+
132+
/// Execute query and output results as JSON
133+
ClassMethod WriteJSON(folderName As %String = "")
134+
{
135+
#define CRLF $c(13,10)
136+
#define ZENJSISNUM(%val) ($IsValidNum(%val)&&(%val=+(%val)))
137+
#define ZENJSNUM(%num) $fnumber(%num,"LON")
138+
#; JSON utility macros that use the JSON translation table instead of the JS translation table
139+
#define ZENJSTABLE(%format) ("JS"_$S(%format["u":"ML",1:""))
140+
#define ZENJSONTABLE(%format) ("JSON"_$S((%format["u"):"ML",1:""))
141+
#define ZENJSONESCAPE(%str,%format) $S(%format["s":$ZCVT(%str,"O",$$$ZENJSONTABLE(%format)),1:$Replace($ZCVT(%str,"O",$$$ZENJSTABLE(%format)),"\'","'"))
142+
#define ZENJSONSTR(%str,%format) (""""_$$$ZENJSONESCAPE(%str,%format)_"""")
143+
#define ZENJSONPROP(%prop,%format) $$$ZENJSONSTR(%prop,%format)
144+
#define ZENJSONVALUE(%val,%format) $S($$$ZENJSISNUM(%val):$$$ZENJSNUM(%val),$C(0)=(%val)||$ListValid(%val):"""""",1:$$$ZENJSONSTR(%val,%format))
145+
#define ZENJSONPAIR(%pr,%val,%format) $$$ZENJSONPROP(%pr,%format)_":"_$$$ZENJSONVALUE(%val,%format)
146+
147+
set rs = ..%New(,folderName)
148+
write "{ ""children"":["
149+
set separator=0
150+
while rs.%Next() {
151+
write:separator ",",$$$CRLF
152+
write "{"
153+
write $$$ZENJSONPAIR("title",rs.title,""),","
154+
write $$$ZENJSONPAIR("path",rs.path,""),","
155+
write $$$ZENJSONPAIR("Cover",rs.cover,"")
156+
write "}"
157+
158+
set separator = 1
159+
}
160+
write "]}"
161+
}
162+
163+
}

0 commit comments

Comments
 (0)