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.kernel.InvalidPropertyException;
13 import org.splat.kernel.Name;
14 import org.splat.service.DocumentTypeService;
15 import org.splat.service.UserService;
16 import org.splat.som.ApplicationRights;
17 import org.splat.som.StudyRights;
18 import org.splat.wapp.Constants;
21 * Edit/display study properties (study configuration) screen action.
23 public class StudyPropertiesAction extends DisplayStudyStepAction {
28 private static final long serialVersionUID = 4210696018741092900L;
30 // Presentation fields
31 private transient List<User> _staff;
32 private transient List<User> _member;
33 private transient List<Name> _validor;
34 private transient List<ValidationFacade> _validation;
35 private transient ValidationFacade _validefault;
36 private transient List<DocumentType> _other;
40 * Edition action (title, contributors or cycle).
42 private transient Save _tosave;
43 private transient String _edicycle;
47 private transient String _stitle;
49 * List of existing contributors, some of them may have been removed.
51 private transient String _contributors;
53 * List of added contributors.
55 private transient String _candidates;
57 * Type of document to be included in the validation process.
59 private transient long _type;
60 private transient int _publisher;
61 private transient int _reviewer;
62 private transient int _approver;
65 * Injected document type service.
67 private DocumentTypeService _documentTypeService;
70 * Injected user service.
72 private UserService _userService;
75 * Save operation type enumeration pointing which section of properties has been edited.
87 * Save validation cycle.
92 // ==============================================================================================================================
94 // ==============================================================================================================================
97 * Initialize study properties action.
99 * @return "edit" if user can edit study properties, otherwise return "display"
101 public String doInitialize() {
104 _openStudy = getOpenStudy();
105 _validation = new ArrayList<ValidationFacade>();
107 _other = getDocumentTypeService().selectResultTypes();
109 Study study = _openStudy.getStudyObject();
110 StudyRights user = _openStudy.getStudyRights();
111 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
112 DocumentType type = i.next();
113 ValidationCycle cycle = getStudyService().getValidationCycleOf(
115 if (cycle.isDefault()) {
116 _validefault = new ValidationFacade(cycle,
117 getApplicationSettings().getCurrentLocale());
120 _validation.add(new ValidationFacade(cycle,
121 getApplicationSettings().getCurrentLocale()));
124 if (_validefault != null) {
125 _validation.add(_validefault); // In order to be at the end
127 _member = getStudyService().getContributors(study);
131 initializationFullScreenContext(Constants.STUDY_MENU,
132 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
135 if (_openStudy.isOpenForWriting() && user.canEditProperties()) {
143 public String doEditTitle() {
145 _openStudy = getOpenStudy();
146 _validation = new ArrayList<ValidationFacade>();
148 _other = getDocumentTypeService().selectResultTypes();
150 Study study = _openStudy.getStudyObject();
151 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
152 DocumentType type = i.next();
153 ValidationCycle cycle = getStudyService().getValidationCycleOf(
155 if (cycle.isDefault()) {
156 _validefault = new ValidationFacade(cycle,
157 getApplicationSettings().getCurrentLocale());
160 _validation.add(new ValidationFacade(cycle,
161 getApplicationSettings().getCurrentLocale()));
163 if (_validefault != null) {
164 _validation.add(_validefault); // In order to be at the end
166 _member = getStudyService().getContributors(study);
171 initializationFullScreenContext(Constants.STUDY_MENU,
172 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
174 setActionType("edititle");
179 public String doEditContributors() {
181 _openStudy = getOpenStudy();
182 _validation = new ArrayList<ValidationFacade>();
184 _other = getDocumentTypeService().selectAllTypes();
186 Study study = _openStudy.getStudyObject();
187 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
188 DocumentType type = i.next();
189 ValidationCycle cycle = getStudyService().getValidationCycleOf(
191 if (cycle.isDefault()) {
192 _validefault = new ValidationFacade(cycle,
193 getApplicationSettings().getCurrentLocale());
196 _validation.add(new ValidationFacade(cycle,
197 getApplicationSettings().getCurrentLocale()));
199 if (_validefault != null) {
200 _validation.add(_validefault); // In order to be at the end
202 _member = getStudyService().getContributors(study);
203 _staff = getUserService().selectAllUsers();
206 User me = this.getConnectedUser();
207 for (Iterator<User> i = _staff.iterator(); i.hasNext();) {
208 User next = i.next();
209 ApplicationRights he = new ApplicationRights(next);
210 if (next.equals(me) || _member.contains(next)
211 || !he.canContributeToStudy()) {
216 initializationFullScreenContext(Constants.STUDY_MENU,
217 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
220 setActionType("edibutor");
224 public String doEditCycle() {
226 _openStudy = getOpenStudy();
227 _validation = new ArrayList<ValidationFacade>();
229 _other = getDocumentTypeService().selectResultTypes();
231 Study study = _openStudy.getStudyObject();
232 for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
233 DocumentType type = i.next();
234 ValidationCycle cycle = getStudyService().getValidationCycleOf(
236 if (cycle.isDefault()) {
237 _validefault = new ValidationFacade(cycle,
238 getApplicationSettings().getCurrentLocale());
241 if (type.getName().equals(_edicycle)) {
242 this._type = type.getIndex();
244 _validation.add(new ValidationFacade(cycle,
245 getApplicationSettings().getCurrentLocale()));
248 if (_validefault != null) {
249 _validation.add(_validefault); // In order to be at the end
251 _member = getStudyService().getContributors(study);
252 _validor = new ArrayList<Name>();
254 List<User> user = getUserService().selectAllUsers();
255 for (Iterator<User> i = user.iterator(); i.hasNext();) {
256 User next = i.next();
257 ApplicationRights he = new ApplicationRights(next);
258 if (he.canValidate()) {
259 if (next.equals(study.getAuthor())) {
260 _validor.add(new ValidationFacade.ByManager(next,
261 getApplicationSettings().getCurrentLocale()));
268 initializationFullScreenContext(Constants.STUDY_MENU,
269 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
272 setActionType("edicycle");
277 public String doEdition() {
278 Study study = getOpenStudy().getStudyObject();
280 if (_tosave == Save.title) {
282 // Edition of the title
283 Study.Properties sprop = new Study.Properties();
285 getStudyService().update(study, sprop.setTitle(_stitle));
286 } catch (InvalidPropertyException e) {
288 LOG.error(e.getMessage(), e);
290 } else if (_tosave == Save.contributor) {
292 // Edition of contributors
293 if (_contributors == null) {
296 if (_candidates == null) {
300 String[] parsekept = _contributors.split(",");
301 String[] parsenew = _candidates.split(",");
302 List<User> toremove = new ArrayList<User>(getStudyService()
303 .getContributors(study));
305 for (int i = 0; i < parsekept.length; i++) {
306 if (parsekept[i].length() == 0) {
307 continue; // Yet no contributor
309 int index = Integer.valueOf(parsekept[i].trim());
310 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
311 long present = j.next().getIndex();
312 if (present != index) {
319 int size = toremove.size();
321 getStudyService().removeContributor(study,
322 toremove.toArray(new User[size]));
325 for (int i = 0; i < parsenew.length; i++) {
326 if (parsenew[i].length() == 0) {
327 continue; // No any new contributor
329 int index = Integer.valueOf(parsenew[i].trim());
330 User newser = getUserService().selectUser(index);
332 getStudyService().addContributor(study, newser);
334 } else if (_tosave == Save.cycle) {
336 // Addition of a document validation cycle
337 DocumentType apply = getDocumentTypeService().selectType(_type);
338 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
339 if (_publisher > 0) {
340 User actor = getUserService().selectUser(_publisher);
341 vprop.setActor(ValidationStep.PROMOTION, actor);
344 User actor = getUserService().selectUser(_reviewer);
345 vprop.setActor(ValidationStep.REVIEW, actor);
348 User actor = getUserService().selectUser(_approver);
349 vprop.setActor(ValidationStep.APPROVAL, actor);
351 getStudyService().setValidationCycle(study, apply, vprop);
354 doInitialize(); // Re-initialization following the above edition
356 initializationFullScreenContext(Constants.STUDY_MENU,
357 Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
363 // ==============================================================================================================================
365 // ==============================================================================================================================
367 public User getAuthor() {
368 return _openStudy.getStudyObject().getAuthor();
371 public List<User> getCandidates() {
375 public String getCycle() {
379 public List<User> getContributors() {
383 public ValidationFacade getDefaultValidation() {
387 public long getDocumentTypeIndex() {
391 public List<DocumentType> getOtherDocumentTypes() {
395 public String getStudyTitle() {
396 return _openStudy.getTitle();
399 public List<ValidationFacade> getValidations() {
403 public List<Name> getValidationActors() {
407 // ==============================================================================================================================
409 // ==============================================================================================================================
411 public void setCandidates(final String indices) {
412 _candidates = indices;
415 public void setCycle(final String type) {
419 public void setMembers(final String indices) {
420 _contributors = indices;
423 public void setDocumentType(final String index) {
424 _type = Integer.valueOf(index);
427 public void setApprover(final String index) {
428 _approver = Integer.valueOf(index);
431 public void setPublisher(final String index) {
432 _publisher = Integer.valueOf(index);
435 public void setReviewer(final String index) {
436 _reviewer = Integer.valueOf(index);
439 public void setTitle(final String title) {
443 public void setSaveTitle(final String save) {
444 _tosave = Save.title;
447 public void setSaveContributors(final String save) {
448 _tosave = Save.contributor;
451 public void setSaveCycle(final String save) {
452 _tosave = Save.cycle;
456 * Get the documentTypeService.
458 * @return the documentTypeService
460 public DocumentTypeService getDocumentTypeService() {
461 return _documentTypeService;
465 * Set the documentTypeService.
467 * @param documentTypeService
468 * the documentTypeService to set
470 public void setDocumentTypeService(
471 final DocumentTypeService documentTypeService) {
472 _documentTypeService = documentTypeService;
476 * Get the userService.
478 * @return the userService
480 public UserService getUserService() {
485 * Set the userService.
488 * the userService to set
490 public void setUserService(final UserService userService) {
491 _userService = userService;