/connect-service/src/main/java/org/osforce/connect/service/rating/impl/RatingServiceImpl.java

http://focus-sns.googlecode.com/ · Java · 90 lines · 68 code · 14 blank · 8 comment · 5 complexity · 06e64cff06a2885cd268f9d34451c185 MD5 · raw file

  1. package org.osforce.connect.service.rating.impl;
  2. import java.util.Date;
  3. import org.osforce.connect.dao.review.RatingDao;
  4. import org.osforce.connect.dao.system.ProjectDao;
  5. import org.osforce.connect.dao.system.UserDao;
  6. import org.osforce.connect.entity.review.Rating;
  7. import org.osforce.connect.entity.system.Project;
  8. import org.osforce.connect.entity.system.User;
  9. import org.osforce.connect.service.rating.RatingService;
  10. import org.osforce.spring4me.dao.Page;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. /**
  15. *
  16. * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
  17. * @since 1.1.2
  18. * @create Jun 23, 2011 - 12:53:29 PM
  19. * <a href="http://www.opensourceforce.org">????</a>
  20. */
  21. @Service
  22. @Transactional
  23. public class RatingServiceImpl implements RatingService {
  24. private RatingDao ratingDao;
  25. private UserDao userDao;
  26. private ProjectDao projectDao;
  27. public RatingServiceImpl() {
  28. }
  29. @Autowired
  30. public void setRatingDao(RatingDao ratingDao) {
  31. this.ratingDao = ratingDao;
  32. }
  33. @Autowired
  34. public void setUserDao(UserDao userDao) {
  35. this.userDao = userDao;
  36. }
  37. @Autowired
  38. public void setProjectDao(ProjectDao projectDao) {
  39. this.projectDao = projectDao;
  40. }
  41. public Rating getRating(Long ratingId) {
  42. return ratingDao.get(ratingId);
  43. }
  44. public void createRating(Rating rating) {
  45. updateRating(rating);
  46. }
  47. public void updateRating(Rating rating) {
  48. if(rating.getProjectId()!=null) {
  49. Project project = projectDao.get(rating.getProjectId());
  50. rating.setProject(project);
  51. }
  52. if(rating.getEnteredId()!=null) {
  53. User enteredBy = userDao.get(rating.getEnteredId());
  54. rating.setEnteredBy(enteredBy);
  55. }
  56. if(rating.getModifiedId()!=null) {
  57. User modifiedBy = userDao.get(rating.getModifiedId());
  58. rating.setModifiedBy(modifiedBy);
  59. }
  60. //
  61. Date now = new Date();
  62. rating.setModified(now);
  63. if(rating.getId()==null) {
  64. rating.setEntered(now);
  65. ratingDao.save(rating);
  66. } else {
  67. ratingDao.update(rating);
  68. }
  69. }
  70. public void deleteRating(Long ratingId) {
  71. ratingDao.delete(ratingId);
  72. }
  73. public Page<Rating> getRatingPage(Page<Rating> page, Project project) {
  74. return ratingDao.findRatingPage(page, project.getId());
  75. }
  76. }