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

smartsheet / smartsheet-java-sdk / #58

23 Sep 2025 06:13PM UTC coverage: 59.737% (-1.1%) from 60.803%
#58

push

github

web-flow
Add user downgrade seat type endpoint (#131)

* Add support for upgrade user seat type route

* Change return type

* Add support for the user downgrade seat type endpoint

* Remove * imports, replace switch with if statement, remove overload

* Update changelog and build.gradle

* Add user downgrade and upgrade API calls

* Add user downgrade and upgrade API calls

* Add user downgrade and upgrade API calls

* Add user downgrade and upgrade API calls

---------

Co-authored-by: Velihan Zelev <velihan.zelev@smartsheet.com>

12 of 13 new or added lines in 2 files covered. (92.31%)

192 existing lines in 7 files now uncovered.

4310 of 7215 relevant lines covered (59.74%)

0.6 hits per line

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

60.98
/src/main/java/com/smartsheet/api/internal/FolderResourcesImpl.java
1
/*
2
 * Copyright (C) 2025 Smartsheet
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.smartsheet.api.internal;
18

19
import com.smartsheet.api.FolderResources;
20
import com.smartsheet.api.SmartsheetException;
21
import com.smartsheet.api.internal.util.QueryUtil;
22
import com.smartsheet.api.models.ContainerDestination;
23
import com.smartsheet.api.models.Folder;
24
import com.smartsheet.api.models.PagedResult;
25
import com.smartsheet.api.models.PaginationParameters;
26
import com.smartsheet.api.models.enums.CopyExclusion;
27
import com.smartsheet.api.models.enums.FolderCopyInclusion;
28
import com.smartsheet.api.models.enums.FolderRemapExclusion;
29
import com.smartsheet.api.models.enums.SourceInclusion;
30
import com.smartsheet.api.models.enums.GetFolderMetadataInclusion;
31
import com.smartsheet.api.models.enums.GetFolderChildrenInclusion;
32
import com.smartsheet.api.models.enums.ChildrenResourceType;
33
import com.smartsheet.api.models.TokenPaginatedResult;
34
import com.smartsheet.api.internal.json.ChildrenResourceDeserializer;
35

36
import java.util.EnumSet;
37
import java.util.HashMap;
38
import java.util.Map;
39

40
/**
41
 * This is the implementation of the FolderResources.
42
 * <p>
43
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
44
 */
45
public class FolderResourcesImpl extends AbstractResources implements FolderResources {
46
    private static final String FOLDERS_PATH = "folders/";
47
    private static final String INCLUDE_PARAM = "include";
48

49
    /**
50
     * Constructor.
51
     * <p>
52
     * Parameters: - smartsheet : the SmartsheetImpl
53
     * <p>
54
     * Exceptions: - IllegalArgumentException : if any argument is null
55
     *
56
     * @param smartsheet the smartsheet
57
     */
58
    public FolderResourcesImpl(SmartsheetImpl smartsheet) {
59
        super(smartsheet);
1✔
60
    }
1✔
61

62
    /**
63
     * Get a folder.
64
     * <p>
65
     * It mirrors to the following Smartsheet REST API method: GET /folder/{id}
66
     * <p>
67
     * Exceptions:
68
     * InvalidRequestException : if there is any problem with the REST API request
69
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
70
     * ResourceNotFoundException : if the resource can not be found
71
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
72
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
73
     * SmartsheetException : if there is any other error occurred during the operation
74
     *
75
     * @param folderId the folder id
76
     * @param includes the include parameters
77
     * @return the folder (note that if there is no such resource, this method will throw ResourceNotFoundException
78
     * rather than returning null)
79
     * @throws SmartsheetException the smartsheet exception
80
     */
81
    @Override
82
    @Deprecated(since = "3.4.0", forRemoval = true)
83
    public Folder getFolder(long folderId, EnumSet<SourceInclusion> includes) throws SmartsheetException {
84
        String path = FOLDERS_PATH + folderId;
1✔
85
        Map<String, Object> parameters = new HashMap<>();
1✔
86
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
1✔
87
        path += QueryUtil.generateUrl(null, parameters);
1✔
88

89
        return this.getResource(path, Folder.class);
1✔
90
    }
91

92
    /**
93
     * Update a folder.
94
     * <p>
95
     * It mirrors to the following Smartsheet REST API method: PUT /folder/{id}
96
     * <p>
97
     * Exceptions:
98
     * IllegalArgumentException : if folder is null
99
     * InvalidRequestException : if there is any problem with the REST API request
100
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
101
     * ResourceNotFoundException : if the resource can not be found
102
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
103
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
104
     * SmartsheetException : if there is any other error occurred during the operation
105
     *
106
     * @param folder the folder to update
107
     * @return the updated folder (note that if there is no such folder, this method will throw
108
     * ResourceNotFoundException rather than returning null).
109
     * @throws SmartsheetException the smartsheet exception
110
     */
111
    public Folder updateFolder(Folder folder) throws SmartsheetException {
112

113
        return this.updateResource(FOLDERS_PATH + folder.getId(), Folder.class, folder);
1✔
114
    }
115

116
    /**
117
     * Delete a folder.
118
     * <p>
119
     * It mirrors to the following Smartsheet REST API method: DELETE /folder{id}
120
     * <p>
121
     * Exceptions:
122
     * InvalidRequestException : if there is any problem with the REST API request
123
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
124
     * ResourceNotFoundException : if the resource can not be found
125
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
126
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
127
     * SmartsheetException : if there is any other error occurred during the operation
128
     *
129
     * @param folderId the folder id
130
     * @throws SmartsheetException the smartsheet exception
131
     */
132
    public void deleteFolder(long folderId) throws SmartsheetException {
133

134
        this.deleteResource(FOLDERS_PATH + folderId, Folder.class);
1✔
135
    }
1✔
136

137
    /**
138
     * List child folders of a given folder.
139
     * <p>
140
     * It mirrors to the following Smartsheet REST API method: GET /folder/{id}/folders
141
     * <p>
142
     * Parameters: - parentFolderId : the parent folder ID
143
     * <p>
144
     * Exceptions:
145
     * InvalidRequestException : if there is any problem with the REST API request
146
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
147
     * ResourceNotFoundException : if the resource can not be found
148
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
149
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
150
     * SmartsheetException : if there is any other error occurred during the operation
151
     *
152
     * @param parentFolderId the parent folder id
153
     * @param parameters     the parameters for pagination
154
     * @return the child folders (note that empty list will be returned if no child folder found)
155
     * @throws SmartsheetException the smartsheet exception
156
     */
157
    @Deprecated(since = "3.4.0", forRemoval = true)
158
    public PagedResult<Folder> listFolders(long parentFolderId, PaginationParameters parameters) throws SmartsheetException {
159
        String path = FOLDERS_PATH + parentFolderId + "/folders";
1✔
160

161
        if (parameters != null) {
1✔
162
            path += parameters.toQueryString();
1✔
163
        }
164

165
        return this.listResourcesWithWrapper(path, Folder.class);
1✔
166
    }
167

168
    /**
169
     * Create a folder.
170
     * <p>
171
     * It mirrors to the following Smartsheet REST API method: POST /folder/{id}/folders
172
     * <p>
173
     * Exceptions:
174
     * IllegalArgumentException : if folder is null
175
     * InvalidRequestException : if there is any problem with the REST API request
176
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
177
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
178
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
179
     * SmartsheetException : if there is any other error occurred during the operation
180
     *
181
     * @param parentFolderId the parent folder id
182
     * @param folder         the folder to create
183
     * @return the folder
184
     * @throws SmartsheetException the smartsheet exception
185
     */
186
    public Folder createFolder(long parentFolderId, Folder folder) throws SmartsheetException {
187

188
        return this.createResource(FOLDERS_PATH + parentFolderId + "/folders", Folder.class, folder);
1✔
189
    }
190

191
    /**
192
     * Creates a copy of the specified Folder.
193
     * <p>
194
     * It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/copy
195
     * <p>
196
     * Exceptions:
197
     * IllegalArgumentException : if folder is null
198
     * InvalidRequestException : if there is any problem with the REST API request
199
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
200
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
201
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
202
     * SmartsheetException : if there is any other error occurred during the operation
203
     *
204
     * @param folderId             the folder id
205
     * @param containerDestination describes the destination container
206
     * @param includes             optional parameters to include
207
     * @param skipRemap            optional parameters to exclude
208
     * @return the folder
209
     * @throws SmartsheetException the smartsheet exception
210
     */
211
    public Folder copyFolder(
212
            long folderId,
213
            ContainerDestination containerDestination,
214
            EnumSet<FolderCopyInclusion> includes,
215
            EnumSet<FolderRemapExclusion> skipRemap
216
    ) throws SmartsheetException {
217
        return copyFolder(folderId, containerDestination, includes, skipRemap, null);
1✔
218
    }
219

220
    /**
221
     * Creates a copy of the specified Folder.
222
     * <p>
223
     * It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/copy
224
     * <p>
225
     * Exceptions:
226
     * IllegalArgumentException : if folder is null
227
     * InvalidRequestException : if there is any problem with the REST API request
228
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
229
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
230
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
231
     * SmartsheetException : if there is any other error occurred during the operation
232
     *
233
     * @param folderId             the folder id
234
     * @param containerDestination describes the destination container
235
     * @param includes             optional parameters to include
236
     * @param skipRemap            optional parameters to NOT re-map in the new folder
237
     * @param excludes             optional parameters to exclude
238
     * @return the folder
239
     * @throws SmartsheetException the smartsheet exception
240
     */
241
    public Folder copyFolder(long folderId, ContainerDestination containerDestination, EnumSet<FolderCopyInclusion> includes,
242
                             EnumSet<FolderRemapExclusion> skipRemap, EnumSet<CopyExclusion> excludes) throws SmartsheetException {
243

244
        String path = FOLDERS_PATH + folderId + "/copy";
1✔
245
        Map<String, Object> parameters = new HashMap<>();
1✔
246

247
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
1✔
248
        parameters.put("skipRemap", QueryUtil.generateCommaSeparatedList(skipRemap));
1✔
249
        parameters.put("exclude", QueryUtil.generateCommaSeparatedList(excludes));
1✔
250

251
        path += QueryUtil.generateUrl(null, parameters);
1✔
252

253
        return this.createResource(path, Folder.class, containerDestination);
1✔
254
    }
255

256
    /**
257
     * Moves the specified Folder to another location.
258
     * <p>
259
     * It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/move
260
     * <p>
261
     * Exceptions:
262
     * IllegalArgumentException : if folder is null
263
     * InvalidRequestException : if there is any problem with the REST API request
264
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
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 folderId             the folder id
270
     * @param containerDestination describes the destination container
271
     * @return the folder
272
     * @throws SmartsheetException the smartsheet exception
273
     */
274
    public Folder moveFolder(long folderId, ContainerDestination containerDestination) throws SmartsheetException {
275

276
        String path = FOLDERS_PATH + folderId + "/move";
1✔
277
        return this.createResource(path, Folder.class, containerDestination);
1✔
278
    }
279

280
    /**
281
     * Get metadata of a folder.
282
     * <p>
283
     * It mirrors to the following Smartsheet REST API method: GET /folders/{folderId}/metadata
284
     * <p>
285
     * Exceptions:
286
     * - InvalidRequestException : if there is any problem with the REST API request
287
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
288
     * - ResourceNotFoundException : if the resource can not be found
289
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
290
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
291
     * - SmartsheetException : if there is any other error occurred during the operation
292
     *
293
     * @param folderId the folder id
294
     * @param includes used to specify the optional objects to include
295
     * @return the folder metadata (note that if there is no such resource, this method will throw ResourceNotFoundException
296
     * rather than returning null).
297
     * @throws SmartsheetException the smartsheet exception
298
     */
299
    @Override
300
    public Folder getFolderMetadata(long folderId, EnumSet<GetFolderMetadataInclusion> includes) throws SmartsheetException {
UNCOV
301
        String path = FOLDERS_PATH + folderId + "/metadata";
×
302

303
        // Add the parameters to a map and build the query string at the end
UNCOV
304
        Map<String, Object> parameters = new HashMap<>();
×
UNCOV
305
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
UNCOV
306
        path += QueryUtil.generateUrl(null, parameters);
×
307

UNCOV
308
        return this.getResource(path, Folder.class);
×
309
    }
310

311
    /**
312
     * Get children of a folder.
313
     * <p>
314
     * It mirrors to the following Smartsheet REST API method: GET /folders/{folderId}/children
315
     * <p>
316
     * Exceptions:
317
     * - InvalidRequestException : if there is any problem with the REST API request
318
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
319
     * - ResourceNotFoundException : if the resource can not be found
320
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
321
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
322
     * - SmartsheetException : if there is any other error occurred during the operation
323
     *
324
     * @param folderId              the folder id
325
     * @param childrenResourceTypes the resource types to filter by (optional)
326
     * @param includes              used to specify the optional objects to include
327
     * @param lastKey               the last key for pagination (optional)
328
     * @param maxItems              the maximum number of items to return (optional)
329
     * @return the paginated children response
330
     * @throws SmartsheetException the smartsheet exception
331
     */
332
    @Override
333
    public TokenPaginatedResult<Object> getFolderChildren(long folderId, EnumSet<ChildrenResourceType> childrenResourceTypes,
334
                                                       EnumSet<GetFolderChildrenInclusion> includes,
335
                                                       String lastKey, Integer maxItems) throws SmartsheetException {
UNCOV
336
        String path = FOLDERS_PATH + folderId + "/children";
×
337

338
        // Add the parameters to a map and build the query string at the end
UNCOV
339
        Map<String, Object> parameters = new HashMap<>();
×
UNCOV
340
        if (childrenResourceTypes != null && !childrenResourceTypes.isEmpty()) {
×
UNCOV
341
            parameters.put("childrenResourceTypes", QueryUtil.generateCommaSeparatedList(childrenResourceTypes));
×
342
        }
UNCOV
343
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
UNCOV
344
        if (lastKey != null) {
×
UNCOV
345
            parameters.put("lastKey", lastKey);
×
346
        }
UNCOV
347
        if (maxItems != null) {
×
UNCOV
348
            parameters.put("maxItems", maxItems);
×
349
        }
UNCOV
350
        path += QueryUtil.generateUrl(null, parameters);
×
351

UNCOV
352
        return this.listResourcesWithTokenPagination(path, new ChildrenResourceDeserializer());
×
353
    }
354
}
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

© 2025 Coveralls, Inc