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 * Save operation type enumeration pointing which section of properties has been edited.
82 * Save validation cycle.
87 // ==============================================================================================================================
89 // ==============================================================================================================================
92 * Initialize study properties action.
94 * @return "edit" if user can edit study properties, otherwise return "display"
96 public String doInitialize() {
98 mystudy = getOpenStudy();
99 validation = new Vector<ValidationFacade>();
101 other = getDocumentTypeService().selectResultTypes();
103 Study study = mystudy.getStudyObject();
104 StudyRights user = mystudy.getStudyRights();
105 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
106 DocumentType type = i.next();
107 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
108 if (cycle.isDefault()) {
109 validefault = new ValidationFacade(cycle);
112 validation.add(new ValidationFacade(cycle));
115 if (validefault != null)
116 validation.add(validefault); // In order to be at the end
117 member = getStudyService().getContributors(study);
121 setMenuProperty("study");
122 initializationScreenContext(_menuProperty);
124 if (mystudy.isOpenForWriting() && user.canEditProperties()) {
132 public String doEditTitle() {
133 // Session connex = Database.getCurSession();
134 // Transaction transax = connex.beginTransaction();
136 mystudy = getOpenStudy();
137 validation = new Vector<ValidationFacade>();
139 other = getDocumentTypeService().selectResultTypes();
141 Study study = mystudy.getStudyObject();
142 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
143 DocumentType type = i.next();
144 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
145 if (cycle.isDefault()) {
146 validefault = new ValidationFacade(cycle);
149 validation.add(new ValidationFacade(cycle));
151 if (validefault != null)
152 validation.add(validefault); // In order to be at the end
153 member = getStudyService().getContributors(study);
160 setMenuProperty("study");
161 initializationScreenContext(_menuProperty);
166 public String doEditContributors() {
167 // Session connex = Database.getCurSession();
168 // Transaction transax = connex.beginTransaction();
170 mystudy = getOpenStudy();
171 validation = new Vector<ValidationFacade>();
173 other = getDocumentTypeService().selectAllTypes();
175 Study study = mystudy.getStudyObject();
176 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
177 DocumentType type = i.next();
178 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
179 if (cycle.isDefault()) {
180 validefault = new ValidationFacade(cycle);
183 validation.add(new ValidationFacade(cycle));
185 if (validefault != null)
186 validation.add(validefault); // In order to be at the end
187 member = getStudyService().getContributors(study);
188 staff = getUserService().selectAllUsers();
191 User me = this.getConnectedUser();
192 for (Iterator<User> i = staff.iterator(); i.hasNext();) {
193 User next = i.next();
194 ApplicationRights he = new ApplicationRights(next);
195 if (next.equals(me) || member.contains(next)
196 || !he.canContributeToStudy())
201 setMenuProperty("study");
202 initializationScreenContext(_menuProperty);
207 public String doEditCycle() {
208 // Session connex = Database.getCurSession();
209 // Transaction transax = connex.beginTransaction();
211 mystudy = getOpenStudy();
212 validation = new Vector<ValidationFacade>();
214 other = getDocumentTypeService().selectResultTypes();
216 Study study = mystudy.getStudyObject();
217 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
218 DocumentType type = i.next();
219 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
220 if (cycle.isDefault()) {
221 validefault = new ValidationFacade(cycle);
224 if (type.getName().equals(edicycle)) {
225 this.type = type.getIndex();
227 validation.add(new ValidationFacade(cycle));
230 if (validefault != null)
231 validation.add(validefault); // In order to be at the end
232 member = getStudyService().getContributors(study);
233 validor = new Vector<Name>();
235 List<User> user = getUserService().selectAllUsers();
236 for (Iterator<User> i = user.iterator(); i.hasNext();) {
237 User next = i.next();
238 ApplicationRights he = new ApplicationRights(next);
239 if (he.canValidate()) {
240 if (next.equals(study.getAuthor()))
241 validor.add(new ValidationFacade.ByManager(next));
248 setMenuProperty("study");
249 initializationScreenContext(_menuProperty);
254 public String doEdition() {
255 // --------------------------
256 // Session connex = Database.getCurSession();
257 // Transaction transax = connex.beginTransaction();
258 Study study = getOpenStudy().getStudyObject();
260 if (tosave == Save.title) {
262 // Edition of the title
263 Study.Properties sprop = new Study.Properties();
265 getStudyService().update(study, sprop.setTitle(stitle));
266 } catch (InvalidPropertyException e) {
269 } else if (tosave == Save.contributor) {
271 // Edition of contributors
272 if (contributors == null)
274 if (candidates == null)
277 String[] parsekept = contributors.split(",");
278 String[] parsenew = candidates.split(",");
279 Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
281 for (int i = 0; i < parsekept.length; i++) {
282 if (parsekept[i].length() == 0)
283 continue; // Yet no contributor
284 int index = Integer.valueOf(parsekept[i].trim());
285 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
286 long present = j.next().getIndex();
287 if (present != index)
293 int size = toremove.size();
295 getStudyService().removeContributor(study,
296 toremove.toArray(new User[size]));
298 for (int i = 0; i < parsenew.length; i++) {
299 if (parsenew[i].length() == 0)
300 continue; // No any new contributor
301 int index = Integer.valueOf(parsenew[i].trim());
302 User newser = getUserService().selectUser(index);
304 getStudyService().addContributor(study, newser);
306 } else if (tosave == Save.cycle) {
308 // Addition of a document validation cycle
309 DocumentType apply = getDocumentTypeService().selectType(type);
310 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
312 User actor = getUserService().selectUser(publisher);
313 vprop.setActor(ValidationStep.PROMOTION, actor);
316 User actor = getUserService().selectUser(reviewer);
317 vprop.setActor(ValidationStep.REVIEW, actor);
320 User actor = getUserService().selectUser(approver);
321 vprop.setActor(ValidationStep.APPROVAL, actor);
323 getStudyService().setValidationCycle(study, apply, vprop);
327 doInitialize(); // Re-initialization following the above edition
332 // ==============================================================================================================================
334 // ==============================================================================================================================
336 public User getAuthor() {
337 // ------------------------
338 return mystudy.getStudyObject().getAuthor();
341 public List<User> getCandidates() {
342 // ----------------------------------
346 public String getCycle() {
347 // -------------------------
351 public List<User> getContributors() {
352 // ------------------------------------
356 public ValidationFacade getDefaultValidation() {
357 // -----------------------------------------------
361 public long getDocumentTypeIndex() {
362 // ----------------------------------
366 public List<DocumentType> getOtherDocumentTypes() {
367 // --------------------------------------------------
371 public String getStudyTitle() {
372 // ------------------------------
373 return mystudy.getTitle();
376 public List<ValidationFacade> getValidations() {
377 // -----------------------------------------------
381 public List<Name> getValidationActors() {
382 // ----------------------------------------
386 // ==============================================================================================================================
388 // ==============================================================================================================================
390 public void setCandidates(String indices) {
391 // ------------------------------------------
392 candidates = indices;
395 public void setCycle(String type) {
396 // ----------------------------------
400 public void setMembers(String indices) {
401 // ---------------------------------------
402 contributors = indices;
405 public void setDocumentType(String index) {
406 // ------------------------------------------
407 type = Integer.valueOf(index);
410 public void setApprover(String index) {
411 // --------------------------------------
412 approver = Integer.valueOf(index);
415 public void setPublisher(String index) {
416 // ---------------------------------------
417 publisher = Integer.valueOf(index);
420 public void setReviewer(String index) {
421 // --------------------------------------
422 reviewer = Integer.valueOf(index);
425 public void setTitle(String title) {
426 // -----------------------------------
430 public void setSaveTitle(String save) {
431 // --------------------------------------
435 public void setSaveContributors(String save) {
436 // ---------------------------------------------
437 tosave = Save.contributor;
440 public void setSaveCycle(String save) {
441 // --------------------------------------
446 * Get the studyService.
448 * @return the studyService
450 public StudyService getStudyService() {
451 return _studyService;
455 * Set the studyService.
457 * @param studyService
458 * the studyService to set
460 public void setStudyService(StudyService studyService) {
461 _studyService = studyService;
465 * Get the documentTypeService.
467 * @return the documentTypeService
469 public DocumentTypeService getDocumentTypeService() {
470 return _documentTypeService;
474 * Set the documentTypeService.
476 * @param documentTypeService
477 * the documentTypeService to set
479 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
480 _documentTypeService = documentTypeService;
484 * Get the userService.
485 * @return the userService
487 public UserService getUserService() {
492 * Set the userService.
493 * @param userService the userService to set
495 public void setUserService(UserService userService) {
496 _userService = userService;
500 * Get the menuProperty.
501 * @return the menuProperty
503 public String getMenuProperty() {
504 return _menuProperty;
508 * Set the menuProperty.
509 * @param menuProperty the menuProperty to set
511 public void setMenuProperty(String menuProperty) {
512 this._menuProperty = menuProperty;