Skip to content

Commit a16b4af

Browse files
authored
Merge pull request #77 from psteiwer/dev
v1.3
2 parents 02a6b16 + d892f01 commit a16b4af

9 files changed

Lines changed: 371 additions & 293 deletions

File tree

PivotSubscriptions/EventLog.cls

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
Class PivotSubscriptions.EventLog Extends %Persistent
33
{
44

5-
/*
6-
* Only possible values are creation, update, deletion, send, and tableError
7-
*/
8-
/// Event Type covers: creation, update, deletion and sent email subscriptions
9-
Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,sendError,tableError");
5+
/// Event Type covers: create, update, delete, sendSubscription, and tableError
6+
Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,tableError");
107

118
Property StartTime As %TimeStamp [ InitialExpression = {$zdt($h, 3, 1)} ];
129

@@ -31,7 +28,7 @@ Property Name As %String(MAXLEN = 100);
3128
Property Status As %Status;
3229

3330
/// Takes in info about an Alert Task and logs the information to the TaskLog
34-
ClassMethod LogEvent(pType, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status
31+
ClassMethod CreateEvent(pType, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status
3532
{
3633
Set tSC=$$$OK
3734

@@ -48,18 +45,13 @@ ClassMethod LogEvent(pType, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat,
4845
Set tEventLog.Format=pFormat
4946
Set tEventLog.Emails=pEmails
5047

51-
If pType="tableError" {
52-
Set tEventLog.Status=$$$OK
53-
Set tEventLog.EndTime=$zdt($h,3,1)
54-
}
55-
5648
Set tSC=tEventLog.%Save()
5749
Set pEvent=tEventLog
5850

5951
Quit tSC
6052
}
6153

62-
Method LogUpdate(pStatus) As %Status
54+
Method UpdateStatus(pStatus) As %Status
6355
{
6456
Set tSC=$$$OK
6557

@@ -70,6 +62,22 @@ Method LogUpdate(pStatus) As %Status
7062
Quit tSC
7163
}
7264

65+
Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName) As %Status
66+
{
67+
Set tSC=$$$OK
68+
69+
Set ..DayOfWeek=pDayOfWeek
70+
Set ..Hour=pHour
71+
Set ..Minute=pMinute
72+
Set ..Format=pFormat
73+
Set ..Emails=pEmails
74+
Set ..Name=pName
75+
76+
Set tSC=..%Save()
77+
78+
Quit tSC
79+
}
80+
7381
ClassMethod DayOfWeekDisplay(pDayOfWeek) As %String [ SqlProc ]
7482
{
7583
Set pDayOfWeek=$Replace(pDayOfWeek,0,"Sunday")

PivotSubscriptions/Installer.cls

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
Class PivotSubscriptions.Installer
2-
{
3-
4-
ClassMethod RunInstaller(pRootDir)
5-
{
6-
Set tSC=$$$OK
7-
8-
If pRootDir'="" {
9-
Do $system.OBJ.LoadDir(pRootDir_"/PivotSubscriptions","ck",,1)
10-
Set tSC=..ImportImage(pRootDir_"/Assets/PivotSubscriptions_BookCover.png")
11-
If $$$ISERR(tSC) Quit
12-
}
13-
14-
Set tItem=##class(%DeepSee.UserLibrary.Link).%New()
15-
Set tItem.fullName="Pivot Subscriptions"
16-
Set tPage="PivotSubscriptions.UI.SubscriptionManager.zen"
17-
Set tItem.href=$system.CSP.GetPortalApp($namespace,tPage)_tPage
18-
Set tItem.title="Pivot Subscriptions"
19-
Set tItem.bookCover="{background: {style:'background:white;',src:'covers/PivotSubscriptions_Cover.png'},header: {text:'$type',style:'display: none;'},title: {text:'$title',style:'display: none;'},image: {style:'display: none;',src:'deepsee/ds2_globe_44.png',imageStyle:'width:64px;height:64px;'},subtitle: {style:'display: none;'},footer: {text:'$owner',style:'display: none;'}}"
20-
Set tSC=tItem.%Save()
21-
22-
If $$$ISERR(tSC) Quit
23-
24-
Set tSC=##class(PivotSubscriptions.Task).ConfigureTask()
25-
26-
Quit tSC
27-
}
28-
29-
/// Import Cover, code taken from %DeepSee.UI.Dialog.ImageUpload:%OnSubmit
30-
ClassMethod ImportImage(pDir) As %Status
31-
{
32-
Set tSC=$$$OK
33-
Set tStream=##class(%Stream.FileBinary).%New()
34-
Set tSC=tStream.LinkToFile(pDir)
35-
If $$$ISERR(tSC) Quit
36-
Set tName="PivotSubscriptions_Cover.png"
37-
38-
If $IsObject(tStream)&&(tName'="") {
39-
Set tFileName=##class(%File).NormalizeDirectory(tName,##class(%DeepSee.UI.Dialog.ImageUpload).%GetImageDirectory())
40-
Set tLocalFile=##class(%File).%New(tFileName)
41-
Set tSC=tLocalFile.Open("WSN")
42-
If $$$ISERR(tSC) Quit
43-
44-
Set tSC=tLocalFile.CopyFrom(tStream)
45-
If $$$ISERR(tSC) Quit
46-
47-
Do tLocalFile.Close()
48-
}
49-
50-
Quit tSC
51-
}
52-
53-
}
1+
Class PivotSubscriptions.Installer
2+
{
3+
4+
ClassMethod RunInstaller(pRootDir)
5+
{
6+
Set tSC=$$$OK
7+
8+
If pRootDir'="" {
9+
Do $system.OBJ.LoadDir(pRootDir_"/PivotSubscriptions","ck",,1)
10+
Set tSC=..ImportImage(pRootDir_"/Assets/PivotSubscriptions_BookCover.png")
11+
If $$$ISERR(tSC) Quit
12+
}
13+
14+
Set tItem=##class(%DeepSee.UserLibrary.Link).%New()
15+
Set tItem.fullName="Pivot Subscriptions"
16+
Set tPage="PivotSubscriptions.UI.SubscriptionManager.zen"
17+
Set tItem.href=$system.CSP.GetPortalApp($namespace,tPage)_tPage
18+
Set tItem.title="Pivot Subscriptions"
19+
Set tItem.bookCover="{background: {style:'background:white;',src:'covers/PivotSubscriptions_Cover.png'},header: {text:'$type',style:'display: none;'},title: {text:'$title',style:'display: none;'},image: {style:'display: none;',src:'deepsee/ds2_globe_44.png',imageStyle:'width:64px;height:64px;'},subtitle: {style:'display: none;'},footer: {text:'$owner',style:'display: none;'}}"
20+
Set tSC=tItem.%Save()
21+
22+
If $$$ISERR(tSC) Quit
23+
24+
Set tSC=##class(PivotSubscriptions.Task).ConfigureTask()
25+
26+
Quit tSC
27+
}
28+
29+
/// Import Cover, code taken from %DeepSee.UI.Dialog.ImageUpload:%OnSubmit
30+
ClassMethod ImportImage(pDir) As %Status
31+
{
32+
Set tSC=$$$OK
33+
Set tStream=##class(%Stream.FileBinary).%New()
34+
Set tSC=tStream.LinkToFile(pDir)
35+
If $$$ISERR(tSC) Quit
36+
Set tName="PivotSubscriptions_Cover.png"
37+
38+
If $IsObject(tStream)&&(tName'="") {
39+
Set tFileName=##class(%File).NormalizeDirectory(tName,##class(%DeepSee.UI.Dialog.ImageUpload).%GetImageDirectory())
40+
Set tLocalFile=##class(%File).%New(tFileName)
41+
Set tSC=tLocalFile.Open("WSN")
42+
If $$$ISERR(tSC) Quit
43+
44+
Set tSC=tLocalFile.CopyFrom(tStream)
45+
If $$$ISERR(tSC) Quit
46+
47+
Do tLocalFile.Close()
48+
}
49+
50+
Quit tSC
51+
}
52+
53+
}

PivotSubscriptions/Subscription.cls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Property Name As %String(MAXLEN = 100);
2323

2424
Property CustomFilters As array Of %String(MAXLEN = "");
2525

26+
Property CustomEmailText As %String(MAXLEN = "");
27+
2628
Storage Default
2729
{
2830
<Data name="CustomFilters">
@@ -61,6 +63,9 @@ Storage Default
6163
<Value name="10">
6264
<Value>Name</Value>
6365
</Value>
66+
<Value name="11">
67+
<Value>CustomEmailText</Value>
68+
</Value>
6469
</Data>
6570
<DataLocation>^PivotSubscriptions.SubD</DataLocation>
6671
<DefaultData>SubscriptionDefaultData</DefaultData>

PivotSubscriptions/Task.cls

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Method OnTask() As %Status
1212
Set tHour=$PIECE($ZTIME($PIECE($HOROLOG,",",2),2),":",1)
1313
Set tMinute=$PIECE($ZTIME($PIECE($HOROLOG,",",2),2),":",2)
1414

15-
If $G(^PivotSubscriptions.Settings("TestEnv")) {
15+
If ##class(PivotSubscriptions.Utils).GetSettings("TestEnv",0) {
1616
// Ignore minute for testing purposes
1717
// This will allow the task to be run on demand and send emails immediately
1818
// Leaving DayOfWeek and Hour so the scheduled task does not spam emails
@@ -41,9 +41,6 @@ Method OnTask() As %Status
4141
ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat As %String, pDayOfWeek, pHour, pMinute, pName) As %Status
4242
{
4343
Set tSC=$$$OK
44-
45-
Set tSC=##class(PivotSubscriptions.EventLog).LogEvent("sendSubscription", $username, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, .pEvent)
46-
If $$$ISERR(tSC) Quit tSC
4744

4845
If pName="" {
4946
Set pName=$E(pPivot,1,*-6)
@@ -54,14 +51,6 @@ ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat
5451
} Catch ex {
5552
Set tSC=ex.AsStatus()
5653
}
57-
// Update send event with status and end time
58-
Set tSC=pEvent.LogUpdate(tSC)
59-
If $$$ISERR(tSC) Quit tSC
60-
61-
If '(##class(PivotSubscriptions.Utils).CheckTable(pName)) {
62-
Set tSC=##class(PivotSubscriptions.EventLog).LogEvent("tableError", $username, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName)
63-
If $$$ISERR(tSC) Quit tSC
64-
}
6554

6655
Quit tSC
6756
}
@@ -72,14 +61,17 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
7261
Set tFilename=""
7362

7463
Set mdx=##class(%DeepSee.Utils).%GetMDXFromPivot(pPivot,.tSC,0)
64+
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pID)
7565

7666
// Iterate through all subscribers and send emails to each individually
77-
For count=1:1:$l(pEmails,",") {
78-
Set tEmail=$p(pEmails,",",count)
67+
For tCount=1:1:$l(pEmails,",") {
68+
Set tEmail=$p(pEmails,",",tCount)
69+
70+
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent)
71+
If $$$ISERR(tSC) Quit tSC
7972

8073
Set tHasResults=0
8174

82-
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pID)
8375
Set tCustomFilter=tSubscription.CustomFilters.GetAt(tEmail)
8476
Set tSC=##class(PivotSubscriptions.Utils).ExecuteForSubscription(mdx,tCustomFilter,.tHasResults)
8577

@@ -101,7 +93,7 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
10193
Set validAdminEmail=##class(PivotSubscriptions.Utils).CheckConfigurationGlobal("AdminEmail")
10294

10395
If validAdminEmail {
104-
Set msg.ReplyTo=^PivotSubscriptions.Settings("AdminEmail")
96+
Set msg.ReplyTo=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")
10597
}
10698

10799
// Remove ".pivot" extension for subject
@@ -110,17 +102,16 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
110102
Set msg.IsHTML=1 // Set IsHTML to 1 if email uses HTML
111103

112104
If tHasResults {
113-
114105
// Add attachment
115-
Do ##class(PivotSubscriptions.Utils).WriteEmail(pName, msg, tableStatus)
106+
Do ##class(PivotSubscriptions.Utils).WriteEmail(tSubscription, msg, tableStatus)
116107

117108
// if table is too large, then just attach Excel instead
118109
If ((pFormat = "PDF") && (tableStatus)) {
119110
Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("PDF",mdx,tCustomFilter,pName,pPivot,.tFilename)
120111
} ElseIf 'tableStatus {
121112
// Check if both configuration settings for admin email is valid before sending error message
122113
If validAdminEmail {
123-
Do ##class(PivotSubscriptions.Utils).SendErrorMessage(pPivot,^PivotSubscriptions.Settings("AdminEmail"),pName)
114+
Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"TooLarge")
124115
}
125116
}
126117

