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.kernel.User;
12 import org.splat.kernel.UserDirectory;
13 import org.splat.som.ApplicationRights;
14 import org.splat.som.Database;
15 import org.splat.som.Document;
16 import org.splat.som.DocumentType;
17 import org.splat.som.Study;
18 import org.splat.som.StudyRights;
19 import org.splat.som.ValidationCycle;
20 import org.splat.som.ValidationStep;
23 public class StudyPropertiesAction extends DisplayStudyStepAction {
25 // Presentation fields
26 private List<User> staff;
27 private List<User> member;
28 private List<Name> validor;
29 private List<ValidationFacade> validation;
30 private ValidationFacade validefault;
31 private List<DocumentType> other;
34 private Save tosave; // Edition action (title, contributors or cycle)
35 private String edicycle;
36 private String stitle; // Title of the study
37 private String contributors; // List of existing contributors, some of them may have been removed
38 private String candidates; // List of added contributors
39 private int type; // Type of document to be included in the validation process
40 private int publisher;
44 private static final long serialVersionUID = 4210696018741092900L;
46 private enum Save { title, contributor, cycle }
48 // ==============================================================================================================================
50 // ==============================================================================================================================
52 public String doInitialize () {
53 // -----------------------------
54 Session connex = Database.getSession();
55 Transaction transax = connex.beginTransaction();
57 mystudy = getOpenStudy();
58 validation = new Vector<ValidationFacade>();
60 other = Document.selectResultTypes();
62 Study study = mystudy.getStudyObject();
63 StudyRights user = mystudy.getStudyRights();
64 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
65 DocumentType type = i.next();
66 ValidationCycle cycle = study.getValidationCycleOf(type);
67 if (cycle.isDefault()) {
68 validefault = new ValidationFacade(cycle);
71 validation.add( new ValidationFacade(cycle) );
74 if (validefault != null) validation.add(validefault); // In order to be at the end
75 member = study.getContributors();
80 if (mystudy.isOpenForWriting() && user.canEditProperties()) return "edit";
81 else return "display";
84 public String doEditTitle () {
85 // ----------------------------
86 Session connex = Database.getSession();
87 Transaction transax = connex.beginTransaction();
89 mystudy = getOpenStudy();
90 validation = new Vector<ValidationFacade>();
92 other = Document.selectResultTypes();
94 Study study = mystudy.getStudyObject();
95 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
96 DocumentType type = i.next();
97 ValidationCycle cycle = study.getValidationCycleOf(type);
98 if (cycle.isDefault()) {
99 validefault = new ValidationFacade(cycle);
102 validation.add( new ValidationFacade(cycle) );
104 if (validefault != null) validation.add(validefault); // In order to be at the end
105 member = study.getContributors();
114 public String doEditContributors () {
115 // -----------------------------------
116 Session connex = Database.getSession();
117 Transaction transax = connex.beginTransaction();
119 mystudy = getOpenStudy();
120 validation = new Vector<ValidationFacade>();
122 other = Document.selectAllTypes();
124 Study study = mystudy.getStudyObject();
125 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
126 DocumentType type = i.next();
127 ValidationCycle cycle = study.getValidationCycleOf(type);
128 if (cycle.isDefault()) {
129 validefault = new ValidationFacade(cycle);
132 validation.add( new ValidationFacade(cycle) );
134 if (validefault != null) validation.add(validefault); // In order to be at the end
135 member = study.getContributors();
136 staff = UserDirectory.selectAllUsers();
139 User me = this.getConnectedUser();
140 for (Iterator<User> i=staff.iterator(); i.hasNext(); ) {
141 User next = i.next();
142 ApplicationRights he = new ApplicationRights(next);
143 if (next.equals(me) || member.contains(next) || !he.canContributeToStudy()) i.remove();
149 public String doEditCycle () {
150 // ----------------------------
151 Session connex = Database.getSession();
152 Transaction transax = connex.beginTransaction();
154 mystudy = getOpenStudy();
155 validation = new Vector<ValidationFacade>();
157 other = Document.selectResultTypes();
159 Study study = mystudy.getStudyObject();
160 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
161 DocumentType type = i.next();
162 ValidationCycle cycle = study.getValidationCycleOf(type);
163 if (cycle.isDefault()) {
164 validefault = new ValidationFacade(cycle);
167 if (type.getName().equals(edicycle)) {
168 this.type = type.getIndex();
170 validation.add( new ValidationFacade(cycle) );
173 if (validefault != null) validation.add(validefault); // In order to be at the end
174 member = study.getContributors();
175 validor = new Vector<Name>();
177 List<User> user = UserDirectory.selectAllUsers();
178 for (Iterator<User> i=user.iterator(); i.hasNext(); ) {
179 User next = i.next();
180 ApplicationRights he = new ApplicationRights(next);
181 if (he.canValidate()) {
182 if (next.equals(study.getAuthor())) validor.add( new ValidationFacade.ByManager(next) );
183 else validor.add(next);
190 public String doEdition () {
191 // --------------------------
192 Session connex = Database.getSession();
193 Transaction transax = connex.beginTransaction();
194 Study study = getOpenStudy().getStudyObject();
196 if (tosave == Save.title) {
198 // Edition of the title
199 Study.Properties sprop = new Study.Properties();
201 study.update(sprop.setTitle(stitle));
203 catch (InvalidPropertyException e) {
207 if (tosave == Save.contributor) {
209 // Edition of contributors
210 if (contributors == null) contributors = "";
211 if (candidates == null) candidates = "";
213 String[] parsekept = contributors.split(",");
214 String[] parsenew = candidates.split(",");
215 Vector<User> toremove = new Vector<User>(study.getContributors());
217 for (int i=0; i<parsekept.length; i++) {
218 if (parsekept[i].length() == 0) continue; // Yet no contributor
219 int index = Integer.valueOf(parsekept[i].trim());
220 for (Iterator<User> j=toremove.iterator(); j.hasNext(); ){
221 int present = j.next().getIndex();
222 if (present != index) continue;
227 int size = toremove.size();
228 if (size > 0) study.removeContributor(toremove.toArray(new User[size]));
230 for (int i=0; i<parsenew.length; i++) {
231 if (parsenew[i].length() == 0) continue; // No any new contributor
232 int index = Integer.valueOf(parsenew[i].trim());
233 User newser = UserDirectory.selectUser(index);
235 study.addContributor(newser);
238 if (tosave == Save.cycle) {
240 // Addition of a document validation cycle
241 DocumentType apply = Document.selectType(type);
242 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
244 User actor = UserDirectory.selectUser(publisher);
245 vprop.setActor(ValidationStep.PROMOTION, actor);
248 User actor = UserDirectory.selectUser(reviewer);
249 vprop.setActor(ValidationStep.REVIEW, actor);
252 User actor = UserDirectory.selectUser(approver);
253 vprop.setActor(ValidationStep.APPROVAL, actor);
255 study.setValidationCycle(apply, vprop);
259 doInitialize(); // Re-initialization following the above edition
263 // ==============================================================================================================================
265 // ==============================================================================================================================
267 public User getAuthor () {
268 // ------------------------
269 return mystudy.getStudyObject().getAuthor();
271 public List<User> getCandidates () {
272 // ----------------------------------
275 public String getCycle () {
276 // -------------------------
279 public List<User> getContributors () {
280 // ------------------------------------
283 public ValidationFacade getDefaultValidation () {
284 // -----------------------------------------------
287 public int getDocumentTypeIndex () {
288 // ----------------------------------
291 public List<DocumentType> getOtherDocumentTypes () {
292 // --------------------------------------------------
295 public String getStudyTitle () {
296 // ------------------------------
297 return mystudy.getTitle();
299 public List<ValidationFacade> getValidations () {
300 // -----------------------------------------------
303 public List<Name> getValidationActors () {
304 // ----------------------------------------
308 // ==============================================================================================================================
310 // ==============================================================================================================================
312 public void setCandidates (String indices) {
313 // ------------------------------------------
314 candidates = indices;
316 public void setCycle (String type) {
317 // ----------------------------------
320 public void setMembers (String indices) {
321 // ---------------------------------------
322 contributors = indices;
324 public void setDocumentType (String index) {
325 // ------------------------------------------
326 type = Integer.valueOf(index);
328 public void setApprover (String index) {
329 // --------------------------------------
330 approver = Integer.valueOf(index);
332 public void setPublisher (String index) {
333 // ---------------------------------------
334 publisher = Integer.valueOf(index);
336 public void setReviewer (String index) {
337 // --------------------------------------
338 reviewer = Integer.valueOf(index);
340 public void setTitle (String title) {
341 // -----------------------------------
344 public void setSaveTitle (String save) {
345 // --------------------------------------
348 public void setSaveContributors (String save) {
349 // ---------------------------------------------
350 tosave = Save.contributor;
352 public void setSaveCycle (String save) {
353 // --------------------------------------