1 package org.splat.simer;
3 import java.util.Iterator;
5 import java.util.Vector;
7 import org.hibernate.Session;
8 import org.hibernate.Transaction;
9 import org.splat.kernel.InvalidPropertyException;
10 import org.splat.kernel.Name;
11 import org.splat.dal.bo.kernel.User;
12 import org.splat.kernel.UserDirectory;
13 import org.splat.service.DocumentTypeService;
14 import org.splat.service.StudyService;
15 import org.splat.som.ApplicationRights;
16 import org.splat.dal.dao.som.Database;
17 import org.splat.dal.bo.som.DocumentType;
18 import org.splat.dal.bo.som.Study;
19 import org.splat.som.StudyRights;
20 import org.splat.dal.bo.som.ValidationCycle;
21 import org.splat.dal.bo.som.ValidationStep;
24 * Edit/display study properties (study configuration) screen action.
26 public class StudyPropertiesAction extends DisplayStudyStepAction {
31 private static final long serialVersionUID = 4210696018741092900L;
33 // Presentation fields
34 private List<User> staff;
35 private List<User> member;
36 private List<Name> validor;
37 private List<ValidationFacade> validation;
38 private ValidationFacade validefault;
39 private List<DocumentType> other;
42 private Save tosave; // Edition action (title, contributors or cycle)
43 private String edicycle;
44 private String stitle; // Title of the study
45 private String contributors; // List of existing contributors, some of them may have been removed
46 private String candidates; // List of added contributors
47 private long type; // Type of document to be included in the validation process
48 private int publisher;
53 * Injected study service.
55 private StudyService _studyService;
57 * Injected document type service.
59 private DocumentTypeService _documentTypeService;
62 * Save operation type enumeration pointing which section of properties has been edited.
74 * Save validation cycle.
79 // ==============================================================================================================================
81 // ==============================================================================================================================
84 * Initialize study properties action.
86 * @return "edit" if user can edit study properties, otherwise return "display"
88 public String doInitialize() {
90 mystudy = getOpenStudy();
91 validation = new Vector<ValidationFacade>();
93 other = getDocumentTypeService().selectResultTypes();
95 Study study = mystudy.getStudyObject();
96 StudyRights user = mystudy.getStudyRights();
97 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
98 DocumentType type = i.next();
99 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
100 if (cycle.isDefault()) {
101 validefault = new ValidationFacade(cycle);
104 validation.add(new ValidationFacade(cycle));
107 if (validefault != null)
108 validation.add(validefault); // In order to be at the end
109 member = getStudyService().getContributors(study);
113 if (mystudy.isOpenForWriting() && user.canEditProperties())
119 public String doEditTitle() {
120 // ----------------------------
121 Session connex = Database.getSession();
122 Transaction transax = connex.beginTransaction();
124 mystudy = getOpenStudy();
125 validation = new Vector<ValidationFacade>();
127 other = getDocumentTypeService().selectResultTypes();
129 Study study = mystudy.getStudyObject();
130 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
131 DocumentType type = i.next();
132 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
133 if (cycle.isDefault()) {
134 validefault = new ValidationFacade(cycle);
137 validation.add(new ValidationFacade(cycle));
139 if (validefault != null)
140 validation.add(validefault); // In order to be at the end
141 member = getStudyService().getContributors(study);
150 public String doEditContributors() {
151 // -----------------------------------
152 Session connex = Database.getSession();
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 = UserDirectory.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 // ----------------------------
190 Session connex = Database.getSession();
191 Transaction transax = connex.beginTransaction();
193 mystudy = getOpenStudy();
194 validation = new Vector<ValidationFacade>();
196 other = getDocumentTypeService().selectResultTypes();
198 Study study = mystudy.getStudyObject();
199 for (Iterator<DocumentType> i = other.iterator(); i.hasNext();) {
200 DocumentType type = i.next();
201 ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type);
202 if (cycle.isDefault()) {
203 validefault = new ValidationFacade(cycle);
206 if (type.getName().equals(edicycle)) {
207 this.type = type.getIndex();
209 validation.add(new ValidationFacade(cycle));
212 if (validefault != null)
213 validation.add(validefault); // In order to be at the end
214 member = getStudyService().getContributors(study);
215 validor = new Vector<Name>();
217 List<User> user = UserDirectory.selectAllUsers();
218 for (Iterator<User> i = user.iterator(); i.hasNext();) {
219 User next = i.next();
220 ApplicationRights he = new ApplicationRights(next);
221 if (he.canValidate()) {
222 if (next.equals(study.getAuthor()))
223 validor.add(new ValidationFacade.ByManager(next));
232 public String doEdition() {
233 // --------------------------
234 Session connex = Database.getSession();
235 Transaction transax = connex.beginTransaction();
236 Study study = getOpenStudy().getStudyObject();
238 if (tosave == Save.title) {
240 // Edition of the title
241 Study.Properties sprop = new Study.Properties();
243 getStudyService().update(study, sprop.setTitle(stitle));
244 } catch (InvalidPropertyException e) {
247 } else if (tosave == Save.contributor) {
249 // Edition of contributors
250 if (contributors == null)
252 if (candidates == null)
255 String[] parsekept = contributors.split(",");
256 String[] parsenew = candidates.split(",");
257 Vector<User> toremove = new Vector<User>(getStudyService().getContributors(study));
259 for (int i = 0; i < parsekept.length; i++) {
260 if (parsekept[i].length() == 0)
261 continue; // Yet no contributor
262 int index = Integer.valueOf(parsekept[i].trim());
263 for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
264 long present = j.next().getIndex();
265 if (present != index)
271 int size = toremove.size();
273 getStudyService().removeContributor(study,
274 toremove.toArray(new User[size]));
276 for (int i = 0; i < parsenew.length; i++) {
277 if (parsenew[i].length() == 0)
278 continue; // No any new contributor
279 int index = Integer.valueOf(parsenew[i].trim());
280 User newser = UserDirectory.selectUser(index);
282 getStudyService().addContributor(study, newser);
284 } else if (tosave == Save.cycle) {
286 // Addition of a document validation cycle
287 DocumentType apply = getDocumentTypeService().selectType(type);
288 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
290 User actor = UserDirectory.selectUser(publisher);
291 vprop.setActor(ValidationStep.PROMOTION, actor);
294 User actor = UserDirectory.selectUser(reviewer);
295 vprop.setActor(ValidationStep.REVIEW, actor);
298 User actor = UserDirectory.selectUser(approver);
299 vprop.setActor(ValidationStep.APPROVAL, actor);
301 getStudyService().setValidationCycle(study, apply, vprop);
305 doInitialize(); // Re-initialization following the above edition
309 // ==============================================================================================================================
311 // ==============================================================================================================================
313 public User getAuthor() {
314 // ------------------------
315 return mystudy.getStudyObject().getAuthor();
318 public List<User> getCandidates() {
319 // ----------------------------------
323 public String getCycle() {
324 // -------------------------
328 public List<User> getContributors() {
329 // ------------------------------------
333 public ValidationFacade getDefaultValidation() {
334 // -----------------------------------------------
338 public long getDocumentTypeIndex() {
339 // ----------------------------------
343 public List<DocumentType> getOtherDocumentTypes() {
344 // --------------------------------------------------
348 public String getStudyTitle() {
349 // ------------------------------
350 return mystudy.getTitle();
353 public List<ValidationFacade> getValidations() {
354 // -----------------------------------------------
358 public List<Name> getValidationActors() {
359 // ----------------------------------------
363 // ==============================================================================================================================
365 // ==============================================================================================================================
367 public void setCandidates(String indices) {
368 // ------------------------------------------
369 candidates = indices;
372 public void setCycle(String type) {
373 // ----------------------------------
377 public void setMembers(String indices) {
378 // ---------------------------------------
379 contributors = indices;
382 public void setDocumentType(String index) {
383 // ------------------------------------------
384 type = Integer.valueOf(index);
387 public void setApprover(String index) {
388 // --------------------------------------
389 approver = Integer.valueOf(index);
392 public void setPublisher(String index) {
393 // ---------------------------------------
394 publisher = Integer.valueOf(index);
397 public void setReviewer(String index) {
398 // --------------------------------------
399 reviewer = Integer.valueOf(index);
402 public void setTitle(String title) {
403 // -----------------------------------
407 public void setSaveTitle(String save) {
408 // --------------------------------------
412 public void setSaveContributors(String save) {
413 // ---------------------------------------------
414 tosave = Save.contributor;
417 public void setSaveCycle(String save) {
418 // --------------------------------------
423 * Get the studyService.
425 * @return the studyService
427 public StudyService getStudyService() {
428 return _studyService;
432 * Set the studyService.
434 * @param studyService
435 * the studyService to set
437 public void setStudyService(StudyService studyService) {
438 _studyService = studyService;
442 * Get the documentTypeService.
444 * @return the documentTypeService
446 public DocumentTypeService getDocumentTypeService() {
447 return _documentTypeService;
451 * Set the documentTypeService.
453 * @param documentTypeService
454 * the documentTypeService to set
456 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
457 _documentTypeService = documentTypeService;