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;
64 * This class defines all methods for creation, modification the study.
66 * @author Maria KRUCHININA
69 public class StudyServiceImpl implements StudyService {
72 * logger for the service.
74 public final static AppLogger LOG = AppLogger
75 .getLogger(StudyServiceImpl.class);
78 * Injected index service.
80 private IndexService _indexService;
83 * Injected step service.
85 private StepService _stepService;
88 * Injected project service.
90 private ProjectSettingsService _projectSettings;
93 * Injected project element service.
95 private ProjectElementService _projectElementService;
100 private StudyDAO _studyDAO;
103 * Injected scenario DAO.
105 private ScenarioDAO _scenarioDAO;
108 * Injected validation cycle DAO.
110 private ValidationCycleDAO _validationCycleDAO;
113 * Injected IDBuilder DAO.
115 private IDBuilderDAO _iDBuilderDAO;
118 * Injected document type service.
120 private DocumentTypeService _documentTypeService;
123 * Injected user service.
125 private UserService _userService;
128 * Injected publication DAO.
130 private PublicationDAO _publicationDAO;
133 * Injected repository service.
135 private RepositoryService _repositoryService;
138 * Injected document DAO.
140 private DocumentDAO _documentDAO;
143 * Injected description attribute DAO.
145 private DescriptionAttributeDAO _descriptionAttributeDAO;
150 * @see org.splat.service.StudyService#selectStudy(long)
154 public Study selectStudy(final long index) {
155 Study result = getStudyDAO().get(index);
156 loadWorkflow(result);
161 * Get study by its reference.
164 * the study reference
165 * @return found study or null
167 @Transactional(readOnly = true)
168 public Study selectStudy(final String refid) {
169 Study result = getStudyDAO().findByCriteria(
170 Restrictions.eq("sid", refid));
171 loadWorkflow(result);
178 * @see org.splat.service.StudyService#createStudy(org.splat.dal.bo.som.Study.Properties)
182 public Study createStudy(final Study.Properties sprop)
183 throws MissedPropertyException, InvalidPropertyException,
184 MultiplyDefinedException {
185 sprop.setReference(getProjectSettings().getReferencePattern());
186 Study study = new Study(sprop);
188 buildReference(study);
189 getStudyDAO().create(study);
191 IndexService lucin = getIndex();
193 } catch (IOException error) {
194 LOG.error("Unable to index the study '" + study.getIndex()
195 + "', reason:", error);
196 // Continue and try to index later
204 * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext.Properties)
208 public SimulationContext addProjectContext(final Study aStudy,
209 final SimulationContext.Properties cprop)
210 throws MissedPropertyException, InvalidPropertyException,
211 MultiplyDefinedException {
212 SimulationContext added = getStepService().addSimulationContext(
213 getProjectElementService().getFirstStep(aStudy), cprop);
221 * @see org.splat.service.StudyService#addProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
225 public SimulationContext addProjectContext(final Study aStudy,
226 final SimulationContext context) {
227 SimulationContext added = getStepService().addSimulationContext(
228 getProjectElementService().getFirstStep(aStudy), context);
236 * @see org.splat.service.StudyService#addContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User)
239 public boolean addContributor(final Study aStudy, final User user) {
240 List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
241 for (Iterator<User> i = contributor.iterator(); i.hasNext();) {
242 User present = i.next();
243 if (present.equals(user)) {
247 boolean absent = getModifiableActors(aStudy).add(user); // User may already be a reviewer or an approver
249 aStudy.addRelation(new ContributorRelation(aStudy, user));
251 update(aStudy); // Else, useless to re-index the study
253 contributor.add(user);
258 * Moves this study from the Public to the Reference area of the repository. For being moved to the Reference area, the study must
259 * previously be approved.
263 * @return true if the move succeeded.
264 * @see #moveToPublic()
266 * @see Publication#approve(Date)
269 public boolean moveToReference(final Study aStudy) {
270 if (aStudy.getProgressState() != ProgressState.APPROVED) {
273 if (aStudy.getVisibility() != Visibility.PUBLIC) {
277 aStudy.setVisibility(Visibility.REFERENCE);
278 if (update(aStudy)) {
279 return updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller
287 * @see org.splat.service.StudyService#update(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Study.Properties)
290 public boolean update(final Study aStudy, final Properties sprop)
291 throws InvalidPropertyException {
292 if (sprop.getTitle() != null) {
293 aStudy.setTitle(sprop.getTitle());
295 if (sprop.getSummary() != null) {
296 aStudy.setAttribute(new DescriptionAttribute(aStudy, sprop
299 // TODO: To be completed
300 return update(aStudy);
304 * Check if the document is published in the study.
310 * @return true if the document is published in the study
312 /* private boolean publishes(final Study aStudy, final Document doc) {
313 if (!aStudy.publishes(doc)) {
314 Scenario[] scene = aStudy.getScenarii();
315 for (int i = 0; i < scene.length; i++) {
316 if (scene[i].publishes(doc)) {
327 * @see org.splat.service.StudyService#removeContributor(org.splat.dal.bo.som.Study, org.splat.dal.bo.kernel.User[])
330 public boolean removeContributor(final Study aStudy, final User... users) {
331 List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
332 Boolean done = false;
333 for (int i = 0; i < users.length; i++) {
334 User user = users[i];
335 for (Iterator<User> j = contributor.iterator(); j.hasNext();) {
336 User present = j.next();
337 if (!present.equals(user)) {
341 aStudy.removeRelation(ContributorRelation.class, user);
342 j.remove(); // Updates the contributor shortcut
356 * @see org.splat.service.StudyService#removeProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext)
359 public boolean removeProjectContext(final Study aStudy,
360 final SimulationContext context) {
361 boolean done = getStepService().removeSimulationContext(
362 getProjectElementService().getFirstStep(aStudy), context);
370 * @see org.splat.service.StudyService#setValidationCycle(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.DocumentType,
371 * org.splat.dal.bo.som.ValidationCycle.Properties)
375 public void setValidationCycle(final Study aStudyDTO, final DocumentType type,
376 final ValidationCycle.Properties vprop) {
377 Map<String, ValidationCycle> validactor = aStudyDTO.getValidationCycles();
378 if (validactor == null) {
379 setShortCuts(aStudyDTO); // Initializes validactor and actor
382 Study aStudy = selectStudy(aStudyDTO.getIndex());
384 String cname = type.getName();
385 ValidationCycle cycle = validactor.get(cname);
387 if (cycle != null && cycle.isAssigned()) {
388 resetActors(cycle, vprop);
391 cycle = new ValidationCycle(aStudy, vprop.setDocumentType(type));
393 getValidationCycleDAO().create(cycle); // RKV
395 ValidationCycleRelation link = cycle.getContext();
396 aStudy.addRelation(link);
397 aStudyDTO.getAllRelations().add(link); // RKV
399 validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default,
400 } catch (Exception error) {
401 LOG.error("Unable to re-index Knowledge Elements, reason:",
406 resetActorsShortCut(aStudyDTO);
407 update(aStudy); // Re-index the study, just in case
411 * Demotes this study from In-Check to In-Draft then In-Work states. This function is called internally when demoting the final result
412 * document of the study.
416 * @return true if the demotion succeeded.
419 public boolean demote(final Study aStudy) {
420 if (aStudy.getProgressState() == ProgressState.inCHECK) {
421 aStudy.setProgressState(ProgressState.inDRAFT);
422 } else if (aStudy.getProgressState() == ProgressState.inDRAFT) {
423 aStudy.setProgressState(ProgressState.inWORK);
427 return update(aStudy);
433 * @see org.splat.service.StudyService#generateLocalIndex(org.splat.dal.bo.som.Study)
437 public int generateLocalIndex(final Study aStudy) {
438 aStudy.setLastLocalIndex(aStudy.getLastLocalIndex() + 1);
439 return aStudy.getLastLocalIndex();
443 * Promotes this study from In-Work to In-Draft then In-Check and APPROVED states. This function is called internally when promoting the
444 * final result document of the study.
448 * @return true if the demotion succeeded.
452 public boolean promote(final Study aStudy) {
453 if (aStudy.getProgressState() == ProgressState.inWORK) {
454 aStudy.setProgressState(ProgressState.inDRAFT);
455 } else if (aStudy.getProgressState() == ProgressState.inDRAFT) {
456 aStudy.setProgressState(ProgressState.inCHECK);
457 Revision myvers = new Revision(aStudy.getVersion());
458 if (myvers.isMinor()) {
459 aStudy.setVersion(myvers.incrementAs(aStudy.getProgressState())
462 } else if (aStudy.getProgressState() == ProgressState.inCHECK) {
463 aStudy.setProgressState(ProgressState.APPROVED);
468 return update(aStudy);
472 * Moves this study from the Private to the Public area of the repository.
476 * @return true if the move succeeded.
481 public boolean moveToPublic(final Study aStudy) {
482 boolean isOk = false;
483 if (aStudy.getVisibility() == Visibility.PRIVATE) {
484 aStudy.setVisibility(Visibility.PUBLIC);
485 if (update(aStudy)) {
486 isOk = updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller
493 * Moves this study from the Public to the Private area of the repository.
497 * @return true if the move succeeded.
501 public boolean moveToPrivate(final Study aStudy) {
502 boolean isOk = false;
503 if (aStudy.getVisibility() == Visibility.PUBLIC) {
504 aStudy.setVisibility(Visibility.PRIVATE);
505 if (update(aStudy)) {
506 isOk = updateKnowledgeElementsIndex(aStudy); // If fails, the database roll-back is under responsibility of the caller
513 * Update a study in the database.
516 * the study to update
517 * @return true if the study is updated successfully
520 private boolean update(final Study aStudy) {
521 boolean isOk = false;
523 getStudyDAO().merge(aStudy); // Update of relational base
524 setShortCuts(aStudy); // RKV: initialize transient actors set
525 getIndex().update(aStudy); // Update of Lucene index
527 } catch (Exception e) {
528 LOG.error("STD-000001", e, aStudy.getIndex(), e.getMessage());
534 * Build reference for the study. The reference of the study is stored as a new reference pattern (IDBuilder).
538 * @return true if reference building is succeded
541 private boolean buildReference(final Study aStudy) {
542 String pattern = aStudy.getReference(); // The study being supposed just created, its reference is the reference pattern
543 IDBuilder tool = selectIDBuilder(aStudy.getDate());
545 tool = new IDBuilder(aStudy.getDate());
546 getIDBuilderDAO().create(tool);
548 aStudy.setReference(buildReference(tool, pattern, aStudy));
553 * Build reference for the study. The reference of the study is stored as a new reference pattern (IDBuilder).
560 * the reference pattern
561 * @return true if reference building is succeded
564 public String buildReference(final IDBuilder aBuilder,
565 final String pattern, final Study study) {
566 char[] format = pattern.toCharArray();
567 char[] ref = new char[80]; // Better evaluate the length of the generated string
568 int next = aBuilder.getBase() + 1;
571 for (int i = 0; i < format.length; i++) {
573 // Insertion of attribute values
574 if (format[i] == '%') {
577 if (format[i] == 'y') { // Insertion of year in format 2 (e.g. 09) or 4 (e.g. 2009) digits
579 while (format[i] == 'y') {
581 if (i == format.length) {
585 SimpleDateFormat tostring = new SimpleDateFormat("yyyy"); //RKV: NOPMD: TODO: Use locale here?
586 String year = tostring.format(study.getDate());
587 year = year.substring(4 - (i - n), 4); // 4-(i-n) must be equal to either 0 or 2
588 for (int j = 0; j < year.length(); j++) {
589 ref[count] = year.charAt(j);
592 i -= 1; // Back to the last 'y' character
593 } else if (format[i] == '0') { // Insertion of the index
595 while (format[i] == '0') {
597 if (i == format.length) {
601 DecimalFormat tostring = new DecimalFormat(pattern
603 String number = tostring.format(next);
604 for (int j = 0; j < number.length(); j++) {
605 ref[count] = number.charAt(j);
608 i -= 1; // Back to the last '0' character
610 // Keep the character
612 ref[count] = format[i];
616 // Incrementation of the number of study
617 aBuilder.setBase(next);
618 getIDBuilderDAO().update(aBuilder);
619 return String.copyValueOf(ref, 0, count);
623 * Find an id builder by date.
627 * @return found id builder
629 private IDBuilder selectIDBuilder(final Date date) {
630 Calendar aDate = Calendar.getInstance();
632 return getIDBuilderDAO().findByCriteria(
633 Restrictions.eq("cycle", aDate.get(Calendar.YEAR)));
637 * Fill transient collection ModifiableActors of the study.
642 private void resetActorsShortCut(final Study aStudy) {
643 getModifiableActors(aStudy).clear();
644 // Get all actors involved in validation cycles
645 for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
646 .values().iterator(); i.hasNext();) {
647 ValidationCycle cycle = i.next();
648 User[] user = cycle.getAllActors();
649 for (int j = 0; j < user.length; j++) {
650 getModifiableActors(aStudy).add(user[j]);
653 // Get all other actors
654 for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
656 Relation link = i.next();
657 Class<?> kindof = link.getClass().getSuperclass();
658 if (!kindof.equals(ActorRelation.class)) {
661 getModifiableActors(aStudy).add(((ActorRelation) link).getTo());
666 * Update lucene index for the study knowledge elements.
670 * @return true if reindexing succeeded
672 private boolean updateKnowledgeElementsIndex(final Study aStudy) {
673 boolean isOk = false;
675 IndexService lucin = getIndex();
677 for (Iterator<Scenario> i = aStudy.getScenariiList().iterator(); i
679 Scenario scene = i.next();
680 for (Iterator<KnowledgeElement> j = scene
681 .getAllKnowledgeElements().iterator(); j.hasNext();) {
682 KnowledgeElement kelm = j.next();
687 } catch (Exception error) {
688 LOG.error("Unable to re-index Knowledge Elements, reason:",
695 * Get lucene index service. Create a lucene index if it does not exist.
697 * @return index service
698 * @throws IOException
699 * if error occurs during lucene index creation
701 private IndexService getIndex() throws IOException {
702 IndexService lucin = getIndexService();
703 if (!lucin.exists()) {
704 lucin.create(); // Happens when re-indexing all studies
710 * Create a new validation cycle for documents of the given study.
715 * the cycle description
716 * @return the new validation cycle
718 protected ValidationCycle createValidationCycle(
720 final ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle) {
721 Actor[] actype = cycle.getActorTypes();
722 User.Properties uprop = new User.Properties();
724 ValidationCycle aValidationCycle = new ValidationCycle();
725 aValidationCycle.setDocumentType(getDocumentTypeService().selectType(
726 cycle.getName())); // Null in case of default validation cycle
727 // context = new ValidationCycleRelation(from, vprop);
728 // RKV aValidationCycle.context = null; // Validation cycle defined in the workflow
729 for (int i = 0; i < actype.length; i++) {
731 if (actype[i] != null) {
733 if (actype[i] == Actor.manager) {
734 actor = from.getAuthor();
735 } else if (actype[i] == Actor.Nx1) {
736 List<User> manager = getUserService().selectUsersWhere(
737 uprop.setOrganizationName("Nx1"));
738 if (manager.size() == 1) {
739 actor = manager.get(0);
741 } else if (actype[i] == Actor.Nx2) {
742 List<User> manager = getUserService().selectUsersWhere(
743 uprop.setOrganizationName("Nx2"));
744 if (manager.size() == 1) {
745 actor = manager.get(0);
747 } else { /* Actor.customer */
748 actor = from.getAuthor();
749 // TODO: Get the customer of the study, if exists
751 } catch (Exception e) { // Should not happen
756 aValidationCycle.setReviewer(actor);
758 aValidationCycle.setApprover(actor);
760 aValidationCycle.setSignatory(actor);
763 return aValidationCycle;
767 * Remove a validation step from the validation cycle.
769 * @param aValidationCycle
770 * the validation cycle
772 * the validation step to remove
775 protected void remove(final ValidationCycle aValidationCycle,
776 final ValidationStep step) {
777 if (step == ValidationStep.REVIEW) {
778 aValidationCycle.setReviewer(null);
779 } else if (step == ValidationStep.APPROVAL) {
780 aValidationCycle.setApprover(null);
781 } else if (step == ValidationStep.ACCEPTANCE
782 || step == ValidationStep.REFUSAL) {
783 aValidationCycle.setSignatory(null);
785 if (aValidationCycle.isSaved()) {
786 getValidationCycleDAO().update(aValidationCycle);
791 * Reset actors for the validation cycle.
793 * @param aValidationCycle
794 * the validation cycle to update
796 * new validation cycle properties containing new actors
799 public void resetActors(final ValidationCycle aValidationCycle,
800 final ValidationCycle.Properties vprop) {
801 aValidationCycle.setPublisher(vprop.getPublisher()); // May be null
802 aValidationCycle.setReviewer(vprop.getReviewer()); // May be null
803 aValidationCycle.setApprover(vprop.getApprover()); // May be null
804 aValidationCycle.setSignatory(vprop.getSignatory()); // May be null
805 if (aValidationCycle.isSaved()) {
806 getValidationCycleDAO().merge(aValidationCycle);
811 * Set actor for the given validation cycle and validation step.
813 * @param aValidationCycle
814 * the validation cycle
816 * the validation step
821 protected void setActor(final ValidationCycle aValidationCycle,
822 final ValidationStep step, final User actor) {
823 if (step == ValidationStep.PROMOTION) {
824 aValidationCycle.setPublisher(actor);
825 } else if (step == ValidationStep.REVIEW) {
826 aValidationCycle.setReviewer(actor);
827 } else if (step == ValidationStep.APPROVAL) {
828 aValidationCycle.setApprover(actor);
829 } else if (step == ValidationStep.ACCEPTANCE
830 || step == ValidationStep.REFUSAL) {
831 aValidationCycle.setSignatory(actor);
833 if (aValidationCycle.isSaved()) {
834 getValidationCycleDAO().update(aValidationCycle);
839 * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
843 * @return the actors of this study
844 * @see #hasActor(User)
846 public Set<User> getActors(final Study aStudy) {
847 if (aStudy.getActor() == null) {
848 setShortCuts(aStudy);
850 return Collections.unmodifiableSet(aStudy.getActor());
854 * Returns all actors of this study other than the author, including contributors, reviewers and approvers.
858 * @return the modifiable set of actors of this study
859 * @see #hasActor(User)
861 public Set<User> getModifiableActors(final Study aStudy) {
862 if (aStudy.getActor() == null) {
863 setShortCuts(aStudy);
865 return aStudy.getActor();
869 * Returns unmodifiable initialized transient list of contributors of this study.
873 * @return the unmodifiable not null transient list of contributors of this study
876 public List<User> getContributors(final Study aStudy) {
877 if (aStudy.getContributor() == null) {
878 setShortCuts(aStudy);
880 return Collections.unmodifiableList(aStudy.getContributor()); // May be empty
884 * Returns modifiable initialized transient list of contributors of this study.
888 * @return the modifiable not null transient list of contributors of this study
890 public List<User> getModifiableContributors(final Study aStudy) {
891 if (aStudy.getContributor() == null) {
892 setShortCuts(aStudy);
894 return aStudy.getContributor(); // May be empty
898 * Returns the validation cycle of the given document type.
903 * the document type being subject of validation
904 * @return the validation cycle of the document, or null if not defined.
907 public ValidationCycle getValidationCycleOf(final Study aStudy,
908 final DocumentType type) {
909 if (aStudy.getValidationCycles() == null || aStudy.getValidationCycles().isEmpty()) {
910 setShortCuts(aStudy);
912 ValidationCycle result = aStudy.getValidationCycles().get(
914 if (result == null) {
915 if (type.isStepResult()) {
916 result = aStudy.getValidationCycles().get("default"); // "default" validation cycle defined in the configuration, if exist
918 if (result == null) {
919 result = aStudy.getValidationCycles().get("built-in");
926 * Checks if the given user is actor of this study. Actors include contributors, reviewers and approvers.
931 * the user to look for
932 * @return true if the given user is actor of this study.
936 public boolean hasActor(final Study aStudy, final User user) {
940 for (Iterator<User> i = getActors(aStudy).iterator(); i.hasNext();) {
941 User involved = i.next();
942 if (involved.equals(user)) {
950 * Checks if the given user participates to this study. The Study staff includes the author and contributors.
955 * the user to look for
956 * @return true if the given user is actor of this study.
957 * @see #getContributors()
960 public boolean isStaffedBy(final Study aStudy, final User user) {
964 if (aStudy == null) {
967 if (aStudy.getAuthor() == null) {
970 if (aStudy.getAuthor().equals(user)) {
973 for (Iterator<User> i = getContributors(aStudy).iterator(); i.hasNext();) {
974 if (i.next().equals(user)) {
982 * Initialize shortcuts of the study as its transient collections.
988 public void loadWorkflow(final Study aStudy) {
989 setShortCuts(aStudy);
993 * Initialize shortcuts of the study as its transient collections.
998 public void setShortCuts(final Study aStudy) {
999 aStudy.getContributor().clear();
1000 aStudy.getValidationCycles().clear();
1001 aStudy.getActor().clear();
1003 // Get the contributors
1004 for (Iterator<Relation> i = aStudy.getRelations(
1005 ContributorRelation.class).iterator(); i.hasNext();) {
1006 ContributorRelation link = (ContributorRelation) i.next();
1007 aStudy.getContributor().add(link.getTo());
1009 // Get the validation cycles specific to this study
1010 for (Iterator<Relation> i = aStudy.getRelations(
1011 ValidationCycleRelation.class).iterator(); i.hasNext();) {
1012 ValidationCycleRelation link = (ValidationCycleRelation) i.next();
1013 aStudy.getValidationCycles().put(link.getDocumentType().getName(),
1014 link.getTo()); // The associated document type is necessarily not null in this
1017 // Get the validation cycles coming from the configured workflow and not overridden in this study
1018 for (Iterator<ProjectSettingsServiceImpl.ProjectSettingsValidationCycle> i = getProjectSettings()
1019 .getAllValidationCycles().iterator(); i.hasNext();) {
1020 ProjectSettingsServiceImpl.ProjectSettingsValidationCycle cycle = i
1022 String type = cycle.getName();
1023 if (!aStudy.getValidationCycles().containsKey(type)) {
1024 aStudy.getValidationCycles().put(type,
1025 createValidationCycle(aStudy, cycle));
1028 // Get all corresponding actors
1029 for (Iterator<ValidationCycle> i = aStudy.getValidationCycles()
1030 .values().iterator(); i.hasNext();) {
1031 ValidationCycle cycle = i.next();
1032 User[] user = cycle.getAllActors();
1033 for (int j = 0; j < user.length; j++) {
1034 aStudy.getActor().add(user[j]);
1037 // Get all other actors
1038 for (Iterator<Relation> i = aStudy.getAllRelations().iterator(); i
1040 Relation link = i.next();
1041 Class<?> kindof = link.getClass().getSuperclass();
1042 if (!kindof.equals(ActorRelation.class)) {
1045 aStudy.getActor().add(((ActorRelation) link).getTo());
1052 * @see org.splat.service.StudyService#markStudyAsReference(org.splat.dal.bo.som.Study)
1056 public void markStudyAsReference (final Study aStudy) {
1058 aStudy.setMarkreference(1);
1059 aStudy.setProgressState(ProgressState.TEMPLATE);
1060 getStudyDAO().merge(aStudy);
1066 * @see org.splat.service.StudyService#removeStudyAsReference(org.splat.dal.bo.som.Study)
1070 public void removeStudyAsReference(final Study aStudy) {
1072 aStudy.setMarkreference(0);
1073 aStudy.setProgressState(ProgressState.APPROVED);
1074 getStudyDAO().merge(aStudy);
1080 * @see org.splat.service.StudyService#getDescription(java.lang.Long)
1083 @Transactional(readOnly = true)
1084 public String getDescription(final Long studyId) throws InvalidParameterException {
1085 if(studyId == null) {
1086 throw new InvalidParameterException("studyId", "null");
1088 Study study = _studyDAO.get(studyId);
1090 throw new InvalidParameterException("studyId", studyId.toString());
1092 return study.getDescription();
1098 * @see org.splat.service.StudyService#setDescription(java.lang.Long, java.lang.String)
1102 public void setDescription(final Long studyId, final String descriptionText)
1103 throws InvalidParameterException {
1104 if(studyId == null) {
1105 throw new InvalidParameterException("studyId", "null");
1107 Study study = _studyDAO.get(studyId);
1109 throw new InvalidParameterException("studyId", studyId.toString());
1111 study.setAttribute(new DescriptionAttribute(study, descriptionText));
1116 * @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long)
1120 public boolean removeDescription(final Long studyId) throws InvalidParameterException {
1121 if(studyId == null) {
1122 throw new InvalidParameterException("studyId", String.valueOf(studyId));
1124 Study study = _studyDAO.get(studyId);
1126 throw new InvalidParameterException("studyId", String.valueOf(studyId));
1128 return study.removeAttribute(study.getAttribute(DescriptionAttribute.class));
1132 * Get project settings.
1134 * @return Project settings service
1136 private ProjectSettingsService getProjectSettings() {
1137 return _projectSettings;
1141 * Set project settings service.
1143 * @param projectSettingsService
1144 * project settings service
1146 public void setProjectSettings(
1147 final ProjectSettingsService projectSettingsService) {
1148 _projectSettings = projectSettingsService;
1152 * Get the projectElementService.
1154 * @return the projectElementService
1156 public ProjectElementService getProjectElementService() {
1157 return _projectElementService;
1161 * Set the projectElementService.
1163 * @param projectElementService
1164 * the projectElementService to set
1166 public void setProjectElementService(
1167 final ProjectElementService projectElementService) {
1168 _projectElementService = projectElementService;
1172 * Get the stepService.
1174 * @return the stepService
1176 public StepService getStepService() {
1177 return _stepService;
1181 * Set the stepService.
1183 * @param stepService
1184 * the stepService to set
1186 public void setStepService(final StepService stepService) {
1187 _stepService = stepService;
1191 * Get the indexService.
1193 * @return the indexService
1195 public IndexService getIndexService() {
1196 return _indexService;
1200 * Set the indexService.
1202 * @param indexService
1203 * the indexService to set
1205 public void setIndexService(final IndexService indexService) {
1206 _indexService = indexService;
1212 * @return the studyDAO
1214 public StudyDAO getStudyDAO() {
1222 * the studyDAO to set
1224 public void setStudyDAO(final StudyDAO studyDAO) {
1225 _studyDAO = studyDAO;
1229 * Get the iDBuilderDAO.
1231 * @return the iDBuilderDAO
1233 public IDBuilderDAO getIDBuilderDAO() {
1234 return _iDBuilderDAO;
1238 * Set the iDBuilderDAO.
1241 * the iDBuilderDAO to set
1243 public void setIDBuilderDAO(final IDBuilderDAO builderDAO) {
1244 _iDBuilderDAO = builderDAO;
1248 * Get the scenarioDAO.
1250 * @return the scenarioDAO
1252 public ScenarioDAO getScenarioDAO() {
1253 return _scenarioDAO;
1257 * Set the scenarioDAO.
1259 * @param scenarioDAO
1260 * the scenarioDAO to set
1262 public void setScenarioDAO(final ScenarioDAO scenarioDAO) {
1263 _scenarioDAO = scenarioDAO;
1267 * Get the validationCycleDAO.
1269 * @return the validationCycleDAO
1271 public ValidationCycleDAO getValidationCycleDAO() {
1272 return _validationCycleDAO;
1276 * Set the validationCycleDAO.
1278 * @param validationCycleDAO
1279 * the validationCycleDAO to set
1281 public void setValidationCycleDAO(
1282 final ValidationCycleDAO validationCycleDAO) {
1283 _validationCycleDAO = validationCycleDAO;
1287 * Get the documentTypeService.
1289 * @return the documentTypeService
1291 public DocumentTypeService getDocumentTypeService() {
1292 return _documentTypeService;
1296 * Set the documentTypeService.
1298 * @param documentTypeService
1299 * the documentTypeService to set
1301 public void setDocumentTypeService(
1302 final DocumentTypeService documentTypeService) {
1303 _documentTypeService = documentTypeService;
1307 * Get the userService.
1309 * @return the userService
1311 public UserService getUserService() {
1312 return _userService;
1316 * Set the userService.
1318 * @param userService
1319 * the userService to set
1321 public void setUserService(final UserService userService) {
1322 _userService = userService;
1326 * Get the publicationDAO.
1327 * @return the publicationDAO
1329 public PublicationDAO getPublicationDAO() {
1330 return _publicationDAO;
1334 * Set the publicationDAO.
1335 * @param publicationDAO the publicationDAO to set
1337 public void setPublicationDAO(final PublicationDAO publicationDAO) {
1338 _publicationDAO = publicationDAO;
1342 * Get the repositoryService.
1343 * @return the repositoryService
1345 public RepositoryService getRepositoryService() {
1346 return _repositoryService;
1350 * Set the repositoryService.
1351 * @param repositoryService the repositoryService to set
1353 public void setRepositoryService(final RepositoryService repositoryService) {
1354 _repositoryService = repositoryService;
1358 * Get the documentDAO.
1359 * @return the documentDAO
1361 public DocumentDAO getDocumentDAO() {
1362 return _documentDAO;
1366 * Set the documentDAO.
1367 * @param documentDAO the documentDAO to set
1369 public void setDocumentDAO(final DocumentDAO documentDAO) {
1370 _documentDAO = documentDAO;
1374 * Get the descriptionAttributeDAO.
1375 * @return the descriptionAttributeDAO
1377 public DescriptionAttributeDAO getDescriptionAttributeDAO() {
1378 return _descriptionAttributeDAO;
1382 * Set the descriptionAttributeDAO.
1383 * @param descriptionAttributeDAO the descriptionAttributeDAO to set
1385 public void setDescriptionAttributeDAO(
1386 final DescriptionAttributeDAO descriptionAttributeDAO) {
1387 _descriptionAttributeDAO = descriptionAttributeDAO;