43
43
import twitter4j .TwitterFactory ;
44
44
import twitter4j .conf .ConfigurationBuilder ;
45
45
46
+ /** Main Spring application configuration. */
46
47
@ Configuration
47
48
@ EnableAutoConfiguration
48
49
@ EnableScheduling
55
56
})
56
57
public class ApplicationConfiguration {
57
58
59
+ /**
60
+ * Defines the {@link DateUtils} bean.
61
+ *
62
+ * @return The {@link DateUtils} bean.
63
+ */
58
64
@ Bean
59
65
public DateUtils dateUtils () {
60
66
return new DateUtils ();
61
67
}
62
68
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
+ */
63
76
@ Bean
64
77
public EnvironmentEndpoint environmentEndpoint (final Environment environment ) {
65
78
/*
@@ -82,36 +95,67 @@ public EnvironmentEndpoint environmentEndpoint(final Environment environment) {
82
95
return endpoint ;
83
96
}
84
97
98
+ /**
99
+ * Jackson {@link ObjectMapper} bean.
100
+ *
101
+ * @return A Jackson {@link ObjectMapper} bean.
102
+ */
85
103
@ Bean
86
104
public ObjectMapper objectMapper () {
87
105
final ObjectMapper mapper = new ObjectMapper ();
88
106
mapper .setSerializationInclusion (Include .NON_NULL );
89
107
return mapper ;
90
108
}
91
109
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
+ */
92
119
@ Bean
93
120
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 ) {
98
125
final twitter4j .conf .Configuration configuration =
99
126
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 )
104
131
.build ();
105
132
return new TwitterFactory (configuration ).getInstance ();
106
133
}
107
134
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
+ */
108
142
@ Bean
109
143
public TweetFormatUtils tweetFormatUtils (
110
144
@ Qualifier ("textTemplateEngine" ) final ITemplateEngine templateEngine ,
111
145
final TweetContext tweetContext ) {
112
146
return new TweetFormatUtils (templateEngine , tweetContext );
113
147
}
114
148
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
+ */
115
159
@ Bean
116
160
public TwitterTimelineEventScheduler twitterTimelineEventScheduler (
117
161
final DateUtils dateUtils ,
@@ -128,18 +172,35 @@ public TwitterTimelineEventScheduler twitterTimelineEventScheduler(
128
172
.build ();
129
173
}
130
174
175
+ /**
176
+ * Defines the {@link ResourcePatternResolver} bean used to find and load the data file.
177
+ *
178
+ * @return The {@link ResourcePatternResolver} bean.
179
+ */
131
180
@ Bean
132
181
public ResourcePatternResolver timelineDataFileResourceResolver () {
133
182
return new PathMatchingResourcePatternResolver (getClass ().getClassLoader ());
134
183
}
135
184
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
+ */
136
192
@ Bean
137
193
public TimelineDataLoader timelineDataLoader (
138
194
final ObjectMapper objectMapper ,
139
195
final ResourcePatternResolver timelineDataFileResourceResolver ) {
140
196
return new TimelineDataLoader (objectMapper , timelineDataFileResourceResolver );
141
197
}
142
198
199
+ /**
200
+ * Defines the {@link TweetContext} bean.
201
+ *
202
+ * @return The {@link TweetContext} bean.
203
+ */
143
204
@ Bean
144
205
@ ConfigurationProperties (prefix = "tweet.context" )
145
206
public TweetContext tweetContext () {
0 commit comments