• 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

90.1
/src/main/java/com/smartsheet/api/internal/SheetRowResourcesImpl.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.ResourceNotFoundException;
26
import com.smartsheet.api.RowAttachmentResources;
27
import com.smartsheet.api.RowColumnResources;
28
import com.smartsheet.api.RowDiscussionResources;
29
import com.smartsheet.api.ServiceUnavailableException;
30
import com.smartsheet.api.SheetRowResources;
31
import com.smartsheet.api.SmartsheetException;
32
import com.smartsheet.api.SmartsheetRestException;
33
import com.smartsheet.api.internal.http.HttpEntity;
34
import com.smartsheet.api.internal.http.HttpMethod;
35
import com.smartsheet.api.internal.http.HttpRequest;
36
import com.smartsheet.api.internal.http.HttpResponse;
37
import com.smartsheet.api.internal.util.QueryUtil;
38
import com.smartsheet.api.internal.util.Util;
39
import com.smartsheet.api.models.BulkItemFailure;
40
import com.smartsheet.api.models.BulkItemResult;
41
import com.smartsheet.api.models.BulkRowFailedItem;
42
import com.smartsheet.api.models.Cell;
43
import com.smartsheet.api.models.CopyOrMoveRowDirective;
44
import com.smartsheet.api.models.CopyOrMoveRowResult;
45
import com.smartsheet.api.models.MultiRowEmail;
46
import com.smartsheet.api.models.PartialRowUpdateResult;
47
import com.smartsheet.api.models.Row;
48
import com.smartsheet.api.models.RowEmail;
49
import com.smartsheet.api.models.enums.ObjectExclusion;
50
import com.smartsheet.api.models.enums.RowCopyInclusion;
51
import com.smartsheet.api.models.enums.RowInclusion;
52
import com.smartsheet.api.models.enums.RowMoveInclusion;
53

54
import java.io.ByteArrayInputStream;
55
import java.io.ByteArrayOutputStream;
56
import java.util.ArrayList;
57
import java.util.EnumSet;
58
import java.util.HashMap;
59
import java.util.List;
60
import java.util.Map;
61
import java.util.Set;
62

63
/**
64
 * This is the implementation of the SheetRowResources.
65
 * <p>
66
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
67
 */
