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 * Value of the tool bar property.
77 * It can be: none, standard, study, back.
79 private String _toolProperty;
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.
86 private String _editDisabledProperty = "false";
89 * Save operation type enumeration pointing which section of properties has been edited.
101 * Save validation cycle.
106 // ==============================================================================================================================
108 // ==============================================================================================================================
111 * Initialize study properties action.
113 * @return "edit" if user can edit study properties, otherwise return "display"
115 public String doInitialize() {
117 mystudy = getOpenStudy();
118 validation = new Vector<ValidationFacade>();
120 other = getDocumentTypeService().selectResultTypes();
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);
131 validation.add(new ValidationFacade(cycle));
134 if (validefault != null)
135 validation.add(validefault); // In order to be at the end
136 member = getStudyService().getContributors(study);
140 setMenuProperty("study");
141 setTitleProperty("study");
142 setEditDisabledProperty("true");
143 setToolProperty("back");
144 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
146 if (mystudy.isOpenForWriting() && user.canEditProperties()) {
154 public String doEditTitle() {
155 // Session connex = Database.getCurSession();
156 // Transaction transax = connex.beginTransaction();
158 mystudy = getOpenStudy();
159 validation = new Vector<ValidationFacade>();
161 other = getDocumentTypeService().selectResultTypes();
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);
171 validation.add(new ValidationFacade(cycle));
173 if (validefault != null)
174 validation.add(validefault); // In order to be at the end
175 member = getStudyService().getContributors(study);
182 setMenuProperty("study");
183 setTitleProperty("study");
184 setEditDisabledProperty("true");
185 setToolProperty("back");
186 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
191 public String doEditContributors() {
192 // Session connex = Database.getCurSession();
193 // Transaction transax = connex.beginTransaction();
195 mystudy = getOpenStudy();
196 validation = new Vector<ValidationFacade>();
198 other = getDocumentTypeService().selectAllTypes();
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);
208 validation.add(new ValidationFacade(cycle));
210 if (validefault != null)
211 validation.add(validefault); // In order to be at the end
212 member = getStudyService().getContributors(study);
213 staff = getUserService().selectAllUsers();
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())
226 setMenuProperty("study");
227 setTitleProperty("study");
228 setEditDisabledProperty("true");
229 setToolProperty("back");
230 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
235 public String doEditCycle() {
236 // Session connex = Database.getCurSession();
237 // Transaction transax = connex.beginTransaction();
239 mystudy = getOpenStudy();
240 validation = new Vector<ValidationFacade>();
242 other = getDocumentTypeService().selectResultTypes();
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);
252 if (type.getName().equals(edicycle)) {
253 this.type = type.getIndex();
255 validation.add(new ValidationFacade(cycle));
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>();
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));
276 setMenuProperty("study");
277 setTitleProperty("study");
278 setEditDisabledProperty("true");
279 setToolProperty("back");
280 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
285 public String doEdition() {
286 // --------------------------
287 // Session connex = Database.getCurSession();
288 // Transaction transax = connex.beginTransaction();
289 Study study = getOpenStudy().getStudyObject();
291 if (tosave == Save.title) {
293 // Edition of the title
294 Study.Properties sprop = new Study.Properties();
296 getStudyService().update(study, sprop.setTitle(stitle));
297 } catch (InvalidPropertyException e) {
300 } else if (tosave == Save.contributor) {
302 // Edition of contributors
303 if (contributors == null)
305 if (candidates == null)
308 String[] parsekept = contributors.split(",");
309 String[] parsenew = candidates.split(",");
310 Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
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)
324 int size = toremove.size();
326 getStudyService().removeContributor(study,
327 toremove.toArray(new User[size]));
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);
335 getStudyService().addContributor(study, newser);
337 } else if (tosave == Save.cycle) {
339 // Addition of a document validation cycle
340 DocumentType apply = getDocumentTypeService().selectType(type);
341 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
343 User actor = getUserService().selectUser(publisher);
344 vprop.setActor(ValidationStep.PROMOTION, actor);
347 User actor = getUserService().selectUser(reviewer);
348 vprop.setActor(ValidationStep.REVIEW, actor);
351 User actor = getUserService().selectUser(approver);
352 vprop.setActor(ValidationStep.APPROVAL, actor);
354 getStudyService().setValidationCycle(study, apply, vprop);
358 doInitialize(); // Re-initialization following the above edition
360 setMenuProperty("study");
361 setTitleProperty("study");
362 setEditDisabledProperty("true");
363 setToolProperty("back");
364 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
369 // ==============================================================================================================================
371 // ==============================================================================================================================
373 public User getAuthor() {
374 // ------------------------
375 return mystudy.getStudyObject().getAuthor();
378 public List<User> getCandidates() {
379 // ----------------------------------
383 public String getCycle() {
384 // -------------------------
388 public List<User> getContributors() {
389 // ------------------------------------
393 public ValidationFacade getDefaultValidation() {
394 // -----------------------------------------------
398 public long getDocumentTypeIndex() {
399 // ----------------------------------
403 public List<DocumentType> getOtherDocumentTypes() {
404 // --------------------------------------------------
408 public String getStudyTitle() {
409 // ------------------------------
410 return mystudy.getTitle();
413 public List<ValidationFacade> getValidations() {
414 // -----------------------------------------------
418 public List<Name> getValidationActors() {
419 // ----------------------------------------
423 // ==============================================================================================================================
425 // ==============================================================================================================================
427 public void setCandidates(String indices) {
428 // ------------------------------------------
429 candidates = indices;
432 public void setCycle(String type) {
433 // ----------------------------------
437 public void setMembers(String indices) {
438 // ---------------------------------------
439 contributors = indices;
442 public void setDocumentType(String index) {
443 // ------------------------------------------
444 type = Integer.valueOf(index);
447 public void setApprover(String index) {
448 // --------------------------------------
449 approver = Integer.valueOf(index);
452 public void setPublisher(String index) {
453 // ---------------------------------------
454 publisher = Integer.valueOf(index);
457 public void setReviewer(String index) {
458 // --------------------------------------
459 reviewer = Integer.valueOf(index);
462 public void setTitle(String title) {
463 // -----------------------------------
467 public void setSaveTitle(String save) {
468 // --------------------------------------
472 public void setSaveContributors(String save) {
473 // ---------------------------------------------
474 tosave = Save.contributor;
477 public void setSaveCycle(String save) {
478 // --------------------------------------
483 * Get the studyService.
485 * @return the studyService
487 public StudyService getStudyService() {
488 return _studyService;
492 * Set the studyService.
494 * @param studyService
495 * the studyService to set
497 public void setStudyService(StudyService studyService) {
498 _studyService = studyService;
502 * Get the documentTypeService.
504 * @return the documentTypeService
506 public DocumentTypeService getDocumentTypeService() {
507 return _documentTypeService;
511 * Set the documentTypeService.
513 * @param documentTypeService
514 * the documentTypeService to set
516 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
517 _documentTypeService = documentTypeService;
521 * Get the userService.
522 * @return the userService
524 public UserService getUserService() {
529 * Set the userService.
530 * @param userService the userService to set
532 public void setUserService(UserService userService) {
533 _userService = userService;
537 * Get the menuProperty.
538 * @return the menuProperty
540 public String getMenuProperty() {
541 return _menuProperty;
545 * Set the menuProperty.
546 * @param menuProperty the menuProperty to set
548 public void setMenuProperty(String menuProperty) {
549 this._menuProperty = menuProperty;
553 * Get the _titleProperty.
554 * @return the _titleProperty
556 public String getTitleProperty() {
557 return _titleProperty;
561 * Set the _titleProperty.
562 * @param _titleProperty the titleProperty to set
564 public void setTitleProperty(String titleProperty) {
565 _titleProperty = titleProperty;
569 * Get the editDisabledProperty.
570 * @return the editDisabledProperty
572 public final String getEditDisabledProperty() {
573 return _editDisabledProperty;
577 * Set the editDisabledProperty.
578 * @param editDisabledProperty the editDisabledProperty to set
580 public final void setEditDisabledProperty(String editDisabledProperty) {
581 _editDisabledProperty = editDisabledProperty;
585 * Get the toolProperty.
586 * @return the toolProperty
588 public String getToolProperty() {
589 return _toolProperty;
593 * Set the toolProperty.
594 * @param toolProperty the toolProperty to set
596 public void setToolProperty(final String toolProperty) {
597 _toolProperty = toolProperty;