• 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.0
/src/main/java/com/smartsheet/api/internal/WorkspaceResourcesImpl.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.ShareResources;
20
import com.smartsheet.api.SmartsheetException;
21
import com.smartsheet.api.WorkspaceFolderResources;
22
import com.smartsheet.api.WorkspaceResources;
23
import com.smartsheet.api.internal.util.QueryUtil;
24
import com.smartsheet.api.models.ContainerDestination;
25
import com.smartsheet.api.models.PagedResult;
26
import com.smartsheet.api.models.PaginationParameters;
27
import com.smartsheet.api.models.Workspace;
28
import com.smartsheet.api.models.enums.CopyExclusion;
29
import com.smartsheet.api.models.enums.SourceInclusion;
30
import com.smartsheet.api.models.enums.WorkspaceCopyInclusion;
31
import com.smartsheet.api.models.enums.WorkspaceRemapExclusion;
32
import com.smartsheet.api.models.enums.GetWorkspaceMetadataInclusion;
33
import com.smartsheet.api.models.enums.GetWorkspaceChildrenInclusion;
34
import com.smartsheet.api.models.enums.ChildrenResourceType;
35
import com.smartsheet.api.models.TokenPaginatedResult;
36
import com.smartsheet.api.internal.json.ChildrenResourceDeserializer;
37

38
import java.util.EnumSet;
39
import java.util.HashMap;
40
import java.util.Map;
41

42
/**
43
 * This is the implementation of the WorkspaceResources.
44
 * <p>
45
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
46
 */
