1 package org.splat.simer;
3 import java.util.Iterator;
5 import java.util.Vector;
7 import org.splat.kernel.InvalidPropertyException;
8 import org.splat.kernel.Name;
9 import org.splat.dal.bo.kernel.User;
10 import org.splat.service.DocumentTypeService;
11 import org.splat.service.StudyService;
12 import org.splat.service.UserService;
13 import org.splat.som.ApplicationRights;
14 import org.splat.dal.bo.som.DocumentType;
15 import org.splat.dal.bo.som.Study;
16 import org.splat.som.StudyRights;
17 import org.splat.dal.bo.som.ValidationCycle;
18 import org.splat.dal.bo.som.ValidationStep;
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.
65 * It can be: none, create, open, study, knowledge, sysadmin, help.
67 private String _menuProperty;
70 * Value of the title bar property.
71 * It can be: study, knowledge.
73 private String _titleProperty;
76 * Value of the tool bar property.
77 * It can be: none, standard, study, back.
79 private String _toolProperty;
82 * Value of the left menu property.
83 * It can be: open, study, knowledge, scenario.
85 private String _leftMenuProperty;
88 * Property that indicates whether the current open study is editable or not.
89 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
90 * It is necessary for correct building the title bar.
92 private String _editDisabledProperty = "false";
95 * Save operation type enumeration pointing which section of properties has been edited.
107 * Save validation cycle.
112 // ==============================================================================================================================
114 // ==============================================================================================================================
117 * Initialize study properties action.
119 * @return "edit" if user can edit study properties, otherwise return "display"
121 public String doInitialize() {
123 _openStudy = getOpenStudy();
124 validation = new Vector<ValidationFacade>();
126 other = getDocumentTypeService().selectResultTypes();
128 Study study = _openStudy.getStudyObject();
129 StudyRights user = _openStudy.getStudyRights();
130 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
131 DocumentType type = i.next();
132 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
133 if (cycle.isDefault()) {
134 validefault = new ValidationFacade(cycle);
137 validation.add(new ValidationFacade(cycle));
140 if (validefault != null)
141 validation.add(validefault); // In order to be at the end
142 member = getStudyService().getContributors(study);
146 setMenuProperty("study");
147 setTitleProperty("study");
148 setEditDisabledProperty("true");
149 setToolProperty("back");
150 setLeftMenuProperty("open");
151 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
153 if (_openStudy.isOpenForWriting() && user.canEditProperties()) {
161 public String doEditTitle() {
162 // Session connex = Database.getCurSession();
163 // Transaction transax = connex.beginTransaction();
165 _openStudy = getOpenStudy();
166 validation = new Vector<ValidationFacade>();
168 other = getDocumentTypeService().selectResultTypes();
170 Study study = _openStudy.getStudyObject();
171 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
172 DocumentType type = i.next();
173 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
174 if (cycle.isDefault()) {
175 validefault = new ValidationFacade(cycle);
178 validation.add(new ValidationFacade(cycle));
180 if (validefault != null)
181 validation.add(validefault); // In order to be at the end
182 member = getStudyService().getContributors(study);
189 setMenuProperty("study");
190 setTitleProperty("study");
191 setEditDisabledProperty("true");
192 setToolProperty("back");
193 setLeftMenuProperty("open");
194 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
199 public String doEditContributors() {
200 // Session connex = Database.getCurSession();
201 // Transaction transax = connex.beginTransaction();
203 _openStudy = getOpenStudy();
204 validation = new Vector<ValidationFacade>();
206 other = getDocumentTypeService().selectAllTypes();
208 Study study = _openStudy.getStudyObject();
209 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
210 DocumentType type = i.next();
211 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
212 if (cycle.isDefault()) {
213 validefault = new ValidationFacade(cycle);
216 validation.add(new ValidationFacade(cycle));
218 if (validefault != null)
219 validation.add(validefault); // In order to be at the end
220 member = getStudyService().getContributors(study);
221 staff = getUserService().selectAllUsers();
224 User me = this.getConnectedUser();
225 for (Iterator<User> i = staff.iterator(); i.hasNext();) {
226 User next = i.next();
227 ApplicationRights he = new ApplicationRights(next);
228 if (next.equals(me) || member.contains(next)
229 || !he.canContributeToStudy())
234 setMenuProperty("study");
235 setTitleProperty("study");
236 setEditDisabledProperty("true");
237 setToolProperty("back");
238 setLeftMenuProperty("open");
239 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
244 public String doEditCycle() {
245 // Session connex = Database.getCurSession();
246 // Transaction transax = connex.beginTransaction();
248 _openStudy = getOpenStudy();
249 validation = new Vector<ValidationFacade>();
251 other = getDocumentTypeService().selectResultTypes();
253 Study study = _openStudy.getStudyObject();
254 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
255 DocumentType type = i.next();
256 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
257 if (cycle.isDefault()) {
258 validefault = new ValidationFacade(cycle);
261 if (type.getName().equals(edicycle)) {
262 this.type = type.getIndex();
264 validation.add(new ValidationFacade(cycle));
267 if (validefault != null)
268 validation.add(validefault); // In order to be at the end
269 member = getStudyService().getContributors(study);
270 validor = new Vector<Name>();
272 List<User> user = getUserService().selectAllUsers();
273 for (Iterator<User> i = user.iterator(); i.hasNext();) {
274 User next = i.next();
275 ApplicationRights he = new ApplicationRights(next);
276 if (he.canValidate()) {
277 if (next.equals(study.getAuthor()))
278 validor.add(new ValidationFacade.ByManager(next));
285 setMenuProperty("study");
286 setTitleProperty("study");
287 setEditDisabledProperty("true");
288 setToolProperty("back");
289 setLeftMenuProperty("open");
290 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
295 public String doEdition() {
296 // --------------------------
297 // Session connex = Database.getCurSession();
298 // Transaction transax = connex.beginTransaction();
299 Study study = getOpenStudy().getStudyObject();
301 if (tosave == Save.title) {
303 // Edition of the title
304 Study.Properties sprop = new Study.Properties();
306 getStudyService().update(study, sprop.setTitle(stitle));
307 } catch (InvalidPropertyException e) {
310 } else if (tosave == Save.contributor) {
312 // Edition of contributors
313 if (contributors == null)
315 if (candidates == null)
318 String[] parsekept = contributors.split(",");
319 String[] parsenew = candidates.split(",");
320 Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
322 for (int i = 0; i < parsekept.length; i++) {
323 if (parsekept[i].length() == 0)
324 continue; // Yet no contributor
325 int index = Integer.valueOf(parsekept[i].trim());
326 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
327 long present = j.next().getIndex();
328 if (present != index)
334 int size = toremove.size();
336 getStudyService().removeContributor(study,
337 toremove.toArray(new User[size]));
339 for (int i = 0; i < parsenew.length; i++) {
340 if (parsenew[i].length() == 0)
341 continue; // No any new contributor
342 int index = Integer.valueOf(parsenew[i].trim());
343 User newser = getUserService().selectUser(index);
345 getStudyService().addContributor(study, newser);
347 } else if (tosave == Save.cycle) {
349 // Addition of a document validation cycle
350 DocumentType apply = getDocumentTypeService().selectType(type);
351 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
353 User actor = getUserService().selectUser(publisher);
354 vprop.setActor(ValidationStep.PROMOTION, actor);
357 User actor = getUserService().selectUser(reviewer);
358 vprop.setActor(ValidationStep.REVIEW, actor);
361 User actor = getUserService().selectUser(approver);
362 vprop.setActor(ValidationStep.APPROVAL, actor);
364 getStudyService().setValidationCycle(study, apply, vprop);
368 doInitialize(); // Re-initialization following the above edition
370 setMenuProperty("study");
371 setTitleProperty("study");
372 setEditDisabledProperty("true");
373 setToolProperty("back");
374 setLeftMenuProperty("open");
375 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
380 // ==============================================================================================================================
382 // ==============================================================================================================================
384 public User getAuthor() {
385 // ------------------------
386 return _openStudy.getStudyObject().getAuthor();
389 public List<User> getCandidates() {
390 // ----------------------------------
394 public String getCycle() {
395 // -------------------------
399 public List<User> getContributors() {
400 // ------------------------------------
404 public ValidationFacade getDefaultValidation() {
405 // -----------------------------------------------
409 public long getDocumentTypeIndex() {
410 // ----------------------------------
414 public List<DocumentType> getOtherDocumentTypes() {
415 // --------------------------------------------------
419 public String getStudyTitle() {
420 // ------------------------------
421 return _openStudy.getTitle();
424 public List<ValidationFacade> getValidations() {
425 // -----------------------------------------------
429 public List<Name> getValidationActors() {
430 // ----------------------------------------
434 // ==============================================================================================================================
436 // ==============================================================================================================================
438 public void setCandidates(String indices) {
439 // ------------------------------------------
440 candidates = indices;
443 public void setCycle(String type) {
444 // ----------------------------------
448 public void setMembers(String indices) {
449 // ---------------------------------------
450 contributors = indices;
453 public void setDocumentType(String index) {
454 // ------------------------------------------
455 type = Integer.valueOf(index);
458 public void setApprover(String index) {
459 // --------------------------------------
460 approver = Integer.valueOf(index);
463 public void setPublisher(String index) {
464 // ---------------------------------------
465 publisher = Integer.valueOf(index);
468 public void setReviewer(String index) {
469 // --------------------------------------
470 reviewer = Integer.valueOf(index);
473 public void setTitle(String title) {
474 // -----------------------------------
478 public void setSaveTitle(String save) {
479 // --------------------------------------
483 public void setSaveContributors(String save) {
484 // ---------------------------------------------
485 tosave = Save.contributor;
488 public void setSaveCycle(String save) {
489 // --------------------------------------
494 * Get the studyService.
496 * @return the studyService
498 public StudyService getStudyService() {
499 return _studyService;
503 * Set the studyService.
505 * @param studyService
506 * the studyService to set
508 public void setStudyService(StudyService studyService) {
509 _studyService = studyService;
513 * Get the documentTypeService.
515 * @return the documentTypeService
517 public DocumentTypeService getDocumentTypeService() {
518 return _documentTypeService;
522 * Set the documentTypeService.
524 * @param documentTypeService
525 * the documentTypeService to set
527 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
528 _documentTypeService = documentTypeService;
532 * Get the userService.
533 * @return the userService
535 public UserService getUserService() {
540 * Set the userService.
541 * @param userService the userService to set
543 public void setUserService(UserService userService) {
544 _userService = userService;
548 * Get the menuProperty.
549 * @return the menuProperty
551 public String getMenuProperty() {
552 return _menuProperty;
556 * Set the menuProperty.
557 * @param menuProperty the menuProperty to set
559 public void setMenuProperty(String menuProperty) {
560 this._menuProperty = menuProperty;
564 * Get the _titleProperty.
565 * @return the _titleProperty
567 public String getTitleProperty() {
568 return _titleProperty;
572 * Set the _titleProperty.
573 * @param _titleProperty the titleProperty to set
575 public void setTitleProperty(String titleProperty) {
576 _titleProperty = titleProperty;
580 * Get the editDisabledProperty.
581 * @return the editDisabledProperty
583 public final String getEditDisabledProperty() {
584 return _editDisabledProperty;
588 * Set the editDisabledProperty.
589 * @param editDisabledProperty the editDisabledProperty to set
591 public final void setEditDisabledProperty(String editDisabledProperty) {
592 _editDisabledProperty = editDisabledProperty;
596 * Get the toolProperty.
597 * @return the toolProperty
599 public String getToolProperty() {
600 return _toolProperty;
604 * Set the toolProperty.
605 * @param toolProperty the toolProperty to set
607 public void setToolProperty(final String toolProperty) {
608 _toolProperty = toolProperty;
612 * Get the leftMenuProperty.
613 * @return the leftMenuProperty
615 public String getLeftMenuProperty() {
616 return _leftMenuProperty;
620 * Set the leftMenuProperty.
621 * @param leftMenuProperty the leftMenuProperty to set
623 public void setLeftMenuProperty(final String leftMenuProperty) {
624 _leftMenuProperty = leftMenuProperty;