From 8c20705ddcd75e1bf1f497e5a87092b68e54eaf4 Mon Sep 17 00:00:00 2001 From: rkv Date: Mon, 8 Apr 2013 12:33:35 +0000 Subject: [PATCH] Fix of study configuration modification: all document types are available now for validation cycles definition, error when adding a contributor just after adding a cycle is fixed. --- .../src/org/splat/dal/bo/kernel/Any.java | 1 - .../org/splat/service/StudyServiceImpl.java | 1 + .../splat/simer/StudyPropertiesAction.java | 615 +++++++++++------- 3 files changed, 384 insertions(+), 233 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java index e131b6a..1887b33 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/kernel/Any.java @@ -35,7 +35,6 @@ public abstract class Any extends Persistent { // Initialization constructors protected Any(final ObjectProperties oprop) throws MissedPropertyException, InvalidPropertyException, MultiplyDefinedException { - // -------------------------------------- super(oprop); } diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index 4660ca7..d7e6b90 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -491,6 +491,7 @@ public class StudyServiceImpl implements StudyService { ValidationCycleRelation link = cycle.getContext(); aStudy.addRelation(link); + getValidationCycleDAO().flush(); aStudyDTO.getAllRelations().add(link); // RKV validactor.put(cname, link.getTo()); // Replaces the cycle if exists as default, diff --git a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java index fc016f3..b29f239 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java @@ -31,11 +31,29 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { private static final long serialVersionUID = 4210696018741092900L; // Presentation fields + /** + * List of available users which are not yet included into contributors. + */ private transient List _staff; + /** + * Study contributors list. + */ private transient List _member; + /** + * List of validators. + */ private transient List _validor; + /** + * List of specific study validation cycles presentations. + */ private transient List _validation; + /** + * Default validation cycle presentation. + */ private transient ValidationFacade _validefault; + /** + * List of document types which have no specific validation cycles for this study. + */ private transient List _other; // User input fields @@ -43,6 +61,9 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * Edition action (title, contributors or cycle). */ private transient Save _tosave; + /** + * Document type name for the modified validation cycle. + */ private transient String _edicycle; /** * Title of the study. @@ -60,9 +81,18 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * 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; + /** + * Validation cycle publisher's id. + */ + private transient long _publisher; + /** + * Validation cycle reviewer's id. + */ + private transient long _reviewer; + /** + * Validation cycle approver's id. + */ + private transient long _approver; /** * Injected document type service. @@ -73,16 +103,16 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * Injected user service. */ private UserService _userService; - + /** * Study readers list. */ - List _readers; + private List _readers; /** * Study reader id list. */ - List _readerIds; + private List _readerIds; /** * Save operation type enumeration pointing which section of properties has been edited. @@ -117,117 +147,109 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { */ public String doInitialize() { - String res; _openStudy = getOpenStudy(); - _validation = new ArrayList(); - _validefault = null; - _other = getDocumentTypeService().selectResultTypes(); - 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); - 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); + + initData(study); + _staff = null; _validor = null; - initializationFullScreenContext(Constants.STUDY_MENU, - Constants.STUDY_MENU, Constants.TRUE, Constants.BACK, - Constants.OPEN); - + String res; + StudyRights user = _openStudy.getStudyRights(); 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); + _readers = getStudyService().getReaders( + getOpenStudy().getIndex().longValue()); + } catch (InvalidParameterException e) { + LOG.error(e.getMessage(), e); } return res; } - public String doEditTitle() { - - _openStudy = getOpenStudy(); + /** + * Initialize common study data presented on the screen. + * + * @param study + * the selected study + */ + private void initData(final Study study) { _validation = new ArrayList(); _validefault = null; - _other = getDocumentTypeService().selectResultTypes(); + // RKV: _other = getDocumentTypeService().selectResultTypes(); + _other = getDocumentTypeService().selectAllTypes(); // RKV - Study study = _openStudy.getStudyObject(); for (Iterator 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 (_validefault == null) { + _validefault = new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale()); + } + } else { + if (type.getName().equals(_edicycle)) { + this._type = type.getIndex(); + } + _validation.add(new ValidationFacade(cycle, + getApplicationSettings().getCurrentLocale())); + i.remove(); } - _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); - + } + + /** + * Prepare study title editing. + * + * @return SUCCESS + */ + public String doEditTitle() { + + _openStudy = getOpenStudy(); + + initData(_openStudy.getStudyObject()); + + _staff = null; + _validor = null; + _other = null; + try { - _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); - } catch(InvalidParameterException e) { - LOG.error(e.getMessage(), e); + _readers = getStudyService().getReaders( + getOpenStudy().getIndex().longValue()); + } catch (InvalidParameterException e) { + LOG.error(e.getMessage(), e); } setActionType("edititle"); return SUCCESS; } + /** + * Prepare contributors list editing for the selected study. + * + * @return SUCCESS + */ public String doEditContributors() { _openStudy = getOpenStudy(); - _validation = new ArrayList(); - _validefault = null; - _other = getDocumentTypeService().selectAllTypes(); - Study study = _openStudy.getStudyObject(); - for (Iterator 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); + + initData(study); + _staff = getUserService().selectAllUsers(); _validor = null; _other = null; @@ -241,76 +263,58 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { } } - initializationFullScreenContext(Constants.STUDY_MENU, - Constants.STUDY_MENU, Constants.TRUE, Constants.BACK, - Constants.OPEN); - try { - _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); - } catch(InvalidParameterException e) { + _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(); - + _staff = getUserService().selectAllUsers(); - - //remove user from potential readers + + // remove user from potential readers _staff.remove(getConnectedUser()); - - //remove contributors from potential readers - if(_member != null) { + + // remove contributors from potential readers + if (_member != null) { _staff.removeAll(_member); } - - //remove readers from potential readers + + // remove readers from potential readers List readers = new ArrayList(); - for(UserDTO userDTO : _readers) { + for (UserDTO userDTO : _readers) { readers.add(BeanHelper.copyBean(userDTO, User.class)); } _staff.removeAll(readers); - + setActionType("editReaders"); - - return SUCCESS; + + return SUCCESS; } + /** + * Add or edit a document validation cycle for the selected study. + * + * @return SUCCESS + */ public String doEditCycle() { _openStudy = getOpenStudy(); - _validation = new ArrayList(); - _validefault = null; - _other = getDocumentTypeService().selectResultTypes(); - Study study = _openStudy.getStudyObject(); - for (Iterator 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); + + initData(study); + _validor = new ArrayList(); _staff = null; List user = getUserService().selectAllUsers(); @@ -327,19 +331,23 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { } } - 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); + _readers = getStudyService().getReaders( + getOpenStudy().getIndex().longValue()); + } catch (InvalidParameterException e) { + LOG.error(e.getMessage(), e); } setActionType("edicycle"); return SUCCESS; } + /** + * Save modifications. + * + * @return SUCCESS + * @throws InvalidParameterException + * if can't modify readers list + */ public String doEdition() throws InvalidParameterException { Study study = getOpenStudy().getStudyObject(); @@ -350,217 +358,354 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { try { getStudyService().update(study, sprop.setTitle(_stitle)); } catch (InvalidPropertyException e) { - // TODO: LOG.error(e.getMessage(), e); } } else if (_tosave == Save.contributor) { + saveContributor(study); + + } else if (_tosave == Save.cycle) { + saveValidationCycle(study); - // Edition of contributors - if (_contributors == null) { - _contributors = ""; + } else if (_tosave == Save.readers) { + saveReaders(study); + } + + doInitialize(); // Re-initialization following the above edition + + return SUCCESS; + } + + /** + * Save the study readers list. + * + * @param study + * the selected study + * @throws InvalidParameterException + * if the study readers list modification is failed + */ + private void saveReaders(final Study study) + throws InvalidParameterException { + 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()); + } } - if (_candidates == null) { - _candidates = ""; + } + + // 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); + } + } } + } - String[] parsekept = _contributors.split(","); - String[] parsenew = _candidates.split(","); - List toremove = new ArrayList(getStudyService() - .getContributors(study)); + // Update OpenStudy + _openStudy.open(getConnectedUser(), getStudyService().selectStudy( + _openStudy.getIndex())); + } - for (int i = 0; i < parsekept.length; i++) { - if (parsekept[i].length() == 0) { - continue; // Yet no contributor - } + /** + * Save the study document validation cycle. + * + * @param study + * the selected study + */ + private void saveValidationCycle(final Study study) { + // 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); + } + + /** + * Save the study contributors list. + * + * @param study + * the selected study + */ + private void saveContributor(final Study study) { + // Edition of contributors + if (_contributors == null) { + _contributors = ""; + } + if (_candidates == null) { + _candidates = ""; + } + + 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) { int index = Integer.valueOf(parsekept[i].trim()); for (Iterator j = toremove.iterator(); j.hasNext();) { long present = j.next().getIndex(); - if (present != index) { - continue; + if (present == index) { + j.remove(); + break; } - j.remove(); - break; } } - int size = toremove.size(); - if (size > 0) { - getStudyService().removeContributor(study, - toremove.toArray(new User[size])); - } + } + 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 - } + for (int i = 0; i < parsenew.length; i++) { + if (parsenew[i].length() != 0) { 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); - } 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())); } - - doInitialize(); // Re-initialization following the above edition - - initializationFullScreenContext(Constants.STUDY_MENU, - Constants.STUDY_MENU, Constants.TRUE, Constants.BACK, - Constants.OPEN); - - return SUCCESS; } - // ============================================================================================================================== - // Getters - // ============================================================================================================================== - + /** + * Get the study author. + * + * @return the study author + */ public User getAuthor() { return _openStudy.getStudyObject().getAuthor(); } + /** + * Get list of available candidates. + * + * @return list of candidates + */ public List getCandidates() { return _staff; } + /** + * Get the document type name of the modified validation cycle. + * + * @return the type name of the modified cycle + */ public String getCycle() { return _edicycle; } + /** + * Get study contributors list. + * + * @return list of contributors + */ public List getContributors() { return _member; } + /** + * Get default validation cycle presentation. + * + * @return default validation cycle presentation + */ public ValidationFacade getDefaultValidation() { return _validefault; } + /** + * Get selected document type id. + * + * @return the selected document type id + */ public long getDocumentTypeIndex() { return _type; } + /** + * Get list of document types which have no specific validation cycles for this study. + * + * @return list of document types + */ public List getOtherDocumentTypes() { return _other; } + /** + * Get study title. + * + * @return the study title + */ public String getStudyTitle() { return _openStudy.getTitle(); } + /** + * Get the list of specific study validation cycles presentations. + * + * @return list of validation cycles facades + */ public List getValidations() { return _validation; } + /** + * Get the list of validators. + * + * @return list of user names + */ public List getValidationActors() { return _validor; } - // ============================================================================================================================== - // Setters - // ============================================================================================================================== - + /** + * Set the list of candidates ids. + * + * @param indices + * the list of users ids + */ public void setCandidates(final String indices) { _candidates = indices; } + /** + * Set the document type name for the modified validation cycle. + * + * @param type + * the document type name + */ public void setCycle(final String type) { _edicycle = type; } + /** + * Set the list of contributors ids. + * + * @param indices + * the list of users ids + */ public void setMembers(final String indices) { _contributors = indices; } + /** + * Set the id of the selected document type. + * + * @param index + * document type id + */ public void setDocumentType(final String index) { - _type = Integer.valueOf(index); + _type = Long.valueOf(index); } + /** + * Set the selected approver id. + * + * @param index + * the user id + */ public void setApprover(final String index) { - _approver = Integer.valueOf(index); + _approver = Long.valueOf(index); } + /** + * Set the selected publisher id. + * + * @param index + * the user id + */ public void setPublisher(final String index) { - _publisher = Integer.valueOf(index); + _publisher = Long.valueOf(index); } + /** + * Set the selected reviewer id. + * + * @param index + * the user id + */ public void setReviewer(final String index) { - _reviewer = Integer.valueOf(index); + _reviewer = Long.valueOf(index); } + /** + * Set the study title. + * + * @param title + * the study title + */ public void setTitle(final String title) { _stitle = title; } + /** + * Set the current operation to title saving. + * + * @param save + * unused parameter + */ public void setSaveTitle(final String save) { _tosave = Save.title; } + /** + * Set the current operation to contributors saving. + * + * @param save + * unused parameter + */ public void setSaveContributors(final String save) { _tosave = Save.contributor; } + /** + * Set the current operation to validation cycle saving. + * + * @param save + * unused parameter + */ public void setSaveCycle(final String save) { _tosave = Save.cycle; } /** - * Set tosave to readers. - * @param save the save + * Set the current operation to readers saving. + * + * @param save + * unused parameter */ public void setSaveReaders(final String save) { _tosave = Save.readers; } - + /** * Get the documentTypeService. * @@ -602,6 +747,7 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Get the readers. + * * @return the readers */ public List getReaders() { @@ -610,23 +756,28 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Set the readers. - * @param readers the readers to set + * + * @param readers + * the readers to set */ public void setReaders(final List readers) { _readers = readers; } /** - * Get the readerIds. - * @return the readerIds + * Get the list of readers ids. + * + * @return the list of users ids */ public List getReaderIds() { return _readerIds; } /** - * Set the readerIds. - * @param readerIds the readerIds to set + * Set the list of readers ids. + * + * @param readerIds + * the list of users ids to set */ public void setReaderIds(final List readerIds) { this._readerIds = readerIds; -- 2.39.2