• 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

0.0
/src/main/java/com/smartsheet/api/oauth/OAuthFlowBuilder.java
1
package com.smartsheet.api.oauth;
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.http.DefaultHttpClient;
24
import com.smartsheet.api.internal.http.HttpClient;
25
import com.smartsheet.api.internal.json.JacksonJsonSerializer;
26
import com.smartsheet.api.internal.json.JsonSerializer;
27
import com.smartsheet.api.internal.oauth.OAuthFlowImpl;
28
import com.smartsheet.api.internal.util.Util;
29

30
/**
31
 * <p>This is the builder that is used to build {@link OAuthFlow} instances.</p>
32
 *
33
 * <p>Thread Safety: This class is not thread safe since it's mutable, one builder instance is NOT expected to be used in
34
 * multiple threads.</p>
35
 */
36
public class OAuthFlowBuilder {
37
    /**
38
     * <p>Represents the default OAuth authorization URL</p>
39
     *
40
     * <p>It is a constant with value "https://www.smartsheet.com/b/authorize".</p>
41
     */
42
    public static final String DEFAULT_AUTHORIZATION_URL = "https://www.smartsheet.com/b/authorize";
43

44
    /**
45
     * <p>Represents the default token URL</p>
46
     *
47
     * <p>It is a constant with value "https://api.smartsheet.com/1.1/token".</p>
48
     */
49
    public static final String DEFAULT_TOKEN_URL = "https://api.smartsheet.com/2.0/token";
50

51
    /**
52
     * <p>Represents the HttpClient.</p>
53
     *
54
     * <p>It can be set using corresponding setter.</p>
55
     */
56
    private HttpClient httpClient;
57

58
    /**
59
     * <p>Represents the JsonSerializer.</p>
60
     *
61
     * <p>It can be set using corresponding setter.</p>
62
     */
63
    private JsonSerializer jsonSerializer;
64

65
    /**
66
     * <p>Represents the client ID.</p>
67
     *
68
     * <p>It can be set using corresponding setter.</p>
69
     */
70
    private String clientId;
71

72
    /**
73
     * <p>Represents the client secret.</p>
74
     *
75
     * <p>It can be set using corresponding setter.</p>
76
     */
77
    private String clientSecret;
78

79
    /**
80
     * <p>Represents the redirect URL.</p>
81
     *
82
     * <p>It can be set using corresponding setter.</p>
83
     */
84
    private String redirectURL;
85

86
    /**
87
     * <p>Represents the authorization URL.</p>
88
     *
89
     * <p>It can be set using corresponding setter.</p>
90
     */
91
    private String authorizationURL;
92

93
    /**
94
     * <p>Represents the token URL.</p>
95
     *
96
     * <p>It can be set using corresponding setter.</p>
97
     */
98
    private String tokenURL;
99

100
    /**
101
     * Constructor.
102
     */
103
    public OAuthFlowBuilder() {
×
104
    }
×
105

106
    /**
107
     * Set the HttpClient.
108
     *
109
     * @param httpClient the httpClient
110
     * @return the OAuthFlowBuilder
111
     */
112
    public OAuthFlowBuilder setHttpClient(HttpClient httpClient) {
113
        Util.throwIfNull(httpClient);
×
114

115
        this.httpClient = httpClient;
×
116
        return this;
×
117
    }
118

119
    /**
120
     * <p>Set the JsonSerializer.</p>
121
     *
122
     * @param jsonSerializer the JsonSerializer
123
     * @return the oAuthFlowBuilder
124
     * @throws IllegalArgumentException if any argument is null/empty string
125
     */
126
    public OAuthFlowBuilder setJsonSerializer(JsonSerializer jsonSerializer) {
127
        Util.throwIfNull(jsonSerializer);
×
128

129
        this.jsonSerializer = jsonSerializer;
×
130
        return this;
×
131
    }
132

133
    /**
134
     * Set the client ID
135
     *
136
     * @param clientId the value to set
137
     * @return the OAuthFlowBuilder
138
     * @throws IllegalArgumentException if any argument is null/empty string
139
     */
140
    public OAuthFlowBuilder setClientId(String clientId) {
141
        Util.throwIfNull(clientId);
×
142

143
        this.clientId = clientId;
×
144
        return this;
×
145
    }
146

147
    /**
148
     * Set the client secret.
149
     *
150
     * @param clientSecret the client secret
151
     * @return the OAuthFlowBuilder
152
     * @throws IllegalArgumentException if any argument is null/empty string
153
     */
154
    public OAuthFlowBuilder setClientSecret(String clientSecret) {
155
        Util.throwIfNull(clientSecret);
×
156

157
        this.clientSecret = clientSecret;
×
158
        return this;
×
159
    }
160

161
    /**
162
     * Set the redirect URL
163
     *
164
     * @param redirectURL the redirect url
165
     * @return the OAuthFlowBuilder
166
     * @throws IllegalArgumentException if any argument is null/empty string
167
     */
168
    public OAuthFlowBuilder setRedirectURL(String redirectURL) {
169
        Util.throwIfNull(redirectURL);
×
170

171
        this.redirectURL = redirectURL;
×
172
        return this;
×
173
    }
174

175
    /**
176
     * Set the authorization URL.
177
     *
178
     * @param authorizationURL the authorization URL
179
     * @return the OAuthFlowBuilder
180
     * @throws IllegalArgumentException if any argument is null/empty string
181
     */
182
    public OAuthFlowBuilder setAuthorizationURL(String authorizationURL) {
183
        Util.throwIfNull(authorizationURL);
×
184

185
        this.authorizationURL = authorizationURL;
×
186
        return this;
×
187
    }
188

189
    /**
190
     * Set the token URL.
191
     *
192
     * @param tokenURL the token url
193
     * @return the OAuthFlowBuilder
194
     * @throws IllegalArgumentException if any argument is null/empty string
195
     */
196
    public OAuthFlowBuilder setTokenURL(String tokenURL) {
197
        Util.throwIfNull(tokenURL);
×
198

199
        this.tokenURL = tokenURL;
×
200
        return this;
×
201
    }
202

203
    /**
204
     * Gets the default authorization url.
205
     *
206
     * @return the default authorization url
207
     */
208
    public static String getDefaultAuthorizationUrl() {
209
        return DEFAULT_AUTHORIZATION_URL;
×
210
    }
211

212
    /**
213
     * Gets the default token url.
214
     *
215
     * @return the default token url
216
     */
217
    public static String getDefaultTokenUrl() {
218
        return DEFAULT_TOKEN_URL;
×
219
    }
220

221
    /**
222
     * Gets the http client.
223
     *
224
     * @return the http client
225
     */
226
    public HttpClient getHttpClient() {
227
        return httpClient;
×
228
    }
229

230
    /**
231
     * Gets the json serializer.
232
     *
233
     * @return the json serializer
234
     */
235
    public JsonSerializer getJsonSerializer() {
236
        return jsonSerializer;
×
237
    }
238

239
    /**
240
     * Gets the client id.
241
     *
242
     * @return the client id
243
     */
244
    public String getClientId() {
245
        return clientId;
×
246
    }
247

248
    /**
249
     * Gets the client secret.
250
     *
251
     * @return the client secret
252
     */
253
    public String getClientSecret() {
254
        return clientSecret;
×
255
    }
256

257
    /**
258
     * Gets the redirect url.
259
     *
260
     * @return the redirect url
261
     */
262
    public String getRedirectURL() {
263
        return redirectURL;
×
264
    }
265

266
    /**
267
     * Gets the authorization url.
268
     *
269
     * @return the authorization url
270
     */
271
    public String getAuthorizationURL() {
272
        return authorizationURL;
×
273
    }
274

275
    /**
276
     * Gets the token url.
277
     *
278
     * @return the token url
279
     */
280
    public String getTokenURL() {
281
        return tokenURL;
×
282
    }
283

284
    /**
285
     * Build the OAuthFlow instance.
286
     *
287
     * @return the OAuthFlow instance
288
     * @throws IllegalArgumentException if clientId, clientSecret or redirectURL isn't set yet.
289
     */
290
    public OAuthFlow build() {
291
        if (httpClient == null) {
×
292
            httpClient = new DefaultHttpClient();
×
293
        }
294

295
        if (tokenURL == null) {
×
296
            tokenURL = DEFAULT_TOKEN_URL;
×
297
        }
298

299
        if (authorizationURL == null) {
×
300
            authorizationURL = DEFAULT_AUTHORIZATION_URL;
×
301
        }
302

303
        if (jsonSerializer == null) {
×
304
            jsonSerializer = new JacksonJsonSerializer();
×
305
        }
306

307
        if (clientId == null || clientSecret == null || redirectURL == null) {
×
308
            throw new IllegalStateException();
×
309
        }
310

311
        return new OAuthFlowImpl(clientId, clientSecret, redirectURL, authorizationURL, tokenURL, httpClient,
×
312
                jsonSerializer);
313
    }
314
}
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