-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented basic user/posts/timeline services
- Loading branch information
Showing
14 changed files
with
213 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 46 additions & 4 deletions
50
server/src/main/java/org/aurifa/demo/strutter/action/TimelineController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,79 @@ | ||
package org.aurifa.demo.strutter.action; | ||
|
||
import org.aurifa.demo.strutter.service.MessageService; | ||
import org.aurifa.demo.strutter.service.UserService; | ||
import org.aurifa.demo.strutter.model.Message; | ||
import org.aurifa.demo.strutter.model.User; | ||
import org.aurifa.demo.strutter.helper.Replicator; | ||
import org.aurifa.demo.strutter.helper.HibernateLazyKillingReplicator; | ||
import org.aurifa.demo.strutter.exception.NonExistentUserException; | ||
import org.apache.struts2.convention.annotation.Results; | ||
import org.apache.struts2.convention.annotation.Result; | ||
import org.apache.struts2.rest.HttpHeaders; | ||
import org.apache.struts2.rest.DefaultHttpHeaders; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import com.opensymphony.xwork2.ModelDriven; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* <code>TimelineController</code> | ||
* | ||
* @author <a href="mailto:hermanns@aixcept.de">Rainer Hermanns</a> | ||
* @version $Id: $ | ||
* @author Rainer Hermanns | ||
*/ | ||
@Results({ | ||
@Result(name="success", type="redirectAction", params = {"actionName", "timeline"}) | ||
}) | ||
@Transactional | ||
public class TimelineController implements ModelDriven<Object> { | ||
|
||
@Resource | ||
UserService userService; | ||
|
||
@Resource | ||
MessageService messageService; | ||
|
||
User model = new User(); | ||
List<Message> list; | ||
|
||
List<Message> messages = new ArrayList<Message>(); | ||
String id; | ||
|
||
public void setUserService(UserService userService) { | ||
this.userService = userService; | ||
} | ||
|
||
public void setMessageService(MessageService messageService) { | ||
this.messageService = messageService; | ||
} | ||
|
||
// GET /timeline/1 | ||
public HttpHeaders show() { | ||
List<Message> temp = messageService.getTimeline(model.getAlias()); | ||
Replicator r = new HibernateLazyKillingReplicator(); | ||
for ( Message m : temp) { | ||
messages.add(r.deepCopy(m)); | ||
} | ||
return new DefaultHttpHeaders("show").disableCaching(); | ||
|
||
} | ||
|
||
// GET /timeline | ||
public HttpHeaders index() { | ||
return new DefaultHttpHeaders("index").disableCaching(); | ||
} | ||
|
||
public Object getModel() { | ||
return list != null ? list : model; | ||
return messages; | ||
} | ||
|
||
public void setId(String id) { | ||
if ( id != null) { | ||
model = userService.get(id); | ||
} | ||
this.id = id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.