|
| 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