forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduledMail.java
More file actions
278 lines (226 loc) · 10 KB
/
Copy pathScheduledMail.java
File metadata and controls
278 lines (226 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata.md;
import com.fasterxml.jackson.annotation.*;
import com.gooddata.export.ExportFormat;
import com.gooddata.md.report.ReportDefinition;
import com.gooddata.report.ReportExportFormat;
import com.gooddata.util.GoodDataToStringBuilder;
import org.joda.time.LocalDate;
import java.io.Serializable;
import java.util.*;
import static com.gooddata.util.Validate.notNull;
/**
* A scheduled mail MD object. It represents a <a href="http://search.cpan.org/~sbeck/Date-Manip-6.49/lib/Date/Manip/Recur.pod">schedule</a> on mail-sending of
* exported dashboards and reports.
*/
@JsonTypeName("scheduledMail")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScheduledMail extends AbstractObj implements Queryable, Updatable {
private static final long serialVersionUID = -4433891105896592638L;
@JsonProperty("content")
private final Content content;
@JsonCreator
ScheduledMail(@JsonProperty("meta") Meta meta, @JsonProperty("content") Content content) {
super(meta);
this.content = content;
}
private ScheduledMail(String title, String summary, Set<String> tags, boolean deprecated, String recurrency,
LocalDate startDate, String timeZone, Collection<String> toAddresses,
Collection<String> bccAddresses, String subject, String body, List<Attachment> attachments) {
super(new Meta(null, null, null, null, summary, title, null, tags, null, null, deprecated, null, false, false,
null, null));
notNull(toAddresses, "toAddresses");
notNull(subject, "subject");
notNull(body, "body");
notNull(attachments, "attachments");
content = new Content(new ScheduledMailWhen(recurrency, startDate, timeZone), toAddresses, bccAddresses,
subject, body, attachments);
}
/**
* Creates an almost empty instance of the object. It's up to the user's responsibility to call all the necessary setters.
*
* @param title the title of the MD object
* @param summary the summary of the MD object
*/
public ScheduledMail(String title, String summary) {
super(new Meta(null, null, null, null, summary, title, null, Collections.emptySet(), null, null, false,
null, false, false, null, null));
this.content = new Content();
}
/**
* Creates full, safe mail schedule object.
*
* @param title the title of the MD object
* @param summary the summary of the MD object
* @param recurrency schedule in format defined in <a href="http://search.cpan.org/~sbeck/Date-Manip-6.49/lib/Date/Manip/Recur.pod">schedule</a>
* @param startDate schedule starting date
* @param timeZone time zone of the starting date
* @param toAddresses collection of email addresses to send the mail to
* @param bccAddresses collection of blind copy addresses to send the mail to
* @param subject the subject of the scheduled mail
* @param body the text body of the scheduled mail
* @param attachments reports and dashboards to send in the scheduled email
*/
public ScheduledMail(String title, String summary, String recurrency, LocalDate startDate, String timeZone,
Collection<String> toAddresses, Collection<String> bccAddresses, String subject, String body,
List<Attachment> attachments) {
this(title, summary, Collections.emptySet(), false, recurrency, startDate, timeZone, toAddresses,
bccAddresses, subject, body, attachments);
}
/**
* Mail schedule MD object payload.
*/
private static class Content implements Serializable {
private static final long serialVersionUID = -6676890634279968527L;
@JsonProperty("when")
private ScheduledMailWhen scheduledMailWhen;
/**
* Collection of email addresses.
*/
@JsonProperty("to")
private Collection<String> toAddress;
/**
* Collection of email addresses.
*/
@JsonProperty("bcc")
private Collection<String> bccAddress;
private String subject;
private String body;
private Collection<Attachment> attachments;
@JsonCreator
public Content(
@JsonProperty("when") ScheduledMailWhen scheduledMailWhen,
@JsonProperty("to") Collection<String> toAddress,
@JsonProperty("bcc") Collection<String> bccAddress,
@JsonProperty("subject") String subject,
@JsonProperty("body") String body,
@JsonProperty("attachments") Collection<Attachment> attachments) {
this.scheduledMailWhen = scheduledMailWhen;
this.toAddress = toAddress;
this.bccAddress = bccAddress;
this.subject = subject;
this.body = body;
this.attachments = attachments;
}
public Content() {
this.scheduledMailWhen = new ScheduledMailWhen();
this.toAddress = new ArrayList<>();
this.bccAddress = new ArrayList<>();
this.attachments = new ArrayList<>();
}
@JsonIgnore
public ScheduledMailWhen getScheduledMailWhen() { return scheduledMailWhen; }
@JsonIgnore
public Collection<String> getToAddresses() { return toAddress; }
@JsonIgnore
public Collection<String> getBccAddresses() { return bccAddress; }
public String getSubject() { return subject; }
public String getBody() { return body; }
public Collection<Attachment> getAttachments() { return attachments; }
public void setScheduledMailWhen(ScheduledMailWhen scheduledMailWhen) {
this.scheduledMailWhen = scheduledMailWhen;
}
public void setToAddress(Collection<String> toAddress) {
this.toAddress = toAddress;
}
public void setBccAddress(Collection<String> bccAddress) {
this.bccAddress = bccAddress;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setBody(String body) {
this.body = body;
}
public void setAttachments(Collection<Attachment> attachments) {
this.attachments = attachments;
}
@Override
public String toString() {
return GoodDataToStringBuilder.defaultToString(this);
}
}
@JsonIgnore
public ScheduledMailWhen getWhen() { return content.getScheduledMailWhen(); }
@JsonIgnore
public Collection<String> getToAddresses() { return content.getToAddresses(); }
@JsonIgnore
public Collection<String> getBccAddresses() { return content.getBccAddresses(); }
@JsonIgnore
public String getSubject() { return content.getSubject(); }
@JsonIgnore
public String getBody() { return content.getBody(); }
@JsonIgnore
public Collection<? extends Attachment> getAttachments() { return content.getAttachments(); }
public ScheduledMail setRecurrency(String recurrency) {
this.content.getScheduledMailWhen().setRecurrency(recurrency);
return this;
}
public ScheduledMail setStartDate(LocalDate startDate) {
this.content.getScheduledMailWhen().setStartDate(startDate);
return this;
}
public ScheduledMail setTimeZone(String timeZone) {
this.content.getScheduledMailWhen().setTimeZone(timeZone);
return this;
}
public ScheduledMail setTo(Collection<String> toAddresses) {
this.content.setToAddress(toAddresses);
return this;
}
public ScheduledMail setBcc(Collection<String> bccAddresses) {
this.content.setBccAddress(bccAddresses);
return this;
}
public ScheduledMail setSubject(String subject) {
this.content.setSubject(subject);
return this;
}
public ScheduledMail setBody(String body) {
this.content.setBody(body);
return this;
}
public ScheduledMail setAttachments(List<Attachment> attachments) {
this.content.setAttachments(attachments);
return this;
}
public ScheduledMail addToAddress(String toAdd) {
this.content.getToAddresses().add(toAdd);
return this;
}
public ScheduledMail addBccAddress(String bccAdd) {
this.content.getBccAddresses().add(bccAdd);
return this;
}
public ScheduledMail addReportAttachment(ReportDefinition reportDefinition, Map<String, String> exportOptions, String... formats) {
notNull(formats, "formats");
ReportAttachment ra = new ReportAttachment(reportDefinition.getUri(), exportOptions, formats);
this.content.getAttachments().add(ra);
return this;
}
/**
* @deprecated use {@link #addReportAttachment(ReportDefinition, Map, ExportFormat...)}
*/
@Deprecated
public ScheduledMail addReportAttachment(ReportDefinition reportDefinition, Map<String, String> exportOptions, ReportExportFormat... formats) {
return addReportAttachment(reportDefinition, exportOptions, ReportExportFormat.arrayToStringArray(formats));
}
public ScheduledMail addReportAttachment(ReportDefinition reportDefinition, Map<String, String> exportOptions, ExportFormat... formats) {
return addReportAttachment(reportDefinition, exportOptions, ExportFormat.arrayToStringArray(formats));
}
public ScheduledMail addDashboardAttachment(String uri, Integer allTabs, String executionContext, String... tabs) {
notNull(tabs, "tabs");
DashboardAttachment da = new DashboardAttachment(uri, allTabs, executionContext, tabs);
this.content.getAttachments().add(da);
return this;
}
@Override
public String toString() {
return GoodDataToStringBuilder.defaultToString(this);
}
}