68
public class SheetRowResourcesImpl extends AbstractResources implements SheetRowResources {
69
    RowAttachmentResources attachments;
70
    RowDiscussionResources discussions;
71
    RowColumnResources columns;
72

73
    private static final String IGNORE_ROWS_NOT_FOUND = "ignoreRowsNotFound";
74
    private static final String SHEETS_PATH = "sheets/";
75
    private static final String ROWS = "rows";
76
    private static final String INCLUDE = "include";
77
    private static final String EXCLUDE = "exclude";
78

79
    /**
80
     * Constructor.
81
     * @param smartsheet the SmartsheetImpl
82
     * @throws IllegalArgumentException : if any argument is null
83
     */
84
    public SheetRowResourcesImpl(SmartsheetImpl smartsheet) {
85
        super(smartsheet);
1✔
86
        this.attachments = new RowAttachmentResourcesImpl(smartsheet);
1✔
87
        this.discussions = new RowDiscussionResourcesImpl(smartsheet);
1✔
88
        this.columns = new RowColumnResourcesImpl(smartsheet);
1✔
89
    }
1✔
90

91
    /**
92
     * Insert rows to a sheet.
93
     * <p>
94
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows
95
     * @param sheetId the sheet id
96
     * @param rows the list of rows to create
97
     * @return the created rows
98
     * @throws IllegalArgumentException : if any argument is null
99
     * @throws InvalidRequestException : if there is any problem with the REST API request
100
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
101
     * @throws ResourceNotFoundException : if the resource can not be found
102
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
103
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
104
     * @throws SmartsheetException : if there is any other error occurred during the operation
105
     */
106
    public List<Row> addRows(long sheetId, List<Row> rows) throws SmartsheetException {
107
        return this.addRows(sheetId, rows, null, null);
1✔
108
    }
109

110
    /**
111
     * Insert rows to a sheet.
112
     * <p>
113
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows
114
     * @param sheetId the sheet id
115
     * @param rows the list of rows to create
116
     * @param includes optional objects to include
117
     * @param excludes optional objects to exclude
118
     * @return the created rows
119
     * @throws IllegalArgumentException : if any argument is null
120
     * @throws InvalidRequestException : if there is any problem with the REST API request
121
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
122
     * @throws ResourceNotFoundException : if the resource can not be found
123
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
124
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
125
     * @throws SmartsheetException : if there is any other error occurred during the operation
126
     */
127
    public List<Row> addRows(
128
            long sheetId,
129
            List<Row> rows,
130
            EnumSet<RowInclusion> includes,
131
            EnumSet<ObjectExclusion> excludes
132
    ) throws SmartsheetException {
133
        String path = SHEETS_PATH + sheetId + "/" + ROWS;
1✔
134

135
        Map<String, Object> parameters = new HashMap<>();
1✔
136

137
        parameters.put(INCLUDE, QueryUtil.generateCommaSeparatedList(includes));
1✔
138
        parameters.put(EXCLUDE, QueryUtil.generateCommaSeparatedList(excludes));
1✔
139

140
        path += QueryUtil.generateUrl(null, parameters);
1✔
141
        return this.postAndReceiveList(path, rows, Row.class);
1✔
142
    }
143

144
    /**
145
     * Insert rows to a sheet, allowing partial success. If a row cannot be inserted, it will fail, while the others may succeed.
146
     * <p>
147
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{id}/rows
148
     * @param sheetId the sheet id
149
     * @param rows the list of rows to create
150
     * @return the list of created rows
151
     * @throws IllegalArgumentException if any argument is null or empty string
152
     * @throws InvalidRequestException if there is any problem with the REST API request
153
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
154
     * @throws ResourceNotFoundException if the resource cannot be found
155
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
156
     * @throws SmartsheetException if there is any other error during the operation
157
     */
158
    @Override
159
    public PartialRowUpdateResult addRowsAllowPartialSuccess(long sheetId, List<Row> rows) throws SmartsheetException {
160
        return doPartialRowOperation(sheetId, rows, null, null, HttpMethod.POST);
1✔
161
    }
162

163
    /**
164
     * Insert rows to a sheet, allowing partial success. If a row cannot be inserted, it will fail, while the others may succeed.
165
     * <p>
166
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{id}/rows
167
     * @param sheetId the sheet id
168
     * @param rows the list of rows to create
169
     * @param includes optional objects to include
170
     * @param excludes optional objects to exclude
171
     * @return the list of created rows
172
     * @throws IllegalArgumentException if any argument is null or empty string
173
     * @throws InvalidRequestException if there is any problem with the REST API request
174
     * @throws AuthorizationException if there is any problem with  the REST API authorization (access token)
175
     * @throws ResourceNotFoundException if the resource cannot be found
176
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
177
     * @throws SmartsheetException if there is any other error during the operation
178
     */
179
    @Override
180
    public PartialRowUpdateResult addRowsAllowPartialSuccess(
181
            long sheetId,
182
            List<Row> rows,
183
            EnumSet<RowInclusion> includes,
184
            EnumSet<ObjectExclusion> excludes
185
    ) throws SmartsheetException {
186
        return doPartialRowOperation(sheetId, rows, includes, excludes, HttpMethod.POST);
1✔
187
    }
188

189
    /**
190
     * Get a row.
191
     * <p>
192
     * It mirrors to the following Smartsheet REST API method: GET /sheets/{sheetId}/rows/{rowId}
193
     * @param sheetId the id of the sheet
194
     * @param rowId the id of the row
195
     * @param includes optional objects to include
196
     * @param excludes optional objects to exclude
197
     * @return the row (note that if there is no such resource, this method will throw ResourceNotFoundException rather
198
     *     than returning null).
199
     * @throws InvalidRequestException : if there is any problem with the REST API request
200
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
201
     * @throws ResourceNotFoundException : if the resource can not be found
202
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
203
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
204
     * @throws SmartsheetException : if there is any other error occurred during the operation
205
     */
206
    public Row getRow(
207
            long sheetId,
208
            long rowId,
209
            EnumSet<RowInclusion> includes,
210
            EnumSet<ObjectExclusion> excludes
211
    ) throws SmartsheetException {
212
        String path = SHEETS_PATH + sheetId + "/" + ROWS + "/" + rowId;
1✔
213

214
        Map<String, Object> parameters = new HashMap<>();
1✔
215

216
        parameters.put(INCLUDE, QueryUtil.generateCommaSeparatedList(includes));
1✔
217
        parameters.put(EXCLUDE, QueryUtil.generateCommaSeparatedList(excludes));
1✔
218

219
        path += QueryUtil.generateUrl(null, parameters);
1✔
220
        return this.getResource(path, Row.class);
1✔
221
    }
222

223
    /**
224
     * Delete a row.
225
     * <p>
226
     * It mirrors to the following Smartsheet REST API method: DELETE /sheets/{sheetId}/rows/{rowId}
227
     * @param sheetId the sheet id
228
     * @param rowId the ID of the row
229
     * @throws InvalidRequestException : if there is any problem with the REST API request
230
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
231
     * @throws ResourceNotFoundException : if the resource can not be found
232
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
233
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
234
     * @throws SmartsheetException : if there is any other error occurred during the operation
235
     * @deprecated as of API 2.0.2 release, replaced by {@link #deleteRows(long, Set, boolean)}
236
     */
237
    @Deprecated
238
    public void deleteRow(long sheetId, long rowId) throws SmartsheetException {
239
        this.deleteResource(SHEETS_PATH + sheetId + "/" + ROWS + "/" + rowId, Row.class);
×
240
    }
×
241

242
    /**
243
     * Deletes one or more row(s) from the Sheet specified in the URL.
244
     * <p>
245
     * It mirrors to the following Smartsheet REST API method: DELETE /sheets/{sheetId}/rows/{rowId}
246
     * @param sheetId the sheet id
247
     * @param rowIds the row ids
248
     * @param ignoreRowsNotFound boolean for ignoring row ids not found
249
     * @return a list of deleted rows
250
     * @throws InvalidRequestException : if there is any problem with the REST API request
251
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
252
     * @throws ResourceNotFoundException : if the resource can not be found
253
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
254
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
255
     * @throws SmartsheetException : if there is any other error occurred during the operation
256
     */
257
    public List<Long> deleteRows(long sheetId, Set<Long> rowIds, boolean ignoreRowsNotFound) throws SmartsheetException {
258
        Util.throwIfNull(rowIds);
1✔
259
        Map<String, Object> parameters = new HashMap<>();
1✔
260
        String path = SHEETS_PATH + sheetId + "/" + ROWS + "/";
1✔
261
        parameters.put("ids", QueryUtil.generateCommaSeparatedList(rowIds));
1✔
262
        parameters.put(IGNORE_ROWS_NOT_FOUND, ignoreRowsNotFound);
1✔
263

264
        path += QueryUtil.generateUrl(null, parameters);
1✔
265

266
        return this.deleteListResources(path, Long.class);
1✔
267
    }
268

269
    /**
270
     * Send a row via email to the designated recipients.
271
     * <p>
272
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows/{rowId}/emails
273
     * @param sheetId the id of the sheet
274
     * @param rowId the id of the row
275
     * @param email the row email
276
     * @throws IllegalArgumentException : if any argument is null
277
     * @throws InvalidRequestException : if there is any problem with the REST API request
278
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
279
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
280
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
281
     * @throws SmartsheetException : if there is any other error occurred during the operation
282
     * @deprecated as of API V2.0.2, replaced by {@link #sendRows(long, MultiRowEmail)}
283
     */
284
    @Deprecated
285
    public void sendRow(long sheetId, long rowId, RowEmail email) throws SmartsheetException {
286
        this.createResource(SHEETS_PATH + sheetId + "/" + ROWS + "/" + rowId + "/emails", RowEmail.class, email);
×
287
    }
×
288

289
    /**
290
     * Send a row via email to the designated recipients.
291
     * <p>
292
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows/emails
293
     * @param sheetId the id of the sheet
294
     * @param email the multi row email
295
     * @throws IllegalArgumentException : if any argument is null
296
     * @throws InvalidRequestException : if there is any problem with the REST API request
297
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
298
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
299
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
300
     * @throws SmartsheetException : if there is any other error occurred during the operation
301
     */
302
    public void sendRows(long sheetId, MultiRowEmail email) throws SmartsheetException {
303
        this.createResource(SHEETS_PATH + sheetId + "/rows/emails", MultiRowEmail.class, email);
1✔
304
    }
1✔
305

306
    /**
307
     * Update rows.
308
     * <p>
309
     * It mirrors to the following Smartsheet REST API method: PUT /sheets/{sheetId}/rows
310
     * @param sheetId the id of the sheet
311
     * @param rows the list of rows
312
     * @return a list of rows
313
     * @throws IllegalArgumentException : if any argument is null
314
     * @throws InvalidRequestException : if there is any problem with the REST API request
315
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
316
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
317
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
318
     * @throws SmartsheetException : if there is any other error occurred during the operation
319
     */
320
    public List<Row> updateRows(long sheetId, List<Row> rows) throws SmartsheetException {
321
        return this.updateRows(sheetId, rows, null, null);
1✔
322
    }
323

324
    /**
325
     * Update rows.
326
     * <p>
327
     * It mirrors to the following Smartsheet REST API method: PUT /sheets/{sheetId}/rows
328
     * @param sheetId the id of the sheet
329
     * @param rows the list of rows
330
     * @param includes optional objects to include
331
     * @param excludes optional objects to exclude
332
     * @return a list of rows
333
     * @throws IllegalArgumentException : if any argument is null
334
     * @throws InvalidRequestException : if there is any problem with the REST API request
335
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
336
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
337
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
338
     * @throws SmartsheetException : if there is any other error occurred during the operation
339
     */
340
    public List<Row> updateRows(
341
            long sheetId,
342
            List<Row> rows,
343
            EnumSet<RowInclusion> includes,
344
            EnumSet<ObjectExclusion> excludes
345
    ) throws SmartsheetException {
346
        String path = SHEETS_PATH + sheetId + "/" + ROWS;
1✔
347

348
        Map<String, Object> parameters = new HashMap<>();
1✔
349

350
        parameters.put(INCLUDE, QueryUtil.generateCommaSeparatedList(includes));
1✔
351
        parameters.put(EXCLUDE, QueryUtil.generateCommaSeparatedList(excludes));
1✔
352

353
        path += QueryUtil.generateUrl(null, parameters);
1✔
354
        return this.putAndReceiveList(path, rows, Row.class);
1✔
355
    }
356

357
    /**
358
     * Update rows, but allow partial success. The PartialRowUpdateResult will contain the successful
359
     * rows and those that failed, with specific messages for each.
360
     * <p>
361
     * It mirrors to the following Smartsheet REST API method: PUT /sheets/{sheetId}/rows
362
     * @param sheetId the id of the sheet
363
     * @param rows the list of rows
364
     * @return a list of rows
365
     * @throws IllegalArgumentException : if any argument is null
366
     * @throws InvalidRequestException : if there is any problem with the REST API request
367
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
368
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
369
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
370
     * @throws SmartsheetException : if there is any other error occurred during the operation
371
     */
372
    @Override
373
    public PartialRowUpdateResult updateRowsAllowPartialSuccess(long sheetId, List<Row> rows) throws SmartsheetException {
374
        return doPartialRowOperation(sheetId, rows, null, null, HttpMethod.PUT);
1✔
375
    }
376

377
    /**
378
     * Update rows, but allow partial success. The PartialRowUpdateResult will contain the successful
379
     * rows and those that failed, with specific messages for each.
380
     * <p>
381
     * It mirrors to the following Smartsheet REST API method: PUT /sheets/{sheetId}/rows
382
     * @param sheetId the id of the sheet
383
     * @param rows the list of rows
384
     * @param includes optional objects to include
385
     * @param excludes optional objects to exclude
386
     * @return a list of rows
387
     * @throws IllegalArgumentException : if any argument is null
388
     * @throws InvalidRequestException : if there is any problem with the REST API request
389
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
390
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
391
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
392
     * @throws SmartsheetException : if there is any other error occurred during the operation
393
     */
394
    @Override
395
    public PartialRowUpdateResult updateRowsAllowPartialSuccess(
396
            long sheetId,
397
            List<Row> rows,
398
            EnumSet<RowInclusion> includes,
399
            EnumSet<ObjectExclusion> excludes
400
    ) throws SmartsheetException {
401
        return doPartialRowOperation(sheetId, rows, includes, excludes, HttpMethod.PUT);
1✔
402
    }
403

404
    private PartialRowUpdateResult doPartialRowOperation(
405
            long sheetId,
406
            List<Row> rows,
407
            EnumSet<RowInclusion> includes,
408
            EnumSet<ObjectExclusion> excludes,
409
            HttpMethod method
410
    ) throws SmartsheetException {
411
        Util.throwIfNull(rows, method);
1✔
412
        if (method != HttpMethod.POST && method != HttpMethod.PUT) {
1✔
413
            throw new IllegalArgumentException();
×
414
        }
415

416
        String path = SHEETS_PATH + sheetId + "/" + ROWS;
1✔
417
        Map<String, Object> parameters = new HashMap<>();
1✔
418
        parameters.put("allowPartialSuccess", "true");
1✔
419
        parameters.put(INCLUDE, QueryUtil.generateCommaSeparatedList(includes));
1✔
420
        parameters.put(EXCLUDE, QueryUtil.generateCommaSeparatedList(excludes));
1✔
421

422
        path = QueryUtil.generateUrl(path, parameters);
1✔
423

424
        HttpRequest request;
425
        request = createHttpRequest(smartsheet.getBaseURI().resolve(path), method);
1✔
426

427
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
1✔
428

429
        this.smartsheet.getJsonSerializer().serialize(rows, baos);
1✔
430

431
        HttpEntity entity = new HttpEntity();
1✔
432
        entity.setContentType("application/json");
1✔
433
        entity.setContent(new ByteArrayInputStream(baos.toByteArray()));
1✔
434
        entity.setContentLength(baos.size());
1✔
435
        request.setEntity(entity);
1✔
436

437
        HttpResponse response = this.smartsheet.getHttpClient().request(request);
1✔
438

439
        PartialRowUpdateResult result = null;
1✔
440
        switch (response.getStatusCode()) {
1✔
441
            case 200:
442
                BulkItemResult<Row> bulkItemResult;
443
                bulkItemResult = this.smartsheet.getJsonSerializer().deserializeBulkItemResult(Row.class,
1✔
444
                        response.getEntity().getContent());
1✔
445
                result = new PartialRowUpdateResult();
1✔
446
                result.setResult(bulkItemResult.getResult());
1✔
447
                result.setResultCode(bulkItemResult.getResultCode());
1✔
448
                result.setMessage(bulkItemResult.getMessage());
1✔
449
                result.setVersion(bulkItemResult.getVersion());
1✔
450
                if (bulkItemResult.getFailedItems() != null) {
1✔
451
                    List<BulkRowFailedItem> failedItems = new ArrayList<>();
1✔
452
                    for (BulkItemFailure bulkItemFailure : bulkItemResult.getFailedItems()) {
1✔
453
                        BulkRowFailedItem bulkRowFailedItem = new BulkRowFailedItem();
1✔
454
                        bulkRowFailedItem.setError(bulkItemFailure.getError());
1✔
455
                        bulkRowFailedItem.setIndex(bulkItemFailure.getIndex());
1✔
456
                        bulkRowFailedItem.setRowId(bulkItemFailure.getRowId());
1✔
457
                        failedItems.add(bulkRowFailedItem);
1✔
458
                    }
1✔
459
                    result.setFailedItems(failedItems);
1✔
460
                }
1✔
461
                break;
462
            default:
463
                handleError(response);
×
464
        }
465

466
        smartsheet.getHttpClient().releaseConnection();
1✔
467

468
        return result;
1✔
469
    }
470

471
    /**
472
     * Moves Row(s) from the Sheet specified in the URL to (the bottom of) another sheet.
473
     * <p>
474
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows/move
475
     * @param sheetId the sheet ID to move
476
     * @param includes the parameters to include
477
     * @param ignoreRowsNotFound optional,specifying row Ids that do not exist within the source sheet
478
     * @param moveParameters   CopyOrMoveRowDirective object
479
     * @return the result object
480
     * @throws IllegalArgumentException : if any argument is null, or path is empty string
481
     * @throws InvalidRequestException : if there is any problem with the REST API request
482
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
483
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
484
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
485
     * @throws SmartsheetException : if there is any other error occurred during the operation
486
     */
487
    public CopyOrMoveRowResult moveRows(
488
            Long sheetId,
489
            EnumSet<RowMoveInclusion> includes,
490
            Boolean ignoreRowsNotFound,
491
            CopyOrMoveRowDirective moveParameters
492
    ) throws SmartsheetException {
493
        String path = SHEETS_PATH + sheetId + "/rows/move";
1✔
494
        Map<String, Object> parameters = new HashMap<>();
1✔
495
        parameters.put(INCLUDE, QueryUtil.generateCommaSeparatedList(includes));
1✔
496

497
        if (ignoreRowsNotFound != null) {
1✔
498
            parameters.put(IGNORE_ROWS_NOT_FOUND, ignoreRowsNotFound.toString());
1✔
499
        }
500

501
        path += QueryUtil.generateUrl(null, parameters);
1✔
502
        return this.postAndReceiveRowObject(path, moveParameters);
1✔
503
    }
504

505
    /**
506
     * Copies Row(s) from the Sheet specified in the URL to (the bottom of) another sheet.
507
     * <p>
508
     * It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows/copy
509
     * @param sheetId the sheet ID to move
510
     * @param includes the parameters to include
511
     * @param ignoreRowsNotFound optional,specifying row Ids that do not exist within the source sheet
512
     * @param copyParameters   CopyOrMoveRowDirective object
513
     * @return the result object
514
     * @throws IllegalArgumentException : if any argument is null, or path is empty string
515
     * @throws InvalidRequestException : if there is any problem with the REST API request
516
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
517
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
518
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
519
     * @throws SmartsheetException : if there is any other error occurred during the operation
520
     */
521
    public CopyOrMoveRowResult copyRows(
522
            Long sheetId,
523
            EnumSet<RowCopyInclusion> includes,
524
            Boolean ignoreRowsNotFound,
525
            CopyOrMoveRowDirective copyParameters
526
    ) throws SmartsheetException {
527
        String path = SHEETS_PATH + sheetId + "/rows/copy";
1✔
528
        Map<String, Object> parameters = new HashMap<>();
1✔
529
        parameters.put(INCLUDE, QueryUtil.generateCommaSeparatedList(includes));
1✔
530

531
        if (ignoreRowsNotFound != null) {
1✔
532
            parameters.put(IGNORE_ROWS_NOT_FOUND, ignoreRowsNotFound.toString());
1✔
533
        }
534

535
        path += QueryUtil.generateUrl(null, parameters);
1✔
536
        return this.postAndReceiveRowObject(path, copyParameters);
1✔
537
    }
538

539
    /**
540
    /**
541
     * Update the values of the Cells in a Row.
542
     * <p>
543
     * It mirrors to the following Smartsheet REST API method: PUT /row/{id}/cells
544
     * @param rowId the row id
545
     * @param cells the cells to update (Cells must have the following attributes set: *
546
     *     columnId * value * strict (optional)
547
     * @return the updated cells (note that if there is no such resource, this method will throw
548
     *     ResourceNotFoundException rather than returning null).
549
     * @throws IllegalArgumentException : if any argument is null
550
     * @throws InvalidRequestException : if there is any problem with the REST API request
551
     * @throws AuthorizationException : if there is any problem with the REST API authorization(access token)
552
     * @throws ResourceNotFoundException : if the resource can not be found
553
     * @throws ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
554
     * @throws SmartsheetRestException : if there is any other REST API related error occurred during the operation
555
     * @throws SmartsheetException : if there is any other error occurred during the operation
556
     * @deprecated replaced by {@link #updateRows(long, List)}
557
     */
558
    @Deprecated
559
    public List<Cell> updateCells(long rowId, List<Cell> cells) throws SmartsheetException {
560
        return this.putAndReceiveList("row/" + rowId + "/cells", cells, Cell.class);
×
561
    }
562

563
    /**
564
     * Creates an object of RowAttachmentResources.
565
     *
566
     * @return the created RowAttachmentResources object
567
     */
568
    public RowAttachmentResources attachmentResources() {
569
        return attachments;
×
570
    }
571

572
    /**
573
     * Creates an object of RowDiscussionResources.
574
     *
575
     * @return the created RowDiscussionResources object
576
     */
577
    public RowDiscussionResources discussionResources() {
578
        return discussions;
×
579
    }
580

581
    /**
582
     * Creates an object of RowColumnResources.
583
     *
584
     * @return the created RowColumnResources object
585
     */
586
    public RowColumnResources cellResources() {
587
        return columns;
×
588
    }
589
}
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