X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Workspace%2FSiman%2Fsrc%2Forg%2Fsplat%2Fsimer%2FStudyPropertiesAction.java;h=fc016f30f00acc12b7038c833d30681274923ca7;hb=b6a6919ef30a5e2d99c3865a02bfb91d16ef4f7b;hp=370355cbe6488b31b7df9bb73e5519bd0eb37e29;hpb=7025b5bbe666dff7c10cb1200b1eaec66b7bc232;p=tools%2Fsiman.git diff --git a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java index 370355c..fc016f3 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java @@ -1,21 +1,24 @@ package org.splat.simer; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Vector; +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.exception.InvalidParameterException; import org.splat.kernel.InvalidPropertyException; import org.splat.kernel.Name; -import org.splat.dal.bo.kernel.User; import org.splat.service.DocumentTypeService; -import org.splat.service.StudyService; import org.splat.service.UserService; +import org.splat.service.dto.UserDTO; import org.splat.som.ApplicationRights; -import org.splat.dal.bo.som.DocumentType; -import org.splat.dal.bo.som.Study; import org.splat.som.StudyRights; -import org.splat.dal.bo.som.ValidationCycle; -import org.splat.dal.bo.som.ValidationStep; +import org.splat.util.BeanHelper; +import org.splat.wapp.Constants; /** * Edit/display study properties (study configuration) screen action. @@ -28,28 +31,39 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { private static final long serialVersionUID = 4210696018741092900L; // Presentation fields - private List staff; - private List member; - private List validor; - private List validation; - private ValidationFacade validefault; - private List other; + private transient List _staff; + private transient List _member; + private transient List _validor; + private transient List _validation; + private transient ValidationFacade _validefault; + private transient List _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 long type; // Type of document to be included in the validation process - private int publisher; - private int reviewer; - private int approver; - /** - * Injected study service. + * Edition action (title, contributors or cycle). + */ + private transient Save _tosave; + private transient String _edicycle; + /** + * Title of the study. */ - private StudyService _studyService; + 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. */ @@ -61,29 +75,14 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { private UserService _userService; /** - * Value of the menu property. - * It can be: none, create, open, study, knowledge, sysadmin, help. - */ - private String _menuProperty; - - /** - * Value of the title bar property. - * It can be: study, knowledge. - */ - private String _titleProperty; - - /** - * Value of the tool bar property. - * It can be: none, standard, study, back. + * Study readers list. */ - private String _toolProperty; - + List _readers; + /** - * Property that indicates whether the current open study is editable or not. - * On the screen it looks like pen on the status icon, pop-up menu also can be called. - * It is necessary for correct building the title bar. + * Study reader id list. */ - private String _editDisabledProperty = "false"; + List _readerIds; /** * Save operation type enumeration pointing which section of properties has been edited. @@ -100,7 +99,11 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Save validation cycle. */ - cycle + cycle, + /** + * Save study readers. + */ + readers } // ============================================================================================================================== @@ -114,255 +117,347 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { */ public String doInitialize() { - mystudy = getOpenStudy(); - validation = new Vector(); - validefault = null; - other = getDocumentTypeService().selectResultTypes(); + String res; + _openStudy = getOpenStudy(); + _validation = new ArrayList(); + _validefault = null; + _other = getDocumentTypeService().selectResultTypes(); - Study study = mystudy.getStudyObject(); - StudyRights user = mystudy.getStudyRights(); - for (Iterator i = other.iterator(); i.hasNext();) { + Study study = _openStudy.getStudyObject(); + StudyRights user = _openStudy.getStudyRights(); + for (Iterator i = _other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + _validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - validation.add(new ValidationFacade(cycle)); + _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; - - setMenuProperty("study"); - setTitleProperty("study"); - setEditDisabledProperty("true"); - setToolProperty("back"); - initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty); - - if (mystudy.isOpenForWriting() && user.canEditProperties()) { - return "edit"; + if (_validefault != null) { + _validation.add(_validefault); // In order to be at the end } - else { - return "display"; + _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"; } + + try { + _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); + } catch(InvalidParameterException e) { + LOG.error(e.getMessage(), e); + } + return res; } public String doEditTitle() { -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); - mystudy = getOpenStudy(); - validation = new Vector(); - validefault = null; - other = getDocumentTypeService().selectResultTypes(); + _openStudy = getOpenStudy(); + _validation = new ArrayList(); + _validefault = null; + _other = getDocumentTypeService().selectResultTypes(); - Study study = mystudy.getStudyObject(); - for (Iterator i = other.iterator(); i.hasNext();) { + Study study = _openStudy.getStudyObject(); + for (Iterator i = _other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + _validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - validation.add(new ValidationFacade(cycle)); + _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; - -// transax.commit(); - - setMenuProperty("study"); - setTitleProperty("study"); - setEditDisabledProperty("true"); - setToolProperty("back"); - initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty); + 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); + try { + _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); + } catch(InvalidParameterException e) { + LOG.error(e.getMessage(), e); + } + setActionType("edititle"); return SUCCESS; } public String doEditContributors() { -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); - mystudy = getOpenStudy(); - validation = new Vector(); - validefault = null; - other = getDocumentTypeService().selectAllTypes(); + _openStudy = getOpenStudy(); + _validation = new ArrayList(); + _validefault = null; + _other = getDocumentTypeService().selectAllTypes(); - Study study = mystudy.getStudyObject(); - for (Iterator i = other.iterator(); i.hasNext();) { + Study study = _openStudy.getStudyObject(); + for (Iterator i = _other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + _validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - validation.add(new ValidationFacade(cycle)); + _validation.add(new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale())); + } + if (_validefault != null) { + _validation.add(_validefault); // In order to be at the end } - if (validefault != null) - validation.add(validefault); // In order to be at the end - member = getStudyService().getContributors(study); - staff = getUserService().selectAllUsers(); - validor = null; - other = null; + _member = getStudyService().getContributors(study); + _staff = getUserService().selectAllUsers(); + _validor = null; + _other = null; User me = this.getConnectedUser(); - for (Iterator i = staff.iterator(); i.hasNext();) { + for (Iterator i = _staff.iterator(); i.hasNext();) { User next = i.next(); ApplicationRights he = new ApplicationRights(next); - if (next.equals(me) || member.contains(next) - || !he.canContributeToStudy()) + if (next.equals(me) || _member.contains(next) + || !he.canContributeToStudy()) { i.remove(); + } } -// transax.commit(); + + initializationFullScreenContext(Constants.STUDY_MENU, + Constants.STUDY_MENU, Constants.TRUE, Constants.BACK, + Constants.OPEN); + + try { + _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); + } catch(InvalidParameterException e) { + LOG.error(e.getMessage(), e); + } + setActionType("edibutor"); + return SUCCESS; + } + + /** + * Initialize edit readers screen. + * @return SUCCES + */ + public String doInitEditReaders() { + doInitialize(); - setMenuProperty("study"); - setTitleProperty("study"); - setEditDisabledProperty("true"); - setToolProperty("back"); - initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty); + _staff = getUserService().selectAllUsers(); - return SUCCESS; + //remove user from potential readers + _staff.remove(getConnectedUser()); + + //remove contributors from potential readers + if(_member != null) { + _staff.removeAll(_member); + } + + //remove readers from potential readers + List readers = new ArrayList(); + for(UserDTO userDTO : _readers) { + readers.add(BeanHelper.copyBean(userDTO, User.class)); + } + _staff.removeAll(readers); + + setActionType("editReaders"); + + return SUCCESS; } public String doEditCycle() { -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); - mystudy = getOpenStudy(); - validation = new Vector(); - validefault = null; - other = getDocumentTypeService().selectResultTypes(); + _openStudy = getOpenStudy(); + _validation = new ArrayList(); + _validefault = null; + _other = getDocumentTypeService().selectResultTypes(); - Study study = mystudy.getStudyObject(); - for (Iterator i = other.iterator(); i.hasNext();) { + Study study = _openStudy.getStudyObject(); + for (Iterator i = _other.iterator(); i.hasNext();) { DocumentType type = i.next(); - ValidationCycle cycle = getStudyService().getValidationCycleOf(study, type); + ValidationCycle cycle = getStudyService().getValidationCycleOf( + study, type); if (cycle.isDefault()) { - validefault = new ValidationFacade(cycle); + _validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); continue; } - if (type.getName().equals(edicycle)) { - this.type = type.getIndex(); + if (type.getName().equals(_edicycle)) { + this._type = type.getIndex(); } - validation.add(new ValidationFacade(cycle)); + _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 Vector(); - staff = null; + if (_validefault != null) { + _validation.add(_validefault); // In order to be at the end + } + _member = getStudyService().getContributors(study); + _validor = new ArrayList(); + _staff = null; List user = getUserService().selectAllUsers(); for (Iterator 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); + if (next.equals(study.getAuthor())) { + _validor.add(new ValidationFacade.ByManager(next, + getApplicationSettings().getCurrentLocale())); + } else { + _validor.add(next); + } } } -// transax.commit(); - - setMenuProperty("study"); - setTitleProperty("study"); - setEditDisabledProperty("true"); - setToolProperty("back"); - initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty); - + + initializationFullScreenContext(Constants.STUDY_MENU, + Constants.STUDY_MENU, Constants.TRUE, Constants.BACK, + Constants.OPEN); + + try { + _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); + } catch(InvalidParameterException e) { + LOG.error(e.getMessage(), e); + } + setActionType("edicycle"); return SUCCESS; } - public String doEdition() { - // -------------------------- -// Session connex = Database.getCurSession(); -// Transaction transax = connex.beginTransaction(); + public String doEdition() throws InvalidParameterException { Study study = getOpenStudy().getStudyObject(); - if (tosave == Save.title) { + if (_tosave == Save.title) { // Edition of the title Study.Properties sprop = new Study.Properties(); try { - getStudyService().update(study, sprop.setTitle(stitle)); + getStudyService().update(study, sprop.setTitle(_stitle)); } catch (InvalidPropertyException e) { - // TODO + // TODO: + LOG.error(e.getMessage(), e); } - } else if (tosave == Save.contributor) { + } else if (_tosave == Save.contributor) { // Edition of contributors - if (contributors == null) - contributors = ""; - if (candidates == null) - candidates = ""; + if (_contributors == null) { + _contributors = ""; + } + if (_candidates == null) { + _candidates = ""; + } - String[] parsekept = contributors.split(","); - String[] parsenew = candidates.split(","); - Vector toremove = new Vector(getStudyService().getContributors(study)); + String[] parsekept = _contributors.split(","); + String[] parsenew = _candidates.split(","); + List toremove = new ArrayList(getStudyService() + .getContributors(study)); for (int i = 0; i < parsekept.length; i++) { - if (parsekept[i].length() == 0) + if (parsekept[i].length() == 0) { continue; // Yet no contributor + } int index = Integer.valueOf(parsekept[i].trim()); for (Iterator j = toremove.iterator(); j.hasNext();) { long present = j.next().getIndex(); - if (present != index) + if (present != index) { continue; + } j.remove(); break; } } int size = toremove.size(); - if (size > 0) + if (size > 0) { getStudyService().removeContributor(study, toremove.toArray(new User[size])); + } for (int i = 0; i < parsenew.length; i++) { - if (parsenew[i].length() == 0) + 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) { + } else if (_tosave == Save.cycle) { // Addition of a document validation cycle - DocumentType apply = getDocumentTypeService().selectType(type); + DocumentType apply = getDocumentTypeService().selectType(_type); ValidationCycle.Properties vprop = new ValidationCycle.Properties(); - if (publisher > 0) { - User actor = getUserService().selectUser(publisher); + if (_publisher > 0) { + User actor = getUserService().selectUser(_publisher); vprop.setActor(ValidationStep.PROMOTION, actor); } - if (reviewer > 0) { - User actor = getUserService().selectUser(reviewer); + if (_reviewer > 0) { + User actor = getUserService().selectUser(_reviewer); vprop.setActor(ValidationStep.REVIEW, actor); } - if (approver > 0) { - User actor = getUserService().selectUser(approver); + if (_approver > 0) { + User actor = getUserService().selectUser(_approver); vprop.setActor(ValidationStep.APPROVAL, actor); } getStudyService().setValidationCycle(study, apply, vprop); + } else if(_tosave == Save.readers) { + long studyId = getOpenStudy().getIndex().longValue(); + _readers = getStudyService().getReaders(studyId); + + //Remove newly unchecked users + if(_readers != null) { + for(UserDTO userDTO : _readers) { + if(_readerIds == null || !_readerIds.contains(userDTO.getIndex())) { + getStudyService().removeReader(studyId, userDTO.getIndex()); + } + } + } + + //Add newly checked users + if(_readerIds != null) { + for(Long userId : _readerIds) { + if(_readers == null) { + getStudyService().addReader(studyId, userId); + } else { + boolean contains = false; + for(UserDTO userDTO : _readers) { + if(userId.longValue() == userDTO.getIndex()) { + contains = true; + break; + } + } + if(!contains) { + getStudyService().addReader(studyId, userId); + } + } + } + } + + //Update OpenStudy + _openStudy.open(getConnectedUser(), getStudyService().selectStudy(_openStudy.getIndex())); } -// transax.commit(); doInitialize(); // Re-initialization following the above edition - - setMenuProperty("study"); - setTitleProperty("study"); - setEditDisabledProperty("true"); - setToolProperty("back"); - initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty); - + + initializationFullScreenContext(Constants.STUDY_MENU, + Constants.STUDY_MENU, Constants.TRUE, Constants.BACK, + Constants.OPEN); + return SUCCESS; } @@ -371,133 +466,101 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { // ============================================================================================================================== public User getAuthor() { - // ------------------------ - return mystudy.getStudyObject().getAuthor(); + return _openStudy.getStudyObject().getAuthor(); } public List getCandidates() { - // ---------------------------------- - return staff; + return _staff; } public String getCycle() { - // ------------------------- - return edicycle; + return _edicycle; } public List getContributors() { - // ------------------------------------ - return member; + return _member; } public ValidationFacade getDefaultValidation() { - // ----------------------------------------------- - return validefault; + return _validefault; } public long getDocumentTypeIndex() { - // ---------------------------------- - return type; + return _type; } public List getOtherDocumentTypes() { - // -------------------------------------------------- - return other; + return _other; } public String getStudyTitle() { - // ------------------------------ - return mystudy.getTitle(); + return _openStudy.getTitle(); } public List getValidations() { - // ----------------------------------------------- - return validation; + return _validation; } public List getValidationActors() { - // ---------------------------------------- - return validor; + return _validor; } // ============================================================================================================================== // Setters // ============================================================================================================================== - public void setCandidates(String indices) { - // ------------------------------------------ - candidates = indices; + public void setCandidates(final String indices) { + _candidates = indices; } - public void setCycle(String type) { - // ---------------------------------- - edicycle = type; + public void setCycle(final String type) { + _edicycle = type; } - public void setMembers(String indices) { - // --------------------------------------- - contributors = indices; + public void setMembers(final String indices) { + _contributors = indices; } - public void setDocumentType(String index) { - // ------------------------------------------ - type = Integer.valueOf(index); + public void setDocumentType(final String index) { + _type = Integer.valueOf(index); } - public void setApprover(String index) { - // -------------------------------------- - approver = Integer.valueOf(index); + public void setApprover(final String index) { + _approver = Integer.valueOf(index); } - public void setPublisher(String index) { - // --------------------------------------- - publisher = Integer.valueOf(index); + public void setPublisher(final String index) { + _publisher = Integer.valueOf(index); } - public void setReviewer(String index) { - // -------------------------------------- - reviewer = Integer.valueOf(index); + public void setReviewer(final String index) { + _reviewer = Integer.valueOf(index); } - public void setTitle(String title) { - // ----------------------------------- - stitle = title; + public void setTitle(final String title) { + _stitle = title; } - public void setSaveTitle(String save) { - // -------------------------------------- - tosave = Save.title; + public void setSaveTitle(final String save) { + _tosave = Save.title; } - public void setSaveContributors(String save) { - // --------------------------------------------- - tosave = Save.contributor; + public void setSaveContributors(final String save) { + _tosave = Save.contributor; } - public void setSaveCycle(String save) { - // -------------------------------------- - tosave = Save.cycle; + public void setSaveCycle(final String save) { + _tosave = Save.cycle; } /** - * Get the studyService. - * - * @return the studyService + * Set tosave to readers. + * @param save the save */ - public StudyService getStudyService() { - return _studyService; + public void setSaveReaders(final String save) { + _tosave = Save.readers; } - - /** - * Set the studyService. - * - * @param studyService - * the studyService to set - */ - public void setStudyService(StudyService studyService) { - _studyService = studyService; - } - + /** * Get the documentTypeService. * @@ -513,12 +576,14 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * @param documentTypeService * the documentTypeService to set */ - public void setDocumentTypeService(DocumentTypeService documentTypeService) { + public void setDocumentTypeService( + final DocumentTypeService documentTypeService) { _documentTypeService = documentTypeService; } /** * Get the userService. + * * @return the userService */ public UserService getUserService() { @@ -527,73 +592,43 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the userService. - * @param userService the userService to set + * + * @param userService + * the userService to set */ - public void setUserService(UserService userService) { + public void setUserService(final UserService userService) { _userService = userService; } - - /** - * Get the menuProperty. - * @return the menuProperty - */ - public String getMenuProperty() { - return _menuProperty; - } - - /** - * Set the menuProperty. - * @param menuProperty the menuProperty to set - */ - public void setMenuProperty(String menuProperty) { - this._menuProperty = menuProperty; - } - - /** - * Get the _titleProperty. - * @return the _titleProperty - */ - public String getTitleProperty() { - return _titleProperty; - } - - /** - * Set the _titleProperty. - * @param _titleProperty the titleProperty to set - */ - public void setTitleProperty(String titleProperty) { - _titleProperty = titleProperty; - } /** - * Get the editDisabledProperty. - * @return the editDisabledProperty + * Get the readers. + * @return the readers */ - public final String getEditDisabledProperty() { - return _editDisabledProperty; + public List getReaders() { + return _readers; } /** - * Set the editDisabledProperty. - * @param editDisabledProperty the editDisabledProperty to set + * Set the readers. + * @param readers the readers to set */ - public final void setEditDisabledProperty(String editDisabledProperty) { - _editDisabledProperty = editDisabledProperty; + public void setReaders(final List readers) { + _readers = readers; } /** - * Get the toolProperty. - * @return the toolProperty + * Get the readerIds. + * @return the readerIds */ - public String getToolProperty() { - return _toolProperty; + public List getReaderIds() { + return _readerIds; } /** - * Set the toolProperty. - * @param toolProperty the toolProperty to set + * Set the readerIds. + * @param readerIds the readerIds to set */ - public void setToolProperty(final String toolProperty) { - _toolProperty = toolProperty; + public void setReaderIds(final List readerIds) { + this._readerIds = readerIds; } } \ No newline at end of file