Skip to content

Commit ac45bcd

Browse files
authored
Refactoring the code examples after adding linter to CI/CD (#118)
* added a linter run command to CI/CD * set failOnViolation property to true * refactoring the code to ensure the build runs smoothly * fixes after merge * fixed build failure * fixed build failure * removing extra catches * changed system.out.printLn to logger calls * renamed static final variable * fixing build issues * fix for linter * fixed build issue * fixes for codestyle --------- Signed-off-by: Anna Hileta <[email protected]>
1 parent 5b868f7 commit ac45bcd

File tree

164 files changed

+2003
-1733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+2003
-1733
lines changed

.github/workflows/maven.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
java-version: '11'
2020
distribution: 'temurin'
2121
cache: maven
22+
- name: Check code with linters
23+
run: mvn -U checkstyle:check
2224
- name: Download dependancies
2325
env:
2426
CLIENT_ID: ${{ secrets.CLIENT_ID }}

checkstyle.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@
22
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
33
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
44
<module name="Checker">
5-
<module name="JavadocPackage"/>
65
<module name="TreeWalker">
76
<!-- Code convention checking -->
87
<!-- One statement per line, one declaration per line -->
98
<module name="OneStatementPerLine">
109
<property name="treatTryResourcesAsStatement" value="true"/>
1110
</module>
1211

13-
<!-- If continuation lines are not indented automatically, indent them one tab stop -->
14-
<module name="JavadocTagContinuationIndentation">
15-
<property name="offset" value="2"/>
16-
<property name="violateExecutionOnNonTightHtml" value="true"/>
17-
</module>
18-
1912
<!-- Add at least one blank line between method definitions and property definitions -->
2013
<module name="EmptyLineSeparator">
2114
<property name="tokens" value="VARIABLE_DEF, METHOD_DEF"/>
@@ -32,9 +25,6 @@
3225
<!-- Avoid Redundant Initializations -->
3326
<module name="ExplicitInitialization"/>
3427

35-
<!-- Check using catch -->
36-
<module name="IllegalCatch"/>
37-
3828
<!-- Other checking -->
3929

4030
<!-- Loops need braces except they are a single line statement -->

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
<configuration>
229229
<configLocation>checkstyle.xml</configLocation>
230230
<violationSeverity>warning</violationSeverity>
231-
<failOnViolation>false</failOnViolation>
231+
<failOnViolation>true</failOnViolation>
232232
</configuration>
233233
</plugin>
234234
</plugins>

src/main/java/com/docusign/App.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
package com.docusign;
22

3-
import java.io.*;
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Import;
9+
10+
import java.awt.*;
11+
import java.io.FileOutputStream;
12+
import java.io.IOException;
13+
import java.io.InputStream;
414
import java.net.URI;
515
import java.net.URISyntaxException;
616
import java.net.URL;
@@ -10,17 +20,8 @@
1020
import java.nio.file.Path;
1121
import java.util.Collections;
1222

13-
import java.awt.Desktop;
14-
15-
import lombok.extern.slf4j.Slf4j;
16-
import org.springframework.boot.SpringApplication;
17-
import org.springframework.boot.autoconfigure.SpringBootApplication;
18-
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
19-
import org.springframework.context.annotation.ComponentScan;
20-
import org.springframework.context.annotation.Import;
21-
2223
@Slf4j
23-
@SpringBootApplication(exclude={JmxAutoConfiguration.class})
24+
@SpringBootApplication(exclude = {JmxAutoConfiguration.class})
2425
@ComponentScan(basePackages = "com.docusign")
2526
@Import(WebSecurityConfig.class)
2627

@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException, URISyntaxException {
3233
ClassLoader classLoader = App.class.getClassLoader();
3334
URL applicationJsonURL = classLoader.getResource("application.json");
3435

35-
if (applicationJsonURL != null){
36+
if (applicationJsonURL != null) {
3637
SpringApplication.run(App.class, args);
3738
openHomePage();
3839
} else {
@@ -46,16 +47,16 @@ public static void main(String[] args) throws IOException, URISyntaxException {
4647
while ((len = inputStream.read(buffer)) != -1) {
4748
out.write(buffer, 0, len);
4849
}
49-
} catch (Exception e) {
50-
System.out.println("File applicationJsonMissingError.html could not be accessed.");
50+
} catch (IOException e) {
51+
log.error("File applicationJsonMissingError.html could not be accessed.");
5152
}
5253

5354
Desktop.getDesktop().browse(path.toUri());
5455
}
5556

56-
System.out.println("");
57-
System.out.println("Please, add the application.json file to the resources folder.");
58-
System.out.println("");
57+
log.info("");
58+
log.info("Please, add the application.json file to the resources folder.");
59+
log.info("");
5960
}
6061
}
6162

@@ -64,15 +65,15 @@ private static void openHomePage() throws IOException {
6465
try {
6566
Desktop.getDesktop().browse(new URI("http://localhost:8080"));
6667
} catch (URISyntaxException use) {
67-
System.err.println("Invalid URI in App.openHomePage()");
68+
log.error("Invalid URI in App.openHomePage()");
6869
}
6970
}
7071

7172
private static void initFileSystem() {
7273
try {
7374
FileSystems.newFileSystem(new URI(""), Collections.emptyMap());
7475
log.info("FileSystem initialized successfully");
75-
} catch (Exception e) {
76+
} catch (FileSystemAlreadyExistsException | URISyntaxException | IOException e) {
7677
if (e instanceof FileSystemAlreadyExistsException) {
7778
log.info("FileSystem is already initialized");
7879
} else {

src/main/java/com/docusign/DSConfiguration.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import com.docusign.core.model.manifestModels.ManifestStructure;
66
import com.docusign.esign.client.auth.OAuth;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import jakarta.ws.rs.HttpMethod;
9+
import jakarta.ws.rs.core.HttpHeaders;
810
import lombok.Getter;
911
import lombok.Setter;
1012
import org.springframework.beans.factory.annotation.Value;
1113
import org.springframework.http.MediaType;
1214
import org.springframework.stereotype.Component;
1315

14-
import jakarta.ws.rs.HttpMethod;
15-
import jakarta.ws.rs.core.HttpHeaders;
1616
import java.io.BufferedReader;
1717
import java.io.InputStreamReader;
1818
import java.net.HttpURLConnection;
@@ -23,6 +23,10 @@
2323
@Setter
2424
public class DSConfiguration {
2525

26+
public Boolean isConsentRedirectActivated = false;
27+
28+
public String apiTypeHeader = "ApiType";
29+
2630
@Value("${com.docusign.github.example-uri}")
2731
private String exampleUrl;
2832

@@ -33,8 +37,6 @@ public class DSConfiguration {
3337

3438
private ManifestStructure codeExamplesText;
3539

36-
public Boolean isConsentRedirectActivated = false;
37-
3840
private boolean additionalRedirect;
3941

4042
private boolean shareAccessExampleScenario;
@@ -104,8 +106,6 @@ public class DSConfiguration {
104106
@Value("${CodeExamplesManifest}")
105107
private String codeExamplesManifest;
106108

107-
public String apiTypeHeader = "ApiType";
108-
109109
public String getDsReturnUrl() {
110110
return appUrl + "/ds-return";
111111
}
@@ -115,37 +115,37 @@ public String getDsPingUrl() {
115115
}
116116

117117
public String getBaseUrl(ApiIndex apiIndex, OAuth.Account oauthAccount) {
118-
if (apiIndex.equals(ApiIndex.ROOMS)) {
118+
if (ApiIndex.ROOMS.equals(apiIndex)) {
119119
return roomsBasePath;
120-
} else if (apiIndex.equals(ApiIndex.CLICK)) {
120+
} else if (ApiIndex.CLICK.equals(apiIndex)) {
121121
return clickBasePath;
122-
} else if (apiIndex.equals(ApiIndex.MONITOR)) {
122+
} else if (ApiIndex.MONITOR.equals(apiIndex)) {
123123
return monitorBasePath;
124-
} else if (apiIndex.equals(ApiIndex.ADMIN)) {
124+
} else if (ApiIndex.ADMIN.equals(apiIndex)) {
125125
return adminBasePath;
126126
}
127127

128128
return oauthAccount.getBaseUri();
129129
}
130130

131131
public ApiType getSelectedApiType() {
132-
if (selectedApiType == null){
132+
if (selectedApiType == null) {
133133
return ApiType.ESIGNATURE;
134134
}
135135

136136
return ApiType.valueOf(selectedApiType);
137137
}
138138

139139
public ApiIndex getSelectedApiIndex() {
140-
if (selectedApiType == null){
140+
if (selectedApiType == null) {
141141
return ApiIndex.ESIGNATURE;
142142
}
143143

144144
return ApiIndex.valueOf(selectedApiType);
145145
}
146146

147147
public ManifestStructure getCodeExamplesText() {
148-
if (codeExamplesText != null){
148+
if (codeExamplesText != null) {
149149
return codeExamplesText;
150150
}
151151

src/main/java/com/docusign/EG001ControllerEmbeddedSigning.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
import com.docusign.common.WorkArguments;
44
import com.docusign.controller.eSignature.examples.AbstractEsignatureController;
5+
import com.docusign.controller.eSignature.services.EmbeddedSigningService;
56
import com.docusign.core.common.Utils;
67
import com.docusign.core.model.Session;
78
import com.docusign.core.model.User;
8-
import com.docusign.esign.api.EnvelopesApi;
99
import com.docusign.esign.client.ApiClient;
1010
import com.docusign.esign.model.EnvelopeDefinition;
11-
import com.docusign.esign.model.EnvelopeSummary;
1211
import com.docusign.esign.model.RecipientViewRequest;
1312
import com.docusign.esign.model.ViewUrl;
14-
15-
import com.docusign.controller.eSignature.services.EmbeddedSigningService;
1613
import org.springframework.beans.factory.annotation.Autowired;
1714
import org.springframework.stereotype.Controller;
1815
import org.springframework.ui.ModelMap;
@@ -33,26 +30,30 @@
3330
public class EG001ControllerEmbeddedSigning extends AbstractEsignatureController {
3431

3532
private static final String DOCUMENT_FILE_NAME = "World_Wide_Corp_lorem.pdf";
33+
3634
private static final String DOCUMENT_NAME = "Lorem Ipsum";
35+
3736
private static final int ANCHOR_OFFSET_Y = 20;
37+
3838
private static final int ANCHOR_OFFSET_X = 10;
39+
3940
private static final String SIGNER_CLIENT_ID = "1000";
4041

4142
@Autowired
42-
public EG001ControllerEmbeddedSigning(DSConfiguration config, Session session, User user){
43+
public EG001ControllerEmbeddedSigning(DSConfiguration config, Session session, User user) {
4344
super(config, Boolean.valueOf(config.getQuickACG()) ? "quickEmbeddedSigning" : "eg001", session, user);
4445
}
4546

4647
@Override
4748
protected void onInitModel(WorkArguments args, ModelMap model) throws Exception {
48-
super.onInitModel(args, model);
49-
if(Utils.isCfr(session.getBasePath(), user.getAccessToken(), session.getAccountId())){
50-
session.setStatusCFR("enabled");
51-
throw new Exception(config.getCodeExamplesText().getSupportingTexts().getCFRError());
52-
}
53-
if(config.getQuickstart().equals("true")){
54-
config.setQuickstart("false");
55-
}
49+
super.onInitModel(args, model);
50+
if (Utils.isCfr(session.getBasePath(), user.getAccessToken(), session.getAccountId())) {
51+
session.setStatusCFR("enabled");
52+
throw new Exception(config.getCodeExamplesText().getSupportingTexts().getCFRError());
53+
}
54+
if (config.getQuickstart().equals("true")) {
55+
config.setQuickstart("false");
56+
}
5657
}
5758

5859
@Override

src/main/java/com/docusign/httpsconnectwebhookhmacvalidation.java renamed to src/main/java/com/docusign/HttpsConnectWebhookhMacValidation.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
package com.docusign;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import javax.crypto.Mac;
7+
import javax.crypto.spec.SecretKeySpec;
8+
import java.io.IOException;
39
import java.io.UnsupportedEncodingException;
10+
import java.nio.charset.StandardCharsets;
411
import java.nio.file.Files;
512
import java.nio.file.Paths;
613
import java.security.InvalidKeyException;
714
import java.security.MessageDigest;
815
import java.security.NoSuchAlgorithmException;
916
import java.util.Base64;
10-
import javax.crypto.Mac;
11-
import javax.crypto.spec.SecretKeySpec;
1217

13-
public class httpsconnectwebhookhmacvalidation {
18+
public class HttpsConnectWebhookhMacValidation {
19+
20+
private static final Logger LOGGER = LoggerFactory.getLogger(HttpsConnectWebhookhMacValidation.class);
21+
1422
/*
1523
* Useful reference:
1624
* https://docs.oracle.com/javase/10/docs/api/javax/crypto/Mac.html
@@ -29,28 +37,22 @@ private static String ComputeHash(String secret, byte[] payload)
2937
public static boolean HashIsValid(String secret, byte[] payload, String verify)
3038
throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
3139
String computedHash = ComputeHash(secret, payload);
32-
boolean isEqual = MessageDigest.isEqual(computedHash.getBytes("UTF-8"),
33-
verify.getBytes("UTF-8"));
40+
boolean isEqual = MessageDigest.isEqual(computedHash.getBytes(StandardCharsets.UTF_8),
41+
verify.getBytes(StandardCharsets.UTF_8));
3442
return isEqual;
3543
}
3644

3745
public static void main(String[] args) {
3846

39-
System.out.println("DocuSign HMAC Tester");
47+
LOGGER.info("DocuSign HMAC Tester");
4048
try {
41-
42-
Boolean response = httpsconnectwebhookhmacvalidation.HashIsValid("{DocuSign HMAC private key}",
49+
Boolean response = HttpsConnectWebhookhMacValidation.HashIsValid("{DocuSign HMAC private key}",
4350
Files.readAllBytes(Paths.get("payload.txt")), "{JSON response Signature}");
44-
System.out.printf("is this HMAC Valid? ");
45-
System.out.println(response);
46-
51+
LOGGER.info("is this HMAC Valid? ");
52+
LOGGER.info(String.valueOf(response));
4753
} catch (Exception e) {
48-
49-
System.out.print("Error!!! ");
50-
System.out.print(e.getMessage());
51-
54+
LOGGER.error("Error!!! ");
55+
LOGGER.error(e.getMessage());
5256
}
53-
5457
}
55-
5658
}

src/main/java/com/docusign/JsonPropertySourceLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class JsonPropertySourceLoader extends YamlPropertySourceLoader {
66
@Override
7-
public String[] getFileExtensions () {
7+
public String[] getFileExtensions() {
88
return new String[]{"json"};
99
}
1010
}

src/main/java/com/docusign/OSDetector.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/java/com/docusign/WebSecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4848
)
4949
.csrf().disable();
5050

51-
return http.build();
51+
return http.build();
5252
}
5353
}

0 commit comments

Comments
 (0)