Skip to content

Commit 6898083

Browse files
author
Ondrej Cernos
committed
Add support for scheduled emails
1 parent a750c45 commit 6898083

19 files changed

Lines changed: 957 additions & 25 deletions

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,34 @@ definition = md.createObj(project, definition);
101101
Report report = md.createObj(project, new Report(definition.getTitle(), definition));
102102
```
103103

104+
Create and retrieve scheduled mails on reports and dashboards:
105+
106+
```java
107+
Project project = ...
108+
ReportDefinition reportDefinition = ...
109+
110+
MetadataService md = gd.getMetadataService();
111+
ScheduledMail scheduledMail = md.createObj(
112+
project,
113+
(new ScheduledMail("Scheduled Mail Title", "Scheduled Mail Summary"))
114+
.setRecurrency("0:0:0:1*12:0:0")
115+
.setStartDate(new LocalDate(2012, 6, 5))
116+
.setTimeZone("America/Los_Angeles")
117+
.addToAddress("[email protected]")
118+
.addBccAddress("[email protected]")
119+
.setSubject("Mail subject")
120+
.setBody("Mail body")
121+
.addReportAttachment(reportDefinition,
122+
Collections.singletonMap("pageOrientation", "landscape"),
123+
pdf, xls)
124+
);
125+
126+
Collection<Entry> result = md.find(project, ScheduledMail.class);
127+
for (Entry e : result) {
128+
ScheduledMail schedule = md.getObjByUri(e.getLink(), ScheduledMail.class);
129+
}
130+
```
131+
104132
### Dataset API
105133

106134
Upload data to datasets,..
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved.
3+
*/
4+
package com.gooddata.md;
5+
6+
import org.codehaus.jackson.annotate.JsonCreator;
7+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
8+
import org.codehaus.jackson.annotate.JsonProperty;
9+
import org.codehaus.jackson.annotate.JsonSubTypes;
10+
import org.codehaus.jackson.annotate.JsonTypeInfo;
11+
import org.codehaus.jackson.map.annotate.JsonSerialize;
12+
13+
/**
14+
* Common ancestor to {@link ScheduledMail} attachments.
15+
*/
16+
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
17+
@JsonIgnoreProperties(ignoreUnknown = true)
18+
@JsonSubTypes({
19+
@JsonSubTypes.Type(name = "dashboardAttachment", value = DashboardAttachment.class),
20+
@JsonSubTypes.Type(name = "reportAttachment", value = ReportAttachment.class),
21+
})
22+
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
23+
public class Attachment {
24+
25+
private final String uri;
26+
27+
@JsonCreator
28+
protected Attachment(@JsonProperty("uri") String uri) {
29+
this.uri = uri;
30+
}
31+
32+
public String getUri() { return uri; }
33+
34+
@Override
35+
public boolean equals(Object o) {
36+
if (this == o) return true;
37+
if (o == null || getClass() != o.getClass()) return false;
38+
39+
Attachment that = (Attachment) o;
40+
41+
return !(uri != null ? !uri.equals(that.uri) : that.uri != null);
42+
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return uri != null ? uri.hashCode() : 0;
48+
}
49+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved.
3+
*/
4+
package com.gooddata.md;
5+
6+
import org.codehaus.jackson.annotate.JsonCreator;
7+
import org.codehaus.jackson.annotate.JsonProperty;
8+
9+
import java.util.Arrays;
10+
import java.util.Collection;
11+
12+
/**
13+
* Attachment to {@link ScheduledMail} represents dashboard-related information for the schedule.
14+
*/
15+
public class DashboardAttachment extends Attachment {
16+
17+
private final Integer allTabs;
18+
private final Collection<String> tabs;
19+
private final String executionContext;
20+
21+
@JsonCreator
22+
protected DashboardAttachment(
23+
@JsonProperty("uri") String uri,
24+
@JsonProperty("allTabs") Integer allTabs,
25+
@JsonProperty("executionContext") String executionContext,
26+
@JsonProperty("tabs") String... tabs
27+
) {
28+
super(uri);
29+
this.allTabs = allTabs;
30+
this.tabs = Arrays.asList(tabs);
31+
this.executionContext = executionContext;
32+
}
33+
34+
public Integer getAllTabs() { return allTabs; }
35+
36+
public Collection<String> getTabs() { return tabs; }
37+
38+
public String getExecutionContext() { return executionContext; }
39+
40+
@Override
41+
public boolean equals(Object o) {
42+
if (!super.equals(o)) return false;
43+
if (this == o) return true;
44+
if (o == null || getClass() != o.getClass()) return false;
45+
46+
DashboardAttachment that = (DashboardAttachment) o;
47+
48+
if (allTabs != null ? !allTabs.equals(that.allTabs) : that.allTabs != null) return false;
49+
if (tabs != null ? !tabs.equals(that.tabs) : that.tabs != null) return false;
50+
return !(executionContext != null ? !executionContext.equals(that.executionContext) : that.executionContext != null);
51+
52+
}
53+
54+
@Override
55+
public int hashCode() {
56+
int result = allTabs != null ? allTabs.hashCode() : 0;
57+
result = 31 * result + (tabs != null ? tabs.hashCode() : 0);
58+
result = 31 * result + (executionContext != null ? executionContext.hashCode() : 0);
59+
return result;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return "DashboardAttachment{" +
65+
"uri=" + getUri() +
66+
", allTabs=" + allTabs +
67+
", tabs=" + tabs +
68+
", executionContext='" + executionContext + '\'' +
69+
'}';
70+
}
71+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved.
3+
*/
4+
package com.gooddata.md;
5+
6+
import com.gooddata.report.ReportExportFormat;
7+
import org.codehaus.jackson.annotate.JsonCreator;
8+
import org.codehaus.jackson.annotate.JsonProperty;
9+
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.Collection;
13+
import java.util.Map;
14+
15+
/**
16+
* Attachment to {@link ScheduledMail} represents report-related information for the schedule.
17+
*/
18+
public class ReportAttachment extends Attachment {
19+
20+
private final Collection<String> formats;
21+
private final Map<String, String> exportOptions;
22+
23+
@JsonCreator
24+
protected ReportAttachment(
25+
@JsonProperty("uri") String uri,
26+
@JsonProperty("exportOptions") Map<String, String> exportOptions,
27+
@JsonProperty("formats") String... formats
28+
) {
29+
super(uri);
30+
this.exportOptions = exportOptions;
31+
this.formats = Arrays.asList(formats);
32+
}
33+
34+
protected ReportAttachment(String uri, Map<String, String> exportOptions, ReportExportFormat... formats) {
35+
this(uri, exportOptions, ReportExportFormat.arrayToStringArray(formats));
36+
}
37+
38+
/**
39+
* Options which modify default export behavior. Due to variety of
40+
* export formats options only work for explicitly listed
41+
* format types.
42+
*
43+
* <ul>
44+
* <li>pageOrientation
45+
* <ul>
46+
* <li>set page orientation</li>
47+
* <li>default value: 'portrait'</li>
48+
* <li>supported in: tabular PDF</li>
49+
* </ul>
50+
* </li>
51+
*
52+
* <li>optimalColumnWidth
53+
* <ul>
54+
* <li>set 'yes' to automatically resize all columns to fit cell's content</li>
55+
* <li>default is: 'no' (do not auto resize)</li>
56+
* <li>supported in: tabular PDF</li>
57+
* </ul>
58+
* </li>
59+
*
60+
* <li>pageScalePercentage
61+
* <ul>
62+
* <li>down-scaling factor (in percent), 100 means no scale-down</li>
63+
* <li>may not be combined with scaleToPages, scaleToPagesX and scaleToPagesY</li>
64+
* <li>default is: 100</li>
65+
* <li>supported in: tabular PDF</li>
66+
* </ul>
67+
* </li>
68+
*
69+
* <li>scaleToPages
70+
* <ul>
71+
* <li>total number of pages of target PDF file</li>
72+
* <li>may not be combined with pageScalePercentage, scaleToPagesX and scaleToPagesY</li>
73+
* <li>default is: unlimited</li>
74+
* <li>supported in: tabular PDF</li>
75+
* </ul>
76+
* </li>
77+
*
78+
* <li>scaleToPagesX
79+
* <ul>
80+
* <li>number of horizontal pages of target PDF file</li>
81+
* <li>may not be combined with pageScalePercentage and scaleToPages, but may be combined with scaleToPagesY</li>
82+
* <li>default is: unlimited</li>
83+
* <li>supported in: tabular PDF</li>
84+
* </ul>
85+
* </li>
86+
*
87+
* <li>scaleToPagesY
88+
* <ul>
89+
* <li>number of vertical pages of target PDF file</li>
90+
* <li>may not be combined with pageScalePercentage and scaleToPages, but may be combined with scaleToPagesX</li>
91+
* <li>default is: unlimited</li>
92+
* <li>supported in: tabular PDF</li>
93+
* </ul>
94+
* </li>
95+
* </ul>
96+
*
97+
* @return
98+
*/
99+
public Map<String, String> getExportOptions() { return exportOptions; }
100+
101+
public Collection<String> getFormats() { return formats; }
102+
103+
@Override
104+
public boolean equals(Object o) {
105+
if (!super.equals(o)) return false;
106+
if (this == o) return true;
107+
if (o == null || getClass() != o.getClass()) return false;
108+
109+
ReportAttachment that = (ReportAttachment) o;
110+
111+
if (formats != null ? !formats.equals(that.formats) : that.formats != null) return false;
112+
return !(exportOptions != null ? !exportOptions.equals(that.exportOptions) : that.exportOptions != null);
113+
114+
}
115+
116+
@Override
117+
public int hashCode() {
118+
int result = formats != null ? formats.hashCode() : 0;
119+
result = 31 * result + (exportOptions != null ? exportOptions.hashCode() : 0);
120+
return result;
121+
}
122+
123+
@Override
124+
public String toString() {
125+
return "ReportAttachment{" +
126+
"uri=" + getUri() +
127+
", formats=" + formats +
128+
", exportOptions=" + exportOptions +
129+
'}';
130+
}
131+
}

0 commit comments

Comments
 (0)