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 int type; // Type of document to be included in the validation process
41 private int publisher;
44 private StudyService _studyService;
46 private static final long serialVersionUID = 4210696018741092900L;
48 private enum Save { title, contributor, cycle }
50 // ==============================================================================================================================
52 // ==============================================================================================================================
54 public String doInitialize () {
55 // -----------------------------
56 Session connex = Database.getSession();
57 Transaction transax = connex.beginTransaction();
59 mystudy = getOpenStudy();
60 validation = new Vector<ValidationFacade>();
62 other = Document.selectResultTypes();
64 Study study = mystudy.getStudyObject();
65 StudyRights user = mystudy.getStudyRights();
66 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
67 DocumentType type = i.next();
68 ValidationCycle cycle = study.getValidationCycleOf(type);
69 if (cycle.isDefault()) {
70 validefault = new ValidationFacade(cycle);
73 validation.add( new ValidationFacade(cycle) );
76 if (validefault != null) validation.add(validefault); // In order to be at the end
77 member = study.getContributors();
82 if (mystudy.isOpenForWriting() && user.canEditProperties()) return "edit";
83 else return "display";
86 public String doEditTitle () {
87 // ----------------------------
88 Session connex = Database.getSession();
89 Transaction transax = connex.beginTransaction();
91 mystudy = getOpenStudy();
92 validation = new Vector<ValidationFacade>();
94 other = Document.selectResultTypes();
96 Study study = mystudy.getStudyObject();
97 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
98 DocumentType type = i.next();
99 ValidationCycle cycle = study.getValidationCycleOf(type);
100 if (cycle.isDefault()) {
101 validefault = new ValidationFacade(cycle);
104 validation.add( new ValidationFacade(cycle) );
106 if (validefault != null) validation.add(validefault); // In order to be at the end
107 member = study.getContributors();
116 public String doEditContributors () {
117 // -----------------------------------
118 Session connex = Database.getSession();
119 Transaction transax = connex.beginTransaction();
121 mystudy = getOpenStudy();
122 validation = new Vector<ValidationFacade>();
124 other = Document.selectAllTypes();
126 Study study = mystudy.getStudyObject();
127 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
128 DocumentType type = i.next();
129 ValidationCycle cycle = study.getValidationCycleOf(type);
130 if (cycle.isDefault()) {
131 validefault = new ValidationFacade(cycle);
134 validation.add( new ValidationFacade(cycle) );
136 if (validefault != null) validation.add(validefault); // In order to be at the end
137 member = study.getContributors();
138 staff = UserDirectory.selectAllUsers();
141 User me = this.getConnectedUser();
142 for (Iterator<User> i=staff.iterator(); i.hasNext(); ) {
143 User next = i.next();
144 ApplicationRights he = new ApplicationRights(next);
145 if (next.equals(me) || member.contains(next) || !he.canContributeToStudy()) i.remove();
151 public String doEditCycle () {
152 // ----------------------------
153 Session connex = Database.getSession();
154 Transaction transax = connex.beginTransaction();
156 mystudy = getOpenStudy();
157 validation = new Vector<ValidationFacade>();
159 other = Document.selectResultTypes();
161 Study study = mystudy.getStudyObject();
162 for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
163 DocumentType type = i.next();
164 ValidationCycle cycle = study.getValidationCycleOf(type);
165 if (cycle.isDefault()) {
166 validefault = new ValidationFacade(cycle);
169 if (type.getName().equals(edicycle)) {
170 this.type = type.getIndex();
172 validation.add( new ValidationFacade(cycle) );
175 if (validefault != null) validation.add(validefault); // In order to be at the end
176 member = study.getContributors();
177 validor = new Vector<Name>();
179 List<User> user = UserDirectory.selectAllUsers();
180 for (Iterator<User> i=user.iterator(); i.hasNext(); ) {
181 User next = i.next();
182 ApplicationRights he = new ApplicationRights(next);
183 if (he.canValidate()) {
184 if (next.equals(study.getAuthor())) validor.add( new ValidationFacade.ByManager(next) );
185 else validor.add(next);
192 public String doEdition () {
193 // --------------------------
194 Session connex = Database.getSession();
195 Transaction transax = connex.beginTransaction();
196 Study study = getOpenStudy().getStudyObject();
198 if (tosave == Save.title) {
200 // Edition of the title
201 Study.Properties sprop = new Study.Properties();
203 getStudyService().update(study, sprop.setTitle(stitle));
205 catch (InvalidPropertyException e) {
209 if (tosave == Save.contributor) {
211 // Edition of contributors
212 if (contributors == null) contributors = "";
213 if (candidates == null) candidates = "";
215 String[] parsekept = contributors.split(",");
216 String[] parsenew = candidates.split(",");
217 Vector<User> toremove = new Vector<User>(study.getContributors());
219 for (int i=0; i<parsekept.length; i++) {
220 if (parsekept[i].length() == 0) continue; // Yet no contributor
221 int index = Integer.valueOf(parsekept[i].trim());
222 for (Iterator<User> j=toremove.iterator(); j.hasNext(); ){
223 int present = j.next().getIndex();
224 if (present != index) continue;
229 int size = toremove.size();
230 if (size > 0) getStudyService().removeContributor(study, toremove.toArray(new User[size]));
232 for (int i=0; i<parsenew.length; i++) {
233 if (parsenew[i].length() == 0) continue; // No any new contributor
234 int index = Integer.valueOf(parsenew[i].trim());
235 User newser = UserDirectory.selectUser(index);
237 getStudyService().addContributor(study, newser);
240 if (tosave == Save.cycle) {
242 // Addition of a document validation cycle
243 DocumentType apply = Document.selectType(type);
244 ValidationCycle.Properties vprop = new ValidationCycle.Properties();
246 User actor = UserDirectory.selectUser(publisher);
247 vprop.setActor(ValidationStep.PROMOTION, actor);
250 User actor = UserDirectory.selectUser(reviewer);
251 vprop.setActor(ValidationStep.REVIEW, actor);
254 User actor = UserDirectory.selectUser(approver);
255 vprop.setActor(ValidationStep.APPROVAL, actor);
257 getStudyService().setValidationCycle(study, apply, vprop);
261 doInitialize(); // Re-initialization following the above edition
265 // ==============================================================================================================================
267 // ==============================================================================================================================
269 public User getAuthor () {
270 // ------------------------
271 return mystudy.getStudyObject().getAuthor();
273 public List<User> getCandidates () {
274 // ----------------------------------
277 public String getCycle () {
278 // -------------------------
281 public List<User> getContributors () {
282 // ------------------------------------
285 public ValidationFacade getDefaultValidation () {
286 // -----------------------------------------------
289 public int getDocumentTypeIndex () {
290 // ----------------------------------
293 public List<DocumentType> getOtherDocumentTypes () {
294 // --------------------------------------------------
297 public String getStudyTitle () {
298 // ------------------------------
299 return mystudy.getTitle();
301 public List<ValidationFacade> getValidations () {
302 // -----------------------------------------------
305 public List<Name> getValidationActors () {
306 // ----------------------------------------
310 // ==============================================================================================================================
312 // ==============================================================================================================================
314 public void setCandidates (String indices) {
315 // ------------------------------------------
316 candidates = indices;
318 public void setCycle (String type) {
319 // ----------------------------------
322 public void setMembers (String indices) {
323 // ---------------------------------------
324 contributors = indices;
326 public void setDocumentType (String index) {
327 // ------------------------------------------
328 type = Integer.valueOf(index);
330 public void setApprover (String index) {
331 // --------------------------------------
332 approver = Integer.valueOf(index);
334 public void setPublisher (String index) {
335 // ---------------------------------------
336 publisher = Integer.valueOf(index);
338 public void setReviewer (String index) {
339 // --------------------------------------
340 reviewer = Integer.valueOf(index);
342 public void setTitle (String title) {
343 // -----------------------------------
346 public void setSaveTitle (String save) {
347 // --------------------------------------
350 public void setSaveContributors (String save) {
351 // ---------------------------------------------
352 tosave = Save.contributor;
354 public void setSaveCycle (String save) {
355 // --------------------------------------
359 * Get the studyService.
361 * @return the studyService
363 public StudyService getStudyService() {
364 return _studyService;
368 * Set the studyService.
370 * @param studyService
371 * the studyService to set
373 public void setStudyService(StudyService studyService) {
374 _studyService = studyService;