1 /*****************************************************************************
5 * Creation date 02.10.2012
6 * @author Author: Maria KRUCHININA
8 *****************************************************************************/
10 package org.splat.service;
12 import java.awt.Graphics2D;
14 import java.io.FileNotFoundException;
15 import java.io.FileOutputStream;
16 import java.io.IOException;
17 import java.text.DecimalFormat;
18 import java.text.SimpleDateFormat;
19 import java.util.ArrayList;
20 import java.util.Calendar;
21 import java.util.Collections;
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Iterator;
26 import java.util.List;
28 import java.util.Scanner;
31 import org.apache.lucene.index.IndexWriter;
32 import org.apache.lucene.store.FSDirectory;
33 import org.hibernate.Criteria;
34 import org.hibernate.Hibernate;
35 import org.hibernate.criterion.DetachedCriteria;
36 import org.hibernate.criterion.Order;
37 import org.hibernate.criterion.Restrictions;
38 import org.hibernate.proxy.HibernateProxy;
39 import org.jfree.chart.ChartFactory;
40 import org.jfree.chart.JFreeChart;
41 import org.jfree.chart.plot.PlotOrientation;
42 import org.jfree.data.xy.XYSeries;
43 import org.jfree.data.xy.XYSeriesCollection;
44 import org.splat.common.properties.MessageKeyEnum;
45 import org.splat.dal.bo.kernel.Relation;
46 import org.splat.dal.bo.kernel.User;
47 import org.splat.dal.bo.som.ActorRelation;
48 import org.splat.dal.bo.som.ContributorRelation;
49 import org.splat.dal.bo.som.DescriptionAttribute;
50 import org.splat.dal.bo.som.DocumentType;
51 import org.splat.dal.bo.som.IDBuilder;
52 import org.splat.dal.bo.som.KnowledgeElement;
53 import org.splat.dal.bo.som.ProgressState;
54 import org.splat.dal.bo.som.ProjectElement;
55 import org.splat.dal.bo.som.Publication;
56 import org.splat.dal.bo.som.ReaderRelation;
57 import org.splat.dal.bo.som.Scenario;
58 import org.splat.dal.bo.som.SimulationContext;
59 import org.splat.dal.bo.som.Study;
60 import org.splat.dal.bo.som.ValidationCycle;
61 import org.splat.dal.bo.som.ValidationCycleRelation;
62 import org.splat.dal.bo.som.ValidationStep;
63 import org.splat.dal.bo.som.Visibility;
64 import org.splat.dal.bo.som.Study.Properties;
65 import org.splat.dal.bo.som.ValidationCycle.Actor;
66 import org.splat.dal.dao.som.DescriptionAttributeDAO;
67 import org.splat.dal.dao.som.DocumentDAO;
68 import org.splat.dal.dao.som.DocumentTypeDAO;
69 import org.splat.dal.dao.som.IDBuilderDAO;
70 import org.splat.dal.dao.som.PublicationDAO;
71 import org.splat.dal.dao.som.ScenarioDAO;
72 import org.splat.dal.dao.som.StudyDAO;
73 import org.splat.dal.dao.som.UsedByRelationDAO;
74 import org.splat.dal.dao.som.ValidationCycleDAO;
75 import org.splat.exception.BusinessException;
76 import org.splat.exception.IncompatibleDataException;
77 import org.splat.exception.InvalidParameterException;
78 import org.splat.kernel.InvalidPropertyException;
79 import org.splat.kernel.MismatchException;
80 import org.splat.kernel.MissedPropertyException;
81 import org.splat.kernel.MultiplyDefinedException;
82 import org.splat.log.AppLogger;
83 import org.splat.service.dto.DocToCompareDTO;
84 import org.splat.service.dto.DocumentDTO;
85 import org.splat.service.dto.StudyFacadeDTO;
86 import org.splat.service.dto.UserDTO;
87 import org.splat.service.technical.IndexService;
88 import org.splat.service.technical.ProjectSettingsService;
89 import org.splat.service.technical.ProjectSettingsServiceImpl;
90 import org.splat.service.technical.RepositoryService;
91 import org.splat.service.technical.ProjectSettingsService.Step;
92 import org.splat.som.Revision;
93 import org.splat.util.BeanHelper;
94 import org.springframework.transaction.annotation.Transactional;
96 import com.lowagie.text.Document;
97 import com.lowagie.text.DocumentException;
98 import com.lowagie.text.Rectangle;
99 import com.lowagie.text.pdf.DefaultFontMapper;
100 import com.lowagie.text.pdf.PdfContentByte;
101 import com.lowagie.text.pdf.PdfTemplate;
102 import com.lowagie.text.pdf.PdfWriter;
105 * This class defines all methods for creation, modification the study.
107 * @author Maria KRUCHININA
110 public class StudyServiceImpl implements StudyService {
113 * logger for the service.
115 public final static AppLogger LOG = AppLogger
116 .getLogger(StudyServiceImpl.class);
118 * "studyId" parameter name.
120 public final static String PARAM_STUDY_ID = "studyId";
123 * Injected index service.
125 private IndexService _indexService;
128 * Injected step service.
130 private StepService _stepService;
133 * Injected project service.
135 private ProjectSettingsService _projectSettings;
138 * Injected project element service.
140 private ProjectElementService _projectElementService;
143 * Injected study DAO.
145 private StudyDAO _studyDAO;
148 * Injected usedBy relations DAO.
150 private UsedByRelationDAO _usedByRelationDAO;
153 * Injected scenario DAO.
155 private ScenarioDAO _scenarioDAO;
158 * Injected validation cycle DAO.
160 private ValidationCycleDAO _validationCycleDAO;
163 * Injected IDBuilder DAO.
165 private IDBuilderDAO _iDBuilderDAO;
168 * Injected document type service.
170 private DocumentTypeService _documentTypeService;
173 * Injected user service.
175 private UserService _userService;
178 * Injected publication DAO.
180 private PublicationDAO _publicationDAO;
183 * Injected repository service.
185 private RepositoryService _repositoryService;
188 * Injected document DAO.
190 private DocumentDAO _documentDAO;
193 * Injected description attribute DAO.
195 private DescriptionAttributeDAO _descriptionAttributeDAO;
197 * Injected document type DAO.
199 private DocumentTypeDAO _documentTypeDAO;
204 * @see org.splat.service.StudyService#selectStudy(long)
207 public Study selectStudy(final long index) {
208 Study result = getStudyDAO().get(index);
209 if (result != null) {
210 loadWorkflow(result);
218 * @see org.splat.service.StudyService#removeStudy(long)
221 public void removeStudy(final Long index) {
222 Study study = getStudyDAO().get(index);
223 Set<org.splat.dal.bo.som.Document> docums = new HashSet<org.splat.dal.bo.som.Document>();
225 // Select all documents published in the study and study's scenarios.
226 DetachedCriteria query = DetachedCriteria.forClass(
227 Publication.class, "pub");
229 .createCriteria("pub.owner", "projelem",
231 .createAlias("projelem.owner", "study", Criteria.LEFT_JOIN)
234 .or(Restrictions.eq("projelem.rid", index),
235 Restrictions.eq("study.rid", index)))
236 .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
238 if (LOG.isDebugEnabled()) {
239 LOG.debug("Find study documents: " + query.toString());
241 for (Publication pub : getPublicationDAO().getFilteredList(query)) {
242 docums.add(pub.value());
243 // Find also all previous versions of the document
244 for (org.splat.dal.bo.som.Document prev = pub.value()
245 .getPreviousVersion(); prev != null; prev = prev
246 .getPreviousVersion()) {
251 // Delete the study with its relations, scenarios and publications
252 getStudyDAO().delete(study);
254 // Remove all relations of study documents
255 for (org.splat.dal.bo.som.Document doc : docums) {
256 LOG.debug("Found doc: " + doc.getTitle() + " ["
257 + doc.getReference() + "]" + " [" + doc.getRid() + "]");
258 doc.getAllRelations().clear();
260 getDocumentDAO().flush();
262 // Remove all documents of the study
263 for (org.splat.dal.bo.som.Document doc : docums) {
264 LOG.debug("Remove doc: " + doc.getTitle() + " ["
265 + doc.getReference() + "]" + " [" + doc.getRid() + "]");
266 getDocumentDAO().delete(doc);
272 * Get study by its reference.
275 * the study reference
276 * @return found study or null
278 @Transactional(readOnly = true)
279 public Study selectStudy(final String refid) {
280 Study result = getStudyDAO().findByCriteria(
281 Restrictions.eq("sid", refid));
282 loadWorkflow(result);
289 * @see org.splat.service.StudyService#createStudy(org.splat.dal.bo.som.Study.Properties)
292 public Study createStudy(final Study.Properties sprop)
293 throws MissedPropertyException, InvalidPropertyException,
294 MultiplyDefinedException {
295 sprop.setReference(getProjectSettings().getReferencePattern());
296 Study study = new Study(sprop);
298 buildReference(study);
299 getStudyDAO().create(study);
301 // IndexService lucin = getIndex();
303 // } catch (IOException error) {
304 // LOG.error("Unable to index the study '" + study.getIndex()
305 // + "', reason:", error);
306 // // Continue and try to index later
314 * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext.Properties)
317 public SimulationContext addProjectContext(final Study aStudy,
318 final SimulationContext.Properties cprop)
319 throws MissedPropertyException, InvalidPropertyException,
320 MultiplyDefinedException {
321 SimulationContext added = getStepService().addSimulationContext(
322 getProjectElementService().getFirstStep(aStudy), cprop);
330 * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
333 public SimulationContext addProjectContext(final Study aStudy,
334 final SimulationContext context) {
335 SimulationContext added = getStepService().addSimulationContext(
336 getProjectElementService().getFirstStep(aStudy), context);
344 * @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User)
347 public boolean addContributor(final Study aStudy, final User user) {
348 List<User> contributors = getModifiableContributors(aStudy); // Initializes contributor
350 if (contributors.contains(user)) {
354 // Remove user from readers
356 List<UserDTO> readers = getReaders(aStudy.getIndex());
357 for (UserDTO reader : readers) {
358 if (reader.getIndex() == user.getIndex()) {
359 // user must be the actual user in the relationship object in the aStudy object for this to work
360 aStudy.removeRelation(ReaderRelation.class, user);
363 } catch (InvalidParameterException e) {
364 LOG.error(e.getMessage(), e);
367 boolean absent = getModifiableActors(aStudy).add(user); // User may already be a reviewer or an approver
369 aStudy.addRelation(new ContributorRelation(aStudy, user));
371 update(aStudy); // Else, useless to re-index the study
379 * @see org.splat.service.StudyService#update(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Study.Properties)
382 public boolean update(final Study aStudy, final Properties sprop)
383 throws InvalidPropertyException {
384 if (sprop.getTitle() != null) {
385 aStudy.setTitle(sprop.getTitle());
387 if (sprop.getSummary() != null) {
388 aStudy.setAttribute(new DescriptionAttribute(aStudy, sprop
391 // TODO: To be completed
392 return update(aStudy);
396 * Check if the document is published in the study.
402 * @return true if the document is published in the study
405 * private boolean publishes(final Study aStudy, final Document doc) { if (!aStudy.publishes(doc)) { Scenario[] scene =
406 * aStudy.getScenarii(); for (int i = 0; i < scene.length; i++) { if (scene[i].publishes(doc)) { return true; } } } return false; }
411 * @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[])
414 public boolean removeContributor(final Study aStudy, final User... users) {
415 List<User> contributors = getModifiableContributors(aStudy); // Initializes contributor
416 Boolean done = false;
417 for (User user : users) {
418 if (contributors.contains(user)) {
419 aStudy.removeRelation(ContributorRelation.class, user);
420 contributors.remove(user);
433 * @see org.splat.service.StudyService#removeProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
436 public boolean removeProjectContext(final Study aStudy,
437 final SimulationContext context) {
438 boolean done = getStepService().removeSimulationContext(
439 getProjectElementService().getFirstStep(aStudy), context);
447 * @see org.splat.service.StudyService#setValidationCycle(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.DocumentType,
448 * org.splat.dal.bo.som.ValidationCycle.Properties)
451 public void setValidationCycle(final Study aStudyDTO,
452 final DocumentType type, final ValidationCycle.Properties vprop) {
453 Map<String, ValidationCycle> validactor = aStudyDTO
454 .getValidationCycles();
455 if (validactor == null) {
456 setShortCuts(aStudyDTO); // Initializes validactor and actor
459 Study aStudy = selectStudy(aStudyDTO.getIndex());
461 String cname = type.getName();
462 ValidationCycle cycle = validactor.get(cname);
464 if (cycle != null && cycle.isAssigned()) {
465 resetActors(cycle, vprop);
468 cycle = new ValidationCycle(aStudy, vprop.setDocumentType(type));
470 getValidationCycleDAO().create(cycle); // RKV
472 ValidationCycleRelation link = cycle.getContext();
473 aStudy.addRelation(link);
474 getValidationCycleDAO().flush();
475 aStudyDTO.getAllRelations().add(link); // RKV
477 validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default,
478 } catch (BusinessException error) {
479 LOG.error("Unable to create validation cycle, reason:", error);
483 resetActorsShortCut(aStudyDTO);
484 update(aStudy); // Re-index the study, just in case
490 * @see org.splat.service.StudyService#generateLocalIndex(org.splat.dal.bo.som.Study)
493 public int generateLocalIndex(final Study aStudy) {
494 aStudy.setLastLocalIndex(aStudy.getLastLocalIndex() + 1);
495 return aStudy.getLastLocalIndex();
499 * Promotes this study from In-Work to In-Draft then In-Check and APPROVED <BR>
500 * states. This function takes into account statuses of final result<BR>
501 * documents of the study.
505 * @return true if the promotion succeeded.
508 public boolean promote(final Study aStudy) {
510 ValidationCycle cycle = getValidationCycleOf(aStudy,
511 getStudyResultType(aStudy));
513 if (aStudy.getProgressState() == ProgressState.inWORK
514 && cycle.enables(ValidationStep.REVIEW)
515 && canBePromoted(aStudy)) {
516 aStudy.setProgressState(ProgressState.inDRAFT);
517 } else if (((!cycle.enables(ValidationStep.REVIEW) && ((aStudy
518 .getProgressState() == ProgressState.inWORK) || (aStudy
519 .getProgressState() == ProgressState.inDRAFT))) || (cycle
520 .enables(ValidationStep.REVIEW) && (aStudy.getProgressState() == ProgressState.inDRAFT)))
521 && canBeReviewed(aStudy)) {
522 aStudy.setProgressState(ProgressState.inCHECK);
523 Revision myvers = new Revision(aStudy.getVersion());
524 if (myvers.isMinor()) {
525 aStudy.setVersion(myvers.incrementAs(aStudy.getProgressState())
528 } else if (aStudy.getProgressState() == ProgressState.inCHECK
529 && canBeApproved(aStudy)) {
530 aStudy.setProgressState(ProgressState.APPROVED);
531 updateKnowledgeElementsState(aStudy);
536 res = update(aStudy);
543 * Demotes this study from In-Check or In-Draft to In-Work states.
547 * @return true if the demotion succeeded.
550 public boolean demote(final Study aStudy) {
553 if (aStudy.getProgressState() == ProgressState.inCHECK
554 || aStudy.getProgressState() == ProgressState.inDRAFT) {
555 aStudy.setProgressState(ProgressState.inWORK);
556 res = update(aStudy);
564 * Moves this study from the Private to the Public area of the repository.
568 * @return true if the move succeeded.
572 public boolean moveToPublic(final Study aStudy) {
573 boolean isOk = false;
574 if (aStudy.getVisibility() == Visibility.PRIVATE) {
575 aStudy.setVisibility(Visibility.PUBLIC);
576 if (update(aStudy)) {
577 isOk = updateKnowledgeElementsState(aStudy); // If fails, the database roll-back is under responsibility of the caller
584 * Moves this study from the Public to the Private area of the repository.
588 * @return true if the move succeeded.
591 public boolean moveToPrivate(final Study aStudy) {
592 boolean isOk = false;
593 if (aStudy.getVisibility() == Visibility.PUBLIC) {
594 aStudy.setVisibility(Visibility.PRIVATE);
595 if (update(aStudy)) {
596 isOk = updateKnowledgeElementsState(aStudy); // If fails, the database roll-back is under responsibility of the caller
603 * Update a study in the database.
606 * the study to update
607 * @return true if the study is updated successfully
609 private boolean update(final Study aStudy) {
610 boolean isOk = false;
612 getStudyDAO().merge(aStudy); // Update of relational base
613 setShortCuts(aStudy); // RKV: initialize transient actors set
614 // RKV: getIndex().update(aStudy); // Update of Lucene index
616 } catch (Exception e) {
617 LOG.error("STD-000001", e, aStudy.getIndex(), e.getMessage());
623 * Build reference for the study. The reference of the study is stored as a new reference pattern (IDBuilder).
627 * @return true if reference building is succeded
630 private boolean buildReference(final Study aStudy) {
631 String pattern = aStudy.getReference(); // The study being supposed just created, its reference is the reference pattern
632 IDBuilder tool = selectIDBuilder(aStudy.getDate());
634 tool = new IDBuilder(aStudy.getDate());
635 getIDBuilderDAO().create(tool);
637 aStudy.setReference(buildReference(tool, pattern, aStudy));
642 * Build reference for the study. The reference of the study is stored as a new reference pattern (IDBuilder).
649 * the reference pattern
650 * @return true if reference building is succeded
653 public String buildReference(final IDBuilder aBuilder,
654 final String pattern, final Study study) {
655 char[] format = pattern.toCharArray();
656 char[] ref = new char[80]; // Better evaluate the length of the generated string
657 int next = aBuilder.getBase() + 1;
660 for (int i = 0; i < format.length; i++) {
662 // Insertion of attribute values
663 if (format[i] == '%') {
666 if (format[i] == 'y') { // Insertion of year in format 2 (e.g. 09) or 4 (e.g. 2009) digits
668 while (format[i] == 'y') {
670 if (i == format.length) {
674 SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); // RKV: NOPMD: TODO: Use locale here?
675 String year = tostring.format(study.getDate());
676 year = year.substring(4 - (i - n), 4); // 4-(i-n) must be equal to either 0 or 2
677 for (int j = 0; j < year.length(); j++) {
678 ref[count] = year.charAt(j);
681 i -= 1; // Back to the last 'y' character
682 } else if (format[i] == '0') { // Insertion of the index
684 while (format[i] == '0') {
686 if (i == format.length) {
690 DecimalFormat tostring = new DecimalFormat(pattern
692 String number = tostring.format(next);
693 for (int j = 0; j < number.length(); j++) {
694 ref[count] = number.charAt(j);
697 i -= 1; // Back to the last '0' character
699 // Keep the character
701 ref[count] = format[i];
705 // Incrementation of the number of study
706 aBuilder.setBase(next);
707 getIDBuilderDAO().update(aBuilder);
708 return String.copyValueOf(ref, 0, count);
712 * Find an id builder by date.
716 * @return found id builder
718 private IDBuilder selectIDBuilder(final Date date) {
719 Calendar aDate = Calendar.getInstance();
721 return getIDBuilderDAO().findByCriteria(
722 Restrictions.eq("cycle", aDate.get(Calendar.YEAR)));
726 * Fill transient collection ModifiableActors of the study.
731 private void resetActorsShortCut(final Study aStudy) {
732 getModifiableActors(aStudy).clear();
733 // Get all actors involved in validation cycles
734 for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
735 .values().iterator(); i.hasNext();) {
736 ValidationCycle cycle = i.next();
737 User[] user = cycle.getAllActors();
738 for (int j = 0; j < user.length; j++) {
739 getModifiableActors(aStudy).add(user[j]);
742 // Get all other actors
743 for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
745 Relation link = i.next();
746 Class<?> kindof = link.getClass().getSuperclass();
747 if (!kindof.equals(ActorRelation.class)) {
750 getModifiableActors(aStudy).add(((ActorRelation) link).getTo());
755 * Update knowledge elements states.
759 * @return true if succeeded
761 private boolean updateKnowledgeElementsState(final Study aStudy) {
762 for (Scenario scenario : aStudy.getScenariiList()) {
763 for (KnowledgeElement element : scenario.getAllKnowledgeElements()) {
764 element.setProgressState(aStudy.getProgressState());
771 * Get lucene index service. Create a lucene index if it does not exist.
773 * @return index service
774 * @throws IOException
775 * if error occurs during lucene index creation
777 private IndexService getIndex() throws IOException {
778 IndexService lucin = getIndexService();
779 if (IndexWriter.isLocked(FSDirectory.open(getRepositoryService()
780 .getRepositoryIndexDirectory()))) {
781 IndexWriter.unlock(FSDirectory.open(getRepositoryService()
782 .getRepositoryIndexDirectory()));
784 if (!lucin.exists()) {
785 lucin.create(); // Happens when re-indexing all studies
791 * Create a new validation cycle for documents of the given study.
796 * the cycle description
797 * @return the new validation cycle
799 protected ValidationCycle createValidationCycle(
801 final ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
802 Actor[] actype = cycle.getActorTypes();
803 User.Properties uprop = new User.Properties();
805 ValidationCycle aValidationCycle = new ValidationCycle();
806 aValidationCycle.setDocumentType(getDocumentTypeService().selectType(
807 cycle.getName())); // Null in case of default validation cycle
808 // context = new ValidationCycleRelation(from, vprop);
809 // RKV aValidationCycle.context = null; // Validation cycle defined in the workflow
810 for (int i = 0; i < actype.length; i++) {
812 if (actype[i] != null) {
814 if (actype[i] == Actor.manager) {
815 actor = from.getAuthor();
816 } else if (actype[i] == Actor.Nx1) {
817 List<User> manager = getUserService().selectUsersWhere(
818 uprop.setOrganizationName("Nx1"));
819 if (manager.size() == 1) {
820 actor = manager.get(0);
822 } else if (actype[i] == Actor.Nx2) {
823 List<User> manager = getUserService().selectUsersWhere(
824 uprop.setOrganizationName("Nx2"));
825 if (manager.size() == 1) {
826 actor = manager.get(0);
828 } else { /* Actor.customer */
829 actor = from.getAuthor();
830 // TODO: Get the customer of the study, if exists
832 } catch (Exception e) { // Should not happen
837 aValidationCycle.setReviewer(actor);
839 aValidationCycle.setApprover(actor);
841 aValidationCycle.setSignatory(actor);
844 return aValidationCycle;
848 * Remove a validation step from the validation cycle.
850 * @param aValidationCycle
851 * the validation cycle
853 * the validation step to remove
856 protected void remove(final ValidationCycle aValidationCycle,
857 final ValidationStep step) {
858 if (step == ValidationStep.REVIEW) {
859 aValidationCycle.setReviewer(null);
860 } else if (step == ValidationStep.APPROVAL) {
861 aValidationCycle.setApprover(null);
862 } else if (step == ValidationStep.ACCEPTANCE
863 || step == ValidationStep.REFUSAL) {
864 aValidationCycle.setSignatory(null);
866 if (aValidationCycle.isSaved()) {
867 getValidationCycleDAO().update(aValidationCycle);
872 * Reset actors for the validation cycle.
874 * @param aValidationCycle
875 * the validation cycle to update
877 * new validation cycle properties containing new actors
880 public void resetActors(final ValidationCycle aValidationCycle,
881 final ValidationCycle.Properties vprop) {
882 aValidationCycle.setPublisher(vprop.getPublisher()); // May be null
883 aValidationCycle.setReviewer(vprop.getReviewer()); // May be null
884 aValidationCycle.setApprover(vprop.getApprover()); // May be null
885 aValidationCycle.setSignatory(vprop.getSignatory()); // May be null
886 if (aValidationCycle.isSaved()) {
887 getValidationCycleDAO().merge(aValidationCycle);
892 * Set actor for the given validation cycle and validation step.
894 * @param aValidationCycle
895 * the validation cycle
897 * the validation step
902 protected void setActor(final ValidationCycle aValidationCycle,
903 final ValidationStep step, final User actor) {
904 if (step == ValidationStep.PROMOTION) {
905 aValidationCycle.setPublisher(actor);
906 } else if (step == ValidationStep.REVIEW) {
907 aValidationCycle.setReviewer(actor);
908 } else if (step == ValidationStep.APPROVAL) {
909 aValidationCycle.setApprover(actor);
910 } else if (step == ValidationStep.ACCEPTANCE
911 || step == ValidationStep.REFUSAL) {
912 aValidationCycle.setSignatory(actor);
914 if (aValidationCycle.isSaved()) {
915 getValidationCycleDAO().update(aValidationCycle);
920 * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
924 * @return the actors of this study
925 * @see #hasActor(User)
927 public Set<User> getActors(final Study aStudy) {
928 if (aStudy.getActor() == null) {
929 setShortCuts(aStudy);
931 return Collections.unmodifiableSet(aStudy.getActor());
935 * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
939 * @return the modifiable set of actors of this study
940 * @see #hasActor(User)
942 public Set<User> getModifiableActors(final Study aStudy) {
943 if (aStudy.getActor() == null) {
944 setShortCuts(aStudy);
946 return aStudy.getActor();
950 * Returns unmodifiable initialized transient list of contributors of this study.
954 * @return the unmodifiable not null transient list of contributors of this study
956 public List<User> getContributors(final Study aStudy) {
957 if (aStudy.getContributor() == null) {
958 setShortCuts(aStudy);
960 return Collections.unmodifiableList(aStudy.getContributor()); // May be empty
964 * Returns modifiable initialized transient list of contributors of this study.
968 * @return the modifiable not null transient list of contributors of this study
970 public List<User> getModifiableContributors(final Study aStudy) {
971 if (aStudy.getContributor() == null) {
972 setShortCuts(aStudy);
974 return aStudy.getContributor(); // May be empty
978 * Returns the validation cycle of the given document type.
983 * the document type being subject of validation
984 * @return the validation cycle of the document, or null if not defined.
986 public ValidationCycle getValidationCycleOf(final Study aStudy,
987 final DocumentType type) {
988 ValidationCycle result = null;
989 if (aStudy != null) {
990 if (aStudy.getValidationCycles() == null
991 || aStudy.getValidationCycles().isEmpty()) {
992 setShortCuts(aStudy);
995 result = aStudy.getValidationCycles().get(type.getName());
998 if ((result == null) && (aStudy != null)) {
999 if ((type == null) || type.isStepResult()) {
1000 result = aStudy.getValidationCycles().get("default"); // "default" validation cycle defined in the configuration, if exist
1002 if (result == null) {
1003 result = aStudy.getValidationCycles().get("built-in");
1010 * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
1015 * the user to look for
1016 * @return true if the given user is actor of this study.
1019 public boolean hasActor(final Study aStudy, final User user) {
1023 for (Iterator<User> i = getActors(aStudy).iterator(); i.hasNext();) {
1024 User involved = i.next();
1025 if (involved.equals(user)) {
1033 * Checks if the given user participates to this study. The Study staff includes the author and contributors.
1038 * the user to look for
1039 * @return true if the given user is actor of this study.
1040 * @see #getContributors()
1042 public boolean isStaffedBy(final Study aStudy, final User user) {
1046 if (aStudy == null) {
1049 if (aStudy.getAuthor() == null) {
1052 if (aStudy.getAuthor().equals(user)) {
1055 for (Iterator<User> i = getContributors(aStudy).iterator(); i.hasNext();) {
1056 if (i.next().equals(user)) {
1064 * Initialize shortcuts of the study as its transient collections.
1069 public void loadWorkflow(final Study aStudy) {
1070 setShortCuts(aStudy);
1074 * Initialize shortcuts of the study as its transient collections.
1079 public void setShortCuts(final Study aStudy) {
1080 aStudy.getContributor().clear();
1081 aStudy.getValidationCycles().clear();
1082 aStudy.getActor().clear();
1084 // Get the contributors
1085 for (Iterator<Relation> i = aStudy.getRelations(
1086 ContributorRelation.class).iterator(); i.hasNext();) {
1087 ContributorRelation link = (ContributorRelation) i.next();
1088 aStudy.getContributor().add(link.getTo());
1090 // Get the validation cycles specific to this study
1091 for (Iterator<Relation> i = aStudy.getRelations(
1092 ValidationCycleRelation.class).iterator(); i.hasNext();) {
1093 ValidationCycleRelation link = (ValidationCycleRelation) i.next();
1094 aStudy.getValidationCycles().put(link.getDocumentType().getName(),
1095 link.getTo()); // The associated document type is necessarily not null in this
1098 // Get the validation cycles coming from the configured workflow and not overridden in this study
1099 for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i = getProjectSettings()
1100 .getAllValidationCycles().iterator(); i.hasNext();) {
1101 ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i
1103 String type = cycle.getName();
1104 if (!aStudy.getValidationCycles().containsKey(type)) {
1105 aStudy.getValidationCycles().put(type,
1106 createValidationCycle(aStudy, cycle));
1109 // Get all corresponding actors
1110 for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
1111 .values().iterator(); i.hasNext();) {
1112 ValidationCycle cycle = i.next();
1113 User[] user = cycle.getAllActors();
1114 for (int j = 0; j < user.length; j++) {
1115 aStudy.getActor().add(user[j]);
1118 // Get all other actors
1119 for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
1121 Relation link = i.next();
1122 Class<?> kindof = link.getClass().getSuperclass();
1123 if (!kindof.equals(ActorRelation.class)) {
1126 aStudy.getActor().add(((ActorRelation) link).getTo());
1134 * @see org.splat.service.StudyService#markStudyAsReference(org.splat.dal.bo.som.Study)
1137 public boolean markStudyAsReference(final Study aStudy) {
1138 boolean res = false;
1139 if (aStudy.getProgressState() == ProgressState.APPROVED) {
1140 aStudy.setMarkreference(1);
1141 aStudy.setProgressState(ProgressState.TEMPLATE);
1142 res = updateKnowledgeElementsState(aStudy);
1143 getStudyDAO().merge(aStudy);
1152 * @see org.splat.service.StudyService#removeStudyAsReference(org.splat.dal.bo.som.Study)
1155 public void removeStudyAsReference(final Study aStudy) {
1156 aStudy.setMarkreference(0);
1157 aStudy.setProgressState(ProgressState.APPROVED);
1158 updateKnowledgeElementsState(aStudy);
1159 getStudyDAO().merge(aStudy);
1165 * @see org.splat.service.StudyService#getDescription(java.lang.Long)
1168 @Transactional(readOnly = true)
1169 public String getDescription(final Long studyId)
1170 throws InvalidParameterException {
1171 if (studyId == null) {
1172 throw new InvalidParameterException(PARAM_STUDY_ID, "null");
1174 Study study = _studyDAO.get(studyId);
1175 if (study == null) {
1176 throw new InvalidParameterException(PARAM_STUDY_ID, studyId
1179 return study.getDescription();
1185 * @see org.splat.service.StudyService#setDescription(java.lang.Long, java.lang.String)
1188 public void setDescription(final Long studyId, final String descriptionText)
1189 throws InvalidParameterException {
1190 if (studyId == null) {
1191 throw new InvalidParameterException(PARAM_STUDY_ID, "null");
1193 Study study = _studyDAO.get(studyId);
1194 if (study == null) {
1195 throw new InvalidParameterException(PARAM_STUDY_ID, studyId
1198 study.setAttribute(new DescriptionAttribute(study, descriptionText));
1204 * @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long)
1207 public boolean removeDescription(final Long studyId)
1208 throws InvalidParameterException {
1209 if (studyId == null) {
1210 throw new InvalidParameterException(PARAM_STUDY_ID, String
1213 Study study = _studyDAO.get(studyId);
1214 if (study == null) {
1215 throw new InvalidParameterException(PARAM_STUDY_ID, String
1218 return study.removeAttribute(study
1219 .getAttribute(DescriptionAttribute.class));
1226 * @see org.splat.service.StudyService#compare(java.util.List)
1229 public String compare(final List<DocToCompareDTO> docsList,
1230 final String userName) throws IncompatibleDataException {
1232 String axis1Name = "";
1233 String axis2Name = "";
1234 String chartTitle = "";
1235 String resultPath = "";
1237 XYSeriesCollection dataset = new XYSeriesCollection();
1239 Iterator<DocToCompareDTO> docListIter = docsList.iterator();
1241 for (; docListIter.hasNext();) {
1243 DocToCompareDTO docDTO = docListIter.next();
1244 String pathToFile = docDTO.getPathToFile();
1245 File compDocFile = new File(pathToFile);
1247 resultPath = pathToFile.substring(0, pathToFile.indexOf("vault"))
1248 + "downloads" + File.separator + userName + File.separator
1249 + "ComparisonResult.pdf";
1251 XYSeries series = new XYSeries("Study: " + docDTO.getStudyTitle()
1252 + " Scenario: " + docDTO.getScenarioTitle() + " Document: "
1253 + docDTO.getDocumentTitle());
1255 // read the file and get points information.
1257 Scanner input = new Scanner(compDocFile);
1259 // get the title of the chart.
1260 if (input.hasNext()) {
1261 chartTitle = input.nextLine();
1264 // get the name of the axis.
1265 if (input.hasNext()) {
1266 String[] tokens = input.nextLine().split(",");
1268 if (tokens.length < 2) {
1269 throw new IncompatibleDataException(
1270 MessageKeyEnum.IDT_000001.toString());
1273 if ("".equals(axis1Name)) {
1274 axis1Name = tokens[0];
1275 } else if (!axis1Name.equals(tokens[0])) {
1276 LOG.debug("Axis must be the same for all documents");
1277 throw new IncompatibleDataException(
1278 MessageKeyEnum.IDT_000001.toString());
1281 if ("".equals(axis2Name)) {
1282 axis2Name = tokens[1];
1283 } else if (!axis2Name.equals(tokens[1])) {
1284 LOG.debug("Axis must be the same for all documents");
1285 throw new IncompatibleDataException(
1286 MessageKeyEnum.IDT_000001.toString());
1290 // Get the XY points series.
1291 while (input.hasNext()) {
1293 String currentString = input.nextLine();
1295 if (!("".equals(currentString))) {
1296 String[] tokens = currentString.split(" ");
1297 series.add(Double.valueOf(tokens[0]), Double
1298 .valueOf(tokens[1]));
1303 dataset.addSeries(series);
1305 } catch (FileNotFoundException e) {
1306 LOG.error("Sorry, the file is not found.", e);
1310 JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // Title
1311 axis1Name, // x-axis Label
1312 axis2Name, // y-axis Label
1314 PlotOrientation.VERTICAL, // Plot Orientation
1315 true, // Show Legend
1316 true, // Use tooltips
1317 false // Configure chart to generate URLs?
1320 // export to PDF - file.
1323 Rectangle pagesize = new Rectangle(x, y);
1324 Document document = new Document(pagesize, 50, 50, 50, 50);
1327 File resFile = new File(resultPath);
1328 File resFolder = new File(resultPath.substring(0, resultPath
1329 .lastIndexOf(File.separator)));
1331 writer = PdfWriter.getInstance(document, new FileOutputStream(
1335 PdfContentByte cb = writer.getDirectContent();
1336 PdfTemplate tp = cb.createTemplate(x, y);
1337 Graphics2D g2 = tp.createGraphics(x, y, new DefaultFontMapper());
1338 chart.draw(g2, new java.awt.Rectangle(x, y));
1340 cb.addTemplate(tp, 0, 0);
1343 } catch (FileNotFoundException e) {
1344 LOG.error("Sorry, the file is not found.", e);
1345 } catch (DocumentException e) {
1346 LOG.error("Sorry, the DocumentException is thrown.", e);
1355 * @see org.splat.service.StudyService#getReaders(long)
1357 @Transactional(readOnly = true)
1358 public List<UserDTO> getReaders(final long studyId)
1359 throws InvalidParameterException {
1360 Study aStudy = selectStudy(studyId);
1361 if (aStudy == null) {
1362 throw new InvalidParameterException(PARAM_STUDY_ID, String
1365 List<Relation> relations = aStudy.getRelations(ReaderRelation.class);
1366 List<UserDTO> result = new ArrayList<UserDTO>();
1367 for (Relation relation : relations) {
1368 result.add(BeanHelper.copyBean(relation.getTo(), UserDTO.class));
1370 return Collections.unmodifiableList(result);
1376 * @see org.splat.service.StudyService#addReader(long, long)
1379 public boolean addReader(final long studyId, final long userId)
1380 throws InvalidParameterException {
1381 Study aStudy = selectStudy(studyId);
1382 if (aStudy == null) {
1383 throw new InvalidParameterException(PARAM_STUDY_ID, String
1386 User user = _userService.selectUser(userId);
1388 throw new InvalidParameterException("userId", String
1392 for (Relation relation : aStudy.getRelations(ReaderRelation.class)) {
1393 if (user.equals(relation.getTo())) {
1397 aStudy.addRelation(new ReaderRelation(aStudy, user));
1405 * @see org.splat.service.StudyService#removeReader(long, long)
1408 public boolean removeReader(final long studyId, final long userId)
1409 throws InvalidParameterException {
1410 Study aStudy = selectStudy(studyId);
1411 if (aStudy == null) {
1412 throw new InvalidParameterException(PARAM_STUDY_ID, String
1415 User user = _userService.selectUser(userId);
1417 throw new InvalidParameterException("userId", String
1421 Relation relation = aStudy.removeRelation(ReaderRelation.class, user);
1423 return relation != null;
1427 * Get project settings.
1429 * @return Project settings service
1431 private ProjectSettingsService getProjectSettings() {
1432 return _projectSettings;
1436 * Set project settings service.
1438 * @param projectSettingsService
1439 * project settings service
1441 public void setProjectSettings(
1442 final ProjectSettingsService projectSettingsService) {
1443 _projectSettings = projectSettingsService;
1447 * Get the projectElementService.
1449 * @return the projectElementService
1451 public ProjectElementService getProjectElementService() {
1452 return _projectElementService;
1456 * Set the projectElementService.
1458 * @param projectElementService
1459 * the projectElementService to set
1461 public void setProjectElementService(
1462 final ProjectElementService projectElementService) {
1463 _projectElementService = projectElementService;
1467 * Get the stepService.
1469 * @return the stepService
1471 public StepService getStepService() {
1472 return _stepService;
1476 * Set the stepService.
1478 * @param stepService
1479 * the stepService to set
1481 public void setStepService(final StepService stepService) {
1482 _stepService = stepService;
1486 * Get the indexService.
1488 * @return the indexService
1490 public IndexService getIndexService() {
1491 return _indexService;
1495 * Set the indexService.
1497 * @param indexService
1498 * the indexService to set
1500 public void setIndexService(final IndexService indexService) {
1501 _indexService = indexService;
1507 * @return the studyDAO
1509 public StudyDAO getStudyDAO() {
1517 * the studyDAO to set
1519 public void setStudyDAO(final StudyDAO studyDAO) {
1520 _studyDAO = studyDAO;
1524 * Get the iDBuilderDAO.
1526 * @return the iDBuilderDAO
1528 public IDBuilderDAO getIDBuilderDAO() {
1529 return _iDBuilderDAO;
1533 * Set the iDBuilderDAO.
1536 * the iDBuilderDAO to set
1538 public void setIDBuilderDAO(final IDBuilderDAO builderDAO) {
1539 _iDBuilderDAO = builderDAO;
1543 * Get the scenarioDAO.
1545 * @return the scenarioDAO
1547 public ScenarioDAO getScenarioDAO() {
1548 return _scenarioDAO;
1552 * Set the scenarioDAO.
1554 * @param scenarioDAO
1555 * the scenarioDAO to set
1557 public void setScenarioDAO(final ScenarioDAO scenarioDAO) {
1558 _scenarioDAO = scenarioDAO;
1562 * Get the validationCycleDAO.
1564 * @return the validationCycleDAO
1566 public ValidationCycleDAO getValidationCycleDAO() {
1567 return _validationCycleDAO;
1571 * Set the validationCycleDAO.
1573 * @param validationCycleDAO
1574 * the validationCycleDAO to set
1576 public void setValidationCycleDAO(
1577 final ValidationCycleDAO validationCycleDAO) {
1578 _validationCycleDAO = validationCycleDAO;
1582 * Get the documentTypeService.
1584 * @return the documentTypeService
1586 public DocumentTypeService getDocumentTypeService() {
1587 return _documentTypeService;
1591 * Set the documentTypeService.
1593 * @param documentTypeService
1594 * the documentTypeService to set
1596 public void setDocumentTypeService(
1597 final DocumentTypeService documentTypeService) {
1598 _documentTypeService = documentTypeService;
1602 * Get the userService.
1604 * @return the userService
1606 public UserService getUserService() {
1607 return _userService;
1611 * Set the userService.
1613 * @param userService
1614 * the userService to set
1616 public void setUserService(final UserService userService) {
1617 _userService = userService;
1623 * @see org.splat.service.StudyService#getComparableStudies()
1625 @Transactional(readOnly = true)
1626 public List<StudyFacadeDTO> getComparableStudies(final long userId)
1627 throws MismatchException {
1628 // retrieve the number of the "Analyze the results" step
1629 List<Step> allSteps = _projectSettings.getAllSteps();
1630 Step theAnalyzeStep = null;
1631 for (Step step : allSteps) {
1632 if (step.getKey().equals("postprocessing")) {
1633 theAnalyzeStep = step;
1636 if (theAnalyzeStep == null) { // TODO: throw some other exception
1637 throw new MismatchException(
1638 "no step with key 'postprocessing' found."
1639 + "Probably, customization settings have been changed.");
1642 List<Publication> publications = _publicationDAO.getFilteredList(
1643 "mydoc", Restrictions.eq("step", Integer.valueOf(theAnalyzeStep
1646 // split retrieved publications into groups by studies and scenarios
1647 Map<Study, List<ProjectElement>> studyMap = new HashMap<Study, List<ProjectElement>>();
1648 Map<ProjectElement, List<Publication>> scenarioMap = new HashMap<ProjectElement, List<Publication>>();
1650 for (Publication publication : publications) {
1651 // filter out publications corresponding to a document of given step which is not a _result_ document
1652 if (!publication.value().getType().isResultOf(theAnalyzeStep)
1653 || !"srd".equals(publication.getSourceFile().getFormat())) {
1657 // check the study visibility to the user
1658 if (!isStaffedBy(publication.getOwnerStudy(), _userService
1659 .selectUser(userId))
1660 && Visibility.PUBLIC.equals(publication.getOwnerStudy()
1661 .getVisibility())) {
1665 Study study = publication.getOwnerStudy();
1666 ProjectElement scenario = publication.getOwner();
1668 Hibernate.initialize(scenario);
1669 if (scenario instanceof HibernateProxy) {
1670 scenario = (ProjectElement) ((HibernateProxy) scenario)
1671 .getHibernateLazyInitializer().getImplementation();
1674 if (!(scenario instanceof Scenario)) {
1675 throw new MismatchException(
1676 "publications from postprocessing step are supposed to have owner scenario");
1679 if (!studyMap.containsKey(study)) {
1680 studyMap.put(study, new ArrayList<ProjectElement>());
1683 if (!studyMap.get(study).contains(scenario)) {
1684 studyMap.get(study).add(scenario);
1687 if (!scenarioMap.containsKey(scenario)) {
1688 scenarioMap.put(scenario, new ArrayList<Publication>());
1690 scenarioMap.get(scenario).add(publication);
1693 // Create the result DTOs
1694 List<StudyFacadeDTO> result = new ArrayList<StudyFacadeDTO>();
1695 for (Study study : studyMap.keySet()) {
1697 StudyFacadeDTO studyDTO = new StudyFacadeDTO();
1698 studyDTO.setName(study.getTitle());
1699 studyDTO.setScenarios(new ArrayList<StudyFacadeDTO.ScenarioDTO>());
1700 result.add(studyDTO);
1702 for (ProjectElement scenario : studyMap.get(study)) {
1704 StudyFacadeDTO.ScenarioDTO scenarioDTO = new StudyFacadeDTO.ScenarioDTO();
1705 scenarioDTO.setName(scenario.getTitle());
1706 scenarioDTO.setDocs(new ArrayList<DocumentDTO>());
1707 studyDTO.getScenarios().add(scenarioDTO);
1709 for (Publication publication : scenarioMap.get(scenario)) {
1711 DocumentDTO documentDTO = new DocumentDTO();
1712 documentDTO.setId(publication.getIndex());
1713 documentDTO.setTitle(publication.value().getTitle());
1715 scenarioDTO.getDocs().add(documentDTO);
1723 * Get the publicationDAO.
1725 * @return the publicationDAO
1727 public PublicationDAO getPublicationDAO() {
1728 return _publicationDAO;
1732 * Set the publicationDAO.
1734 * @param publicationDAO
1735 * the publicationDAO to set
1737 public void setPublicationDAO(final PublicationDAO publicationDAO) {
1738 _publicationDAO = publicationDAO;
1742 * Get the repositoryService.
1744 * @return the repositoryService
1746 public RepositoryService getRepositoryService() {
1747 return _repositoryService;
1751 * Set the repositoryService.
1753 * @param repositoryService
1754 * the repositoryService to set
1756 public void setRepositoryService(final RepositoryService repositoryService) {
1757 _repositoryService = repositoryService;
1761 * Get the documentDAO.
1763 * @return the documentDAO
1765 public DocumentDAO getDocumentDAO() {
1766 return _documentDAO;
1770 * Set the documentDAO.
1772 * @param documentDAO
1773 * the documentDAO to set
1775 public void setDocumentDAO(final DocumentDAO documentDAO) {
1776 _documentDAO = documentDAO;
1780 * Get the descriptionAttributeDAO.
1782 * @return the descriptionAttributeDAO
1784 public DescriptionAttributeDAO getDescriptionAttributeDAO() {
1785 return _descriptionAttributeDAO;
1789 * Set the descriptionAttributeDAO.
1791 * @param descriptionAttributeDAO
1792 * the descriptionAttributeDAO to set
1794 public void setDescriptionAttributeDAO(
1795 final DescriptionAttributeDAO descriptionAttributeDAO) {
1796 _descriptionAttributeDAO = descriptionAttributeDAO;
1800 * Get the usedByRelationDAO.
1802 * @return the usedByRelationDAO
1804 public UsedByRelationDAO getUsedByRelationDAO() {
1805 return _usedByRelationDAO;
1809 * Set the usedByRelationDAO.
1811 * @param usedByRelationDAO
1812 * the usedByRelationDAO to set
1814 public void setUsedByRelationDAO(final UsedByRelationDAO usedByRelationDAO) {
1815 _usedByRelationDAO = usedByRelationDAO;
1821 * @see org.splat.service.StudyService#getStudyResultType(org.splat.dal.bo.som.Study)
1824 @Transactional(readOnly = true)
1825 public DocumentType getStudyResultType(final Study study) {
1826 DetachedCriteria query = DetachedCriteria.forClass(DocumentType.class)
1827 .addOrder(Order.desc("result"));
1828 return getDocumentTypeDAO().getFirstResult(query);
1832 * Get the documentTypeDAO.
1834 * @return the documentTypeDAO
1836 public DocumentTypeDAO getDocumentTypeDAO() {
1837 return _documentTypeDAO;
1841 * Set the documentTypeDAO.
1843 * @param documentTypeDAO
1844 * the documentTypeDAO to set
1846 public void setDocumentTypeDAO(final DocumentTypeDAO documentTypeDAO) {
1847 _documentTypeDAO = documentTypeDAO;
1853 * @see org.splat.service.StudyService#canBeApproved(org.splat.dal.bo.som.Study)
1856 @Transactional(readOnly = true)
1857 public boolean canBeApproved(final Study study) {
1858 return resultDocsAtLeast(study, ProgressState.APPROVED);
1864 * @see org.splat.service.StudyService#canBePromoted(org.splat.dal.bo.som.Study)
1867 @Transactional(readOnly = true)
1868 public boolean canBePromoted(final Study study) {
1870 if (study.getProgressState().compareTo(ProgressState.inDRAFT) < 0) {
1871 res = resultDocsAtLeast(study, ProgressState.inDRAFT);
1873 res = canBeReviewed(study);
1881 * @see org.splat.service.StudyService#canBeReviewed(org.splat.dal.bo.som.Study)
1884 @Transactional(readOnly = true)
1885 public boolean canBeReviewed(final Study study) {
1886 return resultDocsAtLeast(study, ProgressState.inCHECK);
1890 * Check that all result documents of the study are at least in the given state.
1893 * the study to check
1895 * the minimal acceptable state
1896 * @return true if study result documents have acceptable states
1898 private boolean resultDocsAtLeast(final Study study,
1899 final ProgressState state) {
1901 // Check that all study result documents have the state APPROVED or more.
1902 for (Publication pub : getProjectElementService().getLastStep(study)
1903 .getResultDocuments()) {
1904 res = pub.getProgressState().compareTo(state) >= 0;