Skip to content

Commit

Permalink
Merge pull request #77 from psteiwer/dev
Browse files Browse the repository at this point in the history
v1.3
  • Loading branch information
psteiwer authored Mar 3, 2020
2 parents 02a6b16 + d892f01 commit a16b4af
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 293 deletions.
32 changes: 20 additions & 12 deletions PivotSubscriptions/EventLog.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
Class PivotSubscriptions.EventLog Extends %Persistent
{

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

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

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

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

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

If pType="tableError" {
Set tEventLog.Status=$$$OK
Set tEventLog.EndTime=$zdt($h,3,1)
}

Set tSC=tEventLog.%Save()
Set pEvent=tEventLog

Quit tSC
}

Method LogUpdate(pStatus) As %Status
Method UpdateStatus(pStatus) As %Status
{
Set tSC=$$$OK

Expand All @@ -70,6 +62,22 @@ Method LogUpdate(pStatus) As %Status
Quit tSC
}

Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName) As %Status
{
Set tSC=$$$OK

Set ..DayOfWeek=pDayOfWeek
Set ..Hour=pHour
Set ..Minute=pMinute
Set ..Format=pFormat
Set ..Emails=pEmails
Set ..Name=pName

Set tSC=..%Save()

Quit tSC
}

ClassMethod DayOfWeekDisplay(pDayOfWeek) As %String [ SqlProc ]
{
Set pDayOfWeek=$Replace(pDayOfWeek,0,"Sunday")
Expand Down
106 changes: 53 additions & 53 deletions PivotSubscriptions/Installer.cls
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
Class PivotSubscriptions.Installer
{

ClassMethod RunInstaller(pRootDir)
{
Set tSC=$$$OK

If pRootDir'="" {
Do $system.OBJ.LoadDir(pRootDir_"/PivotSubscriptions","ck",,1)
Set tSC=..ImportImage(pRootDir_"/Assets/PivotSubscriptions_BookCover.png")
If $$$ISERR(tSC) Quit
}

Set tItem=##class(%DeepSee.UserLibrary.Link).%New()
Set tItem.fullName="Pivot Subscriptions"
Set tPage="PivotSubscriptions.UI.SubscriptionManager.zen"
Set tItem.href=$system.CSP.GetPortalApp($namespace,tPage)_tPage
Set tItem.title="Pivot Subscriptions"
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;'}}"
Set tSC=tItem.%Save()

If $$$ISERR(tSC) Quit

Set tSC=##class(PivotSubscriptions.Task).ConfigureTask()

Quit tSC
}

/// Import Cover, code taken from %DeepSee.UI.Dialog.ImageUpload:%OnSubmit
ClassMethod ImportImage(pDir) As %Status
{
Set tSC=$$$OK
Set tStream=##class(%Stream.FileBinary).%New()
Set tSC=tStream.LinkToFile(pDir)
If $$$ISERR(tSC) Quit
Set tName="PivotSubscriptions_Cover.png"

If $IsObject(tStream)&&(tName'="") {
Set tFileName=##class(%File).NormalizeDirectory(tName,##class(%DeepSee.UI.Dialog.ImageUpload).%GetImageDirectory())
Set tLocalFile=##class(%File).%New(tFileName)
Set tSC=tLocalFile.Open("WSN")
If $$$ISERR(tSC) Quit

Set tSC=tLocalFile.CopyFrom(tStream)
If $$$ISERR(tSC) Quit

Do tLocalFile.Close()
}

Quit tSC
}

}
Class PivotSubscriptions.Installer
{

ClassMethod RunInstaller(pRootDir)
{
Set tSC=$$$OK

If pRootDir'="" {
Do $system.OBJ.LoadDir(pRootDir_"/PivotSubscriptions","ck",,1)
Set tSC=..ImportImage(pRootDir_"/Assets/PivotSubscriptions_BookCover.png")
If $$$ISERR(tSC) Quit
}

Set tItem=##class(%DeepSee.UserLibrary.Link).%New()
Set tItem.fullName="Pivot Subscriptions"
Set tPage="PivotSubscriptions.UI.SubscriptionManager.zen"
Set tItem.href=$system.CSP.GetPortalApp($namespace,tPage)_tPage
Set tItem.title="Pivot Subscriptions"
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;'}}"
Set tSC=tItem.%Save()

If $$$ISERR(tSC) Quit

Set tSC=##class(PivotSubscriptions.Task).ConfigureTask()

Quit tSC
}