@@ -132,18 +123,22 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
132123
}
133124
} Else {
134125
Do ##class(PivotSubscriptions.Utils).WriteEmailHeader(msg)
135-
Do msg.TextData.WriteLine($G(^PivotSubscriptions.Settings("NoDataMessage"),"No data for requested pivot."))
126+
Do msg.TextData.WriteLine(##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage","No data for requested pivot."))
127+
Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg)
136128
Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(msg)
129+
130+
Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults")
137131
}
138132
}
139133

140134
Do msg.To.SetAt(tEmail,1)
141135

142136
// Send email
143-
If tHasResults||$G(^PivotSubscriptions.Settings("SendNoData"),1) {
137+
If tHasResults||##class(PivotSubscriptions.Utils).GetSettings("SendNoData",1) {
144138
Set tSC=server.Send(msg)
139+
Set tSC=pEvent.UpdateStatus(tSC)
140+
If $$$ISERR(tSC) Quit tSC
145141
}
146-
// TODO: Log individual send status?
147142

148143
If tHasResults {
149144
// Delete file

PivotSubscriptions/UI/ConfigurationPage.cls

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ XData contentPane [ XMLNamespace = "http://www.intersystems.com/zen" ]
2222
<label label="No Data Settings" labelClass="sectionCaption" containerStyle="padding-top:5px;padding-bottom:5px;" />
2323
<radioSet id="NoDataEmail" label="Send No Data Email" displayList="Yes,No" valueList="1,0" value="1"/>
2424
<textarea id="NoDataMessage" label="No Data Message" cols="50" rows="3" value="No data for requested pivot."/>
25+
<label label="Custom Emails" labelClass="sectionCaption" containerStyle="padding-top:5px;padding-bottom:5px;" />
26+
<radioSet id="CustomFooter" label="Custom Footer" displayList="Yes,No" valueList="1,0" value="0"/>
27+
<textarea id="CustomFooterMessage" label="Custom Footer Message" cols="50" rows="3" value="PivotSubcriptions for InterSystems IRIS Business Intelligence" />
2528
</vgroup>
2629
</hgroup>
2730
<hgroup>
@@ -52,23 +55,29 @@ Method %OnGetProductName() As %String [ Internal ]
5255
Method %OnAfterCreatePage() As %Status
5356
{
5457
// check if each global is instantiated and set only if they aren't empty or nonexsistent
55-
If $G(^PivotSubscriptions.Settings("AdminEmail"))'="" {
56-
Set ..%GetComponentById("AdminEmailText").value=^PivotSubscriptions.Settings("AdminEmail")
58+
If ##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")'="" {
59+
Set ..%GetComponentById("AdminEmailText").value=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")
5760
}
58-
If $G(^PivotSubscriptions.Settings("Http"))'="" {
59-
Set ..%GetComponentById("HTTPButton").value=^PivotSubscriptions.Settings("Http")
61+
If ##class(PivotSubscriptions.Utils).GetSettings("Http")'="" {
62+
Set ..%GetComponentById("HTTPButton").value=##class(PivotSubscriptions.Utils).GetSettings("Http")
6063
}
61-
If $G(^PivotSubscriptions.Settings("Server"))'="" {
62-
Set ..%GetComponentById("ServerText").value=^PivotSubscriptions.Settings("Server")
64+
If ##class(PivotSubscriptions.Utils).GetSettings("Server")'="" {
65+
Set ..%GetComponentById("ServerText").value=##class(PivotSubscriptions.Utils).GetSettings("Server")
6366
}
64-
If $G(^PivotSubscriptions.Settings("Port"))'="" {
65-
Set ..%GetComponentById("PortText").value=^PivotSubscriptions.Settings("Port")
67+
If ##class(PivotSubscriptions.Utils).GetSettings("Port")'="" {
68+
Set ..%GetComponentById("PortText").value=##class(PivotSubscriptions.Utils).GetSettings("Port")
6669
}
67-
If $G(^PivotSubscriptions.Settings("SendNoData"))'="" {
68-
Set ..%GetComponentById("NoDataEmail").value=^PivotSubscriptions.Settings("SendNoData")
70+
If ##class(PivotSubscriptions.Utils).GetSettings("SendNoData")'="" {
71+
Set ..%GetComponentById("NoDataEmail").value=##class(PivotSubscriptions.Utils).GetSettings("SendNoData")
6972
}
70-
If $G(^PivotSubscriptions.Settings("NoDataMessage"))'="" {
71-
Set ..%GetComponentById("NoDataMessage").value=^PivotSubscriptions.Settings("NoDataMessage")
73+
If ##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage")'="" {
74+
Set ..%GetComponentById("NoDataMessage").value=##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage")
75+
}
76+
If $G(^PivotSubscriptions.Settings("CustomFooter"))'="" {
77+
Set ..%GetComponentById("CustomFooter").value=^PivotSubscriptions.Settings("CustomFooter")
78+
}
79+
If $G(^PivotSubscriptions.Settings("CustomFooterMessage"))'="" {
80+
Set ..%GetComponentById("CustomFooterMessage").value=^PivotSubscriptions.Settings("CustomFooterMessage")
7281
}
7382

