This commit is contained in:
Josh Long
2010-10-23 16:23:01 -07:00
parent b804f175b0
commit 19871a4484
21 changed files with 274 additions and 75 deletions

View File

@@ -14,22 +14,13 @@
* limitations under the License.
*/
package org.springframework.integration.twitter;
//import twitter4j.Status;
//import twitter4j.Status;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.twitter.model.Status;
import org.springframework.integration.twitter.model.Twitter4jStatusImpl;
import org.springframework.integration.twitter.model.Twitter4jStatus;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/**
@@ -51,7 +42,7 @@ abstract public class AbstractInboundTwitterStatusEndpointSupport extends Abstra
protected List<Status> fromTwitter4jStatuses(List<twitter4j.Status> stats) {
List<Status> fwd = new ArrayList<Status>();
for (twitter4j.Status s : stats)
fwd.add(new Twitter4jStatusImpl(s));
fwd.add(new Twitter4jStatus(s));
return fwd;
}

View File

@@ -15,21 +15,15 @@
*/
package org.springframework.integration.twitter;
//import twitter4j.DirectMessage;
import org.springframework.integration.twitter.model.DirectMessage;
import org.springframework.integration.twitter.model.Twitter4jDirectMessageImpl;
import org.springframework.integration.twitter.model.Twitter4jDirectMessage;
import twitter4j.Paging;
import twitter4j.Twitter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/**
@@ -79,7 +73,7 @@ public class InboundDirectMessageStatusEndpoint extends AbstractInboundTwitterEn
List<DirectMessage> dmsToFwd = new ArrayList<DirectMessage>();
for( twitter4j.DirectMessage dm : dms)
dmsToFwd.add( new Twitter4jDirectMessageImpl( dm));
dmsToFwd.add( new Twitter4jDirectMessage( dm));
forwardAll( dmsToFwd );
}

View File

@@ -27,6 +27,7 @@ import twitter4j.TwitterException;
* @author Josh Long
* @see org.springframework.integration.twitter.TwitterHeaders
* @see twitter4j.Twitter
* @since 2.0
*/
public class OutboundDirectMessageStatusMessageHandler extends AbstractOutboundTwitterEndpointSupport {

View File

@@ -18,7 +18,7 @@ package org.springframework.integration.twitter;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.mapping.OutboundMessageMapper;
import org.springframework.integration.twitter.model.Twitter4jGeoLocationImpl;
import org.springframework.integration.twitter.model.Twitter4jGeoLocation;
import org.springframework.util.StringUtils;
import twitter4j.StatusUpdate;
@@ -33,14 +33,14 @@ import twitter4j.StatusUpdate;
*/
public class StatusUpdateOptboundMessageMapper implements OutboundMessageMapper<StatusUpdate> {
/**
* convenient, interf-ace-oriented way of obtaining a reference to a {@link org.springframework.integration.twitter.model.Twitter4jGeoLocationImpl}
* convenient, interf-ace-oriented way of obtaining a reference to a {@link org.springframework.integration.twitter.model.Twitter4jGeoLocation}
*
* @param lat the latitude
* @param lon the longitude
* @return a {@link org.springframework.integration.twitter.model.GeoLocation} instance
*/
public org.springframework.integration.twitter.model.GeoLocation fromLatitudeLongitudePair(double lat, double lon) {
return new Twitter4jGeoLocationImpl(lat, lon);
return new Twitter4jGeoLocation(lat, lon);
}
/**
@@ -82,8 +82,8 @@ public class StatusUpdateOptboundMessageMapper implements OutboundMessageMapper<
.get(TwitterHeaders.TWITTER_GEOLOCATION);
twitter4j.GeoLocation gl = null;
if (geoLocation instanceof Twitter4jGeoLocationImpl) {
gl = ((Twitter4jGeoLocationImpl) geoLocation).getGeoLocation();
if (geoLocation instanceof Twitter4jGeoLocation) {
gl = ((Twitter4jGeoLocation) geoLocation).getGeoLocation();
if (null != gl) {
statusUpdate.location(gl);
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.AbstractBeanDefinition;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.config;
import org.springframework.beans.factory.support.AbstractBeanDefinition;

View File

@@ -1,5 +1,22 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
import java.util.Date;
/**
* Describes a direct-message in twitter. (Also known as a "DM").
* <p/>
@@ -10,9 +27,9 @@ package org.springframework.integration.twitter.model;
public interface DirectMessage {
int getId();
java.lang.String getText();
String getText();
java.util.Date getCreatedAt();
Date getCreatedAt();
User getSender() ;

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
/**

View File

@@ -1,5 +1,22 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
import java.util.Date;
/**
* describes a simple status message on twitter. this could be a message
* that updates a timeline on behalf of a user, or it could be a message that contains a reply.
@@ -9,13 +26,13 @@ package org.springframework.integration.twitter.model;
*/
public interface Status {
java.util.Date getCreatedAt();
Date getCreatedAt();
long getId();
java.lang.String getText();
String getText();
java.lang.String getSource();
String getSource();
boolean isTruncated();
@@ -33,6 +50,6 @@ public interface Status {
Status getRetweetedStatus();
java.lang.String[] getContributors();
String[] getContributors();
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
import twitter4j.DirectMessage;
@@ -11,10 +26,10 @@ import java.util.Date;
*
* @author Josh Long
*/
public class Twitter4jDirectMessageImpl implements org.springframework.integration.twitter.model.DirectMessage {
public class Twitter4jDirectMessage implements org.springframework.integration.twitter.model.DirectMessage {
private DirectMessage directMessage;
public Twitter4jDirectMessageImpl(DirectMessage directMessage) {
public Twitter4jDirectMessage(DirectMessage directMessage) {
this.directMessage = directMessage;
}
@@ -27,11 +42,11 @@ public class Twitter4jDirectMessageImpl implements org.springframework.integrati
}
public User getSender() {
return new Twitter4jUserImpl(this.directMessage.getSender());
return new Twitter4jUser(this.directMessage.getSender());
}
public User getRecipient() {
return new Twitter4jUserImpl(this.directMessage.getRecipient());
return new Twitter4jUser(this.directMessage.getRecipient());
}
public String getText() {

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
/**
* Implements a notion of GeoLocation that forwards calls to {@link twitter4j.GeoLocation} instance
*
* @author Josh Long
*/
public class Twitter4jGeoLocation implements GeoLocation {
private twitter4j.GeoLocation geoLocation;
public twitter4j.GeoLocation getGeoLocation() {
return this.geoLocation;
}
public Twitter4jGeoLocation(double lat, double lon){
this.geoLocation = new twitter4j.GeoLocation(lat,lon);
}
public Twitter4jGeoLocation(twitter4j.GeoLocation gl) {
this.geoLocation = gl;
}
public double getLongitude() {
return this.geoLocation.getLongitude();
}
public double getLatitude() {
return this.geoLocation.getLatitude();
}
}

View File

@@ -1,30 +0,0 @@
package org.springframework.integration.twitter.model;
/**
* Implements a notion of GeoLocation that forwards calls to {@link twitter4j.GeoLocation} instance
*
* @author Josh Long
*/
public class Twitter4jGeoLocationImpl implements GeoLocation {
private twitter4j.GeoLocation geoLocation;
public twitter4j.GeoLocation getGeoLocation() {
return this.geoLocation;
}
public Twitter4jGeoLocationImpl(double lat, double lon){
this.geoLocation = new twitter4j.GeoLocation(lat,lon);
}
public Twitter4jGeoLocationImpl(twitter4j.GeoLocation gl) {
this.geoLocation = gl;
}
public double getLongitude() {
return this.geoLocation.getLongitude();
}
public double getLatitude() {
return this.geoLocation.getLatitude();
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
import java.util.Date;
@@ -9,10 +24,10 @@ import java.util.Date;
*
* @author Josh Long
*/
public class Twitter4jStatusImpl implements Status {
public class Twitter4jStatus implements Status {
private twitter4j.Status status;
public Twitter4jStatusImpl(twitter4j.Status s) {
public Twitter4jStatus(twitter4j.Status s) {
this.status = s;
}
@@ -53,7 +68,7 @@ public class Twitter4jStatusImpl implements Status {
}
public User getUser() {
return new Twitter4jUserImpl(this.status.getUser());
return new Twitter4jUser(this.status.getUser());
}
public boolean isRetweet() {
@@ -61,7 +76,7 @@ public class Twitter4jStatusImpl implements Status {
}
public Status getRetweetedStatus() {
return new Twitter4jStatusImpl(this.status.getRetweetedStatus());
return new Twitter4jStatus(this.status.getRetweetedStatus());
}
public String[] getContributors() {

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;
import twitter4j.User;
@@ -10,11 +25,11 @@ import java.net.URL;
*
* @author Josh Long
*/
public class Twitter4jUserImpl implements org.springframework.integration.twitter.model.User {
public class Twitter4jUser implements org.springframework.integration.twitter.model.User {
private twitter4j.User user;
public Twitter4jUserImpl(User u) {
public Twitter4jUser(User u) {
this.user = u;
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 2010 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter.model;

View File

@@ -20,11 +20,10 @@ import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.model.Twitter4jGeoLocationImpl;
import org.springframework.integration.twitter.model.Twitter4jGeoLocation;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.util.Assert;
@@ -48,7 +47,7 @@ public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTes
String dmUsr = System.getProperties().getProperty("twitter.dm.user");
Assert.notNull( dmUsr , "the DM user's null");
MessageBuilder<String> mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter")
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocationImpl(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
if (StringUtils.hasText(dmUsr)) {

View File

@@ -23,7 +23,7 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.model.Twitter4jGeoLocationImpl;
import org.springframework.integration.twitter.model.Twitter4jGeoLocation;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@@ -42,7 +42,7 @@ public class TestSendingUpdatesUsingNamespace extends AbstractJUnit4SpringContex
public void testSendingATweet() throws Throwable {
MessageBuilder<String> mb = MessageBuilder.withPayload("simple test demonstrating the ability to encode location information")
.setHeader(TwitterHeaders.TWITTER_IN_REPLY_TO_STATUS_ID, 21927437001L)
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocationImpl(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
Message<String> m = mb.build();
this.messagingTemplate.send(this.channel, m);