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

smartsheet / smartsheet-java-sdk / #44

25 Aug 2023 05:39PM UTC coverage: 50.55% (+0.1%) from 50.427%
#44

push

github-actions

web-flow
Fix remaining Checkstyle violations and Enable Checkstyle (#58)

* Fix remaining Checkstyle violations and Enable Checkstyle

We are now down to `20` checkstyle violations in main and `0` violations in test.

The remaining 20 violations are not trivial to fix, so I've set checkstyle to allow those 20 violations to exist, but to fail the build if we ever exceed 20 violations. This should make the build fail if any new violations are added.

For tests, we do not allow _any_ violations. This means adding a single violation will fail the build. Once the 20 violations in main are cleaned up, we can make main and test have the same config.

Note: This MR also changes our PR pipeline to run `./gradlew clean build` instead of `./gradlew clean test`. The reason for this is that build runs all the tests and performs all the other checks (such as checkstyle), whereas `test` didn't run checkstyle and we wouldn't have noticed violations until we tried to deploy.

148 of 148 new or added lines in 24 files covered. (100.0%)

3448 of 6821 relevant lines covered (50.55%)

0.51 hits per line

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

62.86
/src/main/java/com/smartsheet/api/SmartsheetBuilder.java
1
package com.smartsheet.api;
2

3
/*
4
 * #[license]
5
 * Smartsheet SDK for Java
6
 * %%
7
 * Copyright (C) 2023 Smartsheet
8
 * %%
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *      http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 * %[license]
21
 */
22

23
import com.smartsheet.api.internal.SmartsheetImpl;
24
import com.smartsheet.api.internal.http.HttpClient;
25
import com.smartsheet.api.internal.json.JsonSerializer;
26

27
/**
28
 * <p>A convenience class to help create a {@link Smartsheet} instance with the appropriate fields.</p>
29
 *
30
 * <p>Thread Safety: This class is not thread safe since it's mutable, one builder instance is NOT expected to be used in
31
 * multiple threads.</p>
32
 */
33
public class SmartsheetBuilder {
34
    /**
35
     * <p>Represents the HttpClient.</p>
36
     *
37
     * <p>It can be set using corresponding setter.</p>
38
     */
39
    private HttpClient httpClient;
40

41
    /**
42
     * <p>Represents the JsonSerializer.</p>
43
     *
44
     * <p>It can be set using corresponding setter.</p>
45
     */
46
    private JsonSerializer jsonSerializer;
47

48
    /**
49
     * <p>Represents the base URI.</p>
50
     *
51
     * <p>It can be set using corresponding setter.</p>
52
     */
53
    private String baseURI;
54

55
    /**
56
     * <p>Represents the access token.</p>
57
     *
58
     * <p>It can be set using corresponding setter.</p>
59
     */
60
    private String accessToken;
61

62
    /**
63
     * <p>Represents the maximum retry time allowed for failed API calls.</p>
64
     *
65
     * <p>It can be set using corresponding setter.</p>
66
     */
67
    private Long maxRetryTimeMillis;
68

69
    /**
70
     * <p>Represents the assumed user.</p>
71
     *
72
     * <p>It can be set using corresponding setter.</p>
73
     */
74
    private String assumedUser;
75

76
    /**
77
     * <p>Represents the change agent.</p>
78
     *
79
     * <p>It can be set using corresponding setter.</p>
80
     */
81
    private String changeAgent;
82

83
    /**
84
     * <p>Represents the default base URI of the Smartsheet REST API.</p>
85
     *
86
     * <p>It is a constant with value "https://api.smartsheet.com/2.0".</p>
87
     */
88
    public static final String DEFAULT_BASE_URI = "https://api.smartsheet.com/2.0/";
89

90
    /**
91
     * <p>Represents the default base URI of the Smartsheetgov REST API.</p>
92
     *
93
     * <p>It is a constant with value "https://api.smartsheetgov.com/2.0".</p>
94
     */
95
    public static final String GOV_BASE_URI = "https://api.smartsheetgov.com/2.0/";
96

97
    /**
98
     * Constructor.
99
     */
100
    public SmartsheetBuilder() {
1✔
101
    }
1✔
102

103
    /**
104
     * <p>Set the HttpClient.</p>
105
     *
106
     * @param httpClient the http client
107
     * @return the smartsheet builder
108
     */
109
    public SmartsheetBuilder setHttpClient(HttpClient httpClient) {
110
        this.httpClient = httpClient;
1✔
111
        return this;
1✔
112
    }
113

114
    /**
115
     * <p>Set the JsonSerializer.</p>
116
     *
117
     * @param jsonSerializer the JsonSerializer
118
     * @return the SmartsheetBuilder
119
     */
120
    public SmartsheetBuilder setJsonSerializer(JsonSerializer jsonSerializer) {
121
        this.jsonSerializer = jsonSerializer;
1✔
122
        return this;
1✔
123
    }
124

125
    /**
126
     * <p>Set the base URI.</p>
127
     *
128
     * @param baseURI the base uri
129
     * @return the smartsheet builder
130
     */
131
    public SmartsheetBuilder setBaseURI(String baseURI) {
132
        this.baseURI = baseURI;
1✔
133
        return this;
1✔
134
    }
135

136
    /**
137
     * <p>Set the access token.</p>
138
     *
139
     * @param accessToken the access token
140
     * @return the smartsheet builder
141
     */
142
    public SmartsheetBuilder setAccessToken(String accessToken) {
143
        this.accessToken = accessToken;
1✔
144
        return this;
1✔
145
    }
146

147
    /**
148
     * <p>Store a user provided userCalcBackoff.</p>
149
     *
150
     * <p>This interface is only valid when the DefaultHttpClient is used.</p>
151
     *
152
     * @return the smartsheet builder
153
     */
154
    public SmartsheetBuilder setMaxRetryTimeMillis(long maxRetryTimeMillis) {
155
        this.maxRetryTimeMillis = maxRetryTimeMillis;
×
156
        return this;
×
157
    }
158

159
    /**
160
     * <p>Set the assumed user.</p>
161
     *
162
     * @param assumedUser the assumed user
163
     * @return the smartsheet builder
164
     */
165
    public SmartsheetBuilder setAssumedUser(String assumedUser) {
166
        this.assumedUser = assumedUser;
1✔
167
        return this;
1✔
168
    }
169

170
    /**
171
     * <p>Set the assumed user.</p>
172
     *
173
     * @param changeAgent the identifier to include in the webhooks that result from the changes
174
     *                    made using the API
175
     *
176
     * @return the smartsheet builder
177
     */
178
    public SmartsheetBuilder setChangeAgent(String changeAgent) {
179
        this.changeAgent = changeAgent;
×
180
        return this;
×
181
    }
182

183
    /**
184
     * <p>Gets the http client.</p>
185
     *
186
     * @return the http client
187
     */
188
    public HttpClient getHttpClient() {
189
        return httpClient;
×
190
    }
191

192
    /**
193
     * <p>Gets the json serializer.</p>
194
     *
195
     * @return the json serializer
196
     */
197
    public JsonSerializer getJsonSerializer() {
198
        return jsonSerializer;
×
199
    }
200

201
    /**
202
     * <p>Gets the base uri.</p>
203
     *
204
     * @return the base uri
205
     */
206
    public String getBaseURI() {
207
        return baseURI;
×
208
    }
209

210
    /**
211
     * <p>Gets the access token.</p>
212
     *
213
     * @return the access token
214
     */
215
    public String getAccessToken() {
216
        return accessToken;
×
217
    }
218

219
    /**
220
     * <p>Gets the assumed user.</p>
221
     *
222
     * @return the assumed user
223
     */
224
    public String getAssumedUser() {
225
        return assumedUser;
×
226
    }
227

228
    /**
229
     * <p>Gets the default base uri.</p>
230
     *
231
     * @return the default base uri
232
     */
233
    public static String getDefaultBaseUri() {
234
        return DEFAULT_BASE_URI;
×
235
    }
236

237
    /**
238
     * <p>Gets the Smartsheet Change-Agent</p>
239
     *
240
     * @return the change agent
241
     */
242
    public String getChangeAgent() {
243
        return changeAgent;
×
244
    }
245

246
    /**
247
     * <p>Build the Smartsheet instance.</p>
248
     *
249
     * @return the Smartsheet instance
250
     * @throws IllegalStateException if accessToken isn't set yet.
251
     */
252
    public Smartsheet build() {
253
        if (baseURI == null) {
1✔
254
            baseURI = DEFAULT_BASE_URI;
1✔
255
        }
256

257
        if (accessToken == null) {
1✔
258
            accessToken = System.getenv("SMARTSHEET_ACCESS_TOKEN");
1✔
259
        }
260

261
        SmartsheetImpl smartsheet = new SmartsheetImpl(baseURI, accessToken, httpClient, jsonSerializer);
1✔
262

263
        if (changeAgent != null) {
1✔
264
            smartsheet.setChangeAgent(changeAgent);
×
265
        }
266
        if (assumedUser != null) {
1✔
267
            smartsheet.setAssumedUser(assumedUser);
1✔
268
        }
269
        if (maxRetryTimeMillis != null) {
1✔
270
            smartsheet.setMaxRetryTimeMillis(maxRetryTimeMillis);
×
271
        }
272

273
        return smartsheet;
1✔
274
    }
275
}
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