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 * Save operation type enumeration pointing which section of properties has been edited.
76 * Save validation cycle.
81 // ==============================================================================================================================
83 // ==============================================================================================================================
86 * Initialize study properties action.
88 * @return "edit" if user can edit study properties, otherwise return "display"
90 public String doInitialize() {
92 mystudy = getOpenStudy();
93 validation = new Vector<ValidationFacade>();
95 other = getDocumentTypeService().selectResultTypes();
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);
106 validation.add(new ValidationFacade(cycle));
109 if (validefault != null)
110 validation.add(validefault); // In order to be at the end
111 member = getStudyService().getContributors(study);
115 if (mystudy.isOpenForWriting() && user.canEditProperties())
121 public String doEditTitle() {
122 // Session connex = Database.getCurSession();
123 // Transaction transax = connex.beginTransaction();
125 mystudy = getOpenStudy();
126 validation = new Vector<ValidationFacade>();
128 other = getDocumentTypeService().selectResultTypes();
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);
138 validation.add(new ValidationFacade(cycle));
140 if (validefault != null)
141 validation.add(validefault); // In order to be at the end
142 member = getStudyService().getContributors(study);
151 public String doEditContributors() {
152 // Session connex = Database.getCurSession();
153 // Transaction transax = connex.beginTransaction();
155 mystudy = getOpenStudy();
156 validation = new Vector<ValidationFacade>();
158 other = getDocumentTypeService().selectAllTypes();
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);
168 validation.add(new ValidationFacade(cycle));
170 if (validefault != null)
171 validation.add(validefault); // In order to be at the end
172 member = getStudyService().getContributors(study);
173 staff = getUserService().selectAllUsers();
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())
188 public String doEditCycle() {
189 // Session connex = Database.getCurSession();
190 // Transaction transax = connex.beginTransaction();
192 mystudy = getOpenStudy();
193 validation = new Vector<ValidationFacade>();
195 other = getDocumentTypeService().selectResultTypes();
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);
205 if (type.getName().equals(edicycle)) {
206 this.type = type.getIndex();
208 validation.add(new ValidationFacade(cycle));
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>();
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));
231 public String doEdition() {
232 // --------------------------
233 // Session connex = Database.getCurSession();
234 // Transaction transax = connex.beginTransaction();
235 Study study = getOpenStudy().getStudyObject();
237 if (tosave == Save.title) {
239 // Edition of the title
240 Study.Properties sprop = new Study.Properties();
242 getStudyService().update(study, sprop.setTitle(stitle));
243 } catch (InvalidPropertyException e) {
246 } else if (tosave == Save.contributor) {
248 // Edition of contributors
249 if (contributors == null)
251 if (candidates == null)
254 String[] parsekept = contributors.split(",");
255 String[] parsenew = candidates.split(",");
256 Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
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)
270 int size = toremove.size();
272 getStudyService().removeContributor(study,
273 toremove.toArray(new User[size]));
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);
281 getStudyService().addContributor(study, newser);
283 } else if (tosave == Save.cycle) {
285 // Addition of a document validation cycle
286 DocumentType apply = getDocumentTypeService().selectType(type);
287 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
289 User actor = getUserService().selectUser(publisher);
290 vprop.setActor(ValidationStep.PROMOTION, actor);
293 User actor = getUserService().selectUser(reviewer);
294 vprop.setActor(ValidationStep.REVIEW, actor);
297 User actor = getUserService().selectUser(approver);
298 vprop.setActor(ValidationStep.APPROVAL, actor);
300 getStudyService().setValidationCycle(study, apply, vprop);
304 doInitialize(); // Re-initialization following the above edition
308 // ==============================================================================================================================
310 // ==============================================================================================================================
312 public User getAuthor() {
313 // ------------------------
314 return mystudy.getStudyObject().getAuthor();
317 public List<User> getCandidates() {
318 // ----------------------------------
322 public String getCycle() {
323 // -------------------------
327 public List<User> getContributors() {
328 // ------------------------------------
332 public ValidationFacade getDefaultValidation() {
333 // -----------------------------------------------
337 public long getDocumentTypeIndex() {
338 // ----------------------------------
342 public List<DocumentType> getOtherDocumentTypes() {
343 // --------------------------------------------------
347 public String getStudyTitle() {
348 // ------------------------------
349 return mystudy.getTitle();
352 public List<ValidationFacade> getValidations() {
353 // -----------------------------------------------
357 public List<Name> getValidationActors() {
358 // ----------------------------------------
362 // ==============================================================================================================================
364 // ==============================================================================================================================
366 public void setCandidates(String indices) {
367 // ------------------------------------------
368 candidates = indices;
371 public void setCycle(String type) {
372 // ----------------------------------
376 public void setMembers(String indices) {
377 // ---------------------------------------
378 contributors = indices;
381 public void setDocumentType(String index) {
382 // ------------------------------------------
383 type = Integer.valueOf(index);
386 public void setApprover(String index) {
387 // --------------------------------------
388 approver = Integer.valueOf(index);
391 public void setPublisher(String index) {
392 // ---------------------------------------
393 publisher = Integer.valueOf(index);
396 public void setReviewer(String index) {
397 // --------------------------------------
398 reviewer = Integer.valueOf(index);
401 public void setTitle(String title) {
402 // -----------------------------------
406 public void setSaveTitle(String save) {
407 // --------------------------------------
411 public void setSaveContributors(String save) {
412 // ---------------------------------------------
413 tosave = Save.contributor;
416 public void setSaveCycle(String save) {
417 // --------------------------------------
422 * Get the studyService.
424 * @return the studyService
426 public StudyService getStudyService() {
427 return _studyService;
431 * Set the studyService.
433 * @param studyService
434 * the studyService to set
436 public void setStudyService(StudyService studyService) {
437 _studyService = studyService;
441 * Get the documentTypeService.
443 * @return the documentTypeService
445 public DocumentTypeService getDocumentTypeService() {
446 return _documentTypeService;
450 * Set the documentTypeService.
452 * @param documentTypeService
453 * the documentTypeService to set
455 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
456 _documentTypeService = documentTypeService;
460 * Get the userService.
461 * @return the userService
463 public UserService getUserService() {
468 * Set the userService.
469 * @param userService the userService to set
471 public void setUserService(UserService userService) {
472 _userService = userService;