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