INT-2801 Twitter: Fix Init. of Metadata Key

Key was not initialized unless authorized.
This commit is contained in:
michaljemala
2012-10-31 17:26:34 +00:00
committed by Gary Russell
parent 2055e48111
commit 1eb1301b1f
2 changed files with 17 additions and 13 deletions

View File

@@ -102,31 +102,29 @@ abstract class AbstractTwitterMessageSource<T> extends IntegrationObjectSupport
}
StringBuilder metadataKeyBuilder = new StringBuilder();
if (StringUtils.hasText(this.getComponentType())) {
metadataKeyBuilder.append(this.getComponentType() + ".");
metadataKeyBuilder.append(this.getComponentType());
}
if (StringUtils.hasText(this.getComponentName())) {
metadataKeyBuilder.append(this.getComponentName() + ".");
metadataKeyBuilder.append("." + this.getComponentName());
}
else if (logger.isWarnEnabled()) {
logger.warn(this.getClass().getSimpleName() + " has no name. MetadataStore key might not be unique.");
}
if (this.twitter.isAuthorized()){
UserOperations userOperations = this.twitter.userOperations();
UserOperations userOperations = this.twitter.userOperations();
String profileId = String.valueOf(userOperations.getProfileId());
if (profileId != null) {
metadataKeyBuilder.append(profileId);
metadataKeyBuilder.append("." + profileId);
}
}
this.metadataKey = metadataKeyBuilder.toString();
String lastId = this.metadataStore.get(this.metadataKey);
// initialize the last status ID from the metadataStore
if (StringUtils.hasText(lastId)) {
this.lastProcessedId = Long.parseLong(lastId);
this.lastEnqueuedId = this.lastProcessedId;
}
this.metadataKey = metadataKeyBuilder.toString();
String lastId = this.metadataStore.get(this.metadataKey);
// initialize the last status ID from the metadataStore
if (StringUtils.hasText(lastId)) {
this.lastProcessedId = Long.parseLong(lastId);
this.lastEnqueuedId = this.lastProcessedId;
}
}

View File

@@ -79,17 +79,23 @@ public class SearchReceivingMessageSourceTests {
public void testSearchReceivingMessageSourceInit() {
final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(new TwitterTemplate());
messageSource.setComponentName("twitterSearchMessageSource");
final Object metadataStore = TestUtils.getPropertyValue(messageSource, "metadataStore");
final Object metadataKey = TestUtils.getPropertyValue(messageSource, "metadataKey");
assertNull(metadataStore);
assertNull(metadataKey);
messageSource.afterPropertiesSet();
final Object metadataStoreInitialized = TestUtils.getPropertyValue(messageSource, "metadataStore");
final Object metadataKeyInitialized = TestUtils.getPropertyValue(messageSource, "metadataKey");
assertNotNull(metadataStoreInitialized);
assertTrue(metadataStoreInitialized instanceof SimpleMetadataStore);
assertNotNull(metadataKeyInitialized);
assertEquals("twitter:search-inbound-channel-adapter.twitterSearchMessageSource", metadataKeyInitialized);
final Twitter twitter = TestUtils.getPropertyValue(messageSource, "twitter", Twitter.class);