/connect-web/src/main/java/org/osforce/connect/web/module/review/RatingWidget.java

http://focus-sns.googlecode.com/ · Java · 84 lines · 65 code · 10 blank · 9 comment · 4 complexity · f2650df4111b75c9e9c52efed9953d50 MD5 · raw file

  1. package org.osforce.connect.web.module.review;
  2. import javax.validation.Valid;
  3. import org.osforce.connect.entity.review.Rating;
  4. import org.osforce.connect.entity.system.Project;
  5. import org.osforce.connect.entity.system.ProjectFeature;
  6. import org.osforce.connect.entity.system.User;
  7. import org.osforce.connect.service.rating.RatingService;
  8. import org.osforce.connect.web.AttributeKeys;
  9. import org.osforce.connect.web.security.annotation.Permission;
  10. import org.osforce.spring4me.dao.Page;
  11. import org.osforce.spring4me.web.bind.annotation.RequestAttr;
  12. import org.osforce.spring4me.web.stereotype.Widget;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.ui.Model;
  15. import org.springframework.validation.BindingResult;
  16. import org.springframework.web.bind.annotation.ModelAttribute;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. /**
  19. *
  20. * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
  21. * @since 1.1.2
  22. * @create Jun 23, 2011 - 11:25:27 AM
  23. * <a href="http://www.opensourceforce.org">????</a>
  24. */
  25. @Widget
  26. @RequestMapping("/review/rating")
  27. public class RatingWidget {
  28. private RatingService ratingService;
  29. public RatingWidget() {
  30. }
  31. @Autowired
  32. public void setRatingService(RatingService ratingService) {
  33. this.ratingService = ratingService;
  34. }
  35. @RequestMapping("/list-view")
  36. @Permission(value={"rating-view"}, projectRequired=true)
  37. public String doListView(Page<Rating> page,
  38. @RequestAttr Project project, Model model) {
  39. page = ratingService.getRatingPage(page, project);
  40. model.addAttribute(AttributeKeys.PAGE_KEY_READABLE, page);
  41. return "review/rating-list";
  42. }
  43. @RequestMapping("/form-view")
  44. @Permission(value={"rating-add", "rating-edit"}, projectRequired=true)
  45. public String doFormView(@Valid @ModelAttribute Rating rating,
  46. BindingResult result, Model model, Boolean showErrors,
  47. @RequestAttr Project project, @RequestAttr User user) {
  48. if(!showErrors) {
  49. rating.setProject(project);
  50. rating.setEnteredBy(user);
  51. rating.setModifiedBy(user);
  52. //
  53. model.addAttribute(AttributeKeys.RATING_KEY_READABLE);
  54. }
  55. return "review/rating-form";
  56. }
  57. @RequestMapping("/form-action")
  58. @Permission(value={"rating-add", "rating-edit"})
  59. public String doFormAction(@Valid @ModelAttribute Rating rating,
  60. BindingResult result, Model model) {
  61. if(result.hasErrors()) {
  62. model.addAttribute(AttributeKeys.SHOW_ERRORS_KEY_READABLE, true);
  63. model.addAttribute(AttributeKeys.FEATURE_CODE_KEY_READABLE, ProjectFeature.FEATURE_REVIEW);
  64. return "page:review/rating-form";
  65. }
  66. //
  67. if(rating.getId()==null) {
  68. ratingService.createRating(rating);
  69. } else {
  70. ratingService.updateRating(rating);
  71. }
  72. return String.format("redirect:/%s/review", rating.getProject().getUniqueId());
  73. }
  74. }