/// Import Cover, code taken from %DeepSee.UI.Dialog.ImageUpload:%OnSubmit
ClassMethod ImportImage(pDir) As %Status
{
Set tSC=$$$OK
Set tStream=##class(%Stream.FileBinary).%New()
Set tSC=tStream.LinkToFile(pDir)
If $$$ISERR(tSC) Quit
Set tName="PivotSubscriptions_Cover.png"

If $IsObject(tStream)&&(tName'="") {
Set tFileName=##class(%File).NormalizeDirectory(tName,##class(%DeepSee.UI.Dialog.ImageUpload).%GetImageDirectory())
Set tLocalFile=##class(%File).%New(tFileName)
Set tSC=tLocalFile.Open("WSN")
If $$$ISERR(tSC) Quit

Set tSC=tLocalFile.CopyFrom(tStream)
If $$$ISERR(tSC) Quit

Do tLocalFile.Close()
}

Quit tSC
}

}
5 changes: 5 additions & 0 deletions PivotSubscriptions/Subscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Property Name As %String(MAXLEN = 100);

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

Property CustomEmailText As %String(MAXLEN = "");

Storage Default
{
<Data name="CustomFilters">
Expand Down Expand Up @@ -61,6 +63,9 @@ Storage Default
<Value name="10">
<Value>Name</Value>
</Value>
<Value name="11">
<Value>CustomEmailText</Value>
</Value>
</Data>
<DataLocation>^PivotSubscriptions.SubD</DataLocation>
<DefaultData>SubscriptionDefaultData</DefaultData>
Expand Down
39 changes: 17 additions & 22 deletions PivotSubscriptions/Task.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Method OnTask() As %Status
Set tHour=$PIECE($ZTIME($PIECE($HOROLOG,",",2),2),":",1)
Set tMinute=$PIECE($ZTIME($PIECE($HOROLOG,",",2),2),":",2)

If $G(^PivotSubscriptions.Settings("TestEnv")) {
If ##class(PivotSubscriptions.Utils).GetSettings("TestEnv",0) {
// Ignore minute for testing purposes
// This will allow the task to be run on demand and send emails immediately
// Leaving DayOfWeek and Hour so the scheduled task does not spam emails
Expand Down Expand Up @@ -41,9 +41,6 @@ Method OnTask() As %Status
ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat As %String, pDayOfWeek, pHour, pMinute, pName) As %Status
{
Set tSC=$$$OK

Set tSC=##class(PivotSubscriptions.EventLog).LogEvent("sendSubscription", $username, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, .pEvent)
If $$$ISERR(tSC) Quit tSC

If pName="" {
Set pName=$E(pPivot,1,*-6)
Expand All @@ -54,14 +51,6 @@ ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat
} Catch ex {
Set tSC=ex.AsStatus()
}
// Update send event with status and end time
Set tSC=pEvent.LogUpdate(tSC)
If $$$ISERR(tSC) Quit tSC

If '(##class(PivotSubscriptions.Utils).CheckTable(pName)) {
Set tSC=##class(PivotSubscriptions.EventLog).LogEvent("tableError", $username, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName)
If $$$ISERR(tSC) Quit tSC
}

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

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

// Iterate through all subscribers and send emails to each individually
For count=1:1:$l(pEmails,",") {
Set tEmail=$p(pEmails,",",count)
For tCount=1:1:$l(pEmails,",") {
Set tEmail=$p(pEmails,",",tCount)

Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent)
If $$$ISERR(tSC) Quit tSC

Set tHasResults=0

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

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

If validAdminEmail {
Set msg.ReplyTo=^PivotSubscriptions.Settings("AdminEmail")
Set msg.ReplyTo=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")
}

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

If tHasResults {

// Add attachment
Do ##class(PivotSubscriptions.Utils).WriteEmail(pName, msg, tableStatus)
Do ##class(PivotSubscriptions.Utils).WriteEmail(tSubscription, msg, tableStatus)

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

Expand All @@ -132,18 +123,22 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
}
} Else {
Do ##class(PivotSubscriptions.Utils).WriteEmailHeader(msg)
Do msg.TextData.WriteLine($G(^PivotSubscriptions.Settings("NoDataMessage"),"No data for requested pivot."))
Do msg.TextData.WriteLine(##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage","No data for requested pivot."))
Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg)
Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(msg)

Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults")
}
}

Do msg.To.SetAt(tEmail,1)

// Send email
If tHasResults||$G(^PivotSubscriptions.Settings("SendNoData"),1) {
If tHasResults||##class(PivotSubscriptions.Utils).GetSettings("SendNoData",1) {
Set tSC=server.Send(msg)
Set tSC=pEvent.UpdateStatus(tSC)
If $$$ISERR(tSC) Quit tSC
}
// TODO: Log individual send status?

