1 /*****************************************************************************
5 * Creation date 02.10.2012
6 * @author Author: Maria KRUCHININA
8 *****************************************************************************/
10 package org.splat.service;
12 import java.io.IOException;
13 import java.text.DecimalFormat;
14 import java.text.SimpleDateFormat;
15 import java.util.Calendar;
16 import java.util.Collections;
17 import java.util.Date;
18 import java.util.Iterator;
19 import java.util.List;
23 import org.hibernate.criterion.Restrictions;
24 import org.splat.dal.bo.kernel.Relation;
25 import org.splat.dal.bo.kernel.User;
26 import org.splat.dal.bo.som.ActorRelation;
27 import org.splat.dal.bo.som.ContributorRelation;
28 import org.splat.dal.bo.som.DescriptionAttribute;
29 import org.splat.dal.bo.som.DocumentType;
30 import org.splat.dal.bo.som.IDBuilder;
31 import org.splat.dal.bo.som.KnowledgeElement;
32 import org.splat.dal.bo.som.ProgressState;
33 import org.splat.dal.bo.som.Publication;
34 import org.splat.dal.bo.som.Scenario;
35 import org.splat.dal.bo.som.SimulationContext;
36 import org.splat.dal.bo.som.Study;
37 import org.splat.dal.bo.som.Study.Properties;
38 import org.splat.dal.bo.som.ValidationCycle;
39 import org.splat.dal.bo.som.ValidationCycle.Actor;
40 import org.splat.dal.bo.som.ValidationCycleRelation;
41 import org.splat.dal.bo.som.ValidationStep;
42 import org.splat.dal.bo.som.Visibility;
43 import org.splat.dal.dao.som.DescriptionAttributeDAO;
44 import org.splat.dal.dao.som.DocumentDAO;
45 import org.splat.dal.dao.som.IDBuilderDAO;
46 import org.splat.dal.dao.som.PublicationDAO;
47 import org.splat.dal.dao.som.ScenarioDAO;
48 import org.splat.dal.dao.som.StudyDAO;
49 import org.splat.dal.dao.som.ValidationCycleDAO;
50 import org.splat.exception.InvalidParameterException;
51 import org.splat.kernel.InvalidPropertyException;
52 import org.splat.kernel.MissedPropertyException;
53 import org.splat.kernel.MultiplyDefinedException;
54 import org.splat.log.AppLogger;
55 import org.splat.service.technical.IndexService;
56 import org.splat.service.technical.ProjectSettingsService;
57 import org.splat.service.technical.ProjectSettingsServiceImpl;
58 import org.splat.service.technical.RepositoryService;
59 import org.splat.som.Revision;
60 import org.springframework.transaction.annotation.Transactional;
63 * This class defines all methods for creation, modification the study.
65 * @author Maria KRUCHININA
68 public class StudyServiceImpl implements StudyService {
71 * logger for the service.
73 public final static AppLogger LOG = AppLogger
74 .getLogger(StudyServiceImpl.class);
77 * Injected index service.
79 private IndexService _indexService;
82 * Injected step service.
84 private StepService _stepService;
87 * Injected project service.
89 private ProjectSettingsService _projectSettings;
92 * Injected project element service.
94 private ProjectElementService _projectElementService;
99 private StudyDAO _studyDAO;
102 * Injected scenario DAO.
104 private ScenarioDAO _scenarioDAO;
107 * Injected validation cycle DAO.
109 private ValidationCycleDAO _validationCycleDAO;
112 * Injected IDBuilder DAO.
114 private IDBuilderDAO _iDBuilderDAO;
117 * Injected document type service.
119 private DocumentTypeService _documentTypeService;
122 * Injected user service.
124 private UserService _userService;
127 * Injected publication DAO.
129 private PublicationDAO _publicationDAO;
132 * Injected repository service.
134 private RepositoryService _repositoryService;
137 * Injected document DAO.
139 private DocumentDAO _documentDAO;
142 * Injected description attribute DAO.
144 private DescriptionAttributeDAO _descriptionAttributeDAO;
149 * @see org.splat.service.StudyService#selectStudy(long)
152 public Study selectStudy(final long index) {
153 Study result = getStudyDAO().get(index);
154 loadWorkflow(result);
159 * Get study by its reference.
162 * the study reference
163 * @return found study or null
165 @Transactional(readOnly = true)
166 public Study selectStudy(final String refid) {
167 Study result = getStudyDAO().findByCriteria(
168 Restrictions.eq("sid", refid));
169 loadWorkflow(result);
176 * @see org.splat.service.StudyService#createStudy(org.splat.dal.bo.som.Study.Properties)
179 public Study createStudy(final Study.Properties sprop)
180 throws MissedPropertyException, InvalidPropertyException,
181 MultiplyDefinedException {
182 sprop.setReference(getProjectSettings().getReferencePattern());
183 Study study = new Study(sprop);
185 buildReference(study);
186 getStudyDAO().create(study);
188 IndexService lucin = getIndex();
190 } catch (IOException error) {
191 LOG.error("Unable to index the study '" + study.getIndex()
192 + "', reason:", error);
193 // Continue and try to index later
201 * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext.Properties)
204 public SimulationContext addProjectContext(final Study aStudy,
205 final SimulationContext.Properties cprop)
206 throws MissedPropertyException, InvalidPropertyException,
207 MultiplyDefinedException {
208 SimulationContext added = getStepService().addSimulationContext(
209 getProjectElementService().getFirstStep(aStudy), cprop);
217 * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
220 public SimulationContext addProjectContext(final Study aStudy,
221 final SimulationContext context) {
222 SimulationContext added = getStepService().addSimulationContext(
223 getProjectElementService().getFirstStep(aStudy), context);
231 * @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User)
233 public boolean addContributor(final Study aStudy, final User user) {
234 List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
235 for (Iterator<User> i = contributor.iterator(); i.hasNext();) {
236 User present = i.next();
237 if (present.equals(user)) {
241 boolean absent = getModifiableActors(aStudy).add(user); // User may already be a reviewer or an approver
243 aStudy.addRelation(new ContributorRelation(aStudy, user));
245 update(aStudy); // Else, useless to re-index the study
247 contributor.add(user);
252 * Moves this study from the Public to the Reference area of the repository. For being moved to the Reference area, the study must
253 * previously be approved.
257 * @return true if the move succeeded.
258 * @see #moveToPublic()
260 * @see Publication#approve(Date)
262 public boolean moveToReference(final Study aStudy) {
263 if (aStudy.getProgressState() != ProgressState.APPROVED) {
266 if (aStudy.getVisibility() != Visibility.PUBLIC) {
270 aStudy.setVisibility(Visibility.REFERENCE);
271 if (update(aStudy)) {
272 return updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller
280 * @see org.splat.service.StudyService#update(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Study.Properties)
282 public boolean update(final Study aStudy, final Properties sprop)
283 throws InvalidPropertyException {
284 if (sprop.getTitle() != null) {
285 aStudy.setTitle(sprop.getTitle());
287 if (sprop.getSummary() != null) {
288 aStudy.setAttribute(new DescriptionAttribute(aStudy, sprop
291 // TODO: To be completed
292 return update(aStudy);
296 * Check if the document is published in the study.
302 * @return true if the document is published in the study
304 /* private boolean publishes(final Study aStudy, final Document doc) {
305 if (!aStudy.publishes(doc)) {
306 Scenario[] scene = aStudy.getScenarii();
307 for (int i = 0; i < scene.length; i++) {
308 if (scene[i].publishes(doc)) {
319 * @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[])
321 public boolean removeContributor(final Study aStudy, final User... users) {
322 List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
323 Boolean done = false;
324 for (int i = 0; i < users.length; i++) {
325 User user = users[i];
326 for (Iterator<User> j = contributor.iterator(); j.hasNext();) {
327 User present = j.next();
328 if (!present.equals(user)) {
332 aStudy.removeRelation(ContributorRelation.class, user);
333 j.remove(); // Updates the contributor shortcut
347 * @see org.splat.service.StudyService#removeProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
349 public boolean removeProjectContext(final Study aStudy,
350 final SimulationContext context) {
351 boolean done = getStepService().removeSimulationContext(
352 getProjectElementService().getFirstStep(aStudy), context);
360 * @see org.splat.service.StudyService#setValidationCycle(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.DocumentType,
361 * org.splat.dal.bo.som.ValidationCycle.Properties)
364 public void setValidationCycle(final Study aStudyDTO, final DocumentType type,
365 final ValidationCycle.Properties vprop) {
366 Map<String, ValidationCycle> validactor = aStudyDTO.getValidationCycles();
367 if (validactor == null) {
368 setShortCuts(aStudyDTO); // Initializes validactor and actor
371 Study aStudy = selectStudy(aStudyDTO.getIndex());
373 String cname = type.getName();
374 ValidationCycle cycle = validactor.get(cname);
376 if (cycle != null && cycle.isAssigned()) {
377 resetActors(cycle, vprop);
380 cycle = new ValidationCycle(aStudy, vprop.setDocumentType(type));
382 getValidationCycleDAO().create(cycle); // RKV
384 ValidationCycleRelation link = cycle.getContext();
385 aStudy.addRelation(link);
386 aStudyDTO.getAllRelations().add(link); // RKV
388 validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default,
389 } catch (Exception error) {
390 LOG.error("Unable to re-index Knowledge Elements, reason:",
395 resetActorsShortCut(aStudyDTO);
396 update(aStudy); // Re-index the study, just in case
400 * Demotes this study from In-Check to In-Draft then In-Work states. This function is called internally when demoting the final result
401 * document of the study.
405 * @return true if the demotion succeeded.
407 public boolean demote(final Study aStudy) {
408 if (aStudy.getProgressState() == ProgressState.inCHECK) {
409 aStudy.setProgressState(ProgressState.inDRAFT);
410 } else if (aStudy.getProgressState() == ProgressState.inDRAFT) {
411 aStudy.setProgressState(ProgressState.inWORK);
415 return update(aStudy);
421 * @see org.splat.service.StudyService#generateLocalIndex(org.splat.dal.bo.som.Study)
424 public int generateLocalIndex(final Study aStudy) {
425 aStudy.setLastLocalIndex(aStudy.getLastLocalIndex() + 1);
426 return aStudy.getLastLocalIndex();
430 * Promotes this study from In-Work to In-Draft then In-Check and APPROVED states. This function is called internally when promoting the
431 * final result document of the study.
435 * @return true if the demotion succeeded.
438 public boolean promote(final Study aStudy) {
439 if (aStudy.getProgressState() == ProgressState.inWORK) {
440 aStudy.setProgressState(ProgressState.inDRAFT);
441 } else if (aStudy.getProgressState() == ProgressState.inDRAFT) {
442 aStudy.setProgressState(ProgressState.inCHECK);
443 Revision myvers = new Revision(aStudy.getVersion());
444 if (myvers.isMinor()) {
445 aStudy.setVersion(myvers.incrementAs(aStudy.getProgressState())
448 } else if (aStudy.getProgressState() == ProgressState.inCHECK) {
449 aStudy.setProgressState(ProgressState.APPROVED);
454 return update(aStudy);
458 * Moves this study from the Private to the Public area of the repository.
462 * @return true if the move succeeded.
466 public boolean moveToPublic(final Study aStudy) {
467 boolean isOk = false;
468 if (aStudy.getVisibility() == Visibility.PRIVATE) {
469 aStudy.setVisibility(Visibility.PUBLIC);
470 if (update(aStudy)) {
471 isOk = updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller
478 * Moves this study from the Public to the Private area of the repository.
482 * @return true if the move succeeded.
485 public boolean moveToPrivate(final Study aStudy) {
486 boolean isOk = false;
487 if (aStudy.getVisibility() == Visibility.PUBLIC) {
488 aStudy.setVisibility(Visibility.PRIVATE);
489 if (update(aStudy)) {
490 isOk = updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller
497 * Update a study in the database.
500 * the study to update
501 * @return true if the study is updated successfully
504 private boolean update(final Study aStudy) {
505 boolean isOk = false;
507 getStudyDAO().merge(aStudy); // Update of relational base
508 setShortCuts(aStudy); // RKV: initialize transient actors set
509 getIndex().update(aStudy); // Update of Lucene index
511 } catch (Exception e) {
512 LOG.error("STD-000001", e, aStudy.getIndex(), e.getMessage());
518 * Build reference for the study. The reference of the study is stored as a new reference pattern (IDBuilder).
522 * @return true if reference building is succeded
525 private boolean buildReference(final Study aStudy) {
526 String pattern = aStudy.getReference(); // The study being supposed just created, its reference is the reference pattern
527 IDBuilder tool = selectIDBuilder(aStudy.getDate());
529 tool = new IDBuilder(aStudy.getDate());
530 getIDBuilderDAO().create(tool);
532 aStudy.setReference(buildReference(tool, pattern, aStudy));
537 * Build reference for the study. The reference of the study is stored as a new reference pattern (IDBuilder).
544 * the reference pattern
545 * @return true if reference building is succeded
548 public String buildReference(final IDBuilder aBuilder,
549 final String pattern, final Study study) {
550 char[] format = pattern.toCharArray();
551 char[] ref = new char[80]; // Better evaluate the length of the generated string
552 int next = aBuilder.getBase() + 1;
555 for (int i = 0; i < format.length; i++) {
557 // Insertion of attribute values
558 if (format[i] == '%') {
561 if (format[i] == 'y') { // Insertion of year in format 2 (e.g. 09) or 4 (e.g. 2009) digits
563 while (format[i] == 'y') {
565 if (i == format.length) {
569 SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); //RKV: NOPMD: TODO: Use locale here?
570 String year = tostring.format(study.getDate());
571 year = year.substring(4 - (i - n), 4); // 4-(i-n) must be equal to either 0 or 2
572 for (int j = 0; j < year.length(); j++) {
573 ref[count] = year.charAt(j);
576 i -= 1; // Back to the last 'y' character
577 } else if (format[i] == '0') { // Insertion of the index
579 while (format[i] == '0') {
581 if (i == format.length) {
585 DecimalFormat tostring = new DecimalFormat(pattern
587 String number = tostring.format(next);
588 for (int j = 0; j < number.length(); j++) {
589 ref[count] = number.charAt(j);
592 i -= 1; // Back to the last '0' character
594 // Keep the character
596 ref[count] = format[i];
600 // Incrementation of the number of study
601 aBuilder.setBase(next);
602 getIDBuilderDAO().update(aBuilder);
603 return String.copyValueOf(ref, 0, count);
607 * Find an id builder by date.
611 * @return found id builder
613 private IDBuilder selectIDBuilder(final Date date) {
614 Calendar aDate = Calendar.getInstance();
616 return getIDBuilderDAO().findByCriteria(
617 Restrictions.eq("cycle", aDate.get(Calendar.YEAR)));
621 * Fill transient collection ModifiableActors of the study.
626 private void resetActorsShortCut(final Study aStudy) {
627 getModifiableActors(aStudy).clear();
628 // Get all actors involved in validation cycles
629 for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
630 .values().iterator(); i.hasNext();) {
631 ValidationCycle cycle = i.next();
632 User[] user = cycle.getAllActors();
633 for (int j = 0; j < user.length; j++) {
634 getModifiableActors(aStudy).add(user[j]);
637 // Get all other actors
638 for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
640 Relation link = i.next();
641 Class<?> kindof = link.getClass().getSuperclass();
642 if (!kindof.equals(ActorRelation.class)) {
645 getModifiableActors(aStudy).add(((ActorRelation) link).getTo());
650 * Update lucene index for the study knowledge elements.
654 * @return true if reindexing succeeded
656 private boolean updateKnowledgeElementsIndex(final Study aStudy) {
657 boolean isOk = false;
659 IndexService lucin = getIndex();
661 for (Iterator<Scenario> i = aStudy.getScenariiList().iterator(); i
663 Scenario scene = i.next();
664 for (Iterator<KnowledgeElement> j = scene
665 .getAllKnowledgeElements().iterator(); j.hasNext();) {
666 KnowledgeElement kelm = j.next();
671 } catch (Exception error) {
672 LOG.error("Unable to re-index Knowledge Elements, reason:",
679 * Get lucene index service. Create a lucene index if it does not exist.
681 * @return index service
682 * @throws IOException
683 * if error occurs during lucene index creation
685 private IndexService getIndex() throws IOException {
686 IndexService lucin = getIndexService();
687 if (!lucin.exists()) {
688 lucin.create(); // Happens when re-indexing all studies
694 * Create a new validation cycle for documents of the given study.
699 * the cycle description
700 * @return the new validation cycle
702 protected ValidationCycle createValidationCycle(
704 final ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
705 Actor[] actype = cycle.getActorTypes();
706 User.Properties uprop = new User.Properties();
708 ValidationCycle aValidationCycle = new ValidationCycle();
709 aValidationCycle.setDocumentType(getDocumentTypeService().selectType(
710 cycle.getName())); // Null in case of default validation cycle
711 // context = new ValidationCycleRelation(from, vprop);
712 // RKV aValidationCycle.context = null; // Validation cycle defined in the workflow
713 for (int i = 0; i < actype.length; i++) {
715 if (actype[i] != null) {
717 if (actype[i] == Actor.manager) {
718 actor = from.getAuthor();
719 } else if (actype[i] == Actor.Nx1) {
720 List<User> manager = getUserService().selectUsersWhere(
721 uprop.setOrganizationName("Nx1"));
722 if (manager.size() == 1) {
723 actor = manager.get(0);
725 } else if (actype[i] == Actor.Nx2) {
726 List<User> manager = getUserService().selectUsersWhere(
727 uprop.setOrganizationName("Nx2"));
728 if (manager.size() == 1) {
729 actor = manager.get(0);
731 } else { /* Actor.customer */
732 actor = from.getAuthor();
733 // TODO: Get the customer of the study, if exists
735 } catch (Exception e) { // Should not happen
740 aValidationCycle.setReviewer(actor);
742 aValidationCycle.setApprover(actor);
744 aValidationCycle.setSignatory(actor);
747 return aValidationCycle;
751 * Remove a validation step from the validation cycle.
753 * @param aValidationCycle
754 * the validation cycle
756 * the validation step to remove
759 protected void remove(final ValidationCycle aValidationCycle,
760 final ValidationStep step) {
761 if (step == ValidationStep.REVIEW) {
762 aValidationCycle.setReviewer(null);
763 } else if (step == ValidationStep.APPROVAL) {
764 aValidationCycle.setApprover(null);
765 } else if (step == ValidationStep.ACCEPTANCE
766 || step == ValidationStep.REFUSAL) {
767 aValidationCycle.setSignatory(null);
769 if (aValidationCycle.isSaved()) {
770 getValidationCycleDAO().update(aValidationCycle);
775 * Reset actors for the validation cycle.
777 * @param aValidationCycle
778 * the validation cycle to update
780 * new validation cycle properties containing new actors
783 public void resetActors(final ValidationCycle aValidationCycle,
784 final ValidationCycle.Properties vprop) {
785 aValidationCycle.setPublisher(vprop.getPublisher()); // May be null
786 aValidationCycle.setReviewer(vprop.getReviewer()); // May be null
787 aValidationCycle.setApprover(vprop.getApprover()); // May be null
788 aValidationCycle.setSignatory(vprop.getSignatory()); // May be null
789 if (aValidationCycle.isSaved()) {
790 getValidationCycleDAO().merge(aValidationCycle);
795 * Set actor for the given validation cycle and validation step.
797 * @param aValidationCycle
798 * the validation cycle
800 * the validation step
805 protected void setActor(final ValidationCycle aValidationCycle,
806 final ValidationStep step, final User actor) {
807 if (step == ValidationStep.PROMOTION) {
808 aValidationCycle.setPublisher(actor);
809 } else if (step == ValidationStep.REVIEW) {
810 aValidationCycle.setReviewer(actor);
811 } else if (step == ValidationStep.APPROVAL) {
812 aValidationCycle.setApprover(actor);
813 } else if (step == ValidationStep.ACCEPTANCE
814 || step == ValidationStep.REFUSAL) {
815 aValidationCycle.setSignatory(actor);
817 if (aValidationCycle.isSaved()) {
818 getValidationCycleDAO().update(aValidationCycle);
823 * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
827 * @return the actors of this study
828 * @see #hasActor(User)
830 public Set<User> getActors(final Study aStudy) {
831 if (aStudy.getActor() == null) {
832 setShortCuts(aStudy);
834 return Collections.unmodifiableSet(aStudy.getActor());
838 * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
842 * @return the modifiable set of actors of this study
843 * @see #hasActor(User)
845 public Set<User> getModifiableActors(final Study aStudy) {
846 if (aStudy.getActor() == null) {
847 setShortCuts(aStudy);
849 return aStudy.getActor();
853 * Returns unmodifiable initialized transient list of contributors of this study.
857 * @return the unmodifiable not null transient list of contributors of this study
859 public List<User> getContributors(final Study aStudy) {
860 if (aStudy.getContributor() == null) {
861 setShortCuts(aStudy);
863 return Collections.unmodifiableList(aStudy.getContributor()); // May be empty
867 * Returns modifiable initialized transient list of contributors of this study.
871 * @return the modifiable not null transient list of contributors of this study
873 public List<User> getModifiableContributors(final Study aStudy) {
874 if (aStudy.getContributor() == null) {
875 setShortCuts(aStudy);
877 return aStudy.getContributor(); // May be empty
881 * Returns the validation cycle of the given document type.
886 * the document type being subject of validation
887 * @return the validation cycle of the document, or null if not defined.
889 public ValidationCycle getValidationCycleOf(final Study aStudy,
890 final DocumentType type) {
891 if (aStudy.getValidationCycles() == null || aStudy.getValidationCycles().isEmpty()) {
892 setShortCuts(aStudy);
894 ValidationCycle result = aStudy.getValidationCycles().get(
896 if (result == null) {
897 if (type.isStepResult()) {
898 result = aStudy.getValidationCycles().get("default"); // "default" validation cycle defined in the configuration, if exist
900 if (result == null) {
901 result = aStudy.getValidationCycles().get("built-in");
908 * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
913 * the user to look for
914 * @return true if the given user is actor of this study.
917 public boolean hasActor(final Study aStudy, final User user) {
921 for (Iterator<User> i = getActors(aStudy).iterator(); i.hasNext();) {
922 User involved = i.next();
923 if (involved.equals(user)) {
931 * Checks if the given user participates to this study. The Study staff includes the author and contributors.
936 * the user to look for
937 * @return true if the given user is actor of this study.
938 * @see #getContributors()
940 public boolean isStaffedBy(final Study aStudy, final User user) {
944 if (aStudy == null) {
947 if (aStudy.getAuthor() == null) {
950 if (aStudy.getAuthor().equals(user)) {
953 for (Iterator<User> i = getContributors(aStudy).iterator(); i.hasNext();) {
954 if (i.next().equals(user)) {
962 * Initialize shortcuts of the study as its transient collections.
967 public void loadWorkflow(final Study aStudy) {
968 setShortCuts(aStudy);
972 * Initialize shortcuts of the study as its transient collections.
977 public void setShortCuts(final Study aStudy) {
978 aStudy.getContributor().clear();
979 aStudy.getValidationCycles().clear();
980 aStudy.getActor().clear();
982 // Get the contributors
983 for (Iterator<Relation> i = aStudy.getRelations(
984 ContributorRelation.class).iterator(); i.hasNext();) {
985 ContributorRelation link = (ContributorRelation) i.next();
986 aStudy.getContributor().add(link.getTo());
988 // Get the validation cycles specific to this study
989 for (Iterator<Relation> i = aStudy.getRelations(
990 ValidationCycleRelation.class).iterator(); i.hasNext();) {
991 ValidationCycleRelation link = (ValidationCycleRelation) i.next();
992 aStudy.getValidationCycles().put(link.getDocumentType().getName(),
993 link.getTo()); // The associated document type is necessarily not null in this
996 // Get the validation cycles coming from the configured workflow and not overridden in this study
997 for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i = getProjectSettings()
998 .getAllValidationCycles().iterator(); i.hasNext();) {
999 ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i
1001 String type = cycle.getName();
1002 if (!aStudy.getValidationCycles().containsKey(type)) {
1003 aStudy.getValidationCycles().put(type,
1004 createValidationCycle(aStudy, cycle));
1007 // Get all corresponding actors
1008 for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
1009 .values().iterator(); i.hasNext();) {
1010 ValidationCycle cycle = i.next();
1011 User[] user = cycle.getAllActors();
1012 for (int j = 0; j < user.length; j++) {
1013 aStudy.getActor().add(user[j]);
1016 // Get all other actors
1017 for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
1019 Relation link = i.next();
1020 Class<?> kindof = link.getClass().getSuperclass();
1021 if (!kindof.equals(ActorRelation.class)) {
1024 aStudy.getActor().add(((ActorRelation) link).getTo());
1031 * @see org.splat.service.StudyService#markStudyAsReference(org.splat.dal.bo.som.Study)
1035 public void markStudyAsReference (final Study aStudy) {
1037 aStudy.setMarkreference(1);
1038 aStudy.setProgressState(ProgressState.TEMPLATE);
1039 getStudyDAO().merge(aStudy);
1045 * @see org.splat.service.StudyService#removeStudyAsReference(org.splat.dal.bo.som.Study)
1049 public void removeStudyAsReference(final Study aStudy) {
1051 aStudy.setMarkreference(0);
1052 aStudy.setProgressState(ProgressState.APPROVED);
1053 getStudyDAO().merge(aStudy);
1058 * @see org.splat.service.StudyService#getDescription(java.lang.Long)
1061 @Transactional(readOnly = true)
1062 public String getDescription(final Long studyId) throws InvalidParameterException {
1063 if(studyId == null) {
1064 throw new InvalidParameterException("studyId", "null");
1066 Study study = _studyDAO.get(studyId);
1068 throw new InvalidParameterException("studyId", studyId.toString());
1070 return study.getDescription();
1076 * @see org.splat.service.StudyService#setDescription(java.lang.Long, java.lang.String)
1080 public void setDescription(final Long studyId, final String descriptionText)
1081 throws InvalidParameterException {
1082 if(studyId == null) {
1083 throw new InvalidParameterException("studyId", "null");
1085 Study study = _studyDAO.get(studyId);
1087 throw new InvalidParameterException("studyId", studyId.toString());
1089 study.setAttribute(new DescriptionAttribute(study, descriptionText));
1093 * Get project settings.
1095 * @return Project settings service
1097 private ProjectSettingsService getProjectSettings() {
1098 return _projectSettings;
1102 * Set project settings service.
1104 * @param projectSettingsService
1105 * project settings service
1107 public void setProjectSettings(
1108 final ProjectSettingsService projectSettingsService) {
1109 _projectSettings = projectSettingsService;
1113 * Get the projectElementService.
1115 * @return the projectElementService
1117 public ProjectElementService getProjectElementService() {
1118 return _projectElementService;
1122 * Set the projectElementService.
1124 * @param projectElementService
1125 * the projectElementService to set
1127 public void setProjectElementService(
1128 final ProjectElementService projectElementService) {
1129 _projectElementService = projectElementService;
1133 * Get the stepService.
1135 * @return the stepService
1137 public StepService getStepService() {
1138 return _stepService;
1142 * Set the stepService.
1144 * @param stepService
1145 * the stepService to set
1147 public void setStepService(final StepService stepService) {
1148 _stepService = stepService;
1152 * Get the indexService.
1154 * @return the indexService
1156 public IndexService getIndexService() {
1157 return _indexService;
1161 * Set the indexService.
1163 * @param indexService
1164 * the indexService to set
1166 public void setIndexService(final IndexService indexService) {
1167 _indexService = indexService;
1173 * @return the studyDAO
1175 public StudyDAO getStudyDAO() {
1183 * the studyDAO to set
1185 public void setStudyDAO(final StudyDAO studyDAO) {
1186 _studyDAO = studyDAO;
1190 * Get the iDBuilderDAO.
1192 * @return the iDBuilderDAO
1194 public IDBuilderDAO getIDBuilderDAO() {
1195 return _iDBuilderDAO;
1199 * Set the iDBuilderDAO.
1202 * the iDBuilderDAO to set
1204 public void setIDBuilderDAO(final IDBuilderDAO builderDAO) {
1205 _iDBuilderDAO = builderDAO;
1209 * Get the scenarioDAO.
1211 * @return the scenarioDAO
1213 public ScenarioDAO getScenarioDAO() {
1214 return _scenarioDAO;
1218 * Set the scenarioDAO.
1220 * @param scenarioDAO
1221 * the scenarioDAO to set
1223 public void setScenarioDAO(final ScenarioDAO scenarioDAO) {
1224 _scenarioDAO = scenarioDAO;
1228 * Get the validationCycleDAO.
1230 * @return the validationCycleDAO
1232 public ValidationCycleDAO getValidationCycleDAO() {
1233 return _validationCycleDAO;
1237 * Set the validationCycleDAO.
1239 * @param validationCycleDAO
1240 * the validationCycleDAO to set
1242 public void setValidationCycleDAO(
1243 final ValidationCycleDAO validationCycleDAO) {
1244 _validationCycleDAO = validationCycleDAO;
1248 * Get the documentTypeService.
1250 * @return the documentTypeService
1252 public DocumentTypeService getDocumentTypeService() {
1253 return _documentTypeService;
1257 * Set the documentTypeService.
1259 * @param documentTypeService
1260 * the documentTypeService to set
1262 public void setDocumentTypeService(
1263 final DocumentTypeService documentTypeService) {
1264 _documentTypeService = documentTypeService;
1268 * Get the userService.
1270 * @return the userService
1272 public UserService getUserService() {
1273 return _userService;
1277 * Set the userService.
1279 * @param userService
1280 * the userService to set
1282 public void setUserService(final UserService userService) {
1283 _userService = userService;
1287 * Get the publicationDAO.
1288 * @return the publicationDAO
1290 public PublicationDAO getPublicationDAO() {
1291 return _publicationDAO;
1295 * Set the publicationDAO.
1296 * @param publicationDAO the publicationDAO to set
1298 public void setPublicationDAO(final PublicationDAO publicationDAO) {
1299 _publicationDAO = publicationDAO;
1303 * Get the repositoryService.
1304 * @return the repositoryService
1306 public RepositoryService getRepositoryService() {
1307 return _repositoryService;
1311 * Set the repositoryService.
1312 * @param repositoryService the repositoryService to set
1314 public void setRepositoryService(final RepositoryService repositoryService) {
1315 _repositoryService = repositoryService;
1319 * Get the documentDAO.
1320 * @return the documentDAO
1322 public DocumentDAO getDocumentDAO() {
1323 return _documentDAO;
1327 * Set the documentDAO.
1328 * @param documentDAO the documentDAO to set
1330 public void setDocumentDAO(final DocumentDAO documentDAO) {
1331 _documentDAO = documentDAO;
1335 * Get the descriptionAttributeDAO.
1336 * @return the descriptionAttributeDAO
1338 public DescriptionAttributeDAO getDescriptionAttributeDAO() {
1339 return _descriptionAttributeDAO;
1343 * Set the descriptionAttributeDAO.
1344 * @param descriptionAttributeDAO the descriptionAttributeDAO to set
1346 public void setDescriptionAttributeDAO(
1347 final DescriptionAttributeDAO descriptionAttributeDAO) {
1348 _descriptionAttributeDAO = descriptionAttributeDAO;