GH-116: Fix spring-twitter-function for auto-wire ambiguity

Fixes: https://github.com/spring-cloud/spring-functions-catalog/issues/116
This commit is contained in:
Artem Bilan
2024-12-19 13:10:21 -05:00
parent 1c351c8c45
commit c5971241a7
3 changed files with 17 additions and 10 deletions

View File

@@ -39,6 +39,7 @@ import org.springframework.messaging.Message;
* 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)
@@ -75,7 +76,7 @@ public class TwitterGeoFunctionConfiguration {
};
}
@Bean
@Bean("twitterPlacesFunction")
@ConditionalOnProperty(name = "twitter.geo.search.type", havingValue = "search", matchIfMissing = true)
public Function<GeoQuery, List<Place>> twitterSearchPlacesFunction(Twitter twitter) {
return (geoQuery) -> {
@@ -89,7 +90,7 @@ public class TwitterGeoFunctionConfiguration {
};
}
@Bean
@Bean("twitterPlacesFunction")
@ConditionalOnProperty(name = "twitter.geo.search.type", havingValue = "reverse")
public Function<GeoQuery, List<Place>> twitterReverseGeocodeFunction(Twitter twitter) {
return (geoQuery) -> {
@@ -104,10 +105,12 @@ public class TwitterGeoFunctionConfiguration {
}
@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);
}
}

View File

@@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
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;
/**
@@ -76,9 +77,12 @@ public class TwitterTrendFunctionConfiguration {
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 {

View File

@@ -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) {
@@ -60,7 +60,7 @@ public class TwitterUsersFunctionConfiguration {
};
}
@Bean
@Bean("queryUsers")
@ConditionalOnProperty(name = "twitter.users.type", havingValue = "lookup")
public Function<Message<?>, List<User>> userLookup(Twitter twitter, TwitterUsersFunctionProperties properties) {