/connect-web/src/main/java/org/osforce/connect/web/module/stream/ActivityWidget.java

http://focus-sns.googlecode.com/ · Java · 98 lines · 77 code · 12 blank · 9 comment · 3 complexity · 6557e671b42573174d78a8d715d24fb0 MD5 · raw file

  1. package org.osforce.connect.web.module.stream;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import javax.validation.Valid;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.osforce.connect.entity.stream.Activity;
  7. import org.osforce.connect.entity.system.Project;
  8. import org.osforce.connect.entity.system.ProjectFeature;
  9. import org.osforce.connect.entity.system.User;
  10. import org.osforce.connect.service.stream.ActivityService;
  11. import org.osforce.connect.web.AttributeKeys;
  12. import org.osforce.connect.web.security.annotation.Permission;
  13. import org.osforce.spring4me.dao.Page;
  14. import org.osforce.spring4me.web.bind.annotation.PrefParam;
  15. import org.osforce.spring4me.web.bind.annotation.RequestAttr;
  16. import org.osforce.spring4me.web.stereotype.Widget;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.ui.Model;
  19. import org.springframework.validation.BindingResult;
  20. import org.springframework.web.bind.annotation.ModelAttribute;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.RequestMethod;
  23. /**
  24. *
  25. * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
  26. * @since 1.1.0
  27. * @create May 20, 2011 - 2:04:31 PM
  28. * <a href="http://www.opensourceforce.org">????</a>
  29. */
  30. @Widget
  31. @RequestMapping("/stream/activity")
  32. public class ActivityWidget {
  33. private ActivityService activityService;
  34. public ActivityWidget() {
  35. }
  36. @Autowired
  37. public void setActivityService(ActivityService activityService) {
  38. this.activityService = activityService;
  39. }
  40. @RequestMapping("/recent-view")
  41. public String doRecentView(Page<Activity> page,
  42. @PrefParam String activityTypes, Model model) {
  43. List<String> types = Arrays.asList(StringUtils.split(activityTypes, ","));
  44. page = activityService.getActivityPage(page, types);
  45. model.addAttribute(AttributeKeys.PAGE_KEY_READABLE, page);
  46. return "stream/activity-recent";
  47. }
  48. @RequestMapping("/list-view")
  49. @Permission(value={"activity-view"}, projectRequired=true)
  50. public String doListView(@PrefParam String activityTypes,
  51. Page<Activity> page, @RequestAttr Project project, Model model) {
  52. List<String> types = Arrays.asList(StringUtils.split(activityTypes, ","));
  53. page = activityService.getActivityPage(page, project, types);
  54. model.addAttribute(AttributeKeys.PAGE_KEY_READABLE, page);
  55. return "stream/activity-list";
  56. }
  57. @RequestMapping("/form-view")
  58. @Permission(value={"activity-add", "activity-edit"}, userRequired=true, projectRequired=true)
  59. public String doFormView(@PrefParam String activityType, @RequestAttr User user,
  60. @PrefParam("false") Boolean showToolbar, @RequestAttr Project project,
  61. @ModelAttribute @Valid Activity activity, BindingResult result, Model model) {
  62. activity.setType(activityType);
  63. activity.setEnteredBy(user);
  64. activity.setProject(project);
  65. model.addAttribute(AttributeKeys.ACTIVITY_KEY_READABLE, activity);
  66. //
  67. model.addAttribute("showToolbar", showToolbar);
  68. return "stream/activity-form";
  69. }
  70. @RequestMapping(value="/form-action", method=RequestMethod.POST)
  71. @Permission(value={"activity-add", "activity-edit"}, userRequired=true, projectRequired=true)
  72. public String doFormAction(@ModelAttribute @Valid Activity activity,
  73. BindingResult result, Model model, @RequestAttr Project project) {
  74. if(result.hasErrors()) {
  75. model.addAttribute(AttributeKeys.FEATURE_CODE_KEY_READABLE, ProjectFeature.FEATURE_PROFILE);
  76. return "page:/profile/profile-detail";
  77. }
  78. //
  79. if(activity.getId()==null) {
  80. activityService.createActivity(activity);
  81. } else {
  82. activityService.updateActivity(activity);
  83. }
  84. return String.format("redirect:/%s/profile", project.getUniqueId());
  85. }
  86. }