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

smartsheet / smartsheet-java-sdk / #55

02 Oct 2024 07:40PM UTC coverage: 60.548% (+0.7%) from 59.836%
#55

push

github

web-flow
Release prep for 3.2.1 (#103)

4156 of 6864 relevant lines covered (60.55%)

0.61 hits per line

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

90.0
/src/main/java/com/smartsheet/api/internal/SightResourcesImpl.java
1
/*
2
 * Copyright (C) 2024 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.AuthorizationException;
20
import com.smartsheet.api.InvalidRequestException;
21
import com.smartsheet.api.ResourceNotFoundException;
22
import com.smartsheet.api.ServiceUnavailableException;
23
import com.smartsheet.api.ShareResources;
24
import com.smartsheet.api.SightResources;
25
import com.smartsheet.api.SmartsheetException;
26
import com.smartsheet.api.internal.util.QueryUtil;
27
import com.smartsheet.api.internal.util.Util;
28
import com.smartsheet.api.models.ContainerDestination;
29
import com.smartsheet.api.models.PagedResult;
30
import com.smartsheet.api.models.PaginationParameters;
31
import com.smartsheet.api.models.Sight;
32
import com.smartsheet.api.models.SightPublish;
33
import com.smartsheet.api.models.enums.SightInclusion;
34

35
import java.text.SimpleDateFormat;
36
import java.util.Date;
37
import java.util.EnumSet;
38
import java.util.HashMap;
39
import java.util.Map;
40

41
public class SightResourcesImpl extends AbstractResources implements SightResources {
42

43
    private ShareResources shares;
44

45
    private static final String SIGHTS = "sights";
46

47
    /**
48
     * Constructor.
49
     * <p>
50
     * Exceptions: - IllegalArgumentException : if any argument is null
51
     *
52
     * @param smartsheet the smartsheet
53
     */
54
    public SightResourcesImpl(SmartsheetImpl smartsheet) {
55
        super(smartsheet);
1✔
56
        this.shares = new ShareResourcesImpl(smartsheet, SIGHTS);
1✔
57
    }
1✔
58

59
    /**
60
     * Gets the list of all Sights where the User has access.
61
     * <p>
62
     * It mirrors to the following Smartsheet REST API method: GET /sights
63
     *
64
     * @return IndexResult object containing an array of Sight objects limited to the following attributes:
65
     * id, name, accessLevel, permalink, createdAt, modifiedAt.
66
     * @throws IllegalArgumentException    if any argument is null or empty string
67
     * @throws InvalidRequestException     if there is any problem with the REST API request
68
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
69
     * @throws ResourceNotFoundException   if the resource cannot be found
70
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
71
     * @throws SmartsheetException         if there is any other error during the operation
72
     */
73
    public PagedResult<Sight> listSights(PaginationParameters paging, Date modifiedSince) throws SmartsheetException {
74
        String path = SIGHTS;
1✔
75

76
        Map<String, Object> parameters = new HashMap<>();
1✔
77
        if (paging != null) {
1✔
78
            parameters = paging.toHashMap();
1✔
79
        }
80
        if (modifiedSince != null) {
1✔
81
            String isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(modifiedSince);
×
82
            parameters.put("modifiedSince", isoDate);
×
83
        }
84
        path += QueryUtil.generateUrl(null, parameters);
1✔
85
        return this.listResourcesWithWrapper(path, Sight.class);
1✔
86
    }
87

88
    /**
89
     * Get a specified Sight.
90
     * <p>
91
     * It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}
92
     *
93
     * @param sightId the id of the Sight
94
     * @return the Sight resource.
95
     * @throws IllegalArgumentException    if any argument is null or empty string
96
     * @throws InvalidRequestException     if there is any problem with the REST API request
97
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
98
     * @throws ResourceNotFoundException   if the resource cannot be found
99
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
100
     * @throws SmartsheetException         if there is any other error during the operation
101
     */
102
    public Sight getSight(long sightId) throws SmartsheetException {
103
        return this.getSight(sightId, null, null);
1✔
104
    }
105

106
    /**
107
     * Get a specified Sight.
108
     * <p>
109
     * It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}
110
     *
111
     * @param sightId the id of the Sight
112
     * @param level   compatibility level
113
     * @return the Sight resource.
114
     * @throws IllegalArgumentException    if any argument is null or empty string
115
     * @throws InvalidRequestException     if there is any problem with the REST API request
116
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
117
     * @throws ResourceNotFoundException   if the resource cannot be found
118
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
119
     * @throws SmartsheetException         if there is any other error during the operation
120
     */
121
    public Sight getSight(long sightId, Integer level) throws SmartsheetException {
122
        return this.getSight(sightId, null, level);
1✔
123
    }
124

125
    /**
126
     * Get a specified Sight.
127
     * <p>
128
     * It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}
129
     *
130
     * @param sightId  the id of the Sight
131
     * @param level    compatibility level
132
     * @param includes optional parameters to include
133
     * @return the Sight resource.
134
     * @throws IllegalArgumentException    if any argument is null or empty string
135
     * @throws InvalidRequestException     if there is any problem with the REST API request
136
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
137
     * @throws ResourceNotFoundException   if the resource cannot be found
138
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
139
     * @throws SmartsheetException         if there is any other error during the operation
140
     */
141
    public Sight getSight(long sightId, EnumSet<SightInclusion> includes, Integer level) throws SmartsheetException {
142
        String path = SIGHTS + "/" + sightId;
1✔
143

144
        Map<String, Object> parameters = new HashMap<>();
1✔
145
        parameters.put("level", level);
1✔
146
        parameters.put("include", QueryUtil.generateCommaSeparatedList(includes));
1✔
147
        path += QueryUtil.generateUrl(null, parameters);
1✔
148

149
        return this.getResource(path, Sight.class);
1✔
150
    }
151

152
    /**
153
     * Update a specified Sight.
154
     * <p>
155
     * It mirrors to the following Smartsheet REST API method: PUT /sights/{sightId}
156
     *
157
     * @param sight - the Sight to update
158
     * @return the updated Sight resource.
159
     * @throws IllegalArgumentException    if any argument is null or empty string
160
     * @throws InvalidRequestException     if there is any problem with the REST API request
161
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
162
     * @throws ResourceNotFoundException   if the resource cannot be found
163
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
164
     * @throws SmartsheetException         if there is any other error during the operation
165
     */
166
    public Sight updateSight(Sight sight) throws SmartsheetException {
167
        Util.throwIfNull(sight);
1✔
168
        return this.updateResource(SIGHTS + "/" + sight.getId(), Sight.class, sight);
1✔
169
    }
170

171
    /**
172
     * Delete a specified Sight.
173
     * <p>
174
     * It mirrors to the following Smartsheet REST API method: DELETE /sights/{sightId}
175
     *
176
     * @param sightId the id of the Sight
177
     * @throws IllegalArgumentException    if any argument is null or empty string
178
     * @throws InvalidRequestException     if there is any problem with the REST API request
179
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
180
     * @throws ResourceNotFoundException   if the resource cannot be found
181
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
182
     * @throws SmartsheetException         if there is any other error during the operation
183
     */
184
    public void deleteSight(long sightId) throws SmartsheetException {
185
        this.deleteResource(SIGHTS + "/" + sightId, Sight.class);
1✔
186
    }
1✔
187

188
    /**
189
     * Creates s copy of the specified Sight.
190
     * <p>
191
     * It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/copy
192
     *
193
     * @param sightId     the id of the Sight
194
     * @param destination the destination to copy to
195
     * @return the newly created Sight resource.
196
     * @throws IllegalArgumentException    if any argument is null or empty string
197
     * @throws InvalidRequestException     if there is any problem with the REST API request
198
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
199
     * @throws ResourceNotFoundException   if the resource cannot be found
200
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
201
     * @throws SmartsheetException         if there is any other error during the operation
202
     */
203
    public Sight copySight(long sightId, ContainerDestination destination) throws SmartsheetException {
204
        return this.createResource(SIGHTS + "/" + sightId + "/copy", Sight.class, destination);
1✔
205
    }
206

207
    /**
208
     * Creates s copy of the specified Sight.
209
     * <p>
210
     * It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/move
211
     *
212
     * @param sightId     the id of the Sight
213
     * @param destination the destination to copy to
214
     * @return the newly created Sight resource.
215
     * @throws IllegalArgumentException    if any argument is null or empty string
216
     * @throws InvalidRequestException     if there is any problem with the REST API request
217
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
218
     * @throws ResourceNotFoundException   if the resource cannot be found
219
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
220
     * @throws SmartsheetException         if there is any other error during the operation
221
     */
222
    public Sight moveSight(long sightId, ContainerDestination destination) throws SmartsheetException {
223
        return this.createResource(SIGHTS + "/" + sightId + "/move", Sight.class, destination);
1✔
224
    }
225

226
    /**
227
     * Get the publish status of a Sight.
228
     * <p>
229
     * It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/publish
230
     *
231
     * @param sightId the id of the Sight
232
     * @return the Sight's publish status.
233
     * @throws IllegalArgumentException    if any argument is null or empty string
234
     * @throws InvalidRequestException     if there is any problem with the REST API request
235
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
236
     * @throws ResourceNotFoundException   if the resource cannot be found
237
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
238
     * @throws SmartsheetException         if there is any other error during the operation
239
     */
240
    public SightPublish getPublishStatus(long sightId) throws SmartsheetException {
241
        return this.getResource(SIGHTS + "/" + sightId + "/publish", SightPublish.class);
1✔
242
    }
243

244
    /**
245
     * Sets the publish status of a Sight and returns the new status, including the URLs of any enabled publishing.
246
     * <p>
247
     * It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/publish
248
     *
249
     * @param sightId      the id of the Sight
250
     * @param sightPublish the SightPublish object containing publish status
251
     * @return the Sight's publish status.
252
     * @throws IllegalArgumentException    if any argument is null or empty string
253
     * @throws InvalidRequestException     if there is any problem with the REST API request
254
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
255
     * @throws ResourceNotFoundException   if the resource cannot be found
256
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
257
     * @throws SmartsheetException         if there is any other error during the operation
258
     */
259
    public SightPublish setPublishStatus(long sightId, SightPublish sightPublish) throws SmartsheetException {
260
        Util.throwIfNull(sightPublish);
1✔
261
        return this.updateResource(SIGHTS + "/" + sightId + "/publish", SightPublish.class, sightPublish);
1✔
262
    }
263

264
    /**
265
     * Return the ShareResources object that provides access to share resources associated with
266
     * Sight resources.
267
     *
268
     * @return the associated share resources
269
     */
270
    public ShareResources shareResources() {
271
        return this.shares;
×
272
    }
273

274
}
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