If tHasResults {
// Delete file
Expand Down
41 changes: 26 additions & 15 deletions PivotSubscriptions/UI/ConfigurationPage.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ XData contentPane [ XMLNamespace = "http://www.intersystems.com/zen" ]
<label label="No Data Settings" labelClass="sectionCaption" containerStyle="padding-top:5px;padding-bottom:5px;" />
<radioSet id="NoDataEmail" label="Send No Data Email" displayList="Yes,No" valueList="1,0" value="1"/>
<textarea id="NoDataMessage" label="No Data Message" cols="50" rows="3" value="No data for requested pivot."/>
<label label="Custom Emails" labelClass="sectionCaption" containerStyle="padding-top:5px;padding-bottom:5px;" />
<radioSet id="CustomFooter" label="Custom Footer" displayList="Yes,No" valueList="1,0" value="0"/>
<textarea id="CustomFooterMessage" label="Custom Footer Message" cols="50" rows="3" value="PivotSubcriptions for InterSystems IRIS Business Intelligence" />
</vgroup>
</hgroup>
<hgroup>
Expand Down Expand Up @@ -52,23 +55,29 @@ Method %OnGetProductName() As %String [ Internal ]
Method %OnAfterCreatePage() As %Status
{
// check if each global is instantiated and set only if they aren't empty or nonexsistent
If $G(^PivotSubscriptions.Settings("AdminEmail"))'="" {
Set ..%GetComponentById("AdminEmailText").value=^PivotSubscriptions.Settings("AdminEmail")
If ##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")'="" {
Set ..%GetComponentById("AdminEmailText").value=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")
}
If $G(^PivotSubscriptions.Settings("Http"))'="" {
Set ..%GetComponentById("HTTPButton").value=^PivotSubscriptions.Settings("Http")
If ##class(PivotSubscriptions.Utils).GetSettings("Http")'="" {
Set ..%GetComponentById("HTTPButton").value=##class(PivotSubscriptions.Utils).GetSettings("Http")
}
If $G(^PivotSubscriptions.Settings("Server"))'="" {
Set ..%GetComponentById("ServerText").value=^PivotSubscriptions.Settings("Server")
If ##class(PivotSubscriptions.Utils).GetSettings("Server")'="" {
Set ..%GetComponentById("ServerText").value=##class(PivotSubscriptions.Utils).GetSettings("Server")
}
If $G(^PivotSubscriptions.Settings("Port"))'="" {
Set ..%GetComponentById("PortText").value=^PivotSubscriptions.Settings("Port")
If ##class(PivotSubscriptions.Utils).GetSettings("Port")'="" {
Set ..%GetComponentById("PortText").value=##class(PivotSubscriptions.Utils).GetSettings("Port")
}
If $G(^PivotSubscriptions.Settings("SendNoData"))'="" {
Set ..%GetComponentById("NoDataEmail").value=^PivotSubscriptions.Settings("SendNoData")
If ##class(PivotSubscriptions.Utils).GetSettings("SendNoData")'="" {
Set ..%GetComponentById("NoDataEmail").value=##class(PivotSubscriptions.Utils).GetSettings("SendNoData")
}
If $G(^PivotSubscriptions.Settings("NoDataMessage"))'="" {
Set ..%GetComponentById("NoDataMessage").value=^PivotSubscriptions.Settings("NoDataMessage")
If ##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage")'="" {
Set ..%GetComponentById("NoDataMessage").value=##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage")
}
If $G(^PivotSubscriptions.Settings("CustomFooter"))'="" {
Set ..%GetComponentById("CustomFooter").value=^PivotSubscriptions.Settings("CustomFooter")
}
If $G(^PivotSubscriptions.Settings("CustomFooterMessage"))'="" {
Set ..%GetComponentById("CustomFooterMessage").value=^PivotSubscriptions.Settings("CustomFooterMessage")
}

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

var status=zenPage.SaveConfiguration(adminemail,http,server,port,nodataemail,nodatamessage);
var status=zenPage.SaveConfiguration(adminemail,http,server,port,nodataemail,nodatamessage,customfooter,customfootermessage);
}
catch(ex) {
zenExceptionHandler(ex,arguments);
}
}

Method SaveConfiguration(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage) As %Status [ ZenMethod ]
Method SaveConfiguration(pAdminEmail, pHttp, pServer, pPort, pNoDataEmail, pNoDataMessage, pCustomFooter, pCustomFooterMessage) As %Status [ ZenMethod ]
{
Set tSC=$$$OK

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

Quit tSC
}
Expand Down
Loading

0 comments on commit a16b4af

Please sign in to comment.