• 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

52.78
/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.SmartsheetException;
20
import com.smartsheet.api.WorkspaceFolderResources;
21
import com.smartsheet.api.WorkspaceResources;
22
import com.smartsheet.api.internal.util.QueryUtil;
23
import com.smartsheet.api.models.ContainerDestination;
24
import com.smartsheet.api.models.Workspace;
25
import com.smartsheet.api.models.enums.CopyExclusion;
26
import com.smartsheet.api.models.enums.WorkspaceCopyInclusion;
27
import com.smartsheet.api.models.enums.WorkspaceRemapExclusion;
28
import com.smartsheet.api.models.enums.GetWorkspaceMetadataInclusion;
29
import com.smartsheet.api.models.enums.GetWorkspaceChildrenInclusion;
30
import com.smartsheet.api.models.enums.ChildrenResourceType;
31
import com.smartsheet.api.models.TokenPaginatedResult;
32
import com.smartsheet.api.models.TokenPaginationParameters;
33
import com.smartsheet.api.internal.json.ChildrenResourceDeserializer;
34

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

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

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

55
    /**
56
     * Constructor.
57
     * <p>
58
     * Exceptions:
59
     * - IllegalArgumentException : if any argument is
60
     *
61
     * @param smartsheet the smartsheet
62
     */
63
    public WorkspaceResourcesImpl(SmartsheetImpl smartsheet) {
64
        super(smartsheet);
1✔
65
        this.folders = new WorkspaceFolderResourcesImpl(smartsheet);
1✔
66
    }
1✔
67

68
    /**
69
     * List all workspaces.
70
     * <p>
71
     * It mirrors to the following Smartsheet REST API method: GET /workspaces
72
     * <p>
73
     * Exceptions:
74
     * - InvalidRequestException : if there is any problem with the REST API request
75
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
76
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
77
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
78
     * - SmartsheetException : if there is any other error occurred during the operation
79
     *
80
     * @param paging the object containing the token-based pagination parameters
81
     * @return TokenPaginatedResult of workspaces (empty list if there are none)
82
     * @throws SmartsheetException the smartsheet exception
83
     */
84
    public TokenPaginatedResult<Workspace> listWorkspaces(TokenPaginationParameters paging) throws SmartsheetException {
85
        String path = WORKSPACES;
1✔
86
        if (paging != null) {
1✔
87
            path += paging.toQueryString();
1✔
88
        }
89
        return this.listResourcesWithTokenPagination(path, Workspace.class);
1✔
90
    }
91

92
    /**
93
     * Create a workspace.
94
     * <p>
95
     * It mirrors to the following Smartsheet REST API method: POST /workspaces
96
     * <p>
97
     * Exceptions:
98
     * - IllegalArgumentException : if any argument 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
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
102
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
103
     * - SmartsheetException : if there is any other error occurred during the operation
104
     *
105
     * @param workspace the workspace to create, limited to the following required attributes: * name (string)
106
     * @return the created workspace
107
     * @throws SmartsheetException the smartsheet exception
108
     */
109
    public Workspace createWorkspace(Workspace workspace) throws SmartsheetException {
110
        return this.createResource(WORKSPACES, Workspace.class, workspace);
1✔
111
    }
112

113
    /**
114
     * Update a workspace.
115
     * <p>
116
     * It mirrors to the following Smartsheet REST API method: PUT /workspace/{id}
117
     * <p>
118
     * Exceptions:
119
     * - IllegalArgumentException : if any argument is null
120
     * - InvalidRequestException : if there is any problem with the REST API request
121
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
122
     * - ResourceNotFoundException : if the resource can not be found
123
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
124
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
125
     * - SmartsheetException : if there is any other error occurred during the operation
126
     *
127
     * @param workspace the workspace to update limited to the following attribute: * name (string)
128
     * @return the updated workspace (note that if there is no such resource, this method will throw
129
     * ResourceNotFoundException rather than returning null).
130
     * @throws SmartsheetException the smartsheet exception
131
     */
