+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StudyService#getStudyResultType(org.splat.dal.bo.som.Study)
+ */
+ @Override
+ @Transactional(readOnly = true)
+ public DocumentType getStudyResultType(final Study study) {
+ DetachedCriteria query = DetachedCriteria.forClass(DocumentType.class)
+ .addOrder(Order.desc("result"));
+ return getDocumentTypeDAO().getFirstResult(query);
+ }
+
+ /**
+ * Get the documentTypeDAO.
+ *
+ * @return the documentTypeDAO
+ */
+ public DocumentTypeDAO getDocumentTypeDAO() {
+ return _documentTypeDAO;
+ }
+
+ /**
+ * Set the documentTypeDAO.
+ *
+ * @param documentTypeDAO
+ * the documentTypeDAO to set
+ */
+ public void setDocumentTypeDAO(final DocumentTypeDAO documentTypeDAO) {
+ _documentTypeDAO = documentTypeDAO;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StudyService#canBeApproved(org.splat.dal.bo.som.Study)
+ */
+ @Override
+ @Transactional(readOnly = true)
+ public boolean canBeApproved(final Study study) {
+ return resultDocsAtLeast(study, ProgressState.APPROVED);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StudyService#canBePromoted(org.splat.dal.bo.som.Study)
+ */
+ @Override
+ @Transactional(readOnly = true)
+ public boolean canBePromoted(final Study study) {
+ return resultDocsAtLeast(study, ProgressState.inDRAFT);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.service.StudyService#canBeReviewed(org.splat.dal.bo.som.Study)
+ */
+ @Override
+ @Transactional(readOnly = true)
+ public boolean canBeReviewed(final Study study) {
+ return resultDocsAtLeast(study, ProgressState.inCHECK);
+ }
+
+ /**
+ * Check that all result documents of the study are at least in the given state.
+ *
+ * @param study
+ * the study to check
+ * @param state
+ * the minimal acceptable state
+ * @return true if study result documents have acceptable states
+ */
+ private boolean resultDocsAtLeast(final Study study,
+ final ProgressState state) {
+ boolean res = true;
+ // Check that all study result documents have the state APPROVED or more.
+ for (Publication pub : getProjectElementService().getLastStep(study)
+ .getResultDocuments()) {
+ res = pub.getProgressState().compareTo(ProgressState.APPROVED) >= 0;
+ if (!res) {
+ break;
+ }
+ }
+ return res;
+ }