Initial State

start point
This commit is contained in:
Gary Russell
2012-06-04 16:47:55 -04:00
committed by Gunnar Hillert
parent e90ea836d7
commit dbd1be3579
23 changed files with 1608 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
/*
* Copyright 2002-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.model;
import java.util.Date;
/**
* Represents some common Twitter related fields.
*/
public class TwitterMessage {
private Date createdAt;
private String text;
private String fromUser;
private String profileImageUrl;
/** Default constructor. */
public TwitterMessage() {
super();
}
/** Constructor to initialize all fields available. */
public TwitterMessage(Date createdAt, String text, String fromUser,
String profileImageUrl) {
super();
this.createdAt = createdAt;
this.text = text;
this.fromUser = fromUser;
this.profileImageUrl = profileImageUrl;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getFromUser() {
return fromUser;
}
public void setFromUser(String fromUser) {
this.fromUser = fromUser;
}
public String getProfileImageUrl() {
return profileImageUrl;
}
public void setProfileImageUrl(String profileImageUrl) {
this.profileImageUrl = profileImageUrl;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((createdAt == null) ? 0 : createdAt.hashCode());
result = prime * result
+ ((fromUser == null) ? 0 : fromUser.hashCode());
result = prime * result
+ ((profileImageUrl == null) ? 0 : profileImageUrl.hashCode());
result = prime * result + ((text == null) ? 0 : text.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TwitterMessage other = (TwitterMessage) obj;
if (createdAt == null) {
if (other.createdAt != null)
return false;
} else if (!createdAt.equals(other.createdAt))
return false;
if (fromUser == null) {
if (other.fromUser != null)
return false;
} else if (!fromUser.equals(other.fromUser))
return false;
if (profileImageUrl == null) {
if (other.profileImageUrl != null)
return false;
} else if (!profileImageUrl.equals(other.profileImageUrl))
return false;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
return false;
return true;
}
@Override
public String toString() {
return "Tweet [createdAt=" + createdAt + ", text=" + text
+ ", fromUser=" + fromUser + ", profileImageUrl="
+ profileImageUrl + "]";
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2002-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.mvc.controller;
import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.model.TwitterMessage;
import org.springframework.integration.service.TwitterService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
private static final Log logger = LogFactory.getLog(HomeController.class);
@Autowired
private TwitterService twitterService;
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/")
public String home(Model model, @RequestParam(required=false) String startTwitter,
@RequestParam(required=false) String stopTwitter,
@RequestParam(required=false) String shutdown) {
if (startTwitter != null) {
twitterService.startTwitterAdapter();
return "redirect:/";
}
if (stopTwitter != null) {
twitterService.stopTwitterAdapter();
return "redirect:/";
}
if (shutdown != null) {
twitterService.shutdown();
return "redirect:/";
}
final Collection<TwitterMessage> twitterMessages = twitterService.getTwitterMessages();
logger.info("Retrieved " + twitterMessages.size() + " Twitter messages.");
model.addAttribute("twitterMessages", twitterMessages);
return "home";
}
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/ajax")
public String ajaxCall(Model model) {
final Collection<TwitterMessage> twitterMessages = twitterService.getTwitterMessages();
logger.info("Retrieved " + twitterMessages.size() + " Twitter messages.");
model.addAttribute("twitterMessages", twitterMessages);
return "twitterMessages";
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright 2002-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.service;
import java.util.Collection;
import org.springframework.integration.model.TwitterMessage;
/**
* Provides some basic methods for controlling the flow of Twitter messages.
*/
public interface TwitterService {
/**
* Retrieve the already polled Twitter messages. Keep in mind this
* method does not perform the actual Twitter search. It merely returns all
* the Tweets that were previously polled through Spring Integration and
* which have been cached for returning those to the web-frontend. */
Collection<TwitterMessage> getTwitterMessages();
/**
* By default - After application startup, the Spring Integration Twitter
* search-inbound-channel-adapter is stopped. Use this method to start
* the adapter.
*/
void startTwitterAdapter();
/**
* Allows for stopping the Spring Integration Twitter
* search-inbound-channel-adapter.
*/
void stopTwitterAdapter();
void shutdown();
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2002-2012 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.service.impl;
import java.util.Date;
import org.springframework.social.twitter.api.Tweet;
/**
* @author Gary Russell
* @since 2.2
*
*/
public class DummyTwitter {
private long id;
public Tweet getTweet() {
Tweet tweet = new Tweet(++this.id,
"Spring Integration is the coolest Enterprise Integration project",
new Date(),
"SomeUser",
null,
0L,
0L,
null,
null);
return tweet;
}
}