132
    public Workspace updateWorkspace(Workspace workspace) throws SmartsheetException {
133
        return this.updateResource(WORKSPACES + "/" + workspace.getId(), Workspace.class, workspace);
1✔
134
    }
135

136
    /**
137
     * Delete a workspace.
138
     * <p>
139
     * It mirrors to the following Smartsheet REST API method: DELETE /workspace{id}
140
     * <p>
141
     * Exceptions:
142
     * - InvalidRequestException : if there is any problem with the REST API request
143
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
144
     * - ResourceNotFoundException : if the resource can not be found
145
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
146
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
147
     * - SmartsheetException : if there is any other error occurred during the operation
148
     *
149
     * @param id the ID of the workspace
150
     * @throws SmartsheetException the smartsheet exception
151
     */
152
    public void deleteWorkspace(long id) throws SmartsheetException {
153
        this.deleteResource(WORKSPACES + "/" + id, Workspace.class);
1✔
154
    }
1✔
155

156
    /**
157
     * Creates a copy of the specified workspace.
158
     * <p>
159
     * It mirrors to the following Smartsheet REST API method: POST /workspaces/{workspaceId}/copy
160
     * <p>
161
     * Exceptions:
162
     * IllegalArgumentException : if folder is null
163
     * InvalidRequestException : if there is any problem with the REST API request
164
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
165
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
166
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
167
     * SmartsheetException : if there is any other error occurred during the operation
168
     *
169
     * @param workspaceId          the folder id
170
     * @param containerDestination describes the destination container
171
     * @param includes             optional parameters to include
172
     * @param skipRemap            optional parameters to exclude
173
     * @return the folder
174
     * @throws SmartsheetException the smartsheet exception
175
     */
176
    public Workspace copyWorkspace(
177
            long workspaceId,
178
            ContainerDestination containerDestination,
179
            EnumSet<WorkspaceCopyInclusion> includes,
180
            EnumSet<WorkspaceRemapExclusion> skipRemap
181
    ) throws SmartsheetException {
182
        return copyWorkspace(workspaceId, containerDestination, includes, skipRemap, null);
1✔
183
    }
184

185
    /**
186
     * Creates a copy of the specified workspace.
187
     * <p>
188
     * It mirrors to the following Smartsheet REST API method: POST /workspaces/{workspaceId}/copy
189
     * <p>
190
     * Exceptions:
191
     * IllegalArgumentException : if folder is null
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
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
195
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
196
     * SmartsheetException : if there is any other error occurred during the operation
197
     *
198
     * @param workspaceId          the folder id
199
     * @param containerDestination describes the destination container
200
     * @param includes             optional parameters to include
201
     * @param skipRemap            optional parameters to NOT re-map in the new folder
202
     * @param excludes             optional parameters to exclude     *
203
     * @return the folder
204
     * @throws SmartsheetException the smartsheet exception
205
     * @deprecated As of release 2.0. `excludes` param is deprecated. Please use the `copyWorkspace` method with `includes` instead.
206
     */
207
    @Deprecated(since = "2.0.0", forRemoval = true)
208
    public Workspace copyWorkspace(long workspaceId, ContainerDestination containerDestination, EnumSet<WorkspaceCopyInclusion> includes,
209
                                   EnumSet<WorkspaceRemapExclusion> skipRemap, EnumSet<CopyExclusion> excludes) throws SmartsheetException {
210

211
        String path = WORKSPACES + "/" + workspaceId + "/copy";
1✔
212
        Map<String, Object> parameters = new HashMap<>();
1✔
213

214
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
1✔
215
        parameters.put("skipRemap", QueryUtil.generateCommaSeparatedList(skipRemap));
1✔
216
        parameters.put("exclude", QueryUtil.generateCommaSeparatedList(excludes));
1✔
217

218
        path += QueryUtil.generateUrl(null, parameters);
1✔
219

220
        return this.createResource(path, Workspace.class, containerDestination);
1✔
221
    }
