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

smartsheet / smartsheet-java-sdk / #60

24 Oct 2025 09:43AM UTC coverage: 60.156% (+0.4%) from 59.737%
#60

push

github

web-flow
Add Wiremock integration tests and update dependencies (#145)

* Add Wiremock integration tests and update dependencies

* Update test method names

* Bump version to 3.9.0 and address comments for the wiremock integration tests

* Refactor Wiremock integration tests for user resources to improve query parameter handling and update endpoint paths

* Fix imports

* Fix checkstyle errors

* Move wiremock tests to sdktest

* Remove redundant Wiremock tests from UserResourcesIT

* Remove unused imports from UserResourcesIT

* Revert UserResourcesIT

* Fix changelog

* Add copyright to WiremockTest

* Update wiremock base uri port

* Rename WiremockTest to UserResourcesContractTests for clarity

* Change WireMock default port

4392 of 7301 relevant lines covered (60.16%)

0.6 hits per line

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

97.67
/src/main/java/com/smartsheet/api/internal/AssetShareResourcesImpl.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.AssetShareResources;
20
import com.smartsheet.api.AuthorizationException;
21
import com.smartsheet.api.InvalidRequestException;
22
import com.smartsheet.api.ResourceNotFoundException;
23
import com.smartsheet.api.ServiceUnavailableException;
24
import com.smartsheet.api.SmartsheetException;
25
import com.smartsheet.api.internal.util.QueryUtil;
26
import com.smartsheet.api.internal.util.Util;
27
import com.smartsheet.api.models.CreateShareRequest;
28
import com.smartsheet.api.models.ShareResponse;
29
import com.smartsheet.api.models.UpdateShareRequest;
30
import com.smartsheet.api.models.ListAssetSharesResponse;
31

32
import java.util.HashMap;
33
import java.util.List;
34
import java.util.Map;
35

36
/**
37
 * This is the implementation of the AssetShareResources.
38
 * <p>
39
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
40
 */
41
public class AssetShareResourcesImpl extends AbstractResources implements AssetShareResources {
42
    private static final String SHARES_PATH = "shares";
43
    private static final String ASSET_ID_PARAM = "assetId";
44
    private static final String ASSET_TYPE_PARAM = "assetType";
45

46
    /**
47
     * Constructor.
48
     *
49
     * @param smartsheet the smartsheet
50
     */
51
    public AssetShareResourcesImpl(SmartsheetImpl smartsheet) {
52
        super(smartsheet);
1✔
53
    }
1✔
54

55
    /**
56
     * List shares of a given asset.
57
     * <p>
58
     * It mirrors to the following Smartsheet REST API method:
59
     * GET /shares?assetId={assetId}&amp;assetType={assetType}
60
     * <p>
61
     * Exceptions:
62
     * InvalidRequestException : if there is any problem with the REST API request
63
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
64
     * ResourceNotFoundException : if the resource can not be found
65
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
66
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
67
     * SmartsheetException : if there is any other error occurred during the operation
68
     *
69
     * @param assetId the asset id
70
     * @param assetType the asset type (e.g. "sheet", "workspace", "report", "sight", "file", "collection")
71
     * @param lastKey lastKey from previous response to get next page of results
72
     * @param maxItems The maximum amount of items to return in the response. The default and minimum are 100.
73
     * @param sharingInclude defines the scope of the share. Possible values are ITEM or WORKSPACE.
74
     * @return the shares (note that empty list will be returned if there is none)
75
     * @throws SmartsheetException the smartsheet exception
76
     */
77
    @Override
78
    public ListAssetSharesResponse<ShareResponse> listShares(
79
            String assetId,
80
            String assetType,
81
            String lastKey,
82
            Long maxItems,
83
            String sharingInclude
84
    ) throws SmartsheetException {
85
        String path = SHARES_PATH;
1✔
86

87
        Map<String, Object> queryParameters = new HashMap<>();
1✔
88
        queryParameters.put(ASSET_ID_PARAM, assetId);
1✔
89
        queryParameters.put(ASSET_TYPE_PARAM, assetType);
1✔
90

91
        if (lastKey != null) {
1✔
92
            queryParameters.put("lastKey", lastKey);
×
93
        }
94

95
        if (maxItems != null) {
1✔
96
            queryParameters.put("maxItems", maxItems);
1✔
97
        }
98

99
        if (sharingInclude != null) {
1✔
100
            queryParameters.put("sharingInclude", sharingInclude);
1✔
101
        }
102

103
        path += QueryUtil.generateUrl(null, queryParameters);
1✔
104

105
        return this.listAssetSharesWithTokenPagination(path, ShareResponse.class);
1✔
106
    }
107

108
    /**
109
     * Get a Share.
110
     * <p>
111
     * It mirrors to the following Smartsheet REST API method:
112
     * GET /shares/{shareId}?assetId={assetId}&amp;assetType={assetType}
113
     * <p>
114
     * Exceptions:
115
     * InvalidRequestException : if there is any problem with the REST API request
116
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
117
     * ResourceNotFoundException : if the resource can not be found
118
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
119
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
120
     * SmartsheetException : if there is any other error occurred during the operation
121
     *
122
     * @param shareId the ID of the share
123
     * @param assetId the ID of the asset
124
     * @param assetType the type of the asset (e.g. "sheet", "workspace", "report", "sight", "file", "collection")
125
     * @return the share response (note that if there is no such resource, this method will throw ResourceNotFoundException
126
     * rather than returning null).
127
     * @throws SmartsheetException the smartsheet exception
128
     */
129
    @Override
130
    public ShareResponse getShare(String shareId, String assetId, String assetType) throws SmartsheetException {
131
        String path = SHARES_PATH + "/" + shareId;
1✔
132
        Map<String, Object> queryParameters = new HashMap<>();
1✔
133
        queryParameters.put(ASSET_ID_PARAM, assetId);
1✔
134
        queryParameters.put(ASSET_TYPE_PARAM, assetType);
1✔
135
        path += QueryUtil.generateUrl(null, queryParameters);
1✔
136
        return this.getResource(path, ShareResponse.class);
1✔
137
    }
138

139
    /**
140
     * Shares the asset with the specified Users and Groups.
141
     * <p>
142
     * It mirrors to the following Smartsheet REST API method:
143
     * POST /shares?assetId={assetId}&amp;assetType={assetType}
144
     * <p>
145
     * Exceptions:
146
     * IllegalArgumentException : if shareRequests is null
147
     * InvalidRequestException : if there is any problem with the REST API request
148
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
149
     * ResourceNotFoundException : if the resource can not be found
150
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
151
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
152
     * SmartsheetException : if there is any other error occurred during the operation
153
     *
154
     * @param assetId the ID of the asset to share
155
     * @param assetType the type of the asset (e.g. "sheet", "workspace", "report", "sight", "file", "collection")
156
     * @param shareRequests list of create share request objects
157
     * @param sendEmail whether to send email
158
     * @return the created shares
159
     * @throws SmartsheetException the smartsheet exception
160
     */
161
    @Override
162
    public List<ShareResponse> shareTo(
163
            String assetId,
164
            String assetType,
165
            List<CreateShareRequest> shareRequests,
166
            Boolean sendEmail
167
    ) throws SmartsheetException {
168
        Util.throwIfNull(shareRequests);
1✔
169
        String path = SHARES_PATH;
1✔
170
        Map<String, Object> queryParameters = new HashMap<>();
1✔
171
        queryParameters.put(ASSET_ID_PARAM, assetId);
1✔
172
        queryParameters.put(ASSET_TYPE_PARAM, assetType);
1✔
173
        if (sendEmail != null) {
1✔
174
            queryParameters.put("sendEmail", sendEmail);
1✔
175
        }
176
        path += QueryUtil.generateUrl(null, queryParameters);
1✔
177
        return this.postAndReceiveList(path, shareRequests, ShareResponse.class);
1✔
178
    }
179

180
    /**
181
     * Update a share.
182
     * <p>
183
     * It mirrors to the following Smartsheet REST API method:
184
     * PATCH /shares/{shareId}?assetId={assetId}&amp;assetType={assetType}
185
     *
186
     * @param shareId the ID of the share
187
     * @param assetId the ID of the asset
188
     * @param assetType the type of the asset (e.g. "sheet", "workspace", "report", "sight", "file", "collection")
189
     * @param shareRequest the update share request
190
     * @return the updated share (note that if there is no such resource, this method will throw
191
     * ResourceNotFoundException rather than returning null).
192
     * @throws IllegalArgumentException    if any argument is null or empty string
193
     * @throws InvalidRequestException     if there is any problem with the REST API request
194
     * @throws AuthorizationException      if there is any problem with the REST API authorization (access token)
195
     * @throws ResourceNotFoundException   if the resource cannot be found
196
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
197
     * @throws SmartsheetException         if there is any other error during the operation
198
     */
199
    @Override
200
    public ShareResponse updateShare(
201
            String shareId,
202
            String assetId,
203
            String assetType,
204
            UpdateShareRequest shareRequest
205
    ) throws SmartsheetException {
206
        Util.throwIfNull(shareRequest);
1✔
207
        String path = SHARES_PATH + "/" + shareId;
1✔
208
        Map<String, Object> queryParameters = new HashMap<>();
1✔
209
        queryParameters.put(ASSET_ID_PARAM, assetId);
1✔
210
        queryParameters.put(ASSET_TYPE_PARAM, assetType);
1✔
211
        path += QueryUtil.generateUrl(null, queryParameters);
1✔
212
        return this.patchResource(path, ShareResponse.class, shareRequest);
1✔
213
    }
214

215
    /**
216
     * Delete a share.
217
     * <p>
218
     * It mirrors to the following Smartsheet REST API method:
219
     * DELETE /shares/{shareId}?assetId={assetId}&amp;assetType={assetType}
220
     * <p>
221
     * Exceptions:
222
     * InvalidRequestException : if there is any problem with the REST API request
223
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
224
     * ResourceNotFoundException : if the resource can not be found
225
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
226
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
227
     * SmartsheetException : if there is any other error occurred during the operation
228
     *
229
     * @param shareId the ID of the share to delete
230
     * @param assetId the ID of the asset
231
     * @param assetType the type of the asset (e.g. "sheet", "workspace", "report", "sight", "file", "collection")
232
     * @throws SmartsheetException the smartsheet exception
233
     */
234
    @Override
235
    public void deleteShare(String shareId, String assetId, String assetType) throws SmartsheetException {
236
        String path = SHARES_PATH + "/" + shareId;
1✔
237
        Map<String, Object> queryParameters = new HashMap<>();
1✔
238
        queryParameters.put(ASSET_ID_PARAM, assetId);
1✔
239
        queryParameters.put(ASSET_TYPE_PARAM, assetType);
1✔
240
        path += QueryUtil.generateUrl(null, queryParameters);
1✔
241
        this.deleteResource(path, ShareResponse.class);
1✔
242
    }
1✔
243
}
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