47
public class WorkspaceResourcesImpl extends AbstractResources implements WorkspaceResources {
48
    private static final String WORKSPACES = "workspaces";
49
    private static final String INCLUDE_PARAM = "include";
50

51
    /**
52
     * Represents the WorkspaceFolderResources.
53
     * <p>
54
     * It will be initialized in constructor and will not change afterwards.
55
     */
56
    private WorkspaceFolderResources folders;
57

58
    /**
59
     * Represents the ShareResources.
60
     * <p>
61
     * It will be initialized in constructor and will not change afterwards.
62
     */
63
    private ShareResources shares;
64

65
    /**
66
     * Constructor.
67
     * <p>
68
     * Exceptions:
69
     * - IllegalArgumentException : if any argument is
70
     *
71
     * @param smartsheet the smartsheet
72
     */
73
    public WorkspaceResourcesImpl(SmartsheetImpl smartsheet) {
74
        super(smartsheet);
1✔
75
        this.shares = new ShareResourcesImpl(smartsheet, WORKSPACES);
1✔
76
        this.folders = new WorkspaceFolderResourcesImpl(smartsheet);
1✔
77
    }
1✔
78

79
    /**
80
     * List all workspaces.
81
     * <p>
82
     * It mirrors to the following Smartsheet REST API method: GET /workspaces
83
     * <p>
84
     * Exceptions:
85
     * - InvalidRequestException : if there is any problem with the REST API request
86
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
87
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
88
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
89
     * - SmartsheetException : if there is any other error occurred during the operation
90
     *
91
     * @param parameters the object containing the pagination parameters
92
     * @return all workspaces (note that empty list will be returned if there is none)
93
     * @throws SmartsheetException the smartsheet exception
94
     */
95
    public PagedResult<Workspace> listWorkspaces(PaginationParameters parameters) throws SmartsheetException {
96
        String path = WORKSPACES;
1✔
97

98
        if (parameters != null) {
1✔
99
            path += parameters.toQueryString();
1✔
100
        }
101
        return this.listResourcesWithWrapper(path, Workspace.class);
1✔
102
    }
103

104
    /**
105
     * Get a workspace.
106
     * <p>
107
     * It mirrors to the following Smartsheet REST API method: GET /workspace/{id}
108
     * <p>
109
     * Exceptions:
110
     * - InvalidRequestException : if there is any problem with the REST API request
111
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
112
     * - ResourceNotFoundException : if the resource can not be found
113
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
114
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
115
     * - SmartsheetException : if there is any other error occurred during the operation
116
     *
117
     * @param id       the id
118
     * @param loadAll  load all contents in a workspace
119
     * @param includes used to specify the optional objects to include
120
     * @return the resource (note that if there is no such resource, this method will throw ResourceNotFoundException
121
     * rather than returning null).
122
     * @throws SmartsheetException the smartsheet exception
123
     */
124
    @Override
125
    @Deprecated(since = "3.4.0", forRemoval = true)
126
    public Workspace getWorkspace(long id, Boolean loadAll, EnumSet<SourceInclusion> includes) throws SmartsheetException {
127
        String path = WORKSPACES + "/" + id;
1✔
128

129
        // Add the parameters to a map and build the query string at the end
130
        Map<String, Object> parameters = new HashMap<>();
1✔
131

132
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
1✔
133
        if (loadAll != null) {
1✔
134
            parameters.put("loadAll", Boolean.toString(loadAll));
1✔
135
        }
136

137
        path += QueryUtil.generateUrl(null, parameters);
1✔
138

139
        return this.getResource(path, Workspace.class);
1✔
140
    }
141

142
    /**
143
     * Create a workspace.
144
     * <p>
145
     * It mirrors to the following Smartsheet REST API method: POST /workspaces
146
     * <p>
147
     * Exceptions:
148
     * - IllegalArgumentException : if any argument is null
149
     * - InvalidRequestException : if there is any problem with the REST API request
150
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
151
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
152
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
153
     * - SmartsheetException : if there is any other error occurred during the operation
154
     *
155
     * @param workspace the workspace to create, limited to the following required attributes: * name (string)
156
     * @return the created workspace
157
     * @throws SmartsheetException the smartsheet exception
158
     */
159
    public Workspace createWorkspace(Workspace workspace) throws SmartsheetException {
160
        return this.createResource(WORKSPACES, Workspace.class, workspace);
1✔
161
    }
162

163
    /**
164
     * Update a workspace.
165
     * <p>
166
     * It mirrors to the following Smartsheet REST API method: PUT /workspace/{id}
167
     * <p>
168
     * Exceptions:
169
     * - IllegalArgumentException : if any argument is null
170
     * - InvalidRequestException : if there is any problem with the REST API request
171
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
172
     * - ResourceNotFoundException : if the resource can not be found
173
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
174
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
175
     * - SmartsheetException : if there is any other error occurred during the operation
176
     *
177
     * @param workspace the workspace to update limited to the following attribute: * name (string)
178
     * @return the updated workspace (note that if there is no such resource, this method will throw
179
     * ResourceNotFoundException rather than returning null).
180
     * @throws SmartsheetException the smartsheet exception
181
     */
182
    public Workspace updateWorkspace(Workspace workspace) throws SmartsheetException {
183
        return this.updateResource(WORKSPACES + "/" + workspace.getId(), Workspace.class, workspace);
1✔
184
    }
185

186
    /**
187
     * Delete a workspace.
188
     * <p>
189
     * It mirrors to the following Smartsheet REST API method: DELETE /workspace{id}
190
     * <p>
191
     * Exceptions:
192
     * - InvalidRequestException : if there is any problem with the REST API request
193
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
194
     * - ResourceNotFoundException : if the resource can not be found
195
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
196
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
197
     * - SmartsheetException : if there is any other error occurred during the operation
198
     *
199
     * @param id the ID of the workspace
200
     * @throws SmartsheetException the smartsheet exception
201
     */
202
    public void deleteWorkspace(long id) throws SmartsheetException {
203
        this.deleteResource(WORKSPACES + "/" + id, Workspace.class);
1✔
204
    }
1✔
205

206
    /**
207
     * Creates a copy of the specified workspace.
208
     * <p>
209
     * It mirrors to the following Smartsheet REST API method: POST /workspaces/{workspaceId}/copy
210
     * <p>
211
     * Exceptions:
212
     * IllegalArgumentException : if folder is null
213
     * InvalidRequestException : if there is any problem with the REST API request
214
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
215
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
216
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
217
     * SmartsheetException : if there is any other error occurred during the operation
218
     *
219
     * @param workspaceId          the folder id
220
     * @param containerDestination describes the destination container
221
     * @param includes             optional parameters to include
222
     * @param skipRemap            optional parameters to exclude
223
     * @return the folder
224
     * @throws SmartsheetException the smartsheet exception
225
     */
226
    public Workspace copyWorkspace(
227
            long workspaceId,
228
            ContainerDestination containerDestination,
229
            EnumSet<WorkspaceCopyInclusion> includes,
230
            EnumSet<WorkspaceRemapExclusion> skipRemap
231
    ) throws SmartsheetException {
232
        return copyWorkspace(workspaceId, containerDestination, includes, skipRemap, null);
1✔
233
    }
234

235
    /**
236
     * Creates a copy of the specified workspace.
237
     * <p>
238
     * It mirrors to the following Smartsheet REST API method: POST /workspaces/{workspaceId}/copy
239
     * <p>
240
     * Exceptions:
241
     * IllegalArgumentException : if folder is null
242
     * InvalidRequestException : if there is any problem with the REST API request
243
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
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 workspaceId          the folder id
249
     * @param containerDestination describes the destination container
250
     * @param includes             optional parameters to include
251
     * @param skipRemap            optional parameters to NOT re-map in the new folder
252
     * @param excludes             optional parameters to exclude     *
253
     * @return the folder
254
     * @throws SmartsheetException the smartsheet exception
255
     * @deprecated As of release 2.0. `excludes` param is deprecated. Please use the `copyWorkspace` method with `includes` instead.
256
     */
257
    @Deprecated(since = "2.0.0", forRemoval = true)
258
    public Workspace copyWorkspace(long workspaceId, ContainerDestination containerDestination, EnumSet<WorkspaceCopyInclusion> includes,
259
                                   EnumSet<WorkspaceRemapExclusion> skipRemap, EnumSet<CopyExclusion> excludes) throws SmartsheetException {
260

261
        String path = WORKSPACES + "/" + workspaceId + "/copy";
1✔
262
        Map<String, Object> parameters = new HashMap<>();
1✔
263

264
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
1✔
265
        parameters.put("skipRemap", QueryUtil.generateCommaSeparatedList(skipRemap));
1✔
266
        parameters.put("exclude", QueryUtil.generateCommaSeparatedList(excludes));
1✔
267

268
        path += QueryUtil.generateUrl(null, parameters);
1✔
269

270
        return this.createResource(path, Workspace.class, containerDestination);
1✔
271
    }
272

273
    /**
274
     * Return the WorkspaceFolderResources object that provides access to Folder resources associated with Workspace
275
     * resources.
276
     *
277
     * @return the workspace folder resources
278
     */
279
    public WorkspaceFolderResources folderResources() {
UNCOV
280
        return this.folders;
×
281
    }
282

283
    /**
284
     * Return the ShareResources object that provides access to Share resources associated with Workspace resources.
285
     *
286
     * @return the share resources
287
     */
288
    public ShareResources shareResources() {
UNCOV
289
        return this.shares;
×
290
    }
291

292
    /**
293
     * Get metadata of a workspace.
294
     * <p>
295
     * It mirrors to the following Smartsheet REST API method: GET /workspaces/{workspaceId}/metadata
296
     * <p>
297
     * Exceptions:
298
     * - InvalidRequestException : if there is any problem with the REST API request
299
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
300
     * - ResourceNotFoundException : if the resource can not be found
301
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
302
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
303
     * - SmartsheetException : if there is any other error occurred during the operation
304
     *
305
     * @param workspaceId the workspace id
306
     * @param includes    used to specify the optional objects to include
307
     * @return the workspace metadata (note that if there is no such resource, this method will throw ResourceNotFoundException
308
     * rather than returning null).
309
     * @throws SmartsheetException the smartsheet exception
310
     */
311
    @Override
312
    public Workspace getWorkspaceMetadata(long workspaceId,
313
                                          EnumSet<GetWorkspaceMetadataInclusion> includes) throws SmartsheetException {
UNCOV
314
        String path = WORKSPACES + "/" + workspaceId + "/metadata";
×
315

316
        // Add the parameters to a map and build the query string at the end
UNCOV
317
        Map<String, Object> parameters = new HashMap<>();
×
UNCOV
318
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
UNCOV
319
        path += QueryUtil.generateUrl(null, parameters);
×
320

UNCOV
321
        return this.getResource(path, Workspace.class);
×
322
    }
323

324
    /**
325
     * Get children of a workspace.
326
     * <p>
327
     * It mirrors to the following Smartsheet REST API method: GET /workspaces/{workspaceId}/children
328
     * <p>
329
     * Exceptions:
330
     * - InvalidRequestException : if there is any problem with the REST API request
331
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
332
     * - ResourceNotFoundException : if the resource can not be found
333
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
334
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
335
     * - SmartsheetException : if there is any other error occurred during the operation
336
     *
337
     * @param workspaceId           the workspace id
338
     * @param childrenResourceTypes the resource types to filter by (optional)
339
     * @param includes              used to specify the optional objects to include
340
     * @param lastKey               the last key for pagination (optional)
341
     * @param maxItems              the maximum number of items to return (optional)
342
     * @return the paginated children response
343
     * @throws SmartsheetException the smartsheet exception
344
     */
345
    @Override
346
    public TokenPaginatedResult<Object> getWorkspaceChildren(long workspaceId, EnumSet<ChildrenResourceType> childrenResourceTypes,
347
                                                          EnumSet<GetWorkspaceChildrenInclusion> includes,
348
                                                          String lastKey, Integer maxItems) throws SmartsheetException {
UNCOV
349
        String path = WORKSPACES + "/" + workspaceId + "/children";
×
350

351
        // Add the parameters to a map and build the query string at the end
UNCOV
352
        Map<String, Object> parameters = new HashMap<>();
×
UNCOV
353
        if (childrenResourceTypes != null && !childrenResourceTypes.isEmpty()) {
×
UNCOV
354
            parameters.put("childrenResourceTypes", QueryUtil.generateCommaSeparatedList(childrenResourceTypes));
×
355
        }
UNCOV
356
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
UNCOV
357
        if (lastKey != null) {
×
UNCOV
358
            parameters.put("lastKey", lastKey);
×
359
        }
UNCOV
360
        if (maxItems != null) {
×
UNCOV
361
            parameters.put("maxItems", maxItems);
×
362
        }
UNCOV
363
        path += QueryUtil.generateUrl(null, parameters);
×
364

UNCOV
365
        return this.listResourcesWithTokenPagination(path, new ChildrenResourceDeserializer());
×
366
    }
367
}
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