package org.splat.simer;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Vector;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
+import org.splat.dal.bo.kernel.User;
+import org.splat.dal.bo.som.DocumentType;
+import org.splat.dal.bo.som.Study;
+import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.dal.bo.som.ValidationStep;
import org.splat.kernel.InvalidPropertyException;
import org.splat.kernel.Name;
-import org.splat.kernel.User;
-import org.splat.kernel.UserDirectory;
+import org.splat.service.DocumentTypeService;
+import org.splat.service.UserService;
import org.splat.som.ApplicationRights;
-import org.splat.som.Database;
-import org.splat.som.Document;
-import org.splat.som.DocumentType;
-import org.splat.som.Study;
import org.splat.som.StudyRights;
-import org.splat.som.ValidationCycle;
-import org.splat.som.ValidationStep;
-
+import org.splat.wapp.Constants;
+/**
+ * Edit/display study properties (study configuration) screen action.
+ */
public class StudyPropertiesAction extends DisplayStudyStepAction {
-// Presentation fields
- private List<User> staff;
- private List<User> member;
- private List<Name> validor;
- private List<ValidationFacade> validation;
- private ValidationFacade validefault;
- private List<DocumentType> other;
-
-// User input fields
- private Save tosave; // Edition action (title, contributors or cycle)
- private String edicycle;
- private String stitle; // Title of the study
- private String contributors; // List of existing contributors, some of them may have been removed
- private String candidates; // List of added contributors
- private int type; // Type of document to be included in the validation process
- private int publisher;
- private int reviewer;
- private int approver;
-
+ /**
+ * Serial version ID.
+ */
private static final long serialVersionUID = 4210696018741092900L;
- private enum Save { title, contributor, cycle }
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectResultTypes();
-
- Study study = mystudy.getStudyObject();
- StudyRights user = mystudy.getStudyRights();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- validation.add( new ValidationFacade(cycle) );
- i.remove();
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- staff = null;
- validor = null;
-
- transax.commit();
- if (mystudy.isOpenForWriting() && user.canEditProperties()) return "edit";
- else return "display";
- }
-
- public String doEditTitle () {
-// ----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectResultTypes();
-
- Study study = mystudy.getStudyObject();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- validation.add( new ValidationFacade(cycle) );
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- staff = null;
- validor = null;
- other = null;
-
- transax.commit();
- return SUCCESS;
- }
-
- public String doEditContributors () {
-// -----------------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectAllTypes();
-
- Study study = mystudy.getStudyObject();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- validation.add( new ValidationFacade(cycle) );
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- staff = UserDirectory.selectAllUsers();
- validor = null;
- other = null;
- User me = this.getConnectedUser();
- for (Iterator<User> i=staff.iterator(); i.hasNext(); ) {
- User next = i.next();
- ApplicationRights he = new ApplicationRights(next);
- if (next.equals(me) || member.contains(next) || !he.canContributeToStudy()) i.remove();
- }
- transax.commit();
- return SUCCESS;
- }
-
- public String doEditCycle () {
-// ----------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
- validation = new Vector<ValidationFacade>();
- validefault = null;
- other = Document.selectResultTypes();
-
- Study study = mystudy.getStudyObject();
- for (Iterator<DocumentType> i=other.iterator(); i.hasNext(); ) {
- DocumentType type = i.next();
- ValidationCycle cycle = study.getValidationCycleOf(type);
- if (cycle.isDefault()) {
- validefault = new ValidationFacade(cycle);
- continue;
- }
- if (type.getName().equals(edicycle)) {
- this.type = type.getIndex();
- }
- validation.add( new ValidationFacade(cycle) );
- i.remove();
- }
- if (validefault != null) validation.add(validefault); // In order to be at the end
- member = study.getContributors();
- validor = new Vector<Name>();
- staff = null;
- List<User> user = UserDirectory.selectAllUsers();
- for (Iterator<User> i=user.iterator(); i.hasNext(); ) {
- User next = i.next();
- ApplicationRights he = new ApplicationRights(next);
- if (he.canValidate()) {
- if (next.equals(study.getAuthor())) validor.add( new ValidationFacade.ByManager(next) );
- else validor.add(next);
- }
- }
- transax.commit();
- return SUCCESS;
- }
-
- public String doEdition () {
-// --------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- Study study = getOpenStudy().getStudyObject();
-
- if (tosave == Save.title) {
-
-// Edition of the title
- Study.Properties sprop = new Study.Properties();
- try {
- study.update(sprop.setTitle(stitle));
- }
- catch (InvalidPropertyException e) {
-//TODO
- }
- } else
- if (tosave == Save.contributor) {
-
-// Edition of contributors
- if (contributors == null) contributors = "";
- if (candidates == null) candidates = "";
-
- String[] parsekept = contributors.split(",");
- String[] parsenew = candidates.split(",");
- Vector<User> toremove = new Vector<User>(study.getContributors());
-
- for (int i=0; i<parsekept.length; i++) {
- if (parsekept[i].length() == 0) continue; // Yet no contributor
- int index = Integer.valueOf(parsekept[i].trim());
- for (Iterator<User> j=toremove.iterator(); j.hasNext(); ){
- int present = j.next().getIndex();
- if (present != index) continue;
- j.remove();
- break;
- }
- }
- int size = toremove.size();
- if (size > 0) study.removeContributor(toremove.toArray(new User[size]));
-
- for (int i=0; i<parsenew.length; i++) {
- if (parsenew[i].length() == 0) continue; // No any new contributor
- int index = Integer.valueOf(parsenew[i].trim());
- User newser = UserDirectory.selectUser(index);
-
- study.addContributor(newser);
- }
- } else
- if (tosave == Save.cycle) {
-
-// Addition of a document validation cycle
- DocumentType apply = Document.selectType(type);
- ValidationCycle.Properties vprop = new ValidationCycle.Properties();
- if (publisher > 0) {
- User actor = UserDirectory.selectUser(publisher);
- vprop.setActor(ValidationStep.PROMOTION, actor);
- }
- if (reviewer > 0) {
- User actor = UserDirectory.selectUser(reviewer);
- vprop.setActor(ValidationStep.REVIEW, actor);
- }
- if (approver > 0) {
- User actor = UserDirectory.selectUser(approver);
- vprop.setActor(ValidationStep.APPROVAL, actor);
- }
- study.setValidationCycle(apply, vprop);
- }
- transax.commit();
-
- doInitialize(); // Re-initialization following the above edition
- return SUCCESS;
+ // Presentation fields
+ private transient List<User> _staff;
+ private transient List<User> _member;
+ private transient List<Name> _validor;
+ private transient List<ValidationFacade> _validation;
+ private transient ValidationFacade _validefault;
+ private transient List<DocumentType> _other;
+
+ // User input fields
+ /**
+ * Edition action (title, contributors or cycle).
+ */
+ private transient Save _tosave;
+ private transient String _edicycle;
+ /**
+ * Title of the study.
+ */
+ private transient String _stitle;
+ /**
+ * List of existing contributors, some of them may have been removed.
+ */
+ private transient String _contributors;
+ /**
+ * List of added contributors.
+ */
+ private transient String _candidates;
+ /**
+ * Type of document to be included in the validation process.
+ */
+ private transient long _type;
+ private transient int _publisher;
+ private transient int _reviewer;
+ private transient int _approver;
+
+ /**
+ * Injected document type service.
+ */
+ private DocumentTypeService _documentTypeService;
+
+ /**
+ * Injected user service.
+ */
+ private UserService _userService;
+
+ /**
+ * Save operation type enumeration pointing which section of properties has been edited.
+ */
+ private enum Save {
+ /**
+ * Save study title.
+ */
+ title,
+ /**
+ * Save contributors.
+ */
+ contributor,
+ /**
+ * Save validation cycle.
+ */
+ cycle
+ }
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
+
+ /**
+ * Initialize study properties action.
+ *
+ * @return "edit" if user can edit study properties, otherwise return "display"
+ */
+ public String doInitialize() {
+
+ String res;
+ _openStudy = getOpenStudy();
+ _validation = new ArrayList<ValidationFacade>();
+ _validefault = null;
+ _other = getDocumentTypeService().selectResultTypes();
+
+ Study study = _openStudy.getStudyObject();
+ StudyRights user = _openStudy.getStudyRights();
+ for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ study, type);
+ if (cycle.isDefault()) {
+ _validefault = new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale());
+ continue;
+ }
+ _validation.add(new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale()));
+ i.remove();
+ }
+ if (_validefault != null) {
+ _validation.add(_validefault); // In order to be at the end
+ }
+ _member = getStudyService().getContributors(study);
+ _staff = null;
+ _validor = null;
+
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
+ Constants.OPEN);
+
+ if (_openStudy.isOpenForWriting() && user.canEditProperties()) {
+ res = "edit";
+ } else {
+ res = "display";
+ }
+ return res;
+ }
+
+ public String doEditTitle() {
+
+ _openStudy = getOpenStudy();
+ _validation = new ArrayList<ValidationFacade>();
+ _validefault = null;
+ _other = getDocumentTypeService().selectResultTypes();
+
+ Study study = _openStudy.getStudyObject();
+ for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ study, type);
+ if (cycle.isDefault()) {
+ _validefault = new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale());
+ continue;
+ }
+ _validation.add(new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale()));
+ }
+ if (_validefault != null) {
+ _validation.add(_validefault); // In order to be at the end
+ }
+ _member = getStudyService().getContributors(study);
+ _staff = null;
+ _validor = null;
+ _other = null;
+
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
+ Constants.OPEN);
+ setActionType("edititle");
+
+ return SUCCESS;
+ }
+
+ public String doEditContributors() {
+
+ _openStudy = getOpenStudy();
+ _validation = new ArrayList<ValidationFacade>();
+ _validefault = null;
+ _other = getDocumentTypeService().selectAllTypes();
+
+ Study study = _openStudy.getStudyObject();
+ for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ study, type);
+ if (cycle.isDefault()) {
+ _validefault = new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale());
+ continue;
+ }
+ _validation.add(new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale()));
+ }
+ if (_validefault != null) {
+ _validation.add(_validefault); // In order to be at the end
+ }
+ _member = getStudyService().getContributors(study);
+ _staff = getUserService().selectAllUsers();
+ _validor = null;
+ _other = null;
+ User me = this.getConnectedUser();
+ for (Iterator<User> i = _staff.iterator(); i.hasNext();) {
+ User next = i.next();
+ ApplicationRights he = new ApplicationRights(next);
+ if (next.equals(me) || _member.contains(next)
+ || !he.canContributeToStudy()) {
+ i.remove();
+ }
+ }
+
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
+ Constants.OPEN);
+
+ setActionType("edibutor");
+ return SUCCESS;
+ }
+
+ public String doEditCycle() {
+
+ _openStudy = getOpenStudy();
+ _validation = new ArrayList<ValidationFacade>();
+ _validefault = null;
+ _other = getDocumentTypeService().selectResultTypes();
+
+ Study study = _openStudy.getStudyObject();
+ for (Iterator<DocumentType> i = _other.iterator(); i.hasNext();) {
+ DocumentType type = i.next();
+ ValidationCycle cycle = getStudyService().getValidationCycleOf(
+ study, type);
+ if (cycle.isDefault()) {
+ _validefault = new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale());
+ continue;
+ }
+ if (type.getName().equals(_edicycle)) {
+ this._type = type.getIndex();
+ }
+ _validation.add(new ValidationFacade(cycle,
+ getApplicationSettings().getCurrentLocale()));
+ i.remove();
+ }
+ if (_validefault != null) {
+ _validation.add(_validefault); // In order to be at the end
+ }
+ _member = getStudyService().getContributors(study);
+ _validor = new ArrayList<Name>();
+ _staff = null;
+ List<User> user = getUserService().selectAllUsers();
+ for (Iterator<User> i = user.iterator(); i.hasNext();) {
+ User next = i.next();
+ ApplicationRights he = new ApplicationRights(next);
+ if (he.canValidate()) {
+ if (next.equals(study.getAuthor())) {
+ _validor.add(new ValidationFacade.ByManager(next,
+ getApplicationSettings().getCurrentLocale()));
+ } else {
+ _validor.add(next);
+ }
+ }
+ }
+
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
+ Constants.OPEN);
+
+ setActionType("edicycle");
+
+ return SUCCESS;
+ }
+
+ public String doEdition() {
+ Study study = getOpenStudy().getStudyObject();
+
+ if (_tosave == Save.title) {
+
+ // Edition of the title
+ Study.Properties sprop = new Study.Properties();
+ try {
+ getStudyService().update(study, sprop.setTitle(_stitle));
+ } catch (InvalidPropertyException e) {
+ // TODO:
+ LOG.error(e.getMessage(), e);
+ }
+ } else if (_tosave == Save.contributor) {
+
+ // Edition of contributors
+ if (_contributors == null) {
+ _contributors = "";
+ }
+ if (_candidates == null) {
+ _candidates = "";
+ }
+
+ String[] parsekept = _contributors.split(",");
+ String[] parsenew = _candidates.split(",");
+ List<User> toremove = new ArrayList<User>(getStudyService()
+ .getContributors(study));
+
+ for (int i = 0; i < parsekept.length; i++) {
+ if (parsekept[i].length() == 0) {
+ continue; // Yet no contributor
+ }
+ int index = Integer.valueOf(parsekept[i].trim());
+ for (Iterator<User> j = toremove.iterator(); j.hasNext();) {
+ long present = j.next().getIndex();
+ if (present != index) {
+ continue;
+ }
+ j.remove();
+ break;
+ }
+ }
+ int size = toremove.size();
+ if (size > 0) {
+ getStudyService().removeContributor(study,
+ toremove.toArray(new User[size]));
+ }
+
+ for (int i = 0; i < parsenew.length; i++) {
+ if (parsenew[i].length() == 0) {
+ continue; // No any new contributor
+ }
+ int index = Integer.valueOf(parsenew[i].trim());
+ User newser = getUserService().selectUser(index);
+
+ getStudyService().addContributor(study, newser);
+ }
+ } else if (_tosave == Save.cycle) {
+
+ // Addition of a document validation cycle
+ DocumentType apply = getDocumentTypeService().selectType(_type);
+ ValidationCycle.Properties vprop = new ValidationCycle.Properties();
+ if (_publisher > 0) {
+ User actor = getUserService().selectUser(_publisher);
+ vprop.setActor(ValidationStep.PROMOTION, actor);
+ }
+ if (_reviewer > 0) {
+ User actor = getUserService().selectUser(_reviewer);
+ vprop.setActor(ValidationStep.REVIEW, actor);
+ }
+ if (_approver > 0) {
+ User actor = getUserService().selectUser(_approver);
+ vprop.setActor(ValidationStep.APPROVAL, actor);
+ }
+ getStudyService().setValidationCycle(study, apply, vprop);
+ }
+
+ doInitialize(); // Re-initialization following the above edition
+
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.BACK,
+ Constants.OPEN);
+
+ return SUCCESS;
+ }
+
+ // ==============================================================================================================================
+ // Getters
+ // ==============================================================================================================================
+
+ public User getAuthor() {
+ return _openStudy.getStudyObject().getAuthor();
+ }
+
+ public List<User> getCandidates() {
+ return _staff;
+ }
+
+ public String getCycle() {
+ return _edicycle;
+ }
+
+ public List<User> getContributors() {
+ return _member;
+ }
+
+ public ValidationFacade getDefaultValidation() {
+ return _validefault;
+ }
+
+ public long getDocumentTypeIndex() {
+ return _type;
+ }
+
+ public List<DocumentType> getOtherDocumentTypes() {
+ return _other;
+ }
+
+ public String getStudyTitle() {
+ return _openStudy.getTitle();
+ }
+
+ public List<ValidationFacade> getValidations() {
+ return _validation;
}
-// ==============================================================================================================================
-// Getters
-// ==============================================================================================================================
-
- public User getAuthor () {
-// ------------------------
- return mystudy.getStudyObject().getAuthor();
- }
- public List<User> getCandidates () {
-// ----------------------------------
- return staff;
- }
- public String getCycle () {
-// -------------------------
- return edicycle;
- }
- public List<User> getContributors () {
-// ------------------------------------
- return member;
- }
- public ValidationFacade getDefaultValidation () {
-// -----------------------------------------------
- return validefault;
- }
- public int getDocumentTypeIndex () {
-// ----------------------------------
- return type;
- }
- public List<DocumentType> getOtherDocumentTypes () {
-// --------------------------------------------------
- return other;
- }
- public String getStudyTitle () {
-// ------------------------------
- return mystudy.getTitle();
- }
- public List<ValidationFacade> getValidations () {
-// -----------------------------------------------
- return validation;
- }
- public List<Name> getValidationActors () {
-// ----------------------------------------
- return validor;
- }
-
-// ==============================================================================================================================
-// Setters
-// ==============================================================================================================================
-
- public void setCandidates (String indices) {
-// ------------------------------------------
- candidates = indices;
- }
- public void setCycle (String type) {
-// ----------------------------------
- edicycle = type;
- }
- public void setMembers (String indices) {
-// ---------------------------------------
- contributors = indices;
- }
- public void setDocumentType (String index) {
-// ------------------------------------------
- type = Integer.valueOf(index);
- }
- public void setApprover (String index) {
-// --------------------------------------
- approver = Integer.valueOf(index);
- }
- public void setPublisher (String index) {
-// ---------------------------------------
- publisher = Integer.valueOf(index);
- }
- public void setReviewer (String index) {
-// --------------------------------------
- reviewer = Integer.valueOf(index);
- }
- public void setTitle (String title) {
-// -----------------------------------
- stitle = title;
- }
- public void setSaveTitle (String save) {
-// --------------------------------------
- tosave = Save.title;
- }
- public void setSaveContributors (String save) {
-// ---------------------------------------------
- tosave = Save.contributor;
- }
- public void setSaveCycle (String save) {
-// --------------------------------------
- tosave = Save.cycle;
- }
+ public List<Name> getValidationActors() {
+ return _validor;
+ }
+
+ // ==============================================================================================================================
+ // Setters
+ // ==============================================================================================================================
+
+ public void setCandidates(final String indices) {
+ _candidates = indices;
+ }
+
+ public void setCycle(final String type) {
+ _edicycle = type;
+ }
+
+ public void setMembers(final String indices) {
+ _contributors = indices;
+ }
+
+ public void setDocumentType(final String index) {
+ _type = Integer.valueOf(index);
+ }
+
+ public void setApprover(final String index) {
+ _approver = Integer.valueOf(index);
+ }
+
+ public void setPublisher(final String index) {
+ _publisher = Integer.valueOf(index);
+ }
+
+ public void setReviewer(final String index) {
+ _reviewer = Integer.valueOf(index);
+ }
+
+ public void setTitle(final String title) {
+ _stitle = title;
+ }
+
+ public void setSaveTitle(final String save) {
+ _tosave = Save.title;
+ }
+
+ public void setSaveContributors(final String save) {
+ _tosave = Save.contributor;
+ }
+
+ public void setSaveCycle(final String save) {
+ _tosave = Save.cycle;
+ }
+
+ /**
+ * Get the documentTypeService.
+ *
+ * @return the documentTypeService
+ */
+ public DocumentTypeService getDocumentTypeService() {
+ return _documentTypeService;
+ }
+
+ /**
+ * Set the documentTypeService.
+ *
+ * @param documentTypeService
+ * the documentTypeService to set
+ */
+ public void setDocumentTypeService(
+ final DocumentTypeService documentTypeService) {
+ _documentTypeService = documentTypeService;
+ }
+
+ /**
+ * Get the userService.
+ *
+ * @return the userService
+ */
+ public UserService getUserService() {
+ return _userService;
+ }
+
+ /**
+ * Set the userService.
+ *
+ * @param userService
+ * the userService to set
+ */
+ public void setUserService(final UserService userService) {
+ _userService = userService;
+ }
}
\ No newline at end of file