annotate pkg/imports/report.go @ 5365:74bae79de83e extented-report

Fixed name spelling in report import.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Jun 2021 12:05:05 +0200
parents 2ec8a34ae683
children 4d126cf58fbc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 // This is Free Software under GNU Affero General Public License v >= 3.0
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2 // without warranty, see README.md and license for details.
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 //
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 // SPDX-License-Identifier: AGPL-3.0-or-later
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 // License-Filename: LICENSES/AGPL-3.0.txt
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 //
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 // Copyright (C) 2018 by via donau
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 // Software engineering by Intevation GmbH
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 //
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 // Author(s):
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 package imports
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import (
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
17 "bytes"
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 "context"
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 "database/sql"
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 "errors"
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
21 "fmt"
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
22 "log"
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
23 "os"
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
24 "path/filepath"
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
25 "regexp"
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
26 "strings"
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
27 "text/template"
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
28 "time"
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 "gemma.intevation.de/gemma/pkg/common"
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
31 "gemma.intevation.de/gemma/pkg/config"
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
32 "gemma.intevation.de/gemma/pkg/misc"
5329
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
33 "gemma.intevation.de/gemma/pkg/models"
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
34 "gemma.intevation.de/gemma/pkg/xlsx"
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
35
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
36 "github.com/360EntSecGroup-Skylar/excelize/v2"
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 )
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 type Report struct {
5329
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
40 models.QueueConfigurationType
5365
74bae79de83e Fixed name spelling in report import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5336
diff changeset
41 Name string `json:"name"`
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 const ReportJobKind JobKind = "report"
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 type reportJobCreator struct{}
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
48 const (
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
49 selectReportUsersSQL = `
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
50 SELECT username, email_address
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
51 FROM users.list_users
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
52 WHERE report_reciever
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
53 ORDER BY country, username`
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
54
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
55 selectCurrentUserSQL = `
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
56 SELECT current_user, email_address
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
57 FROM users.list_users
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
58 WHERE username = current_user`
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
59 )
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
60
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
61 var reportMailTmpl = template.Must(template.New("report-mail").
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
62 Parse(`Dear {{ .Receiver }}
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
63
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
64 this is an automatically generated report from the Gemma system.
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
65 You received this mail because you are listed as a report receiver in
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
66 the system. If you received this mail without consent please
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
67 contact {{ .Admin }} under {{ .AdminEmail }}.
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
68
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
69 Find attached {{ .Attachment }} which contains the {{ .Report }} from {{ .When }}.
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
70
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
71 Kind Regards`))
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
72
5328
bc8c082487b2 Fixed compile errors. :-/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5326
diff changeset
73 func init() { RegisterJobCreator(ReportJobKind, reportJobCreator{}) }
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 func (reportJobCreator) Description() string { return "report" }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 func (reportJobCreator) AutoAccept() bool { return true }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 func (reportJobCreator) Create() Job { return new(Report) }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 func (reportJobCreator) Depends() [2][]string { return [2][]string{{}, {}} }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 func (reportJobCreator) StageDone(context.Context, *sql.Tx, int64, Feedback) error {
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 return nil
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 func (r *Report) Description() (string, error) { return r.Name, nil }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
5328
bc8c082487b2 Fixed compile errors. :-/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5326
diff changeset
89 func (*Report) CleanUp() error { return nil }
bc8c082487b2 Fixed compile errors. :-/
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5326
diff changeset
90
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 func (r *Report) MarshalAttributes(attrs common.Attributes) error {
5329
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
92 if err := r.QueueConfigurationType.MarshalAttributes(attrs); err != nil {
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
93 return err
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
94 }
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 attrs.Set("name", r.Name)
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 return nil
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 func (r *Report) UnmarshalAttributes(attrs common.Attributes) error {
5329
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
100 if err := r.QueueConfigurationType.UnmarshalAttributes(attrs); err != nil {
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
101 return err
795a0a0b5047 Embed scheduling type into report import to ensure persistence of schedule data.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5328
diff changeset
102 }
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 name, found := attrs.Get("name")
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 if !found {
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 return errors.New("missing 'name' attribute")
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 r.Name = name
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 return nil
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
111 func (r *Report) loadTemplate() (*excelize.File, *xlsx.Action, error) {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
112 path := config.ReportPath()
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
113 if path == "" {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
114 return nil, nil, errors.New("no report dir configured")
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
115 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
116
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
117 if stat, err := os.Stat(path); err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
118 if os.IsNotExist(err) {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
119 return nil, nil, fmt.Errorf("report dir '%s' does not exists", path)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
120 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
121 return nil, nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
122 } else if !stat.Mode().IsDir() {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
123 return nil, nil, fmt.Errorf("report dir '%s' is not a directory", path)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
124 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
125
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
126 // TODO: Prevent this earlier.
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
127 if match, _ := regexp.MatchString(`^[a-zA-Z0-9_]+$`, r.Name); !match {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
128 return nil, nil, errors.New("invalid report name")
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
129 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
130
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
131 xlsxFilename := filepath.Join(path, r.Name+".xlsx")
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
132 yamlFilename := filepath.Join(path, r.Name+".yaml")
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
133
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
134 for _, check := range []string{xlsxFilename, yamlFilename} {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
135 if _, err := os.Stat(check); err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
136 if os.IsNotExist(err) {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
137 return nil, nil, fmt.Errorf("'%s' does not exists", check)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
138 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
139 return nil, nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
140 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
141 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
142
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
143 template, err := excelize.OpenFile(xlsxFilename)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
144 if err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
145 return nil, nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
146 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
147
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
148 action, err := xlsx.ActionFromFile(yamlFilename)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
149 if err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
150 return nil, nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
151 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
152
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
153 return template, action, nil
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
154 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
155
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 func (r *Report) Do(
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 ctx context.Context,
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 importID int64,
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 conn *sql.Conn,
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 feedback Feedback,
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 ) (interface{}, error) {
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
163 start := time.Now()
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
164
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
165 feedback.Info("Generating report %s.", r.Name)
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
166
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
167 template, action, err := r.loadTemplate()
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
168 if err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
169 return nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
170 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
171
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
172 tx, err := conn.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
173 if err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
174 return nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
175 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
176 defer tx.Rollback()
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
177
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
178 // Fetch receivers
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
179 var users []misc.EmailReceiver
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
180
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
181 if err := func() error {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
182 rows, err := tx.QueryContext(ctx, selectReportUsersSQL)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
183 if err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
184 return err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
185 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
186 defer rows.Close()
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
187
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
188 for rows.Next() {
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
189 var u misc.EmailReceiver
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
190 if err := rows.Scan(&u.Name, &u.Address); err != nil {
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
191 return err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
192 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
193 users = append(users, u)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
194 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
195 return rows.Err()
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
196 }(); err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
197 return nil, err
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
198 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
199
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
200 if len(users) == 0 {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
201 feedback.Warn("No users found to send reports to.")
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
202 return nil, nil
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
203 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
204
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
205 // Fetch admin who is responsible for the report.
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
206 var admin misc.EmailReceiver
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
207 if err := tx.QueryRowContext(
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
208 ctx, selectCurrentUserSQL).Scan(&admin.Name, &admin.Address); err != nil {
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
209 log.Printf("error: Cannot find sender: %v\n")
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
210 return nil, fmt.Errorf("cannot find sender: %v", err)
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
211 }
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
212
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
213 // Generate the actual report.
5334
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
214 if err := action.Execute(ctx, tx, template); err != nil {
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
215 log.Printf("error: %v\n", err)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
216 return nil, fmt.Errorf("Generating report failed: %v", err)
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
217 }
45805c454436 Load users from database who should receive a report.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5329
diff changeset
218
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
219 var buf bytes.Buffer
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
220 if _, err := template.WriteTo(&buf); err != nil {
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
221 log.Printf("error: %v\n", err)
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
222 return nil, fmt.Errorf("generating report failed: %v", err)
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
223 }
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
224
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
225 feedback.Info("Sending reports to %d receivers.", len(users))
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
226
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
227 now := start.UTC().Format("2006-01-02")
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
228
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
229 attached := r.Name + "-" + now + ".xlsx"
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
230
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
231 body := func(u misc.EmailReceiver) (string, error) {
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
232 fill := struct {
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
233 Receiver string
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
234 Attachment string
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
235 Report string
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
236 When string
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
237 Admin string
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
238 AdminEmail string
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
239 }{
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
240 Receiver: u.Name,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
241 Attachment: attached,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
242 Report: r.Name,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
243 When: now,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
244 Admin: admin.Name,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
245 AdminEmail: admin.Address,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
246 }
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
247 var sb strings.Builder
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
248 if err := reportMailTmpl.Execute(&sb, &fill); err != nil {
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
249 return "", err
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
250 }
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
251 return sb.String(), nil
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
252 }
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
253
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
254 errorHandler := func(r misc.EmailReceiver, err error) error {
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
255 // We do not terminate the sending of the emails if
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
256 // sending failed. We only log it.
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
257 feedback.Warn("Sending report to %s failed: %v", r.Name, err)
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
258 return nil
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
259 }
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
260
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
261 if err := misc.SendMailToAll(
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
262 users,
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
263 "Report "+r.Name+" from "+now,
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
264 body,
5336
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
265 []misc.EmailAttachment{{
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
266 Name: attached,
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
267 Content: buf.Bytes(),
2ec8a34ae683 Rephrased the email message of the report and write the reponsible admin and her/his email address into it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5335
diff changeset
268 }},
5335
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
269 errorHandler,
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
270 ); err != nil {
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
271 return nil, err
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
272 }
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
273
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
274 feedback.Info("Generating and sending report took %v.",
dcd5692a2889 Sending generated reports to receivers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5334
diff changeset
275 time.Since(start))
5326
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
276
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
277 return nil, nil
96ceb150ea46 Added infrastructure for report 'import'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
278 }