]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[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          * Save operation type enumeration pointing which section of properties has been edited.
65          */
66         private enum Save {
67                 /**
68                  * Save study title.
69                  */
70                 title,
71                 /**
72                  * Save contributors.
73                  */
74                 contributor,
75                 /**
76                  * Save validation cycle.
77                  */
78                 cycle
79         }
80
81         // ==============================================================================================================================
82         // Action methods
83         // ==============================================================================================================================
84
85         /**
86          * Initialize study properties action.
87          * 
88          * @return "edit" if user can edit study properties, otherwise return "display"
89          */
90         public String doInitialize() {
91
92                 mystudy = getOpenStudy();
93                 validation = new Vector<ValidationFacade>();
94                 validefault = null;
95                 other = getDocumentTypeService().selectResultTypes();
96
97                 Study study = mystudy.getStudyObject();
98                 StudyRights user = mystudy.getStudyRights();
99                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
100                         DocumentType type = i.next();
101                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
102                         if (cycle.isDefault()) {
103                                 validefault = new ValidationFacade(cycle);
104                                 continue;
105                         }
106                         validation.add(new ValidationFacade(cycle));
107                         i.remove();
108                 }
109                 if (validefault != null)
110                         validation.add(validefault); // In order to be at the end
111                 member = getStudyService().getContributors(study);
112                 staff = null;
113                 validor = null;
114
115                 if (mystudy.isOpenForWriting() && user.canEditProperties())
116                         return "edit";
117                 else
118                         return "display";
119         }
120
121         public String doEditTitle() {
122 //              Session connex = Database.getCurSession();
123 //              Transaction transax = connex.beginTransaction();
124
125                 mystudy = getOpenStudy();
126                 validation = new Vector<ValidationFacade>();
127                 validefault = null;
128                 other = getDocumentTypeService().selectResultTypes();
129
130                 Study study = mystudy.getStudyObject();
131                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
132                         DocumentType type = i.next();
133                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
134                         if (cycle.isDefault()) {
135                                 validefault = new ValidationFacade(cycle);
136                                 continue;
137                         }
138                         validation.add(new ValidationFacade(cycle));
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                 other = null;
146
147 //              transax.commit();
148                 return SUCCESS;
149         }
150
151         public String doEditContributors() {
152 //              Session connex = Database.getCurSession();
153 //              Transaction transax = connex.beginTransaction();
154
155                 mystudy = getOpenStudy();
156                 validation = new Vector<ValidationFacade>();
157                 validefault = null;
158                 other = getDocumentTypeService().selectAllTypes();
159
160                 Study study = mystudy.getStudyObject();
161                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
162                         DocumentType type = i.next();
163                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
164                         if (cycle.isDefault()) {
165                                 validefault = new ValidationFacade(cycle);
166                                 continue;
167                         }
168                         validation.add(new ValidationFacade(cycle));
169                 }
170                 if (validefault != null)
171                         validation.add(validefault); // In order to be at the end
172                 member = getStudyService().getContributors(study);
173                 staff = getUserService().selectAllUsers();
174                 validor = null;
175                 other = null;
176                 User me = this.getConnectedUser();
177                 for (Iterator<User> i = staff.iterator(); i.hasNext();) {
178                         User next = i.next();
179                         ApplicationRights he = new ApplicationRights(next);
180                         if (next.equals(me) || member.contains(next)
181                                         || !he.canContributeToStudy())
182                                 i.remove();
183                 }
184 //              transax.commit();
185                 return SUCCESS;
186         }
187
188         public String doEditCycle() {
189 //              Session connex = Database.getCurSession();
190 //              Transaction transax = connex.beginTransaction();
191
192                 mystudy = getOpenStudy();
193                 validation = new Vector<ValidationFacade>();
194                 validefault = null;
195                 other = getDocumentTypeService().selectResultTypes();
196
197                 Study study = mystudy.getStudyObject();
198                 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
199                         DocumentType type = i.next();
200                         ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
201                         if (cycle.isDefault()) {
202                                 validefault = new ValidationFacade(cycle);
203                                 continue;
204                         }
205                         if (type.getName().equals(edicycle)) {
206                                 this.type = type.getIndex();
207                         }
208                         validation.add(new ValidationFacade(cycle));
209                         i.remove();
210                 }
211                 if (validefault != null)
212                         validation.add(validefault); // In order to be at the end
213                 member = getStudyService().getContributors(study);
214                 validor = new Vector<Name>();
215                 staff = null;
216                 List<User> user = getUserService().selectAllUsers();
217                 for (Iterator<User> i = user.iterator(); i.hasNext();) {
218                         User next = i.next();
219                         ApplicationRights he = new ApplicationRights(next);
220                         if (he.canValidate()) {
221                                 if (next.equals(study.getAuthor()))
222                                         validor.add(new ValidationFacade.ByManager(next));
223                                 else
224                                         validor.add(next);
225                         }
226                 }
227 //              transax.commit();
228                 return SUCCESS;
229         }
230
231         public String doEdition() {
232                 // --------------------------
233 //              Session connex = Database.getCurSession();
234 //              Transaction transax = connex.beginTransaction();
235                 Study study = getOpenStudy().getStudyObject();
236
237                 if (tosave == Save.title) {
238
239                         // Edition of the title
240                         Study.Properties sprop = new Study.Properties();
241                         try {
242                                 getStudyService().update(study, sprop.setTitle(stitle));
243                         } catch (InvalidPropertyException e) {
244                                 // TODO
245                         }
246                 } else if (tosave == Save.contributor) {
247
248                         // Edition of contributors
249                         if (contributors == null)
250                                 contributors = "";
251                         if (candidates == null)
252                                 candidates = "";
253
254                         String[] parsekept = contributors.split(",");
255                         String[] parsenew = candidates.split(",");
256                         Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
257
258                         for (int i = 0; i < parsekept.length; i++) {
259                                 if (parsekept[i].length() == 0)
260                                         continue; // Yet no contributor
261                                 int index = Integer.valueOf(parsekept[i].trim());
262                                 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
263                                         long present = j.next().getIndex();
264                                         if (present != index)
265                                                 continue;
266                                         j.remove();
267                                         break;
268                                 }
269                         }
270                         int size = toremove.size();
271                         if (size > 0)
272                                 getStudyService().removeContributor(study,
273                                                 toremove.toArray(new User[size]));
274
275                         for (int i = 0; i < parsenew.length; i++) {
276                                 if (parsenew[i].length() == 0)
277                                         continue; // No any new contributor
278                                 int index = Integer.valueOf(parsenew[i].trim());
279                                 User newser = getUserService().selectUser(index);
280
281                                 getStudyService().addContributor(study, newser);
282                         }
283                 } else if (tosave == Save.cycle) {
284
285                         // Addition of a document validation cycle
286                         DocumentType apply = getDocumentTypeService().selectType(type);
287                         ValidationCycle.Properties vprop = new ValidationCycle.Properties();
288                         if (publisher > 0) {
289                                 User actor = getUserService().selectUser(publisher);
290                                 vprop.setActor(ValidationStep.PROMOTION, actor);
291                         }
292                         if (reviewer > 0) {
293                                 User actor = getUserService().selectUser(reviewer);
294                                 vprop.setActor(ValidationStep.REVIEW, actor);
295                         }
296                         if (approver > 0) {
297                                 User actor = getUserService().selectUser(approver);
298                                 vprop.setActor(ValidationStep.APPROVAL, actor);
299                         }
300                         getStudyService().setValidationCycle(study, apply, vprop);
301                 }
302 //              transax.commit();
303
304                 doInitialize(); // Re-initialization following the above edition
305                 return SUCCESS;
306         }
307
308         // ==============================================================================================================================
309         // Getters
310         // ==============================================================================================================================
311
312         public User getAuthor() {
313                 // ------------------------
314                 return mystudy.getStudyObject().getAuthor();
315         }
316
317         public List<User> getCandidates() {
318                 // ----------------------------------
319                 return staff;
320         }
321
322         public String getCycle() {
323                 // -------------------------
324                 return edicycle;
325         }
326
327         public List<User> getContributors() {
328                 // ------------------------------------
329                 return member;
330         }
331
332         public ValidationFacade getDefaultValidation() {
333                 // -----------------------------------------------
334                 return validefault;
335         }
336
337         public long getDocumentTypeIndex() {
338                 // ----------------------------------
339                 return type;
340         }
341
342         public List<DocumentType> getOtherDocumentTypes() {
343                 // --------------------------------------------------
344                 return other;
345         }
346
347         public String getStudyTitle() {
348                 // ------------------------------
349                 return mystudy.getTitle();
350         }
351
352         public List<ValidationFacade> getValidations() {
353                 // -----------------------------------------------
354                 return validation;
355         }
356
357         public List<Name> getValidationActors() {
358                 // ----------------------------------------
359                 return validor;
360         }
361
362         // ==============================================================================================================================
363         // Setters
364         // ==============================================================================================================================
365
366         public void setCandidates(String indices) {
367                 // ------------------------------------------
368                 candidates = indices;
369         }
370
371         public void setCycle(String type) {
372                 // ----------------------------------
373                 edicycle = type;
374         }
375
376         public void setMembers(String indices) {
377                 // ---------------------------------------
378                 contributors = indices;
379         }
380
381         public void setDocumentType(String index) {
382                 // ------------------------------------------
383                 type = Integer.valueOf(index);
384         }
385
386         public void setApprover(String index) {
387                 // --------------------------------------
388                 approver = Integer.valueOf(index);
389         }
390
391         public void setPublisher(String index) {
392                 // ---------------------------------------
393                 publisher = Integer.valueOf(index);
394         }
395
396         public void setReviewer(String index) {
397                 // --------------------------------------
398                 reviewer = Integer.valueOf(index);
399         }
400
401         public void setTitle(String title) {
402                 // -----------------------------------
403                 stitle = title;
404         }
405
406         public void setSaveTitle(String save) {
407                 // --------------------------------------
408                 tosave = Save.title;
409         }
410
411         public void setSaveContributors(String save) {
412                 // ---------------------------------------------
413                 tosave = Save.contributor;
414         }
415
416         public void setSaveCycle(String save) {
417                 // --------------------------------------
418                 tosave = Save.cycle;
419         }
420
421         /**
422          * Get the studyService.
423          * 
424          * @return the studyService
425          */
426         public StudyService getStudyService() {
427                 return _studyService;
428         }
429
430         /**
431          * Set the studyService.
432          * 
433          * @param studyService
434          *            the studyService to set
435          */
436         public void setStudyService(StudyService studyService) {
437                 _studyService = studyService;
438         }
439
440         /**
441          * Get the documentTypeService.
442          * 
443          * @return the documentTypeService
444          */
445         public DocumentTypeService getDocumentTypeService() {
446                 return _documentTypeService;
447         }
448
449         /**
450          * Set the documentTypeService.
451          * 
452          * @param documentTypeService
453          *            the documentTypeService to set
454          */
455         public void setDocumentTypeService(DocumentTypeService documentTypeService) {
456                 _documentTypeService = documentTypeService;
457         }
458
459         /**
460          * Get the userService.
461          * @return the userService
462          */
463         public UserService getUserService() {
464                 return _userService;
465         }
466
467         /**
468          * Set the userService.
469          * @param userService the userService to set
470          */
471         public void setUserService(UserService userService) {
472                 _userService = userService;
473         }
474 }