Skip to content

Commit 5f9e0c9

Browse files
committed
Add checkstyle
1 parent 50d69f3 commit 5f9e0c9

23 files changed

+670
-38
lines changed

LICENSE_HEADER

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
* KIND, either express or implied. See the License for the
1616
* specific language governing permissions and limitations
1717
* under the License.
18-
*/
18+
*/

autobot/build.gradle

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ plugins {
1414
id 'org.springframework.boot' version "${springBootPluginVersion}"
1515
id 'com.gorylenko.gradle-git-properties' version "${gitPropertiesPluginVersion}"
1616
id "com.diffplug.spotless"
17+
id "checkstyle"
1718
}
1819

1920
import groovy.json.JsonOutput
@@ -31,6 +32,11 @@ configurations {
3132
intTestRuntime.extendsFrom intTestImplementation
3233
}
3334

35+
checkstyle {
36+
configFile project.file('config/checkstyle/checkstyle.xml')
37+
toolVersion checkstyleVersion
38+
}
39+
3440
repositories {
3541
mavenCentral()
3642
}
@@ -46,6 +52,7 @@ spotless {
4652
importOrder()
4753
licenseHeaderFile "${project.rootProject.projectDir}/LICENSE_HEADER"
4854
removeUnusedImports()
55+
trimTrailingWhitespace()
4956
}
5057
}
5158

autobot/config/checkstyle/checkstyle.xml

+363
Large diffs are not rendered by default.

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/Application.java

+6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@
2828
import org.springframework.boot.autoconfigure.SpringBootApplication;
2929
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
3030

