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