222

223
    /**
224
     * Return the WorkspaceFolderResources object that provides access to Folder resources associated with Workspace
225
     * resources.
226
     *
227
     * @return the workspace folder resources
228
     */
229
    public WorkspaceFolderResources folderResources() {
230
        return this.folders;
×
231
    }
232

233
    /**
234
     * Get metadata of a workspace.
235
     * <p>
236
     * It mirrors to the following Smartsheet REST API method: GET /workspaces/{workspaceId}/metadata
237
     * <p>
238
     * Exceptions:
239
     * - InvalidRequestException : if there is any problem with the REST API request
240
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
241
     * - ResourceNotFoundException : if the resource can not be found
242
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
243
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
244
     * - SmartsheetException : if there is any other error occurred during the operation
245
     *
246
     * @param workspaceId the workspace id
247
     * @param includes    used to specify the optional objects to include
248
     * @return the workspace metadata (note that if there is no such resource, this method will throw ResourceNotFoundException
249
     * rather than returning null).
250
     * @throws SmartsheetException the smartsheet exception
251
     */
252
    @Override
253
    public Workspace getWorkspaceMetadata(long workspaceId,
254
                                          EnumSet<GetWorkspaceMetadataInclusion> includes) throws SmartsheetException {
255
        String path = WORKSPACES + "/" + workspaceId + "/metadata";
×
256

257
        // Add the parameters to a map and build the query string at the end
258
        Map<String, Object> parameters = new HashMap<>();
×
259
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
260
        path += QueryUtil.generateUrl(null, parameters);
×
261

262
        return this.getResource(path, Workspace.class);
×
263
    }
264

265
    /**
266
     * Get children of a workspace.
267
     * <p>
268
     * It mirrors to the following Smartsheet REST API method: GET /workspaces/{workspaceId}/children
269
     * <p>
270
     * Exceptions:
271
     * - InvalidRequestException : if there is any problem with the REST API request
272
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
273
     * - ResourceNotFoundException : if the resource can not be found
274
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
275
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
276
     * - SmartsheetException : if there is any other error occurred during the operation
277
     *
278
     * @param workspaceId           the workspace id
279
     * @param childrenResourceTypes the resource types to filter by (optional)
280
     * @param includes              used to specify the optional objects to include
281
     * @param lastKey               the last key for pagination (optional)
282
     * @param maxItems              the maximum number of items to return (optional)
283
     * @return the paginated children response
284
     * @throws SmartsheetException the smartsheet exception
285
     */
286
    @Override
287
    public TokenPaginatedResult<Object> getWorkspaceChildren(long workspaceId, EnumSet<ChildrenResourceType> childrenResourceTypes,
288
                                                          EnumSet<GetWorkspaceChildrenInclusion> includes,
289
                                                          String lastKey, Integer maxItems) throws SmartsheetException {
290
        String path = WORKSPACES + "/" + workspaceId + "/children";
×
291

292
        // Add the parameters to a map and build the query string at the end
293
        Map<String, Object> parameters = new HashMap<>();
×
294
        if (childrenResourceTypes != null && !childrenResourceTypes.isEmpty()) {
×
295
            parameters.put("childrenResourceTypes", QueryUtil.generateCommaSeparatedList(childrenResourceTypes));
×
296
        }
297
        parameters.put(INCLUDE_PARAM, QueryUtil.generateCommaSeparatedList(includes));
×
298
        if (lastKey != null) {
×
299
            parameters.put("lastKey", lastKey);
×
300
        }
301
        if (maxItems != null) {
×
302
            parameters.put("maxItems", maxItems);
×
303
        }
304
        path += QueryUtil.generateUrl(null, parameters);
×
305

306
        return this.listResourcesWithTokenPagination(path, new ChildrenResourceDeserializer());
×
307
    }
308
}
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