• 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

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
import com.smartsheet.api.models.enums.ShareScope;
32

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

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

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

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

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

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

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

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

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

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

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

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

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

216
    /**
217
     * Delete a share.
218
     * <p>
219
     * It mirrors to the following Smartsheet REST API method:
220
     * DELETE /shares/{shareId}?assetId={assetId}&amp;assetType={assetType}
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 shareId the ID of the share to delete
231
     * @param assetId the ID of the asset
232
     * @param assetType the type of the asset (e.g. "sheet", "workspace", "report", "sight", "file", "collection")
233
     * @throws SmartsheetException the smartsheet exception
234
     */
235
    @Override
236
    public void deleteShare(String shareId, String assetId, String assetType) throws SmartsheetException {
237
        String path = SHARES_PATH + "/" + shareId;
1✔
238
        Map<String, Object> queryParameters = new HashMap<>();
1✔
239
        queryParameters.put(ASSET_ID_PARAM, assetId);
1✔
240
        queryParameters.put(ASSET_TYPE_PARAM, assetType);
1✔
241
        path += QueryUtil.generateUrl(null, queryParameters);
1✔
242
        this.deleteResource(path, ShareResponse.class);
1✔
243
    }
1✔
244
}
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