1 package org.splat.simer;
3 import java.util.ArrayList;
4 import java.util.Iterator;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.dal.bo.som.DocumentType;
9 import org.splat.dal.bo.som.Study;
10 import org.splat.dal.bo.som.ValidationCycle;
11 import org.splat.dal.bo.som.ValidationStep;
12 import org.splat.exception.InvalidParameterException;
13 import org.splat.kernel.InvalidPropertyException;
14 import org.splat.kernel.Name;
15 import org.splat.service.DocumentTypeService;
16 import org.splat.service.UserService;
17 import org.splat.service.dto.UserDTO;
18 import org.splat.som.ApplicationRights;
19 import org.splat.som.StudyRights;
20 import org.splat.util.BeanHelper;
21 import org.splat.wapp.Constants;
24 * Edit/display study properties (study configuration) screen action.
26 public class StudyPropertiesAction extends DisplayStudyStepAction {
31 private static final long serialVersionUID = 4210696018741092900L;
33 // Presentation fields
34 private transient List<User> _staff;
35 private transient List<User> _member;
36 private transient List<Name> _validor;
37 private transient List<ValidationFacade> _validation;
38 private transient ValidationFacade _validefault;
39 private transient List<DocumentType> _other;
43 * Edition action (title, contributors or cycle).
45 private transient Save _tosave;
46 private transient String _edicycle;
50 private transient String _stitle;
52 * List of existing contributors, some of them may have been removed.
54 private transient String _contributors;
56 * List of added contributors.
58 private transient String _candidates;
60 * Type of document to be included in the validation process.
62 private transient long _type;
63 private transient int _publisher;
64 private transient int _reviewer;
65 private transient int _approver;
68 * Injected document type service.
70 private DocumentTypeService _documentTypeService;
73 * Injected user service.
75 private UserService _userService;
80 List<UserDTO> _readers;
83 * Study reader id list.
85 List<Long > _readerIds;
88 * Save operation type enumeration pointing which section of properties has been edited.
100 * Save validation cycle.
104 * Save study readers.
109 // ==============================================================================================================================
111 // ==============================================================================================================================
114 * Initialize study properties action.
116 * @return "edit" if user can edit study properties, otherwise return "display"
118 public String doInitialize() {
121 _openStudy = getOpenStudy();
122 _validation = new ArrayList<ValidationFacade>();
124 _other = getDocumentTypeService().selectResultTypes();
126 Study study = _openStudy.getStudyObject();
127 StudyRights user = _openStudy.getStudyRights();
128 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
129 DocumentType type = i.next();
130 ValidationCycle cycle = getStudyService().getValidationCycleOf(
132 if (cycle.isDefault()) {
133 _validefault = new ValidationFacade(cycle,
134 getApplicationSettings().getCurrentLocale());
137 _validation.add(new ValidationFacade(cycle,
138 getApplicationSettings().getCurrentLocale()));
141 if (_validefault != null) {
142 _validation.add(_validefault); // In order to be at the end
144 _member = getStudyService().getContributors(study);
148 initializationFullScreenContext(Constants.STUDY_MENU,
149 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
152 if (_openStudy.isOpenForWriting() && user.canEditProperties()) {
159 _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue());
160 } catch(InvalidParameterException e) {
161 LOG.error(e.getMessage(), e);
166 public String doEditTitle() {
168 _openStudy = getOpenStudy();
169 _validation = new ArrayList<ValidationFacade>();
171 _other = getDocumentTypeService().selectResultTypes();
173 Study study = _openStudy.getStudyObject();
174 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
175 DocumentType type = i.next();
176 ValidationCycle cycle = getStudyService().getValidationCycleOf(
178 if (cycle.isDefault()) {
179 _validefault = new ValidationFacade(cycle,
180 getApplicationSettings().getCurrentLocale());
183 _validation.add(new ValidationFacade(cycle,
184 getApplicationSettings().getCurrentLocale()));
186 if (_validefault != null) {
187 _validation.add(_validefault); // In order to be at the end
189 _member = getStudyService().getContributors(study);
194 initializationFullScreenContext(Constants.STUDY_MENU,
195 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
199 _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue());
200 } catch(InvalidParameterException e) {
201 LOG.error(e.getMessage(), e);
203 setActionType("edititle");
207 public String doEditContributors() {
209 _openStudy = getOpenStudy();
210 _validation = new ArrayList<ValidationFacade>();
212 _other = getDocumentTypeService().selectAllTypes();
214 Study study = _openStudy.getStudyObject();
215 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
216 DocumentType type = i.next();
217 ValidationCycle cycle = getStudyService().getValidationCycleOf(
219 if (cycle.isDefault()) {
220 _validefault = new ValidationFacade(cycle,
221 getApplicationSettings().getCurrentLocale());
224 _validation.add(new ValidationFacade(cycle,
225 getApplicationSettings().getCurrentLocale()));
227 if (_validefault != null) {
228 _validation.add(_validefault); // In order to be at the end
230 _member = getStudyService().getContributors(study);
231 _staff = getUserService().selectAllUsers();
234 User me = this.getConnectedUser();
235 for (Iterator<User> i = _staff.iterator(); i.hasNext();) {
236 User next = i.next();
237 ApplicationRights he = new ApplicationRights(next);
238 if (next.equals(me) || _member.contains(next)
239 || !he.canContributeToStudy()) {
244 initializationFullScreenContext(Constants.STUDY_MENU,
245 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
249 _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue());
250 } catch(InvalidParameterException e) {
251 LOG.error(e.getMessage(), e);
253 setActionType("edibutor");
258 * Initialize edit readers screen.
261 public String doInitEditReaders() {
264 _staff = getUserService().selectAllUsers();
266 //remove user from potential readers
267 _staff.remove(getConnectedUser());
269 //remove contributors from potential readers
270 if(_member != null) {
271 _staff.removeAll(_member);
274 //remove readers from potential readers
275 List<User> readers = new ArrayList<User>();
276 for(UserDTO userDTO : _readers) {
277 readers.add(BeanHelper.copyBean(userDTO, User.class));
279 _staff.removeAll(readers);
281 setActionType("editReaders");
286 public String doEditCycle() {
288 _openStudy = getOpenStudy();
289 _validation = new ArrayList<ValidationFacade>();
291 _other = getDocumentTypeService().selectResultTypes();
293 Study study = _openStudy.getStudyObject();
294 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
295 DocumentType type = i.next();
296 ValidationCycle cycle = getStudyService().getValidationCycleOf(
298 if (cycle.isDefault()) {
299 _validefault = new ValidationFacade(cycle,
300 getApplicationSettings().getCurrentLocale());
303 if (type.getName().equals(_edicycle)) {
304 this._type = type.getIndex();
306 _validation.add(new ValidationFacade(cycle,
307 getApplicationSettings().getCurrentLocale()));
310 if (_validefault != null) {
311 _validation.add(_validefault); // In order to be at the end
313 _member = getStudyService().getContributors(study);
314 _validor = new ArrayList<Name>();
316 List<User> user = getUserService().selectAllUsers();
317 for (Iterator<User> i = user.iterator(); i.hasNext();) {
318 User next = i.next();
319 ApplicationRights he = new ApplicationRights(next);
320 if (he.canValidate()) {
321 if (next.equals(study.getAuthor())) {
322 _validor.add(new ValidationFacade.ByManager(next,
323 getApplicationSettings().getCurrentLocale()));
330 initializationFullScreenContext(Constants.STUDY_MENU,
331 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
335 _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue());
336 } catch(InvalidParameterException e) {
337 LOG.error(e.getMessage(), e);
339 setActionType("edicycle");
343 public String doEdition() throws InvalidParameterException {
344 Study study = getOpenStudy().getStudyObject();
346 if (_tosave == Save.title) {
348 // Edition of the title
349 Study.Properties sprop = new Study.Properties();
351 getStudyService().update(study, sprop.setTitle(_stitle));
352 } catch (InvalidPropertyException e) {
354 LOG.error(e.getMessage(), e);
356 } else if (_tosave == Save.contributor) {
358 // Edition of contributors
359 if (_contributors == null) {
362 if (_candidates == null) {
366 String[] parsekept = _contributors.split(",");
367 String[] parsenew = _candidates.split(",");
368 List<User> toremove = new ArrayList<User>(getStudyService()
369 .getContributors(study));
371 for (int i = 0; i < parsekept.length; i++) {
372 if (parsekept[i].length() == 0) {
373 continue; // Yet no contributor
375 int index = Integer.valueOf(parsekept[i].trim());
376 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
377 long present = j.next().getIndex();
378 if (present != index) {
385 int size = toremove.size();
387 getStudyService().removeContributor(study,
388 toremove.toArray(new User[size]));
391 for (int i = 0; i < parsenew.length; i++) {
392 if (parsenew[i].length() == 0) {
393 continue; // No any new contributor
395 int index = Integer.valueOf(parsenew[i].trim());
396 User newser = getUserService().selectUser(index);
398 getStudyService().addContributor(study, newser);
400 } else if (_tosave == Save.cycle) {
402 // Addition of a document validation cycle
403 DocumentType apply = getDocumentTypeService().selectType(_type);
404 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
405 if (_publisher > 0) {
406 User actor = getUserService().selectUser(_publisher);
407 vprop.setActor(ValidationStep.PROMOTION, actor);
410 User actor = getUserService().selectUser(_reviewer);
411 vprop.setActor(ValidationStep.REVIEW, actor);
414 User actor = getUserService().selectUser(_approver);
415 vprop.setActor(ValidationStep.APPROVAL, actor);
417 getStudyService().setValidationCycle(study, apply, vprop);
418 } else if(_tosave == Save.readers) {
419 long studyId = getOpenStudy().getIndex().longValue();
420 _readers = getStudyService().getReaders(studyId);
422 //Remove newly unchecked users
423 if(_readers != null) {
424 for(UserDTO userDTO : _readers) {
425 if(_readerIds == null || !_readerIds.contains(userDTO.getIndex())) {
426 getStudyService().removeReader(studyId, userDTO.getIndex());
431 //Add newly checked users
432 if(_readerIds != null) {
433 for(Long userId : _readerIds) {
434 if(_readers == null) {
435 getStudyService().addReader(studyId, userId);
437 boolean contains = false;
438 for(UserDTO userDTO : _readers) {
439 if(userId.longValue() == userDTO.getIndex()) {
445 getStudyService().addReader(studyId, userId);
452 _openStudy.open(getConnectedUser(), getStudyService().selectStudy(_openStudy.getIndex()));
455 doInitialize(); // Re-initialization following the above edition
457 initializationFullScreenContext(Constants.STUDY_MENU,
458 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
464 // ==============================================================================================================================
466 // ==============================================================================================================================
468 public User getAuthor() {
469 return _openStudy.getStudyObject().getAuthor();
472 public List<User> getCandidates() {
476 public String getCycle() {
480 public List<User> getContributors() {
484 public ValidationFacade getDefaultValidation() {
488 public long getDocumentTypeIndex() {
492 public List<DocumentType> getOtherDocumentTypes() {
496 public String getStudyTitle() {
497 return _openStudy.getTitle();
500 public List<ValidationFacade> getValidations() {
504 public List<Name> getValidationActors() {
508 // ==============================================================================================================================
510 // ==============================================================================================================================
512 public void setCandidates(final String indices) {
513 _candidates = indices;
516 public void setCycle(final String type) {
520 public void setMembers(final String indices) {
521 _contributors = indices;
524 public void setDocumentType(final String index) {
525 _type = Integer.valueOf(index);
528 public void setApprover(final String index) {
529 _approver = Integer.valueOf(index);
532 public void setPublisher(final String index) {
533 _publisher = Integer.valueOf(index);
536 public void setReviewer(final String index) {
537 _reviewer = Integer.valueOf(index);
540 public void setTitle(final String title) {
544 public void setSaveTitle(final String save) {
545 _tosave = Save.title;
548 public void setSaveContributors(final String save) {
549 _tosave = Save.contributor;
552 public void setSaveCycle(final String save) {
553 _tosave = Save.cycle;
557 * Set tosave to readers.
558 * @param save the save
560 public void setSaveReaders(final String save) {
561 _tosave = Save.readers;
565 * Get the documentTypeService.
567 * @return the documentTypeService
569 public DocumentTypeService getDocumentTypeService() {
570 return _documentTypeService;
574 * Set the documentTypeService.
576 * @param documentTypeService
577 * the documentTypeService to set
579 public void setDocumentTypeService(
580 final DocumentTypeService documentTypeService) {
581 _documentTypeService = documentTypeService;
585 * Get the userService.
587 * @return the userService
589 public UserService getUserService() {
594 * Set the userService.
597 * the userService to set
599 public void setUserService(final UserService userService) {
600 _userService = userService;
605 * @return the readers
607 public List<UserDTO> getReaders() {
613 * @param readers the readers to set
615 public void setReaders(final List<UserDTO> readers) {
621 * @return the readerIds
623 public List<Long> getReaderIds() {
629 * @param readerIds the readerIds to set
631 public void setReaderIds(final List<Long> readerIds) {
632 this._readerIds = readerIds;