]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java
Salome HOME
<jsp:param ... > parameters are removed from the title bar
[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          * Property that indicates whether the current open study is editable or not.
77          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
78          * It is necessary for correct building the title bar.
79          */
80         private String _editDisabledProperty = "false";
81
82         /**
83          * Save operation type enumeration pointing which section of properties has been edited.
84          */
85         private enum Save {
86                 /**
87                  * Save study title.
88                  */
89                 title,
90                 /**
91                  * Save contributors.
92                  */
93                 contributor,
94                 /**
95                  * Save validation cycle.
96                  */
97                 cycle
98         }
99
100         // ==============================================================================================================================
101         // Action methods
102         // ==============================================================================================================================
103
104         /**
105          * Initialize study properties action.
106          * 
107          * @return "edit" if user can edit study properties, otherwise return "display"
108          */
109         public String doInitialize() {
110
111                 mystudy = getOpenStudy();
112                 validation = new Vector<ValidationFacade>();
113                 validefault = null;
114                 other = getDocumentTypeService().selectResultTypes();
115
116                 Study study = mystudy.getStudyObject();
117                 StudyRights user = mystudy.getStudyRights();
118                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
119                         DocumentType type = i.next();
120                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
121                         if (cycle.isDefault()) {
122                                 validefault = new ValidationFacade(cycle);
123                                 continue;
124                         }
125                         validation.add(new ValidationFacade(cycle));
126                         i.remove();
127                 }
128                 if (validefault != null)
129                         validation.add(validefault); // In order to be at the end
130                 member = getStudyService().getContributors(study);
131                 staff = null;
132                 validor = null;
133                 
134                 setMenuProperty("study");
135                 setTitleProperty("study");
136                 setEditDisabledProperty("true");
137         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
138
139                 if (mystudy.isOpenForWriting() && user.canEditProperties()) {                   
140                         return "edit";
141                 }
142                 else {
143                         return "display";
144                 }
145         }
146
147         public String doEditTitle() {
148 //              Session connex = Database.getCurSession();
149 //              Transaction transax = connex.beginTransaction();
150
151                 mystudy = getOpenStudy();
152                 validation = new Vector<ValidationFacade>();
153                 validefault = null;
154                 other = getDocumentTypeService().selectResultTypes();
155
156                 Study study = mystudy.getStudyObject();
157                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
158                         DocumentType type = i.next();
159                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
160                         if (cycle.isDefault()) {
161                                 validefault = new ValidationFacade(cycle);
162                                 continue;
163                         }
164                         validation.add(new ValidationFacade(cycle));
165                 }
166                 if (validefault != null)
167                         validation.add(validefault); // In order to be at the end
168                 member = getStudyService().getContributors(study);
169                 staff = null;
170                 validor = null;
171                 other = null;
172
173 //              transax.commit();
174                 
175                 setMenuProperty("study");
176                 setTitleProperty("study");
177                 setEditDisabledProperty("true");
178         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
179                 
180                 return SUCCESS;
181         }
182
183         public String doEditContributors() {
184 //              Session connex = Database.getCurSession();
185 //              Transaction transax = connex.beginTransaction();
186
187                 mystudy = getOpenStudy();
188                 validation = new Vector<ValidationFacade>();
189                 validefault = null;
190                 other = getDocumentTypeService().selectAllTypes();
191
192                 Study study = mystudy.getStudyObject();
193                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
194                         DocumentType type = i.next();
195                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
196                         if (cycle.isDefault()) {
197                                 validefault = new ValidationFacade(cycle);
198                                 continue;
199                         }
200                         validation.add(new ValidationFacade(cycle));
201                 }
202                 if (validefault != null)
203                         validation.add(validefault); // In order to be at the end
204                 member = getStudyService().getContributors(study);
205                 staff = getUserService().selectAllUsers();
206                 validor = null;
207                 other = null;
208                 User me = this.getConnectedUser();
209                 for (Iterator<User> i = staff.iterator(); i.hasNext();) {
210                         User next = i.next();
211                         ApplicationRights he = new ApplicationRights(next);
212                         if (next.equals(me) || member.contains(next)
213                                         || !he.canContributeToStudy())
214                                 i.remove();
215                 }
216 //              transax.commit();
217                 
218                 setMenuProperty("study");
219                 setTitleProperty("study");
220                 setEditDisabledProperty("true");
221         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
222                 
223                 return SUCCESS;
224         }
225
226         public String doEditCycle() {
227 //              Session connex = Database.getCurSession();
228 //              Transaction transax = connex.beginTransaction();
229
230                 mystudy = getOpenStudy();
231                 validation = new Vector<ValidationFacade>();
232                 validefault = null;
233                 other = getDocumentTypeService().selectResultTypes();
234
235                 Study study = mystudy.getStudyObject();
236                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
237                         DocumentType type = i.next();
238                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
239                         if (cycle.isDefault()) {
240                                 validefault = new ValidationFacade(cycle);
241                                 continue;
242                         }
243                         if (type.getName().equals(edicycle)) {
244                                 this.type = type.getIndex();
245                         }
246                         validation.add(new ValidationFacade(cycle));
247                         i.remove();
248                 }
249                 if (validefault != null)
250                         validation.add(validefault); // In order to be at the end
251                 member = getStudyService().getContributors(study);
252                 validor = new Vector<Name>();
253                 staff = null;
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                                 else
262                                         validor.add(next);
263                         }
264                 }
265 //              transax.commit();
266                 
267                 setMenuProperty("study");
268                 setTitleProperty("study");
269                 setEditDisabledProperty("true");
270         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
271                 
272                 return SUCCESS;
273         }
274
275         public String doEdition() {
276                 // --------------------------
277 //              Session connex = Database.getCurSession();
278 //              Transaction transax = connex.beginTransaction();
279                 Study study = getOpenStudy().getStudyObject();
280
281                 if (tosave == Save.title) {
282
283                         // Edition of the title
284                         Study.Properties sprop = new Study.Properties();
285                         try {
286                                 getStudyService().update(study, sprop.setTitle(stitle));
287                         } catch (InvalidPropertyException e) {
288                                 // TODO
289                         }
290                 } else if (tosave == Save.contributor) {
291
292                         // Edition of contributors
293                         if (contributors == null)
294                                 contributors = "";
295                         if (candidates == null)
296                                 candidates = "";
297
298                         String[] parsekept = contributors.split(",");
299                         String[] parsenew = candidates.split(",");
300                         Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
301
302                         for (int i = 0; i < parsekept.length; i++) {
303                                 if (parsekept[i].length() == 0)
304                                         continue; // Yet no contributor
305                                 int index = Integer.valueOf(parsekept[i].trim());
306                                 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
307                                         long present = j.next().getIndex();
308                                         if (present != index)
309                                                 continue;
310                                         j.remove();
311                                         break;
312                                 }
313                         }
314                         int size = toremove.size();
315                         if (size > 0)
316                                 getStudyService().removeContributor(study,
317                                                 toremove.toArray(new User[size]));
318
319                         for (int i = 0; i < parsenew.length; i++) {
320                                 if (parsenew[i].length() == 0)
321                                         continue; // No any new contributor
322                                 int index = Integer.valueOf(parsenew[i].trim());
323                                 User newser = getUserService().selectUser(index);
324
325                                 getStudyService().addContributor(study, newser);
326                         }
327                 } else if (tosave == Save.cycle) {
328
329                         // Addition of a document validation cycle
330                         DocumentType apply = getDocumentTypeService().selectType(type);
331                         ValidationCycle.Properties vprop = new ValidationCycle.Properties();
332                         if (publisher > 0) {
333                                 User actor = getUserService().selectUser(publisher);
334                                 vprop.setActor(ValidationStep.PROMOTION, actor);
335                         }
336                         if (reviewer > 0) {
337                                 User actor = getUserService().selectUser(reviewer);
338                                 vprop.setActor(ValidationStep.REVIEW, actor);
339                         }
340                         if (approver > 0) {
341                                 User actor = getUserService().selectUser(approver);
342                                 vprop.setActor(ValidationStep.APPROVAL, actor);
343                         }
344                         getStudyService().setValidationCycle(study, apply, vprop);
345                 }
346 //              transax.commit();
347
348                 doInitialize(); // Re-initialization following the above edition
349                 
350                 setMenuProperty("study");
351                 setTitleProperty("study");
352                 setEditDisabledProperty("true");
353         initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
354                 
355                 return SUCCESS;
356         }
357
358         // ==============================================================================================================================
359         // Getters
360         // ==============================================================================================================================
361
362         public User getAuthor() {
363                 // ------------------------
364                 return mystudy.getStudyObject().getAuthor();
365         }
366
367         public List<User> getCandidates() {
368                 // ----------------------------------
369                 return staff;
370         }
371
372         public String getCycle() {
373                 // -------------------------
374                 return edicycle;
375         }
376
377         public List<User> getContributors() {
378                 // ------------------------------------
379                 return member;
380         }
381
382         public ValidationFacade getDefaultValidation() {
383                 // -----------------------------------------------
384                 return validefault;
385         }
386
387         public long getDocumentTypeIndex() {
388                 // ----------------------------------
389                 return type;
390         }
391
392         public List<DocumentType> getOtherDocumentTypes() {
393                 // --------------------------------------------------
394                 return other;
395         }
396
397         public String getStudyTitle() {
398                 // ------------------------------
399                 return mystudy.getTitle();
400         }
401
402         public List<ValidationFacade> getValidations() {
403                 // -----------------------------------------------
404                 return validation;
405         }
406
407         public List<Name> getValidationActors() {
408                 // ----------------------------------------
409                 return validor;
410         }
411
412         // ==============================================================================================================================
413         // Setters
414         // ==============================================================================================================================
415
416         public void setCandidates(String indices) {
417                 // ------------------------------------------
418                 candidates = indices;
419         }
420
421         public void setCycle(String type) {
422                 // ----------------------------------
423                 edicycle = type;
424         }
425
426         public void setMembers(String indices) {
427                 // ---------------------------------------
428                 contributors = indices;
429         }
430
431         public void setDocumentType(String index) {
432                 // ------------------------------------------
433                 type = Integer.valueOf(index);
434         }
435
436         public void setApprover(String index) {
437                 // --------------------------------------
438                 approver = Integer.valueOf(index);
439         }
440
441         public void setPublisher(String index) {
442                 // ---------------------------------------
443                 publisher = Integer.valueOf(index);
444         }
445
446         public void setReviewer(String index) {
447                 // --------------------------------------
448                 reviewer = Integer.valueOf(index);
449         }
450
451         public void setTitle(String title) {
452                 // -----------------------------------
453                 stitle = title;
454         }
455
456         public void setSaveTitle(String save) {
457                 // --------------------------------------
458                 tosave = Save.title;
459         }
460
461         public void setSaveContributors(String save) {
462                 // ---------------------------------------------
463                 tosave = Save.contributor;
464         }
465
466         public void setSaveCycle(String save) {
467                 // --------------------------------------
468                 tosave = Save.cycle;
469         }
470
471         /**
472          * Get the studyService.
473          * 
474          * @return the studyService
475          */
476         public StudyService getStudyService() {
477                 return _studyService;
478         }
479
480         /**
481          * Set the studyService.
482          * 
483          * @param studyService
484          *            the studyService to set
485          */
486         public void setStudyService(StudyService studyService) {
487                 _studyService = studyService;
488         }
489
490         /**
491          * Get the documentTypeService.
492          * 
493          * @return the documentTypeService
494          */
495         public DocumentTypeService getDocumentTypeService() {
496                 return _documentTypeService;
497         }
498
499         /**
500          * Set the documentTypeService.
501          * 
502          * @param documentTypeService
503          *            the documentTypeService to set
504          */
505         public void setDocumentTypeService(DocumentTypeService documentTypeService) {
506                 _documentTypeService = documentTypeService;
507         }
508
509         /**
510          * Get the userService.
511          * @return the userService
512          */
513         public UserService getUserService() {
514                 return _userService;
515         }
516
517         /**
518          * Set the userService.
519          * @param userService the userService to set
520          */
521         public void setUserService(UserService userService) {
522                 _userService = userService;
523         }
524         
525         /**
526          * Get the menuProperty.
527          * @return the menuProperty
528          */
529         public String getMenuProperty() {
530                 return _menuProperty;
531         }
532
533         /**
534          * Set the menuProperty.
535          * @param menuProperty the menuProperty to set
536          */
537         public void setMenuProperty(String menuProperty) {
538                 this._menuProperty = menuProperty;
539         }
540         
541         /**
542          * Get the _titleProperty.
543          * @return the _titleProperty
544          */
545         public String getTitleProperty() {
546                 return _titleProperty;
547         }
548
549         /**
550          * Set the _titleProperty.
551          * @param _titleProperty the titleProperty to set
552          */
553         public void setTitleProperty(String titleProperty) {
554                 _titleProperty = titleProperty;
555         }
556
557         /**
558          * Get the editDisabledProperty.
559          * @return the editDisabledProperty
560          */
561         public final String getEditDisabledProperty() {
562                 return _editDisabledProperty;
563         }
564
565         /**
566          * Set the editDisabledProperty.
567          * @param editDisabledProperty the editDisabledProperty to set
568          */
569         public final void setEditDisabledProperty(String editDisabledProperty) {
570                 _editDisabledProperty = editDisabledProperty;
571         }
572
573         
574 }