1 package org.splat.simer;
3 import java.util.Iterator;
5 import java.util.Vector;
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;
21 * Edit/display study properties (study configuration) screen action.
23 public class StudyPropertiesAction extends DisplayStudyStepAction {
28 private static final long serialVersionUID = 4210696018741092900L;
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;
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;
50 * Injected study service.
52 private StudyService _studyService;
54 * Injected document type service.
56 private DocumentTypeService _documentTypeService;
59 * Injected user service.
61 private UserService _userService;
64 * Value of the menu property.
65 * It can be: none, create, open, study, knowledge, sysadmin, help.
67 private String _menuProperty;
70 * Value of the title bar property.
71 * It can be: study, knowledge.
73 private String _titleProperty;
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.
80 private String _editDisabledProperty = "false";
83 * Save operation type enumeration pointing which section of properties has been edited.
95 * Save validation cycle.
100 // ==============================================================================================================================
102 // ==============================================================================================================================
105 * Initialize study properties action.
107 * @return "edit" if user can edit study properties, otherwise return "display"
109 public String doInitialize() {
111 mystudy = getOpenStudy();
112 validation = new Vector<ValidationFacade>();
114 other = getDocumentTypeService().selectResultTypes();
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);
125 validation.add(new ValidationFacade(cycle));
128 if (validefault != null)
129 validation.add(validefault); // In order to be at the end
130 member = getStudyService().getContributors(study);
134 setMenuProperty("study");
135 setTitleProperty("study");
136 setEditDisabledProperty("true");
137 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
139 if (mystudy.isOpenForWriting() && user.canEditProperties()) {
147 public String doEditTitle() {
148 // Session connex = Database.getCurSession();
149 // Transaction transax = connex.beginTransaction();
151 mystudy = getOpenStudy();
152 validation = new Vector<ValidationFacade>();
154 other = getDocumentTypeService().selectResultTypes();
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);
164 validation.add(new ValidationFacade(cycle));
166 if (validefault != null)
167 validation.add(validefault); // In order to be at the end
168 member = getStudyService().getContributors(study);
175 setMenuProperty("study");
176 setTitleProperty("study");
177 setEditDisabledProperty("true");
178 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
183 public String doEditContributors() {
184 // Session connex = Database.getCurSession();
185 // Transaction transax = connex.beginTransaction();
187 mystudy = getOpenStudy();
188 validation = new Vector<ValidationFacade>();
190 other = getDocumentTypeService().selectAllTypes();
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);
200 validation.add(new ValidationFacade(cycle));
202 if (validefault != null)
203 validation.add(validefault); // In order to be at the end
204 member = getStudyService().getContributors(study);
205 staff = getUserService().selectAllUsers();
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())
218 setMenuProperty("study");
219 setTitleProperty("study");
220 setEditDisabledProperty("true");
221 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
226 public String doEditCycle() {
227 // Session connex = Database.getCurSession();
228 // Transaction transax = connex.beginTransaction();
230 mystudy = getOpenStudy();
231 validation = new Vector<ValidationFacade>();
233 other = getDocumentTypeService().selectResultTypes();
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);
243 if (type.getName().equals(edicycle)) {
244 this.type = type.getIndex();
246 validation.add(new ValidationFacade(cycle));
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>();
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));
267 setMenuProperty("study");
268 setTitleProperty("study");
269 setEditDisabledProperty("true");
270 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
275 public String doEdition() {
276 // --------------------------
277 // Session connex = Database.getCurSession();
278 // Transaction transax = connex.beginTransaction();
279 Study study = getOpenStudy().getStudyObject();
281 if (tosave == Save.title) {
283 // Edition of the title
284 Study.Properties sprop = new Study.Properties();
286 getStudyService().update(study, sprop.setTitle(stitle));
287 } catch (InvalidPropertyException e) {
290 } else if (tosave == Save.contributor) {
292 // Edition of contributors
293 if (contributors == null)
295 if (candidates == null)
298 String[] parsekept = contributors.split(",");
299 String[] parsenew = candidates.split(",");
300 Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
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)
314 int size = toremove.size();
316 getStudyService().removeContributor(study,
317 toremove.toArray(new User[size]));
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);
325 getStudyService().addContributor(study, newser);
327 } else if (tosave == Save.cycle) {
329 // Addition of a document validation cycle
330 DocumentType apply = getDocumentTypeService().selectType(type);
331 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
333 User actor = getUserService().selectUser(publisher);
334 vprop.setActor(ValidationStep.PROMOTION, actor);
337 User actor = getUserService().selectUser(reviewer);
338 vprop.setActor(ValidationStep.REVIEW, actor);
341 User actor = getUserService().selectUser(approver);
342 vprop.setActor(ValidationStep.APPROVAL, actor);
344 getStudyService().setValidationCycle(study, apply, vprop);
348 doInitialize(); // Re-initialization following the above edition
350 setMenuProperty("study");
351 setTitleProperty("study");
352 setEditDisabledProperty("true");
353 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty);
358 // ==============================================================================================================================
360 // ==============================================================================================================================
362 public User getAuthor() {
363 // ------------------------
364 return mystudy.getStudyObject().getAuthor();
367 public List<User> getCandidates() {
368 // ----------------------------------
372 public String getCycle() {
373 // -------------------------
377 public List<User> getContributors() {
378 // ------------------------------------
382 public ValidationFacade getDefaultValidation() {
383 // -----------------------------------------------
387 public long getDocumentTypeIndex() {
388 // ----------------------------------
392 public List<DocumentType> getOtherDocumentTypes() {
393 // --------------------------------------------------
397 public String getStudyTitle() {
398 // ------------------------------
399 return mystudy.getTitle();
402 public List<ValidationFacade> getValidations() {
403 // -----------------------------------------------
407 public List<Name> getValidationActors() {
408 // ----------------------------------------
412 // ==============================================================================================================================
414 // ==============================================================================================================================
416 public void setCandidates(String indices) {
417 // ------------------------------------------
418 candidates = indices;
421 public void setCycle(String type) {
422 // ----------------------------------
426 public void setMembers(String indices) {
427 // ---------------------------------------
428 contributors = indices;
431 public void setDocumentType(String index) {
432 // ------------------------------------------
433 type = Integer.valueOf(index);
436 public void setApprover(String index) {
437 // --------------------------------------
438 approver = Integer.valueOf(index);
441 public void setPublisher(String index) {
442 // ---------------------------------------
443 publisher = Integer.valueOf(index);
446 public void setReviewer(String index) {
447 // --------------------------------------
448 reviewer = Integer.valueOf(index);
451 public void setTitle(String title) {
452 // -----------------------------------
456 public void setSaveTitle(String save) {
457 // --------------------------------------
461 public void setSaveContributors(String save) {
462 // ---------------------------------------------
463 tosave = Save.contributor;
466 public void setSaveCycle(String save) {
467 // --------------------------------------
472 * Get the studyService.
474 * @return the studyService
476 public StudyService getStudyService() {
477 return _studyService;
481 * Set the studyService.
483 * @param studyService
484 * the studyService to set
486 public void setStudyService(StudyService studyService) {
487 _studyService = studyService;
491 * Get the documentTypeService.
493 * @return the documentTypeService
495 public DocumentTypeService getDocumentTypeService() {
496 return _documentTypeService;
500 * Set the documentTypeService.
502 * @param documentTypeService
503 * the documentTypeService to set
505 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
506 _documentTypeService = documentTypeService;
510 * Get the userService.
511 * @return the userService
513 public UserService getUserService() {
518 * Set the userService.
519 * @param userService the userService to set
521 public void setUserService(UserService userService) {
522 _userService = userService;
526 * Get the menuProperty.
527 * @return the menuProperty
529 public String getMenuProperty() {
530 return _menuProperty;
534 * Set the menuProperty.
535 * @param menuProperty the menuProperty to set
537 public void setMenuProperty(String menuProperty) {
538 this._menuProperty = menuProperty;
542 * Get the _titleProperty.
543 * @return the _titleProperty
545 public String getTitleProperty() {
546 return _titleProperty;
550 * Set the _titleProperty.
551 * @param _titleProperty the titleProperty to set
553 public void setTitleProperty(String titleProperty) {
554 _titleProperty = titleProperty;
558 * Get the editDisabledProperty.
559 * @return the editDisabledProperty
561 public final String getEditDisabledProperty() {
562 return _editDisabledProperty;
566 * Set the editDisabledProperty.
567 * @param editDisabledProperty the editDisabledProperty to set
569 public final void setEditDisabledProperty(String editDisabledProperty) {
570 _editDisabledProperty = editDisabledProperty;