Salome HOME
Modifications to respect PMD rules.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / StudyPropertiesAction.java
1 package org.splat.simer;
2
3 import java.util.Iterator;
4 import java.util.List;
5 import java.util.Vector;
6
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;
19
20 /**
21  * Edit/display study properties (study configuration) screen action.
22  */
23 public class StudyPropertiesAction extends DisplayStudyStepAction {
24
25         /**
26          * Serial version ID.
27          */
28         private static final long serialVersionUID = 4210696018741092900L;
29
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;
37
38         // User input fields
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;
46         private int reviewer;
47         private int approver;
48
49         /**
50          * Injected study service.
51          */
52         private StudyService _studyService;
53         /**
54          * Injected document type service.
55          */
56         private DocumentTypeService _documentTypeService;
57
58         /**
59          * Injected user service.
60          */
61         private UserService _userService;
62         
63         /**
64          * Value of the menu property. 
65          * It can be: none, create, open, study, knowledge, sysadmin, help.
66          */
67         private String _menuProperty;
68         
69         /**
70          * Value of the title bar property. 
71          * It can be: study, knowledge.
72          */
73         private String _titleProperty;
74         
75         /**
76          * Value of the tool bar property. 
77          * It can be: none, standard, study, back.
78          */
79         private String _toolProperty;
80         
81         /**
82          * Value of the left menu property. 
83          * It can be: open, study, knowledge, scenario.
84          */
85         private String _leftMenuProperty;
86         
87         /**
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.
91          */
92         private String _editDisabledProperty = "false";
93
94         /**
95          * Save operation type enumeration pointing which section of properties has been edited.
96          */
97         private enum Save {
98                 /**
99                  * Save study title.
100                  */
101                 title,
102                 /**
103                  * Save contributors.
104                  */
105                 contributor,
106                 /**
107                  * Save validation cycle.
108                  */
109                 cycle
110         }
111
112         // ==============================================================================================================================
113         // Action methods
114         // ==============================================================================================================================
115
116         /**
117          * Initialize study properties action.
118          * 
119          * @return "edit" if user can edit study properties, otherwise return "display"
120          */
121         public String doInitialize() {
122
123                 _openStudy = getOpenStudy();
124                 validation = new Vector<ValidationFacade>();
125                 validefault = null;
126                 other = getDocumentTypeService().selectResultTypes();
127
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);
135                                 continue;
136                         }
137                         validation.add(new ValidationFacade(cycle));
138                         i.remove();
139                 }
140                 if (validefault != null)
141                         validation.add(validefault); // In order to be at the end
142                 member = getStudyService().getContributors(study);
143                 staff = null;
144                 validor = null;
145                 
146                 setMenuProperty("study");
147                 setTitleProperty("study");
148                 setEditDisabledProperty("true");
149                 setToolProperty("back");
150                 setLeftMenuProperty("open");
151                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
152
153                 if (_openStudy.isOpenForWriting() && user.canEditProperties()) {                        
154                         return "edit";
155                 }
156                 else {
157                         return "display";
158                 }
159         }
160
161         public String doEditTitle() {
162 //              Session connex = Database.getCurSession();
163 //              Transaction transax = connex.beginTransaction();
164
165                 _openStudy = getOpenStudy();
166                 validation = new Vector<ValidationFacade>();
167                 validefault = null;
168                 other = getDocumentTypeService().selectResultTypes();
169
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);
176                                 continue;
177                         }
178                         validation.add(new ValidationFacade(cycle));
179                 }
180                 if (validefault != null)
181                         validation.add(validefault); // In order to be at the end
182                 member = getStudyService().getContributors(study);
183                 staff = null;
184                 validor = null;
185                 other = null;
186
187 //              transax.commit();
188                 
189                 setMenuProperty("study");
190                 setTitleProperty("study");
191                 setEditDisabledProperty("true");
192                 setToolProperty("back");
193                 setLeftMenuProperty("open");
194                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
195
196                 return SUCCESS;
197         }
198
199         public String doEditContributors() {
200 //              Session connex = Database.getCurSession();
201 //              Transaction transax = connex.beginTransaction();
202
203                 _openStudy = getOpenStudy();
204                 validation = new Vector<ValidationFacade>();
205                 validefault = null;
206                 other = getDocumentTypeService().selectAllTypes();
207
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);
214                                 continue;
215                         }
216                         validation.add(new ValidationFacade(cycle));
217                 }
218                 if (validefault != null)
219                         validation.add(validefault); // In order to be at the end
220                 member = getStudyService().getContributors(study);
221                 staff = getUserService().selectAllUsers();
222                 validor = null;
223                 other = null;
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())
230                                 i.remove();
231                 }
232 //              transax.commit();
233                 
234                 setMenuProperty("study");
235                 setTitleProperty("study");
236                 setEditDisabledProperty("true");
237                 setToolProperty("back");
238                 setLeftMenuProperty("open");
239                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
240
241                 return SUCCESS;
242         }
243
244         public String doEditCycle() {
245 //              Session connex = Database.getCurSession();
246 //              Transaction transax = connex.beginTransaction();
247
248                 _openStudy = getOpenStudy();
249                 validation = new Vector<ValidationFacade>();
250                 validefault = null;
251                 other = getDocumentTypeService().selectResultTypes();
252
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);
259                                 continue;
260                         }
261                         if (type.getName().equals(edicycle)) {
262                                 this.type = type.getIndex();
263                         }
264                         validation.add(new ValidationFacade(cycle));
265                         i.remove();
266                 }
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>();
271                 staff = null;
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));
279                                 else
280                                         validor.add(next);
281                         }
282                 }
283 //              transax.commit();
284                 
285                 setMenuProperty("study");
286                 setTitleProperty("study");
287                 setEditDisabledProperty("true");
288                 setToolProperty("back");
289                 setLeftMenuProperty("open");
290                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
291
292                 return SUCCESS;
293         }
294
295         public String doEdition() {
296                 // --------------------------
297 //              Session connex = Database.getCurSession();
298 //              Transaction transax = connex.beginTransaction();
299                 Study study = getOpenStudy().getStudyObject();
300
301                 if (tosave == Save.title) {
302
303                         // Edition of the title
304                         Study.Properties sprop = new Study.Properties();
305                         try {
306                                 getStudyService().update(study, sprop.setTitle(stitle));
307                         } catch (InvalidPropertyException e) {
308                                 // TODO
309                         }
310                 } else if (tosave == Save.contributor) {
311
312                         // Edition of contributors
313                         if (contributors == null)
314                                 contributors = "";
315                         if (candidates == null)
316                                 candidates = "";
317
318                         String[] parsekept = contributors.split(",");
319                         String[] parsenew = candidates.split(",");
320                         Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
321
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)
329                                                 continue;
330                                         j.remove();
331                                         break;
332                                 }
333                         }
334                         int size = toremove.size();
335                         if (size > 0)
336                                 getStudyService().removeContributor(study,
337                                                 toremove.toArray(new User[size]));
338
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);
344
345                                 getStudyService().addContributor(study, newser);
346                         }
347                 } else if (tosave == Save.cycle) {
348
349                         // Addition of a document validation cycle
350                         DocumentType apply = getDocumentTypeService().selectType(type);
351                         ValidationCycle.Properties vprop = new ValidationCycle.Properties();
352                         if (publisher > 0) {
353                                 User actor = getUserService().selectUser(publisher);
354                                 vprop.setActor(ValidationStep.PROMOTION, actor);
355                         }
356                         if (reviewer > 0) {
357                                 User actor = getUserService().selectUser(reviewer);
358                                 vprop.setActor(ValidationStep.REVIEW, actor);
359                         }
360                         if (approver > 0) {
361                                 User actor = getUserService().selectUser(approver);
362                                 vprop.setActor(ValidationStep.APPROVAL, actor);
363                         }
364                         getStudyService().setValidationCycle(study, apply, vprop);
365                 }
366 //              transax.commit();
367
368                 doInitialize(); // Re-initialization following the above edition
369                 
370                 setMenuProperty("study");
371                 setTitleProperty("study");
372                 setEditDisabledProperty("true");
373                 setToolProperty("back");
374                 setLeftMenuProperty("open");
375                 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
376
377                 return SUCCESS;
378         }
379
380         // ==============================================================================================================================
381         // Getters
382         // ==============================================================================================================================
383
384         public User getAuthor() {
385                 // ------------------------
386                 return _openStudy.getStudyObject().getAuthor();
387         }
388
389         public List<User> getCandidates() {
390                 // ----------------------------------
391                 return staff;
392         }
393
394         public String getCycle() {
395                 // -------------------------
396                 return edicycle;
397         }
398
399         public List<User> getContributors() {
400                 // ------------------------------------
401                 return member;
402         }
403
404         public ValidationFacade getDefaultValidation() {
405                 // -----------------------------------------------
406                 return validefault;
407         }
408
409         public long getDocumentTypeIndex() {
410                 // ----------------------------------
411                 return type;
412         }
413
414         public List<DocumentType> getOtherDocumentTypes() {
415                 // --------------------------------------------------
416                 return other;
417         }
418
419         public String getStudyTitle() {
420                 // ------------------------------
421                 return _openStudy.getTitle();
422         }
423
424         public List<ValidationFacade> getValidations() {
425                 // -----------------------------------------------
426                 return validation;
427         }
428
429         public List<Name> getValidationActors() {
430                 // ----------------------------------------
431                 return validor;
432         }
433
434         // ==============================================================================================================================
435         // Setters
436         // ==============================================================================================================================
437
438         public void setCandidates(String indices) {
439                 // ------------------------------------------
440                 candidates = indices;
441         }
442
443         public void setCycle(String type) {
444                 // ----------------------------------
445                 edicycle = type;
446         }
447
448         public void setMembers(String indices) {
449                 // ---------------------------------------
450                 contributors = indices;
451         }
452
453         public void setDocumentType(String index) {
454                 // ------------------------------------------
455                 type = Integer.valueOf(index);
456         }
457
458         public void setApprover(String index) {
459                 // --------------------------------------
460                 approver = Integer.valueOf(index);
461         }
462
463         public void setPublisher(String index) {
464                 // ---------------------------------------
465                 publisher = Integer.valueOf(index);
466         }
467
468         public void setReviewer(String index) {
469                 // --------------------------------------
470                 reviewer = Integer.valueOf(index);
471         }
472
473         public void setTitle(String title) {
474                 // -----------------------------------
475                 stitle = title;
476         }
477
478         public void setSaveTitle(String save) {
479                 // --------------------------------------
480                 tosave = Save.title;
481         }
482
483         public void setSaveContributors(String save) {
484                 // ---------------------------------------------
485                 tosave = Save.contributor;
486         }
487
488         public void setSaveCycle(String save) {
489                 // --------------------------------------
490                 tosave = Save.cycle;
491         }
492
493         /**
494          * Get the studyService.
495          * 
496          * @return the studyService
497          */
498         public StudyService getStudyService() {
499                 return _studyService;
500         }
501
502         /**
503          * Set the studyService.
504          * 
505          * @param studyService
506          *            the studyService to set
507          */
508         public void setStudyService(StudyService studyService) {
509                 _studyService = studyService;
510         }
511
512         /**
513          * Get the documentTypeService.
514          * 
515          * @return the documentTypeService
516          */
517         public DocumentTypeService getDocumentTypeService() {
518                 return _documentTypeService;
519         }
520
521         /**
522          * Set the documentTypeService.
523          * 
524          * @param documentTypeService
525          *            the documentTypeService to set
526          */
527         public void setDocumentTypeService(DocumentTypeService documentTypeService) {
528                 _documentTypeService = documentTypeService;
529         }
530
531         /**
532          * Get the userService.
533          * @return the userService
534          */
535         public UserService getUserService() {
536                 return _userService;
537         }
538
539         /**
540          * Set the userService.
541          * @param userService the userService to set
542          */
543         public void setUserService(UserService userService) {
544                 _userService = userService;
545         }
546         
547         /**
548          * Get the menuProperty.
549          * @return the menuProperty
550          */
551         public String getMenuProperty() {
552                 return _menuProperty;
553         }
554
555         /**
556          * Set the menuProperty.
557          * @param menuProperty the menuProperty to set
558          */
559         public void setMenuProperty(String menuProperty) {
560                 this._menuProperty = menuProperty;
561         }
562         
563         /**
564          * Get the _titleProperty.
565          * @return the _titleProperty
566          */
567         public String getTitleProperty() {
568                 return _titleProperty;
569         }
570
571         /**
572          * Set the _titleProperty.
573          * @param _titleProperty the titleProperty to set
574          */
575         public void setTitleProperty(String titleProperty) {
576                 _titleProperty = titleProperty;
577         }
578
579         /**
580          * Get the editDisabledProperty.
581          * @return the editDisabledProperty
582          */
583         public final String getEditDisabledProperty() {
584                 return _editDisabledProperty;
585         }
586
587         /**
588          * Set the editDisabledProperty.
589          * @param editDisabledProperty the editDisabledProperty to set
590          */
591         public final void setEditDisabledProperty(String editDisabledProperty) {
592                 _editDisabledProperty = editDisabledProperty;
593         }
594
595         /**
596          * Get the toolProperty.
597          * @return the toolProperty
598          */
599         public String getToolProperty() {
600                 return _toolProperty;
601         }
602
603         /**
604          * Set the toolProperty.
605          * @param toolProperty the toolProperty to set
606          */
607         public void setToolProperty(final String toolProperty) {
608                 _toolProperty = toolProperty;
609         }
610         
611         /**
612          * Get the leftMenuProperty.
613          * @return the leftMenuProperty
614          */
615         public String getLeftMenuProperty() {
616                 return _leftMenuProperty;
617         }
618
619         /**
620          * Set the leftMenuProperty.
621          * @param leftMenuProperty the leftMenuProperty to set
622          */
623         public void setLeftMenuProperty(final String leftMenuProperty) {
624                 _leftMenuProperty = leftMenuProperty;
625         }
626 }