7483
Quit $$$OK
@@ -83,19 +92,21 @@ ClientMethod ButtonClick() [ Language = javascript ]
8392
var port=zen('PortText').getValue();
8493
var nodataemail=zen('NoDataEmail').getValue();
8594
var nodatamessage=zen('NoDataMessage').getValue();
95+
var customfooter=zen('CustomFooter').getValue();
96+
var customfootermessage=zen('CustomFooterMessage').getValue();
8697

87-
var status=zenPage.SaveConfiguration(adminemail,http,server,port,nodataemail,nodatamessage);
98+
var status=zenPage.SaveConfiguration(adminemail,http,server,port,nodataemail,nodatamessage,customfooter,customfootermessage);
8899
}
89100
catch(ex) {
90101
zenExceptionHandler(ex,arguments);
91102
}
92103
}
93104

94-
Method SaveConfiguration(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage) As %Status [ ZenMethod ]
105+
Method SaveConfiguration(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage) As %Status [ ZenMethod ]
95106
{
96107
Set tSC=$$$OK
97108

98-
Set tSC = ##class(PivotSubscriptions.Utils).ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage)
109+
Set tSC = ##class(PivotSubscriptions.Utils).ConfigureSettings(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage)
99110

100111
Quit tSC
101112
}

0 commit comments

Comments
 (0)