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

smartsheet / smartsheet-java-sdk / #66

26 Jun 2026 09:41AM UTC coverage: 59.997% (-0.006%) from 60.003%
#66

push

github

web-flow
Prepare for release v4.1.0 (#180)

4510 of 7517 relevant lines covered (60.0%)

0.6 hits per line

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

51.52
/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.FolderPathNode;
25
import com.smartsheet.api.models.enums.CopyExclusion;
26
import com.smartsheet.api.models.enums.FolderCopyInclusion;
27
import com.smartsheet.api.models.enums.FolderRemapExclusion;
28
import com.smartsheet.api.models.enums.GetFolderMetadataInclusion;
29
import com.smartsheet.api.models.enums.GetFolderChildrenInclusion;
30
import com.smartsheet.api.models.enums.ChildrenResourceType;
31
import com.smartsheet.api.models.TokenPaginatedResult;
32
import com.smartsheet.api.internal.json.ChildrenResourceDeserializer;
33

34
import java.util.EnumSet;
35
import java.util.HashMap;
36
import java.util.Map;
37

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

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

60
    /**
61
     * Update a folder.
62
     * <p>
63
     * It mirrors to the following Smartsheet REST API method: PUT /folder/{id}
64
     * <p>
65
     * Exceptions:
66
     * IllegalArgumentException : if folder is null
67
     * InvalidRequestException : if there is any problem with the REST API request
68
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
69
     * ResourceNotFoundException : if the resource can not be found
70
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
71
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
72
     * SmartsheetException : if there is any other error occurred during the operation
73
     *
74
     * @param folder the folder to update
75
     * @return the updated folder (note that if there is no such folder, this method will throw
76
     * ResourceNotFoundException rather than returning null).
77
     * @throws SmartsheetException the smartsheet exception
78
     */
79
    public Folder updateFolder(Folder folder) throws SmartsheetException {
80

81
        return this.updateResource(FOLDERS_PATH + folder.getId(), Folder.class, folder);
1✔
82
    }
83

84
    /**
85
     * Delete a folder.
86
     * <p>
87
     * It mirrors to the following Smartsheet REST API method: DELETE /folder{id}
88
     * <p>
89
     * Exceptions:
90
     * InvalidRequestException : if there is any problem with the REST API request
91
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
92
     * ResourceNotFoundException : if the resource can not be found
93
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
94
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
95
     * SmartsheetException : if there is any other error occurred during the operation
96
     *
97
     * @param folderId the folder id
98
     * @throws SmartsheetException the smartsheet exception
99
     */
100
    public void deleteFolder(long folderId) throws SmartsheetException {
101

102
        this.deleteResource(FOLDERS_PATH + folderId, Folder.class);
1✔
103
    }
1✔
104

105
    /**
106
     * Create a folder.
107
     * <p>
108
     * It mirrors to the following Smartsheet REST API method: POST /folder/{id}/folders
109
     * <p>
110
     * Exceptions:
111
     * IllegalArgumentException : if folder is null
112
     * InvalidRequestException : if there is any problem with the REST API request
113
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
114
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
115
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
116
     * SmartsheetException : if there is any other error occurred during the operation
117
     *
118
     * @param parentFolderId the parent folder id
119
     * @param folder         the folder to create
120
     * @return the folder
121
     * @throws SmartsheetException the smartsheet exception
122
     */
123
    public Folder createFolder(long parentFolderId, Folder folder) throws SmartsheetException {
124

125
        return this.createResource(FOLDERS_PATH + parentFolderId + "/folders", Folder.class, folder);
1✔
126
    }
127

128
    /**
129
     * Creates a copy of the specified Folder.
130
     * <p>
131
     * It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/copy
132
     * <p>
133
     * Exceptions:
134
     * IllegalArgumentException : if folder is null
135
     * InvalidRequestException : if there is any problem with the REST API request
136
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
137
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
138
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
139
     * SmartsheetException : if there is any other error occurred during the operation
140
     *
141
     * @param folderId             the folder id
142
     * @param containerDestination describes the destination container
143
     * @param includes             optional parameters to include
144
     * @param skipRemap            optional parameters to exclude
145
     * @return the folder
146
     * @throws SmartsheetException the smartsheet exception
147
     */
148
    public Folder copyFolder(
149
            long folderId,
150
            ContainerDestination containerDestination,
151
            EnumSet<FolderCopyInclusion> includes,
152
            EnumSet<FolderRemapExclusion> skipRemap
153
    ) throws SmartsheetException {
154
        return copyFolder(folderId, containerDestination, includes, skipRemap, null);
1✔
155
    }
156

157
    /**
158
     * Creates a copy of the specified Folder.
159
     * <p>
160
     * It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/copy
161
     * <p>
162
     * Exceptions:
163
     * IllegalArgumentException : if folder is null
164
     * InvalidRequestException : if there is any problem with the REST API request
165
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
166
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
167
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
168
     * SmartsheetException : if there is any other error occurred during the operation
169
     *
170
     * @param folderId             the folder id
171
     * @param containerDestination describes the destination container
172
     * @param includes             optional parameters to include
173
     * @param skipRemap            optional parameters to NOT re-map in the new folder
174
     * @param excludes             optional parameters to exclude
175
     * @return the folder
176
     * @throws SmartsheetException the smartsheet exception
177
     */
178
    public Folder copyFolder(long folderId, ContainerDestination containerDestination, EnumSet<FolderCopyInclusion> includes,
179
                             EnumSet<FolderRemapExclusion> skipRemap, EnumSet<CopyExclusion> excludes) throws SmartsheetException {
180

181
        String path = FOLDERS_PATH + folderId + "/copy";
1✔
182
        Map<String, Object> parameters = new HashMap<>();
1✔
183

184
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
1✔
185
        parameters.put("skipRemap", QueryUtil.generateCommaSeparatedList(skipRemap));
1✔
186
        parameters.put("exclude", QueryUtil.generateCommaSeparatedList(excludes));
1✔
187

188
        path += QueryUtil.generateUrl(null, parameters);
1✔
189

190
        return this.createResource(path, Folder.class, containerDestination);
1✔
191
    }
192

193
    /**
194
     * Moves the specified Folder to another location.
195
     * <p>
196
     * It mirrors to the following Smartsheet REST API method: POST /folders/{folderId}/move
197
     * <p>
198
     * Exceptions:
199
     * IllegalArgumentException : if folder is null
200
     * InvalidRequestException : if there is any problem with the REST API request
201
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
202
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
203
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
204
     * SmartsheetException : if there is any other error occurred during the operation
205
     *
206
     * @param folderId             the folder id
207
     * @param containerDestination describes the destination container
208
     * @return the folder
209
     * @throws SmartsheetException the smartsheet exception
210
     */
211
    public Folder moveFolder(long folderId, ContainerDestination containerDestination) throws SmartsheetException {
212

213
        String path = FOLDERS_PATH + folderId + "/move";
1✔
214
        return this.createResource(path, Folder.class, containerDestination);
1✔
215
    }
216

217
    /**
218
     * Get metadata of a folder.
219
     * <p>
220
     * It mirrors to the following Smartsheet REST API method: GET /folders/{folderId}/metadata
221
     * <p>
222
     * Exceptions:
223
     * - InvalidRequestException : if there is any problem with the REST API request
224
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
225
     * - ResourceNotFoundException : if the resource can not be found
226
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
227
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
228
     * - SmartsheetException : if there is any other error occurred during the operation
229
     *
230
     * @param folderId the folder id
231
     * @param includes used to specify the optional objects to include
232
     * @return the folder metadata (note that if there is no such resource, this method will throw ResourceNotFoundException
233
     * rather than returning null).
234
     * @throws SmartsheetException the smartsheet exception
235
     */
236
    @Override
237
    public Folder getFolderMetadata(long folderId, EnumSet<GetFolderMetadataInclusion> includes) throws SmartsheetException {
238
        String path = FOLDERS_PATH + folderId + "/metadata";
×
239

240
        // Add the parameters to a map and build the query string at the end
241
        Map<String, Object> parameters = new HashMap<>();
×
242
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
243
        path += QueryUtil.generateUrl(null, parameters);
×
244

245
        return this.getResource(path, Folder.class);
×
246
    }
247

248
    /**
249
     * Get children of a folder.
250
     * <p>
251
     * It mirrors to the following Smartsheet REST API method: GET /folders/{folderId}/children
252
     * <p>
253
     * Exceptions:
254
     * - InvalidRequestException : if there is any problem with the REST API request
255
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
256
     * - ResourceNotFoundException : if the resource can not be found
257
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
258
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
259
     * - SmartsheetException : if there is any other error occurred during the operation
260
     *
261
     * @param folderId              the folder id
262
     * @param childrenResourceTypes the resource types to filter by (optional)
263
     * @param includes              used to specify the optional objects to include
264
     * @param lastKey               the last key for pagination (optional)
265
     * @param maxItems              the maximum number of items to return (optional)
266
     * @return the paginated children response
267
     * @throws SmartsheetException the smartsheet exception
268
     */
269
    @Override
270
    public TokenPaginatedResult<Object> getFolderChildren(long folderId, EnumSet<ChildrenResourceType> childrenResourceTypes,
271
                                                          EnumSet<GetFolderChildrenInclusion> includes,
272
                                                          String lastKey, Integer maxItems) throws SmartsheetException {
273
        String path = FOLDERS_PATH + folderId + "/children";
×
274

275
        // Add the parameters to a map and build the query string at the end
276
        Map<String, Object> parameters = new HashMap<>();
×
277
        if (childrenResourceTypes != null && !childrenResourceTypes.isEmpty()) {
×
278
            parameters.put("childrenResourceTypes", QueryUtil.generateCommaSeparatedList(childrenResourceTypes));
×
279
        }
280
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
281
        if (lastKey != null) {
×
282
            parameters.put("lastKey", lastKey);
×
283
        }
284
        if (maxItems != null) {
×
285
            parameters.put("maxItems", maxItems);
×
286
        }
287
        path += QueryUtil.generateUrl(null, parameters);
×
288

289
        return this.listResourcesWithTokenPagination(path, new ChildrenResourceDeserializer());
×
290
    }
291

292
    /**
293
     * Get the path of a folder (workspace/folder hierarchy).
294
     * <p>
295
     * It mirrors to the following Smartsheet REST API method: GET /folders/{folderId}/path
296
     *
297
     * @param folderId the folder id
298
     * @return the container path
299
     * @throws SmartsheetException the smartsheet exception
300
     */
301
    @Override
302
    public FolderPathNode getFolderPath(long folderId) throws SmartsheetException {
303
        return this.getResource(FOLDERS_PATH + folderId + "/path", FolderPathNode.class);
1✔
304
    }
305
}
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