31+
/** Main application class. */
3132
@SpringBootApplication
3233
public class Application {
3334

3435
private static final Logger log = LoggerFactory.getLogger(Application.class);
3536

37+
/**
38+
* Main execution method.
39+
*
40+
* @param args Application arguments.
41+
*/
3642
public static void main(final String[] args) {
3743
// Notice any uncaught exceptions at runtime.
3844
Thread.setDefaultUncaughtExceptionHandler(

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/config/ApplicationConfiguration.java

+69-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import twitter4j.TwitterFactory;
4444
import twitter4j.conf.ConfigurationBuilder;
4545

46+
/** Main Spring application configuration. */
4647
@Configuration
4748
@EnableAutoConfiguration
4849
@EnableScheduling
@@ -55,11 +56,23 @@
5556
})
5657
public class ApplicationConfiguration {
5758

59+
/**
60+
* Defines the {@link DateUtils} bean.
61+
*
62+
* @return The {@link DateUtils} bean.
63+
*/
5864
@Bean
5965
public DateUtils dateUtils() {
6066
return new DateUtils();
6167
}
6268

69+
/**
70+
* Overrides the {@link EnvironmentEndpoint} bean to ensure that various configuration
71+
* properties are obfuscated.
72+
*
73+
* @param environment The runtime environment.
74+
* @return The {@link EnvironmentEndpoint} with sanitized properties.
75+
*/
6376
@Bean
6477
public EnvironmentEndpoint environmentEndpoint(final Environment environment) {
6578
/*
@@ -82,36 +95,67 @@ public EnvironmentEndpoint environmentEndpoint(final Environment environment) {
8295
return endpoint;
8396
}
8497

98+
/**
99+
* Jackson {@link ObjectMapper} bean.
100+
*
101+
* @return A Jackson {@link ObjectMapper} bean.
102+
*/
85103
@Bean
86104
public ObjectMapper objectMapper() {
87105
final ObjectMapper mapper = new ObjectMapper();
88106
mapper.setSerializationInclusion(Include.NON_NULL);
89107
return mapper;
90108
}
91109

110+
/**
111+
* Defines the {@link Twitter} API client bean.
112+
*
113+
* @param oauthConsumerKey The OAuth consumer key value.
114+
* @param oauthConsumerSecret The OAuth consumer secret value.
115+
* @param oauthAccessToken The OAuth access token value.
116+
* @param oauthAccessTokenSecret The OAuth access token secret value.
117+
* @return The {@link Twitter} API client bean.
118+
*/
92119
@Bean
93120
public Twitter twitterApi(
94-
@Value("${TWITTER_OAUTH_CONSUMER_KEY}") final String oAuthConsumerKey,
95-
@Value("${TWITTER_OAUTH_CONSUMER_SECRET}") final String oAuthConsumerSecret,
96-
@Value("${TWITTER_OAUTH_ACCESS_TOKEN}") final String oAuthAccessToken,
97-
@Value("${TWITTER_OAUTH_ACCESS_TOKEN_SECRET}") final String oAuthAccessTokenSecret) {
121+
@Value("${TWITTER_OAUTH_CONSUMER_KEY}") final String oauthConsumerKey,
122+
@Value("${TWITTER_OAUTH_CONSUMER_SECRET}") final String oauthConsumerSecret,
123+
@Value("${TWITTER_OAUTH_ACCESS_TOKEN}") final String oauthAccessToken,
124+
@Value("${TWITTER_OAUTH_ACCESS_TOKEN_SECRET}") final String oauthAccessTokenSecret) {
98125
final twitter4j.conf.Configuration configuration =
99126
new ConfigurationBuilder()
100-
.setOAuthConsumerKey(oAuthConsumerKey)
101-
.setOAuthConsumerSecret(oAuthConsumerSecret)
102-
.setOAuthAccessToken(oAuthAccessToken)
103-
.setOAuthAccessTokenSecret(oAuthAccessTokenSecret)
127+
.setOAuthConsumerKey(oauthConsumerKey)
128+
.setOAuthConsumerSecret(oauthConsumerSecret)
129+
.setOAuthAccessToken(oauthAccessToken)
130+
.setOAuthAccessTokenSecret(oauthAccessTokenSecret)
104131
.build();
105132
return new TwitterFactory(configuration).getInstance();
106133
}
107134

135+
/**
136+
* Defines the {@link TweetFormatUtils} bean.
137+
*
138+
* @param templateEngine The template engine used to render the tweet text.
139+
* @param tweetContext The {@link TweetContext}.
140+
* @return The {@link TweetFormatUtils} bean.
141+
*/
108142
@Bean
109143
public TweetFormatUtils tweetFormatUtils(
110144
@Qualifier("textTemplateEngine") final ITemplateEngine templateEngine,
111145
final TweetContext tweetContext) {
112146
return new TweetFormatUtils(templateEngine, tweetContext);
113147
}
114148

149+
/**
150+
* Defines the {@link TwitterTimelineEventScheduler} bean.
151+
*
152+
* @param dateUtils {@link DateUtils} bean.
153+
* @param meterRegistry Micrometer {@link MeterRegistry} bean.
154+
* @param timelineDataLoader The {@link TimelineDataLoader} bean.
155+
* @param tweetFormatUtils The {@link TweetFormatUtils} bean.
156+
* @param twitterApi The {@link Twitter} API client bean.
157+
* @return The {@link TwitterTimelineEventScheduler} bean.
158+
*/
115159
@Bean
116160
public TwitterTimelineEventScheduler twitterTimelineEventScheduler(
117161
final DateUtils dateUtils,
@@ -128,18 +172,35 @@ public TwitterTimelineEventScheduler twitterTimelineEventScheduler(
128172
.build();
129173
}
130174

175+
/**
176+
* Defines the {@link ResourcePatternResolver} bean used to find and load the data file.
177+
*
178+
* @return The {@link ResourcePatternResolver} bean.
179+
*/
131180
@Bean
132181
public ResourcePatternResolver timelineDataFileResourceResolver() {
133182
return new PathMatchingResourcePatternResolver(getClass().getClassLoader());
134183
}
135184

185+
/**
186+
* Defines the {@link TimelineDataLoader} bean.
187+
*
188+
* @param objectMapper A Jackson {@link ObjectMapper} instance.
189+
* @param timelineDataFileResourceResolver The data file resource resolver bean.
190+
* @return The {@link TimelineDataLoader} bean.
191+
*/
136192
@Bean
137193
public TimelineDataLoader timelineDataLoader(
138194
final ObjectMapper objectMapper,
139195
final ResourcePatternResolver timelineDataFileResourceResolver) {
140196
return new TimelineDataLoader(objectMapper, timelineDataFileResourceResolver);
141197
}
142198

199+
/**
200+
* Defines the {@link TweetContext} bean.
201+
*
202+
* @return The {@link TweetContext} bean.
203+
*/
143204
@Bean
144205
@ConfigurationProperties(prefix = "tweet.context")
145206
public TweetContext tweetContext() {

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/config/ControllerConfiguration.java

+21
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,42 @@
3030
import org.springframework.context.annotation.Bean;
3131
import org.springframework.context.annotation.Configuration;
3232

33+
/** Spring configurations for controllers. */
3334
@Configuration
3435
@EnableAutoConfiguration
3536
public class ControllerConfiguration {
3637

38+
/**
39+
* Defines the controller that can be used to publish timeline events to Twitter manually.
40+
*
41+
* @param twitterTimelineEventScheduler The {@link TwitterTimelineEventScheduler} bean.
42+
* @return The {@link EventPublisherController} bean.
43+
*/
3744
@Bean
3845
public EventPublisherController eventPublisherController(
3946
final TwitterTimelineEventScheduler twitterTimelineEventScheduler) {
4047
return new EventPublisherController(twitterTimelineEventScheduler);
4148
}
4249

50+
/**
51+
* Defines the status controller used to verify that the application is running.
52+
*
53+
* @return The {@link StatusController} bean.
54+
*/
4355
@Bean
4456
public StatusController statusController() {
4557
return new StatusController();
4658
}
4759

60+
/**
61+
* Defines the support controller that contains various endpoints used to provide debug or
62+
* diagnostic information.
63+
*
64+
* @param dateUtils The {@link DateUtils} bean.
65+
* @param timelineDataLoader The {@link TimelineDataLoader} bean.
66+
* @param tweetFormatUtils The {@link TweetFormatUtils} bean.
67+
* @return The {@link SupportController} bean.
68+
*/
4869
@Bean
4970
public SupportController supportController(
5071
final DateUtils dateUtils,

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/config/MicrometerConfiguration.java

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.context.annotation.Bean;
3535
import org.springframework.context.annotation.Configuration;
3636

37+
/** Spring configuration for Micrometer metrics. */
3738
@Configuration
3839
@AutoConfigureBefore({
3940
CompositeMeterRegistryAutoConfiguration.class,
@@ -43,6 +44,14 @@
4344
@ConditionalOnClass(NewRelicRegistry.class)
4445
public class MicrometerConfiguration {
4546

47+
/**
48+
* Meter registry used to report metrics to New Relic.
49+
*
50+
* @param insertApiKey The New Relic insert API key value.
51+
* @param metricsApiUri The New Relic metrics API URL.
52+
* @param serviceName The application name.
53+
* @return The {@link MeterRegistry} bean.
54+
*/
4655
@Bean
4756
public MeterRegistry meterRegistry(
4857
@Value("${INSERT_API_KEY}") final String insertApiKey,

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/config/ThymeleafConfiguration.java

+6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@
2828
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
2929
import org.thymeleaf.templateresolver.ITemplateResolver;
3030

31+
/** Spring configuration for Thymeleaf related beans. */
3132
@Configuration
3233
public class ThymeleafConfiguration {
3334

35+
/**
36+
* Defines the text-based {@link TemplateEngine} bean.
37+
*
38+
* @return The text-based {@link TemplateEngine} bean.
39+
*/
3440
@Bean(name = "textTemplateEngine")
3541
public TemplateEngine textTemplateEngine() {
3642
final SpringTemplateEngine templateEngine = new SpringTemplateEngine();

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/config/TweetContext.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.Set;
2525

26+
/** Custom context used to generate templates via Thymeleaf. */
2627
public class TweetContext {
2728

2829
private Set<String> hashtags;

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/config/WebSecurityConfiguration.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2424
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
2525

26+
/** Spring configuration for web security beans. */
2627
@Configuration
2728
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
2829

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/controller/EventPublisherController.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.web.bind.annotation.RequestMapping;
2525
import org.springframework.web.bind.annotation.ResponseBody;
2626

27+
/** Custom controller that can be used to publish timeline events to Twitter manually. */
2728
@Controller
2829
@RequestMapping("/publish")
2930
public class EventPublisherController {

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/controller/StatusController.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.web.bind.annotation.RequestMapping;
2424
import org.springframework.web.bind.annotation.ResponseBody;
2525

26+
/** Custom controller used to verify that the application is running. */
2627
@Controller
2728
@RequestMapping("/status")
2829
public class StatusController {

autobot/src/main/java/com/jdpgrailsdev/oasis/timeline/controller/SupportController.java

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
import org.springframework.web.bind.annotation.ResponseBody;
3838
import twitter4j.TwitterException;
3939

40+
/**
41+
* Support controller that contains various endpoints used to provide debug or diagnostic
42+
* information.
43+
*/
4044
@Controller
4145
@RequestMapping("/support")
4246
public class SupportController {
@@ -49,6 +53,13 @@ public class SupportController {
4953

5054
private final TweetFormatUtils tweetFormatUtils;
5155

56+
/**
57+
* Constructs a new support controller.
58+
*
59+
* @param dateUtils The {@link DateUtils} used to format date strings.
60+
* @param timelineDataLoader The {@link TimelineDataLoader} used to fetch timeline data events.
61+
* @param tweetFormatUtils The {@link TweetFormatUtils} used to generate a tweet.
62+
*/
5263
public SupportController(
5364
final DateUtils dateUtils,
5465
final TimelineDataLoader timelineDataLoader,
@@ -58,6 +69,13 @@ public SupportController(
5869
this.tweetFormatUtils = tweetFormatUtils;
5970
}
6071

72+
/**
73+
* Generates the tweets for a given date.
74+
*
75+
* @param dateString A date string in {@link DateTimeFormatter#ISO_LOCAL_DATE} format.
76+
* @return The list of generated tweets for the provided data or an empty list if no events
77+
* exist.
78+
*/
6179
@RequestMapping("events")
6280
@ResponseBody
6381
public List<Tweet> getEvents(

0 commit comments

Comments
 (0)