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.StudyService;
14 import org.splat.som.ApplicationRights;
15 import org.splat.dal.dao.som.Database;
16 import org.splat.dal.bo.som.Document;
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 public class StudyPropertiesAction extends DisplayStudyStepAction {
26 // Presentation fields
27 private List<User> staff;
28 private List<User> member;
29 private List<Name> validor;
30 private List<ValidationFacade> validation;
31 private ValidationFacade validefault;
32 private List<DocumentType> other;
35 private Save tosave; // Edition action (title, contributors or cycle)
36 private String edicycle;
37 private String stitle; // Title of the study
38 private String contributors; // List of existing contributors, some of them may have been removed
39 private String candidates; // List of added contributors
40 private long type; // Type of document to be included in the validation process
41 private int publisher;
44 private StudyService _studyService;
49 private static final long serialVersionUID = 4210696018741092900L;
51 private enum Save { title, contributor, cycle }
53 // ==============================================================================================================================
55 // ==============================================================================================================================
57 public String doInitialize () {
58 // -----------------------------
59 Session connex = Database.getSession();
60 Transaction transax = connex.beginTransaction();
62 mystudy = getOpenStudy();
63 validation = new Vector<ValidationFacade>();
65 other = Document.selectResultTypes();
67 Study study = mystudy.getStudyObject();
68 StudyRights user = mystudy.getStudyRights();
69 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
70 DocumentType type = i.next();
71 ValidationCycle cycle = study.getValidationCycleOf(type);
72 if (cycle.isDefault()) {
73 validefault = new ValidationFacade(cycle);
76 validation.add( new ValidationFacade(cycle) );
79 if (validefault != null) validation.add(validefault); // In order to be at the end
80 member = study.getContributors();
85 if (mystudy.isOpenForWriting() && user.canEditProperties()) return "edit";
86 else return "display";
89 public String doEditTitle () {
90 // ----------------------------
91 Session connex = Database.getSession();
92 Transaction transax = connex.beginTransaction();
94 mystudy = getOpenStudy();
95 validation = new Vector<ValidationFacade>();
97 other = Document.selectResultTypes();
99 Study study = mystudy.getStudyObject();
100 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
101 DocumentType type = i.next();
102 ValidationCycle cycle = study.getValidationCycleOf(type);
103 if (cycle.isDefault()) {
104 validefault = new ValidationFacade(cycle);
107 validation.add( new ValidationFacade(cycle) );
109 if (validefault != null) validation.add(validefault); // In order to be at the end
110 member = study.getContributors();
119 public String doEditContributors () {
120 // -----------------------------------
121 Session connex = Database.getSession();
122 Transaction transax = connex.beginTransaction();
124 mystudy = getOpenStudy();
125 validation = new Vector<ValidationFacade>();
127 other = Document.selectAllTypes();
129 Study study = mystudy.getStudyObject();
130 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
131 DocumentType type = i.next();
132 ValidationCycle cycle = study.getValidationCycleOf(type);
133 if (cycle.isDefault()) {
134 validefault = new ValidationFacade(cycle);
137 validation.add( new ValidationFacade(cycle) );
139 if (validefault != null) validation.add(validefault); // In order to be at the end
140 member = study.getContributors();
141 staff = UserDirectory.selectAllUsers();
144 User me = this.getConnectedUser();
145 for (Iterator<User> i=staff.iterator(); i.hasNext(); ) {
146 User next = i.next();
147 ApplicationRights he = new ApplicationRights(next);
148 if (next.equals(me) || member.contains(next) || !he.canContributeToStudy()) i.remove();
154 public String doEditCycle () {
155 // ----------------------------
156 Session connex = Database.getSession();
157 Transaction transax = connex.beginTransaction();
159 mystudy = getOpenStudy();
160 validation = new Vector<ValidationFacade>();
162 other = Document.selectResultTypes();
164 Study study = mystudy.getStudyObject();
165 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
166 DocumentType type = i.next();
167 ValidationCycle cycle = study.getValidationCycleOf(type);
168 if (cycle.isDefault()) {
169 validefault = new ValidationFacade(cycle);
172 if (type.getName().equals(edicycle)) {
173 this.type = type.getIndex();
175 validation.add( new ValidationFacade(cycle) );
178 if (validefault != null) validation.add(validefault); // In order to be at the end
179 member = study.getContributors();
180 validor = new Vector<Name>();
182 List<User> user = UserDirectory.selectAllUsers();
183 for (Iterator<User> i=user.iterator(); i.hasNext(); ) {
184 User next = i.next();
185 ApplicationRights he = new ApplicationRights(next);
186 if (he.canValidate()) {
187 if (next.equals(study.getAuthor())) validor.add( new ValidationFacade.ByManager(next) );
188 else validor.add(next);
195 public String doEdition () {
196 // --------------------------
197 Session connex = Database.getSession();
198 Transaction transax = connex.beginTransaction();
199 Study study = getOpenStudy().getStudyObject();
201 if (tosave == Save.title) {
203 // Edition of the title
204 Study.Properties sprop = new Study.Properties();
206 getStudyService().update(study, sprop.setTitle(stitle));
208 catch (InvalidPropertyException e) {
212 if (tosave == Save.contributor) {
214 // Edition of contributors
215 if (contributors == null) contributors = "";
216 if (candidates == null) candidates = "";
218 String[] parsekept = contributors.split(",");
219 String[] parsenew = candidates.split(",");
220 Vector<User> toremove = new Vector<User>(study.getContributors());
222 for (int i=0; i<parsekept.length; i++) {
223 if (parsekept[i].length() == 0) continue; // Yet no contributor
224 int index = Integer.valueOf(parsekept[i].trim());
225 for (Iterator<User> j=toremove.iterator(); j.hasNext(); ){
226 long present = j.next().getIndex();
227 if (present != index) continue;
232 int size = toremove.size();
233 if (size > 0) getStudyService().removeContributor(study, toremove.toArray(new User[size]));
235 for (int i=0; i<parsenew.length; i++) {
236 if (parsenew[i].length() == 0) continue; // No any new contributor
237 int index = Integer.valueOf(parsenew[i].trim());
238 User newser = UserDirectory.selectUser(index);
240 getStudyService().addContributor(study, newser);
243 if (tosave == Save.cycle) {
245 // Addition of a document validation cycle
246 DocumentType apply = Document.selectType(type);
247 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
249 User actor = UserDirectory.selectUser(publisher);
250 vprop.setActor(ValidationStep.PROMOTION, actor);
253 User actor = UserDirectory.selectUser(reviewer);
254 vprop.setActor(ValidationStep.REVIEW, actor);
257 User actor = UserDirectory.selectUser(approver);
258 vprop.setActor(ValidationStep.APPROVAL, actor);
260 getStudyService().setValidationCycle(study, apply, vprop);
264 doInitialize(); // Re-initialization following the above edition
268 // ==============================================================================================================================
270 // ==============================================================================================================================
272 public User getAuthor () {
273 // ------------------------
274 return mystudy.getStudyObject().getAuthor();
276 public List<User> getCandidates () {
277 // ----------------------------------
280 public String getCycle () {
281 // -------------------------
284 public List<User> getContributors () {
285 // ------------------------------------
288 public ValidationFacade getDefaultValidation () {
289 // -----------------------------------------------
292 public long getDocumentTypeIndex () {
293 // ----------------------------------
296 public List<DocumentType> getOtherDocumentTypes () {
297 // --------------------------------------------------
300 public String getStudyTitle () {
301 // ------------------------------
302 return mystudy.getTitle();
304 public List<ValidationFacade> getValidations () {
305 // -----------------------------------------------
308 public List<Name> getValidationActors () {
309 // ----------------------------------------
313 // ==============================================================================================================================
315 // ==============================================================================================================================
317 public void setCandidates (String indices) {
318 // ------------------------------------------
319 candidates = indices;
321 public void setCycle (String type) {
322 // ----------------------------------
325 public void setMembers (String indices) {
326 // ---------------------------------------
327 contributors = indices;
329 public void setDocumentType (String index) {
330 // ------------------------------------------
331 type = Integer.valueOf(index);
333 public void setApprover (String index) {
334 // --------------------------------------
335 approver = Integer.valueOf(index);
337 public void setPublisher (String index) {
338 // ---------------------------------------
339 publisher = Integer.valueOf(index);
341 public void setReviewer (String index) {
342 // --------------------------------------
343 reviewer = Integer.valueOf(index);
345 public void setTitle (String title) {
346 // -----------------------------------
349 public void setSaveTitle (String save) {
350 // --------------------------------------
353 public void setSaveContributors (String save) {
354 // ---------------------------------------------
355 tosave = Save.contributor;
357 public void setSaveCycle (String save) {
358 // --------------------------------------
362 * Get the studyService.
364 * @return the studyService
366 public StudyService getStudyService() {
367 return _studyService;
371 * Set the studyService.
373 * @param studyService
374 * the studyService to set
376 public void setStudyService(StudyService studyService) {
377 _studyService = studyService;