1 package org.splat.simer;
3 import java.util.Iterator;
5 import java.util.Vector;
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.StudyService;
16 import org.splat.service.UserService;
17 import org.splat.som.ApplicationRights;
18 import org.splat.som.StudyRights;
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 List<User> staff;
32 private List<User> member;
33 private List<Name> validor;
34 private List<ValidationFacade> validation;
35 private ValidationFacade validefault;
36 private List<DocumentType> other;
39 private Save tosave; // Edition action (title, contributors or cycle)
40 private String edicycle;
41 private String stitle; // Title of the study
42 private String contributors; // List of existing contributors, some of them may have been removed
43 private String candidates; // List of added contributors
44 private long type; // Type of document to be included in the validation process
45 private int publisher;
50 * Injected study service.
52 private StudyService _studyService;
54 * Injected document type service.
56 private DocumentTypeService _documentTypeService;
59 * Injected user service.
61 private UserService _userService;
64 * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
66 private String _menuProperty;
69 * Value of the title bar property. It can be: study, knowledge.
71 private String _titleProperty;
74 * Value of the tool bar property. It can be: none, standard, study, back.
76 private String _toolProperty;
79 * Value of the left menu property. It can be: open, study, knowledge, scenario.
81 private String _leftMenuProperty;
84 * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
85 * menu also can be called. It is necessary for correct building the title bar.
87 private String _editDisabledProperty = "false";
90 * Save operation type enumeration pointing which section of properties has been edited.
102 * Save validation cycle.
107 // ==============================================================================================================================
109 // ==============================================================================================================================
112 * Initialize study properties action.
114 * @return "edit" if user can edit study properties, otherwise return "display"
116 public String doInitialize() {
118 _openStudy = getOpenStudy();
119 validation = new Vector<ValidationFacade>();
121 other = getDocumentTypeService().selectResultTypes();
123 Study study = _openStudy.getStudyObject();
124 StudyRights user = _openStudy.getStudyRights();
125 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
126 DocumentType type = i.next();
127 ValidationCycle cycle = getStudyService().getValidationCycleOf(
129 if (cycle.isDefault()) {
130 validefault = new ValidationFacade(cycle,
131 getApplicationSettings().getCurrentLocale());
134 validation.add(new ValidationFacade(cycle, getApplicationSettings()
135 .getCurrentLocale()));
138 if (validefault != null) {
139 validation.add(validefault); // In order to be at the end
141 member = getStudyService().getContributors(study);
145 setMenuProperty("study");
146 setTitleProperty("study");
147 setEditDisabledProperty("true");
148 setToolProperty("back");
149 setLeftMenuProperty("open");
150 initializationFullScreenContext(_menuProperty, _titleProperty,
151 _editDisabledProperty, _toolProperty, _leftMenuProperty);
153 if (_openStudy.isOpenForWriting() && user.canEditProperties()) {
160 public String doEditTitle() {
161 // Session connex = Database.getCurSession();
162 // Transaction transax = connex.beginTransaction();
164 _openStudy = getOpenStudy();
165 validation = new Vector<ValidationFacade>();
167 other = getDocumentTypeService().selectResultTypes();
169 Study study = _openStudy.getStudyObject();
170 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
171 DocumentType type = i.next();
172 ValidationCycle cycle = getStudyService().getValidationCycleOf(
174 if (cycle.isDefault()) {
175 validefault = new ValidationFacade(cycle,
176 getApplicationSettings().getCurrentLocale());
179 validation.add(new ValidationFacade(cycle, getApplicationSettings()
180 .getCurrentLocale()));
182 if (validefault != null) {
183 validation.add(validefault); // In order to be at the end
185 member = getStudyService().getContributors(study);
192 setMenuProperty("study");
193 setTitleProperty("study");
194 setEditDisabledProperty("true");
195 setToolProperty("back");
196 setLeftMenuProperty("open");
197 initializationFullScreenContext(_menuProperty, _titleProperty,
198 _editDisabledProperty, _toolProperty, _leftMenuProperty);
199 setActionType("edititle");
204 public String doEditContributors() {
205 // Session connex = Database.getCurSession();
206 // Transaction transax = connex.beginTransaction();
208 _openStudy = getOpenStudy();
209 validation = new Vector<ValidationFacade>();
211 other = getDocumentTypeService().selectAllTypes();
213 Study study = _openStudy.getStudyObject();
214 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
215 DocumentType type = i.next();
216 ValidationCycle cycle = getStudyService().getValidationCycleOf(
218 if (cycle.isDefault()) {
219 validefault = new ValidationFacade(cycle,
220 getApplicationSettings().getCurrentLocale());
223 validation.add(new ValidationFacade(cycle, getApplicationSettings()
224 .getCurrentLocale()));
226 if (validefault != null) {
227 validation.add(validefault); // In order to be at the end
229 member = getStudyService().getContributors(study);
230 staff = getUserService().selectAllUsers();
233 User me = this.getConnectedUser();
234 for (Iterator<User> i = staff.iterator(); i.hasNext();) {
235 User next = i.next();
236 ApplicationRights he = new ApplicationRights(next);
237 if (next.equals(me) || member.contains(next)
238 || !he.canContributeToStudy()) {
244 setMenuProperty("study");
245 setTitleProperty("study");
246 setEditDisabledProperty("true");
247 setToolProperty("back");
248 setLeftMenuProperty("open");
249 initializationFullScreenContext(_menuProperty, _titleProperty,
250 _editDisabledProperty, _toolProperty, _leftMenuProperty);
252 setActionType("edibutor");
256 public String doEditCycle() {
257 // Session connex = Database.getCurSession();
258 // Transaction transax = connex.beginTransaction();
260 _openStudy = getOpenStudy();
261 validation = new Vector<ValidationFacade>();
263 other = getDocumentTypeService().selectResultTypes();
265 Study study = _openStudy.getStudyObject();
266 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
267 DocumentType type = i.next();
268 ValidationCycle cycle = getStudyService().getValidationCycleOf(
270 if (cycle.isDefault()) {
271 validefault = new ValidationFacade(cycle,
272 getApplicationSettings().getCurrentLocale());
275 if (type.getName().equals(edicycle)) {
276 this.type = type.getIndex();
278 validation.add(new ValidationFacade(cycle, getApplicationSettings()
279 .getCurrentLocale()));
282 if (validefault != null) {
283 validation.add(validefault); // In order to be at the end
285 member = getStudyService().getContributors(study);
286 validor = new Vector<Name>();
288 List<User> user = getUserService().selectAllUsers();
289 for (Iterator<User> i = user.iterator(); i.hasNext();) {
290 User next = i.next();
291 ApplicationRights he = new ApplicationRights(next);
292 if (he.canValidate()) {
293 if (next.equals(study.getAuthor())) {
294 validor.add(new ValidationFacade.ByManager(next,
295 getApplicationSettings().getCurrentLocale()));
303 setMenuProperty("study");
304 setTitleProperty("study");
305 setEditDisabledProperty("true");
306 setToolProperty("back");
307 setLeftMenuProperty("open");
308 initializationFullScreenContext(_menuProperty, _titleProperty,
309 _editDisabledProperty, _toolProperty, _leftMenuProperty);
311 setActionType("edicycle");
316 public String doEdition() {
317 // --------------------------
318 // Session connex = Database.getCurSession();
319 // Transaction transax = connex.beginTransaction();
320 Study study = getOpenStudy().getStudyObject();
322 if (tosave == Save.title) {
324 // Edition of the title
325 Study.Properties sprop = new Study.Properties();
327 getStudyService().update(study, sprop.setTitle(stitle));
328 } catch (InvalidPropertyException e) {
331 } else if (tosave == Save.contributor) {
333 // Edition of contributors
334 if (contributors == null) {
337 if (candidates == null) {
341 String[] parsekept = contributors.split(",");
342 String[] parsenew = candidates.split(",");
343 Vector<User> toremove = new Vector<User>(getStudyService()
344 .getContributors(study));
346 for (int i = 0; i < parsekept.length; i++) {
347 if (parsekept[i].length() == 0) {
348 continue; // Yet no contributor
350 int index = Integer.valueOf(parsekept[i].trim());
351 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
352 long present = j.next().getIndex();
353 if (present != index) {
360 int size = toremove.size();
362 getStudyService().removeContributor(study,
363 toremove.toArray(new User[size]));
366 for (int i = 0; i < parsenew.length; i++) {
367 if (parsenew[i].length() == 0) {
368 continue; // No any new contributor
370 int index = Integer.valueOf(parsenew[i].trim());
371 User newser = getUserService().selectUser(index);
373 getStudyService().addContributor(study, newser);
375 } else if (tosave == Save.cycle) {
377 // Addition of a document validation cycle
378 DocumentType apply = getDocumentTypeService().selectType(type);
379 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
381 User actor = getUserService().selectUser(publisher);
382 vprop.setActor(ValidationStep.PROMOTION, actor);
385 User actor = getUserService().selectUser(reviewer);
386 vprop.setActor(ValidationStep.REVIEW, actor);
389 User actor = getUserService().selectUser(approver);
390 vprop.setActor(ValidationStep.APPROVAL, actor);
392 getStudyService().setValidationCycle(study, apply, vprop);
396 doInitialize(); // Re-initialization following the above edition
398 setMenuProperty("study");
399 setTitleProperty("study");
400 setEditDisabledProperty("true");
401 setToolProperty("back");
402 setLeftMenuProperty("open");
403 initializationFullScreenContext(_menuProperty, _titleProperty,
404 _editDisabledProperty, _toolProperty, _leftMenuProperty);
409 // ==============================================================================================================================
411 // ==============================================================================================================================
413 public User getAuthor() {
414 // ------------------------
415 return _openStudy.getStudyObject().getAuthor();
418 public List<User> getCandidates() {
419 // ----------------------------------
423 public String getCycle() {
424 // -------------------------
428 public List<User> getContributors() {
429 // ------------------------------------
433 public ValidationFacade getDefaultValidation() {
434 // -----------------------------------------------
438 public long getDocumentTypeIndex() {
439 // ----------------------------------
443 public List<DocumentType> getOtherDocumentTypes() {
444 // --------------------------------------------------
448 public String getStudyTitle() {
449 // ------------------------------
450 return _openStudy.getTitle();
453 public List<ValidationFacade> getValidations() {
454 // -----------------------------------------------
458 public List<Name> getValidationActors() {
459 // ----------------------------------------
463 // ==============================================================================================================================
465 // ==============================================================================================================================
467 public void setCandidates(final String indices) {
468 // ------------------------------------------
469 candidates = indices;
472 public void setCycle(final String type) {
473 // ----------------------------------
477 public void setMembers(final String indices) {
478 // ---------------------------------------
479 contributors = indices;
482 public void setDocumentType(final String index) {
483 // ------------------------------------------
484 type = Integer.valueOf(index);
487 public void setApprover(final String index) {
488 // --------------------------------------
489 approver = Integer.valueOf(index);
492 public void setPublisher(final String index) {
493 // ---------------------------------------
494 publisher = Integer.valueOf(index);
497 public void setReviewer(final String index) {
498 // --------------------------------------
499 reviewer = Integer.valueOf(index);
502 public void setTitle(final String title) {
503 // -----------------------------------
507 public void setSaveTitle(final String save) {
508 // --------------------------------------
512 public void setSaveContributors(final String save) {
513 // ---------------------------------------------
514 tosave = Save.contributor;
517 public void setSaveCycle(final String save) {
518 // --------------------------------------
523 * Get the studyService.
525 * @return the studyService
528 public StudyService getStudyService() {
529 return _studyService;
533 * Set the studyService.
535 * @param studyService
536 * the studyService to set
539 public void setStudyService(final StudyService studyService) {
540 _studyService = studyService;
544 * Get the documentTypeService.
546 * @return the documentTypeService
548 public DocumentTypeService getDocumentTypeService() {
549 return _documentTypeService;
553 * Set the documentTypeService.
555 * @param documentTypeService
556 * the documentTypeService to set
558 public void setDocumentTypeService(
559 final DocumentTypeService documentTypeService) {
560 _documentTypeService = documentTypeService;
564 * Get the userService.
566 * @return the userService
568 public UserService getUserService() {
573 * Set the userService.
576 * the userService to set
578 public void setUserService(final UserService userService) {
579 _userService = userService;
583 * Get the menuProperty.
585 * @return the menuProperty
588 public String getMenuProperty() {
589 return _menuProperty;
593 * Set the menuProperty.
595 * @param menuProperty
596 * the menuProperty to set
599 public void setMenuProperty(final String menuProperty) {
600 this._menuProperty = menuProperty;
604 * Get the _titleProperty.
606 * @return the _titleProperty
609 public String getTitleProperty() {
610 return _titleProperty;
614 * Set the _titleProperty.
616 * @param _titleProperty
617 * the titleProperty to set
620 public void setTitleProperty(final String titleProperty) {
621 _titleProperty = titleProperty;
625 * Get the editDisabledProperty.
627 * @return the editDisabledProperty
630 public final String getEditDisabledProperty() {
631 return _editDisabledProperty;
635 * Set the editDisabledProperty.
637 * @param editDisabledProperty
638 * the editDisabledProperty to set
641 public final void setEditDisabledProperty(final String editDisabledProperty) {
642 _editDisabledProperty = editDisabledProperty;
646 * Get the toolProperty.
648 * @return the toolProperty
651 public String getToolProperty() {
652 return _toolProperty;
656 * Set the toolProperty.
658 * @param toolProperty
659 * the toolProperty to set
662 public void setToolProperty(final String toolProperty) {
663 _toolProperty = toolProperty;
667 * Get the leftMenuProperty.
669 * @return the leftMenuProperty
672 public String getLeftMenuProperty() {
673 return _leftMenuProperty;
677 * Set the leftMenuProperty.
679 * @param leftMenuProperty
680 * the leftMenuProperty to set
683 public void setLeftMenuProperty(final String leftMenuProperty) {
684 _leftMenuProperty = leftMenuProperty;