• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smartsheet / smartsheet-java-sdk / #41

24 Aug 2023 04:59PM UTC coverage: 50.458% (+0.01%) from 50.444%
#41

push

github-actions

web-flow
Fix Checkstyle Violations in "Impl" Classes (#53)

241 of 241 new or added lines in 32 files covered. (100.0%)

3417 of 6772 relevant lines covered (50.46%)

0.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.53
/src/main/java/com/smartsheet/api/internal/ReportResourcesImpl.java
1
package com.smartsheet.api.internal;
2

3
/*
4
 * #[license]
5
 * Smartsheet SDK for Java
6
 * %%
7
 * Copyright (C) 2023 Smartsheet
8
 * %%
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *      http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 * %[license]
21
 */
22

23
import com.smartsheet.api.AuthorizationException;
24
import com.smartsheet.api.InvalidRequestException;
25
import com.smartsheet.api.ReportResources;
26
import com.smartsheet.api.ResourceNotFoundException;
27
import com.smartsheet.api.ServiceUnavailableException;
28
import com.smartsheet.api.ShareResources;
29
import com.smartsheet.api.SmartsheetException;
30
import com.smartsheet.api.internal.util.QueryUtil;
31
import com.smartsheet.api.models.PagedResult;
32
import com.smartsheet.api.models.PaginationParameters;
33
import com.smartsheet.api.models.Report;
34
import com.smartsheet.api.models.ReportPublish;
35
import com.smartsheet.api.models.SheetEmail;
36
import com.smartsheet.api.models.enums.ReportInclusion;
37

38
import java.io.OutputStream;
39
import java.text.SimpleDateFormat;
40
import java.util.Date;
41
import java.util.EnumSet;
42
import java.util.HashMap;
43
import java.util.Map;
44

45
/**
46
 * This is the implementation of the ReportResources.
47
 * <p>
48
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
49
 */
50

51
public class ReportResourcesImpl extends AbstractResources implements ReportResources {
52

53
    /**
54
     * Represents the ShareResources.
55
     * <p>
56
     * It will be initialized in constructor and will not change afterwards.
57
     */
58
    private ShareResources shares;
59

60
    private static final String REPORTS_PATH = "reports/";
61

62
    /**
63
     * Constructor.
64
     * <p>
65
     * Parameters: - smartsheet : the SmartsheetImpl
66
     * <p>
67
     * Exceptions: - IllegalArgumentException : if any argument is null
68
     *
69
     * @param smartsheet the smartsheet
70
     */
71
    public ReportResourcesImpl(SmartsheetImpl smartsheet) {
72
        super(smartsheet);
1✔
73
        this.shares = new ShareResourcesImpl(smartsheet, "reports");
1✔
74
    }
1✔
75

76
    /**
77
     * Get a report.
78
     * <p>
79
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}
80
     * <p>
81
     * Exceptions:
82
     *   InvalidRequestException : if there is any problem with the REST API request
83
     *   AuthorizationException : if there is any problem with the REST API authorization(access token)
84
     *   ResourceNotFoundException : if the resource can not be found
85
     *   ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
86
     *   SmartsheetRestException : if there is any other REST API related error occurred during the operation
87
     *   SmartsheetException : if there is any other error occurred during the operation
88
     *
89
     * @param reportId the folder id
90
     * @param includes the optional objects to include in response
91
     * @param pageSize Number of rows per page
92
     * @param page page number to return
93
     * @return  the report (note that if there is no such resource, this method will throw ResourceNotFoundException
94
     *     rather than returning null)
95
     * @throws SmartsheetException the smartsheet exception
96
     */
97
    public Report getReport(long reportId, EnumSet<ReportInclusion> includes, Integer pageSize, Integer page) throws SmartsheetException {
98
        return this.getReport(reportId, includes, pageSize, page, null);
1✔
99
    }
100

101
    /**
102
     * Get a report.
103
     * <p>
104
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}
105
     * <p>
106
     * Exceptions:
107
     *   InvalidRequestException : if there is any problem with the REST API request
108
     *   AuthorizationException : if there is any problem with the REST API authorization(access token)
109
     *   ResourceNotFoundException : if the resource can not be found
110
     *   ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
111
     *   SmartsheetRestException : if there is any other REST API related error occurred during the operation
112
     *   SmartsheetException : if there is any other error occurred during the operation
113
     *
114
     * @param reportId the folder id
115
     * @param includes the optional objects to include in response
116
     * @param pageSize Number of rows per page
117
     * @param page page number to return
118
     * @param level compatibility level
119
     * @return  the report (note that if there is no such resource, this method will throw ResourceNotFoundException
120
     *     rather than returning null)
121
     * @throws SmartsheetException the smartsheet exception
122
     */
123
    public Report getReport(
124
            long reportId,
125
            EnumSet<ReportInclusion> includes,
126
            Integer pageSize,
127
            Integer page,
128
            Integer level
129
    ) throws SmartsheetException {
130
        String path = REPORTS_PATH + reportId;
1✔
131
        Map<String, Object> parameters = new HashMap<>();
1✔
132

133
        parameters.put("include", QueryUtil.generateCommaSeparatedList(includes));
1✔
134
        if (pageSize != null) {
1✔
135
            parameters.put("pageSize", pageSize.toString());
1✔
136
        }
137

138
        if (page != null) {
1✔
139
            parameters.put("page", page.toString());
1✔
140
        }
141

142
        if (level != null) {
1✔
143
            parameters.put("level", level);
×
144
        }
145

146
        path += QueryUtil.generateUrl(null, parameters);
1✔
147
        return this.getResource(path, Report.class);
1✔
148
    }
149

150
    /**
151
     * Sends a report as a PDF attachment via email to the designated recipients.
152
     * <p>
153
     * It mirrors to the following Smartsheet REST API method: POST /reports/{id}/emails
154
     * <p>
155
     * Exceptions:
156
     *   InvalidRequestException : if there is any problem with the REST API request
157
     *   AuthorizationException : if there is any problem with the REST API authorization(access token)
158
     *   ResourceNotFoundException : if the resource can not be found
159
     *   ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
160
     *   SmartsheetRestException : if there is any other REST API related error occurred during the operation
161
     *   SmartsheetException : if there is any other error occurred during the operation
162
     *
163
     * @param reportId the report id
164
     * @param email the recipient email
165
     * @throws SmartsheetException the smartsheet exception
166
     */
167
    public void sendReport(long reportId, SheetEmail email) throws SmartsheetException {
168
        this.createResource(REPORTS_PATH + reportId + "/emails", SheetEmail.class, email);
1✔
169
    }
1✔
170

171
    /**
172
     * List all reports.
173
     * <p>
174
     * It mirrors to the following Smartsheet REST API method: GET /reports
175
     * <p>
176
     * Exceptions:
177
     *   - InvalidRequestException : if there is any problem with the REST API request
178
     *   - AuthorizationException : if there is any problem with the REST API authorization(access token)
179
     *   - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
180
     *   - SmartsheetRestException : if there is any other REST API related error occurred during the operation
181
     *   - SmartsheetException : if there is any other error occurred during the operation
182
     *
183
     * @param pagination pagination parameters for paging result
184
     * @return all sheets (note that empty list will be returned if there is none)
185
     * @throws SmartsheetException the smartsheet exception
186
     */
187
    public PagedResult<Report> listReports(PaginationParameters pagination) throws SmartsheetException {
188
        return this.listReports(pagination, null);
×
189
    }
190

191
    /**
192
     * List all reports.
193
     */
194
    public PagedResult<Report> listReports(PaginationParameters pagination, Date modifiedSince) throws SmartsheetException {
195
        String path = "reports";
1✔
196

197
        Map<String, Object> parameters = new HashMap<>();
1✔
198
        if (pagination != null) {
1✔
199
            parameters = pagination.toHashMap();
1✔
200
        }
201
        if (modifiedSince != null) {
1✔
202
            String isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(modifiedSince);
×
203
            parameters.put("modifiedSince", isoDate);
×
204
        }
205

206
        path += QueryUtil.generateUrl(null, parameters);
1✔
207
        return this.listResourcesWithWrapper(path, Report.class);
1✔
208
    }
209

210
    /**
211
     * Get a Report as an Excel file.
212
     * <p>
213
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id} with "application/vnd.ms-excel" Accept
214
     * HTTP header
215
     * <p>
216
     * Exceptions:
217
     *   IllegalArgumentException : if outputStream is null
218
     *   InvalidRequestException : if there is any problem with the REST API request
219
     *   AuthorizationException : if there is any problem with the REST API authorization(access token)
220
     *   ResourceNotFoundException : if the resource can not be found
221
     *   ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
222
     *   SmartsheetRestException : if there is any other REST API related error occurred during the operation
223
     *   SmartsheetException : if there is any other error occurred during the operation
224
     *
225
     * @param id the id
226
     * @param outputStream the OutputStream to which the Excel file will be written
227
     * @throws SmartsheetException the smartsheet exception
228
     */
229
    public void getReportAsExcel(long id, OutputStream outputStream) throws SmartsheetException {
230
        getResourceAsFile(REPORTS_PATH + id, "application/vnd.ms-excel", outputStream);
1✔
231
    }
1✔
232

233
    /**
234
     * Get a Report as a csv file.
235
     * <p>
236
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id} with "text/csv" Accept
237
     * HTTP header
238
     * <p>
239
     * Exceptions:
240
     *   IllegalArgumentException : if outputStream is null
241
     *   InvalidRequestException : if there is any problem with the REST API request
242
     *   AuthorizationException : if there is any problem with the REST API authorization(access token)
243
     *   ResourceNotFoundException : if the resource can not be found
244
     *   ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
245
     *   SmartsheetRestException : if there is any other REST API related error occurred during the operation
246
     *   SmartsheetException : if there is any other error occurred during the operation
247
     *
248
     * @param id the id
249
     * @param outputStream the OutputStream to which the Excel file will be written
250
     * @throws SmartsheetException the smartsheet exception
251
     */
252
    public void getReportAsCsv(long id, OutputStream outputStream) throws SmartsheetException {
253
        getResourceAsFile(REPORTS_PATH + id, "text/csv", outputStream);
×
254
    }
×
255

256
    /**
257
     * Get the publish status of a report.
258
     * <p>
259
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}/publish
260
     * <p>
261
     * Exceptions:
262
     *   InvalidRequestException : if there is any problem with the REST API request
263
     *   AuthorizationException : if there is any problem with the REST API authorization(access token)
264
     *   ResourceNotFoundException : if the resource can not be found
265
     *   ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
266
     *   SmartsheetRestException : if there is any other REST API related error occurred during the operation
267
     *   SmartsheetException : if there is any other error occurred during the operation
268
     *
269
     * @param id the ID of the report
270
     * @return the report publish status (note that if there is no such resource, this method will
271
     *     throw ResourceNotFoundException rather than returning null).
272
     * @throws IllegalArgumentException if any argument is null or empty string
273
     * @throws InvalidRequestException if there is any problem with the REST API request
274
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
275
     * @throws ResourceNotFoundException if the resource cannot be found
276
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
277
     * @throws SmartsheetException if there is any other error during the operation
278
     */
279
    public ReportPublish getPublishStatus(long id) throws SmartsheetException {
280
        return this.getResource(REPORTS_PATH + id + "/publish", ReportPublish.class);
×
281
    }
282

283
    /**
284
     * Sets the publish status of a report and returns the new status, including the URLs of any
285
     * enabled publishing.
286
     * <p>
287
     * It mirrors to the following Smartsheet REST API method: PUT /reports/{id}/publish
288
     * <p>
289
     * Exceptions:
290
     *   - InvalidRequestException : if there is any problem with the REST API request
291
     *   - AuthorizationException : if there is any problem with the REST API authorization(access token)
292
     *   - ResourceNotFoundException : if the resource can not be found
293
     *   - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
294
     *   - SmartsheetRestException : if there is any other REST API related error occurred during the operation
295
     *   - SmartsheetException : if there is any other error occurred during the operation
296
     *
297
     * @param id the ID of the report
298
     * @param reportPublish the ReportPublish object
299
     * @return the updated ReportPublish (note that if there is no such resource, this method will
300
     *     throw ResourceNotFoundException rather than returning null)
301
     * @throws IllegalArgumentException if any argument is null or empty string
302
     * @throws InvalidRequestException if there is any problem with the REST API request
303
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
304
     * @throws ResourceNotFoundException if the resource cannot be found
305
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
306
     * @throws SmartsheetException if there is any other error during the operation
307
     */
308
    public ReportPublish updatePublishStatus(long id, ReportPublish reportPublish) throws SmartsheetException {
309
        return this.updateResource(REPORTS_PATH + id + "/publish", ReportPublish.class, reportPublish);
×
310
    }
311

312
    /**
313
     * <p>Creates an object of ShareResources.</p>
314
     *
315
     * @return the created ShareResources object
316
     */
317
    public ShareResources shareResources() {
318
        return this.shares;
×
319
    }
320
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc