/content-review/impl/service/src/main/java/org/sakaiproject/contentreview/service/ContentReviewQueueServiceImpl.java

https://github.com/sakaiproject/sakai · Java · 279 lines · 163 code · 44 blank · 72 comment · 5 complexity · 2e3b8d67d443d4f6422c73ffbc1867e1 MD5 · raw file

  1. /**
  2. * Copyright (c) 2003 The Apereo Foundation
  3. *
  4. * Licensed under the Educational Community License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://opensource.org/licenses/ecl2
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.sakaiproject.contentreview.service;
  17. import java.util.Date;
  18. import java.util.List;
  19. import java.util.Objects;
  20. import java.util.Optional;
  21. import org.sakaiproject.content.api.ContentResource;
  22. import org.sakaiproject.contentreview.dao.ContentReviewConstants;
  23. import org.sakaiproject.contentreview.dao.ContentReviewItem;
  24. import org.sakaiproject.contentreview.dao.ContentReviewItemDao;
  25. import org.sakaiproject.contentreview.exception.QueueException;
  26. import org.sakaiproject.contentreview.exception.ReportException;
  27. import org.sakaiproject.contentreview.exception.SubmissionException;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import lombok.Setter;
  30. import lombok.extern.slf4j.Slf4j;
  31. @Slf4j
  32. public class ContentReviewQueueServiceImpl implements ContentReviewQueueService {
  33. @Setter
  34. private ContentReviewItemDao itemDao;
  35. /* (non-Javadoc)
  36. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#queueContent(java.lang.Integer, java.lang.String, java.lang.String, java.lang.String, java.util.List, int)
  37. */
  38. @Override
  39. @Transactional
  40. public void queueContent(Integer providerId, String userId, String siteId, String taskId, List<ContentResource> content)
  41. throws QueueException {
  42. Objects.requireNonNull(providerId, "providerId cannot be null");
  43. Objects.requireNonNull(userId, "userId cannot be null");
  44. Objects.requireNonNull(siteId, "siteId cannot be null");
  45. Objects.requireNonNull(taskId, "taskId cannot be null");
  46. Objects.requireNonNull(content, "content cannot be null");
  47. StringBuilder errors = new StringBuilder();
  48. String delim = "";
  49. for (ContentResource resource : content) {
  50. String contentId = resource.getId();
  51. /*
  52. * first check that this content has not been submitted before this may
  53. * not be the best way to do this - perhaps use contentId as the primary
  54. * key for now id is the primary key and so the database won't complain
  55. * if we put in repeats necessitating the check
  56. */
  57. Optional<ContentReviewItem> existingItem = itemDao.findByProviderAndContentId(providerId, contentId);
  58. if (existingItem.isPresent()) {
  59. errors.append(delim).append("Content " + contentId + " is already queued");
  60. delim = ", ";
  61. continue;
  62. }
  63. ContentReviewItem item = new ContentReviewItem(contentId, userId, siteId, taskId, new Date(), ContentReviewConstants.CONTENT_REVIEW_NOT_SUBMITTED_CODE, providerId);
  64. log.debug("Adding content: " + contentId + " from site " + siteId + " and user: " + userId + " for task: " + taskId + " to submission queue");
  65. itemDao.create(item);
  66. }
  67. if (errors.length() > 0)
  68. {
  69. throw new QueueException(errors.toString());
  70. }
  71. }
  72. /* (non-Javadoc)
  73. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getReviewScore(java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
  74. */
  75. @Override
  76. @Transactional(readOnly=true)
  77. @Deprecated
  78. public int getReviewScore(Integer providerId, String contentId) throws QueueException, ReportException, Exception {
  79. Optional<ContentReviewItem> item = getQueuedItem(providerId, contentId);
  80. return item.isPresent() ? item.get().getReviewScore() : null;
  81. }
  82. /* (non-Javadoc)
  83. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getReviewStatus(java.lang.Integer, java.lang.String)
  84. */
  85. @Override
  86. @Transactional(readOnly=true)
  87. @Deprecated
  88. public Long getReviewStatus(Integer providerId, String contentId) throws QueueException {
  89. Optional<ContentReviewItem> item = getQueuedItem(providerId, contentId);
  90. return item.isPresent() ? item.get().getStatus() : null;
  91. }
  92. /* (non-Javadoc)
  93. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getDateQueued(java.lang.Integer, java.lang.String)
  94. */
  95. @Override
  96. @Transactional(readOnly=true)
  97. @Deprecated
  98. public Date getDateQueued(Integer providerId, String contentId) throws QueueException {
  99. Optional<ContentReviewItem> item = getQueuedItem(providerId, contentId);
  100. return item.isPresent() ? item.get().getDateQueued() : null;
  101. }
  102. /* (non-Javadoc)
  103. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getDateSubmitted(java.lang.Integer, java.lang.String)
  104. */
  105. @Override
  106. @Transactional(readOnly=true)
  107. @Deprecated
  108. public Date getDateSubmitted(Integer providerId, String contentId) throws QueueException, SubmissionException {
  109. Optional<ContentReviewItem> item = getQueuedItem(providerId, contentId);
  110. return item.isPresent() ? item.get().getDateSubmitted() : null;
  111. }
  112. /* (non-Javadoc)
  113. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getAllContentReviewItems(java.lang.Integer, java.lang.String, java.lang.String)
  114. */
  115. @Override
  116. @Transactional(readOnly=true)
  117. public List<ContentReviewItem> getContentReviewItems(Integer providerId, String siteId, String taskId) {
  118. Objects.requireNonNull(providerId, "providerId cannot be null");
  119. return itemDao.findByProviderAnyMatching(providerId, null, null, siteId, taskId, null, null, null);
  120. }
  121. /* (non-Javadoc)
  122. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getAllContentReviewItems(java.lang.Integer, java.lang.String, java.lang.String)
  123. */
  124. @Override
  125. @Transactional(readOnly=true)
  126. public List<ContentReviewItem> getAllContentReviewItemsGroupedBySiteAndTask(Integer providerId) {
  127. Objects.requireNonNull(providerId, "providerId cannot be null");
  128. log.debug("Returning list of items grouped by site and task");
  129. return itemDao.findByProviderGroupedBySiteAndTask(providerId);
  130. }
  131. /* (non-Javadoc)
  132. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#getAllContentReviewItems(java.lang.Integer, java.lang.String, java.lang.String)
  133. */
  134. @Override
  135. @Transactional(readOnly=true)
  136. public List<String> getContentReviewItemsGroupedBySite(Integer providerId) {
  137. Objects.requireNonNull(providerId, "providerId cannot be null");
  138. log.debug("Returning list of items grouped by site");
  139. return itemDao.findByProviderGroupedBySite(providerId);
  140. }
  141. /* (non-Javadoc)
  142. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#resetUserDetailsLockedItems(java.lang.Integer, java.lang.String)
  143. */
  144. @Override
  145. @Transactional
  146. public void resetUserDetailsLockedItems(Integer providerId, String userId) {
  147. Objects.requireNonNull(providerId, "providerId cannot be null");
  148. Objects.requireNonNull(userId, "userId cannot be null");
  149. List<ContentReviewItem> lockedItems = itemDao.findByProviderAnyMatching(providerId, null, userId, null, null, null, ContentReviewConstants.CONTENT_REVIEW_SUBMISSION_ERROR_USER_DETAILS_CODE, null);
  150. for (ContentReviewItem item : lockedItems) {
  151. item.setStatus(ContentReviewConstants.CONTENT_REVIEW_SUBMISSION_ERROR_RETRY_CODE);
  152. itemDao.save(item);
  153. }
  154. }
  155. /* (non-Javadoc)
  156. * @see org.sakaiproject.contentreview.common.service.ContentReviewCommonService#removeFromQueue(java.lang.Integer, java.lang.String)
  157. */
  158. @Override
  159. @Transactional
  160. public void removeFromQueue(Integer providerId, String contentId) {
  161. Objects.requireNonNull(providerId, "providerId cannot be null");
  162. Objects.requireNonNull(contentId, "contentId cannot be null");
  163. Optional<ContentReviewItem> item = itemDao.findByProviderAndContentId(providerId, contentId);
  164. if (item.isPresent()) {
  165. itemDao.delete(item.get());
  166. }
  167. }
  168. /* (non-Javadoc)
  169. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#getQueuedItem(java.lang.Integer, java.lang.String)
  170. */
  171. @Override
  172. @Transactional(readOnly=true)
  173. public Optional<ContentReviewItem> getQueuedItem(Integer providerId, String contentId) {
  174. Objects.requireNonNull(providerId, "providerId cannot be null");
  175. Objects.requireNonNull(contentId, "contentId cannot be null");
  176. return itemDao.findByProviderAndContentId(providerId, contentId);
  177. }
  178. /* (non-Javadoc)
  179. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#getQueuedItem(java.lang.Integer, java.lang.String)
  180. */
  181. @Override
  182. @Transactional(readOnly=true)
  183. public Optional<ContentReviewItem> getQueuedItemByExternalId(Integer providerId, String externalId) {
  184. Objects.requireNonNull(providerId, "providerId cannot be null");
  185. Objects.requireNonNull(externalId, "externalId cannot be null");
  186. return itemDao.findByProviderAndExternalId(providerId, externalId);
  187. }
  188. /* (non-Javadoc)
  189. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#getQueuedNotSubmittedItems(java.lang.Integer)
  190. */
  191. @Override
  192. @Transactional(readOnly=true)
  193. public List<ContentReviewItem> getQueuedNotSubmittedItems(Integer providerId) {
  194. return itemDao.findByProviderAnyMatching(providerId, null, null, null, null, null, ContentReviewConstants.CONTENT_REVIEW_NOT_SUBMITTED_CODE, null);
  195. }
  196. /* (non-Javadoc)
  197. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#getNextItemInQueueToSubmit(java.lang.Integer)
  198. */
  199. @Override
  200. @Transactional(readOnly=true)
  201. public Optional<ContentReviewItem> getNextItemInQueueToSubmit(Integer providerId) {
  202. Objects.requireNonNull(providerId, "providerId cannot be null");
  203. return itemDao.findByProviderSingleItemToSubmit(providerId);
  204. }
  205. /* (non-Javadoc)
  206. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#getAwaitingReports(java.lang.Integer)
  207. */
  208. @Override
  209. @Transactional(readOnly=true)
  210. public List<ContentReviewItem> getAwaitingReports(Integer providerId) {
  211. Objects.requireNonNull(providerId, "providerId cannot be null");
  212. return itemDao.findByProviderAwaitingReports(providerId);
  213. }
  214. /* (non-Javadoc)
  215. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#update(org.sakaiproject.contentreview.dao.ContentReviewItem)
  216. */
  217. @Override
  218. @Transactional
  219. public void update(ContentReviewItem item) {
  220. Objects.requireNonNull(item, "item cannot be null");
  221. Objects.requireNonNull(item.getProviderId(), "providerId cannot be null");
  222. itemDao.save(item);
  223. }
  224. /* (non-Javadoc)
  225. * @see org.sakaiproject.contentreview.service.ContentReviewQueueService#delete(org.sakaiproject.contentreview.dao.ContentReviewItem)
  226. */
  227. @Override
  228. @Transactional
  229. public void delete(ContentReviewItem item) {
  230. Objects.requireNonNull(item, "item cannot be null");
  231. Objects.requireNonNull(item.getId(), "Id cannot be null");
  232. Objects.requireNonNull(item.getProviderId(), "providerId cannot be null");
  233. itemDao.delete(item);
  234. }
  235. }