Skip to content

Commit

Permalink
GH-116: Fix spring-twitter-function for auto-wire ambiguity
Browse files Browse the repository at this point in the history
Fixes: #116
  • Loading branch information
artembilan committed Dec 19, 2024
1 parent 1c351c8 commit c597124
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Auto-configuration for Twitter Geo function.
*
* @author Christian Tzolov
* @author Artem Bilan
*/
@ConditionalOnExpression("environment['twitter.geo.search.ip'] != null || (environment['twitter.geo.location.lat'] != null && environment['twitter.geo.location.lon'] != null)")
@AutoConfiguration(after = TwitterConnectionConfiguration.class)
Expand Down Expand Up @@ -75,7 +76,7 @@ public Function<Message<?>, GeoQuery> messageToGeoQueryFunction(TwitterGeoFuncti
};
}

@Bean
@Bean("twitterPlacesFunction")
@ConditionalOnProperty(name = "twitter.geo.search.type", havingValue = "search", matchIfMissing = true)
public Function<GeoQuery, List<Place>> twitterSearchPlacesFunction(Twitter twitter) {
return (geoQuery) -> {
Expand All @@ -89,7 +90,7 @@ public Function<GeoQuery, List<Place>> twitterSearchPlacesFunction(Twitter twitt
};
}

@Bean
@Bean("twitterPlacesFunction")
@ConditionalOnProperty(name = "twitter.geo.search.type", havingValue = "reverse")
public Function<GeoQuery, List<Place>> twitterReverseGeocodeFunction(Twitter twitter) {
return (geoQuery) -> {
Expand All @@ -104,10 +105,12 @@ public Function<GeoQuery, List<Place>> twitterReverseGeocodeFunction(Twitter twi
}

@Bean
public Function<Message<?>, Message<byte[]>> twitterGeoFunction(Function<Message<?>, GeoQuery> toGeoQuery,
Function<GeoQuery, List<Place>> places, Function<Object, Message<byte[]>> managedJson) {
public Function<Message<?>, Message<byte[]>> twitterGeoFunction(
Function<Message<?>, GeoQuery> messageToGeoQueryFunction,
Function<GeoQuery, List<Place>> twitterPlacesFunction,
Function<Object, Message<byte[]>> managedJson) {

return toGeoQuery.andThen(places).andThen(managedJson);
return messageToGeoQueryFunction.andThen(twitterPlacesFunction).andThen(managedJson);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.fn.common.twitter.TwitterConnectionConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.expression.Expression;
import org.springframework.messaging.Message;

/**
Expand Down Expand Up @@ -76,9 +77,12 @@ private Function<Message<?>, List<Location>> closestOrAvailableTrends(TwitterTre

return (message) -> {
try {
if (properties.getClosest().getLat() != null && properties.getClosest().getLon() != null) {
double lat = properties.getClosest().getLat().getValue(message, double.class);
double lon = properties.getClosest().getLon().getValue(message, double.class);
TwitterTrendFunctionProperties.Closest closest = properties.getClosest();
Expression latExpression = closest.getLat();
Expression lonExpression = closest.getLon();
if (latExpression != null && lonExpression != null) {
double lat = latExpression.getValue(message, double.class);
double lon = lonExpression.getValue(message, double.class);
return twitter.getClosestTrends(new GeoLocation(lat, lon));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class TwitterUsersFunctionConfiguration {

private static final Log LOGGER = LogFactory.getLog(TwitterUsersFunctionConfiguration.class);

@Bean
@Bean("queryUsers")
@ConditionalOnProperty(name = "twitter.users.type", havingValue = "search")
public Function<Message<?>, List<User>> userSearch(Twitter twitter, TwitterUsersFunctionProperties properties) {

Expand All @@ -60,7 +60,7 @@ public Function<Message<?>, List<User>> userSearch(Twitter twitter, TwitterUsers
};
}

@Bean
@Bean("queryUsers")
@ConditionalOnProperty(name = "twitter.users.type", havingValue = "lookup")
public Function<Message<?>, List<User>> userLookup(Twitter twitter, TwitterUsersFunctionProperties properties) {

Expand Down

0 comments on commit c597124

Please sign in to comment.