From: mka Date: Wed, 27 Mar 2013 13:58:31 +0000 (+0000) Subject: Readers functionality is implemented. X-Git-Tag: Root_Delivery2_2013_04_22~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=452711f3c334e2c58386bd3af4c60643e9aaaeef;p=tools%2Fsiman.git Readers functionality is implemented. --- diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/ReaderRelation.java b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ReaderRelation.java new file mode 100644 index 0000000..672e793 --- /dev/null +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/ReaderRelation.java @@ -0,0 +1,69 @@ +/***************************************************************************** + * Company EURIWARE + * Application SIMAN + * File $Id$ + * Creation date Mar 18, 2013 + * @author $Author$ + * @version $Revision$ + *****************************************************************************/ + +package org.splat.dal.bo.som; + +import org.splat.dal.bo.kernel.Persistent; +import org.splat.dal.bo.kernel.Relation; +import org.splat.dal.bo.kernel.User; +import org.splat.dal.bo.som.Study; + +/** + * Class representing relation of of user to study. + */ +public class ReaderRelation extends Relation { + + /** + * User bounded by relation. + */ + private User refer; + +// ============================================================================================================================== +// Constructors +// ============================================================================================================================== + + /** + * Database fetch constructor. + */ + public ReaderRelation() { + super(); + } + + /** + * ReaderRelation subclasses constructor. + * @param from the study + * @param to the user + */ + public ReaderRelation(final Study from, final User to) { + super(from); + this.refer = to; + } + +// ============================================================================================================================== +// Public member functions +// ============================================================================================================================== + + /** + * {@inheritDoc} + * @see org.splat.dal.bo.kernel.Relation#getTo() + */ + @Override + public Persistent getTo() { + return refer; + } + + /** + * {@inheritDoc} + * @see org.splat.dal.bo.kernel.Relation#setTo(org.splat.dal.bo.kernel.Persistent) + */ + @Override + public void setTo(Persistent to) { + refer = (User)to; + } +} diff --git a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Relations.hbm.xml b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Relations.hbm.xml index e9d2b57..f327a53 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/bo/som/Relations.hbm.xml +++ b/Workspace/Siman-Common/src/org/splat/dal/bo/som/Relations.hbm.xml @@ -41,6 +41,12 @@ + + + + + diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyService.java b/Workspace/Siman-Common/src/org/splat/service/StudyService.java index 3e644a7..507a5f3 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyService.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyService.java @@ -9,6 +9,7 @@ package org.splat.service; +import java.util.Date; import java.util.List; import org.splat.dal.bo.kernel.User; @@ -27,6 +28,7 @@ import org.splat.kernel.MultiplyDefinedException; import org.splat.service.dto.DocToCompareDTO; import org.splat.service.dto.DocumentDTO; import org.splat.service.dto.StudyFacadeDTO; +import org.splat.service.dto.UserDTO; import org.splat.service.dto.StudyFacadeDTO.ScenarioDTO; /** @@ -350,4 +352,30 @@ public interface StudyService { */ String compare(List docsList, final String userName) throws IncompatibleDataException; + + /** + * Get readers of a given study. + * @param studyId the study id. + * @return list of user DTO corresponding to the study readers. + * @throws InvalidParameterException if no study with such id has been found in the database. + */ + List getReaders(final long studyId) throws InvalidParameterException; + + /** + * Add reader to a given study. + * @param studyId the study id. + * @param userId the user id. + * @return true if the user has been added as a reader + * @throws InvalidParameterException if no study or user with such id has been found in the database. + */ + boolean addReader(final long studyId, final long userId) throws InvalidParameterException; + + /** + * Remove reader from a given study. + * @param studyId the study id. + * @param userId the user id. + * @return true if the relation has been found and removed + * @throws InvalidParameterException if no study or user with such id has been found in the database. + */ + boolean removeReader(final long studyId, final long userId) throws InvalidParameterException; } diff --git a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java index 40f106c..29a27d4 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java @@ -51,6 +51,7 @@ import org.splat.dal.bo.som.IDBuilder; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.ProjectElement; import org.splat.dal.bo.som.Publication; +import org.splat.dal.bo.som.ReaderRelation; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.SimulationContext; import org.splat.dal.bo.som.Study; @@ -79,12 +80,14 @@ import org.splat.log.AppLogger; import org.splat.service.dto.DocToCompareDTO; import org.splat.service.dto.DocumentDTO; import org.splat.service.dto.StudyFacadeDTO; +import org.splat.service.dto.UserDTO; import org.splat.service.technical.IndexService; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.technical.ProjectSettingsServiceImpl; import org.splat.service.technical.RepositoryService; import org.splat.service.technical.ProjectSettingsService.Step; import org.splat.som.Revision; +import org.splat.util.BeanHelper; import org.springframework.transaction.annotation.Transactional; import com.lowagie.text.Document; @@ -335,13 +338,25 @@ public class StudyServiceImpl implements StudyService { */ @Transactional public boolean addContributor(final Study aStudy, final User user) { - List contributor = getModifiableContributors(aStudy); // Initializes contributor - for (Iterator i = contributor.iterator(); i.hasNext();) { - User present = i.next(); - if (present.equals(user)) { - return false; + List contributors = getModifiableContributors(aStudy); // Initializes contributor + + if(contributors.contains(user)) { + return false; + } + + //Remove user from readers + try { + List readers = getReaders(aStudy.getIndex()); + for(UserDTO reader : readers) { + if(reader.getIndex() == user.getIndex()) { + //user must be the actual user in the relationship object in the aStudy object for this to work + aStudy.removeRelation(ReaderRelation.class, user); + } } + } catch(InvalidParameterException e) { + LOG.error(e.getMessage(), e); } + boolean absent = getModifiableActors(aStudy).add(user); // User may already be a reviewer or an approver aStudy.addRelation(new ContributorRelation(aStudy, user)); @@ -362,6 +377,7 @@ public class StudyServiceImpl implements StudyService { * @see #isPublic() * @see Publication#approve(Date) */ + @Transactional public boolean moveToReference(final Study aStudy) { if (aStudy.getProgressState() != ProgressState.APPROVED) { return false; @@ -382,6 +398,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#update(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.Study.Properties) */ + @Transactional public boolean update(final Study aStudy, final Properties sprop) throws InvalidPropertyException { if (sprop.getTitle() != null) { @@ -415,20 +432,13 @@ public class StudyServiceImpl implements StudyService { */ @Transactional public boolean removeContributor(final Study aStudy, final User... users) { - List contributor = getModifiableContributors(aStudy); // Initializes contributor + List contributors = getModifiableContributors(aStudy); // Initializes contributor Boolean done = false; - for (int i = 0; i < users.length; i++) { - User user = users[i]; - for (Iterator j = contributor.iterator(); j.hasNext();) { - User present = j.next(); - if (!present.equals(user)) { - continue; - } - + for(User user : users) { + if(contributors.contains(user)) { aStudy.removeRelation(ContributorRelation.class, user); - j.remove(); // Updates the contributor shortcut + contributors.remove(user); done = true; - break; } } if (done) { @@ -442,6 +452,7 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#removeProjectContext(org.splat.dal.bo.som.Study, org.splat.dal.bo.som.SimulationContext) */ + @Transactional public boolean removeProjectContext(final Study aStudy, final SimulationContext context) { boolean done = getStepService().removeSimulationContext( @@ -500,6 +511,7 @@ public class StudyServiceImpl implements StudyService { * a study to demote * @return true if the demotion succeeded. */ + @Transactional public boolean demote(final Study aStudy) { if (aStudy.getProgressState() == ProgressState.inCHECK) { aStudy.setProgressState(ProgressState.inDRAFT); @@ -596,13 +608,12 @@ public class StudyServiceImpl implements StudyService { * the study to update * @return true if the study is updated successfully */ - @Transactional private boolean update(final Study aStudy) { boolean isOk = false; try { getStudyDAO().merge(aStudy); // Update of relational base setShortCuts(aStudy); // RKV: initialize transient actors set - // RKV: getIndex().update(aStudy); // Update of Lucene index + //RKV: getIndex().update(aStudy); // Update of Lucene index isOk = true; } catch (Exception e) { LOG.error("STD-000001", e, aStudy.getIndex(), e.getMessage()); @@ -1134,7 +1145,6 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#markStudyAsReference(org.splat.dal.bo.som.Study) */ - @Override @Transactional public void markStudyAsReference(final Study aStudy) { @@ -1149,7 +1159,6 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#removeStudyAsReference(org.splat.dal.bo.som.Study) */ - @Override @Transactional public void removeStudyAsReference(final Study aStudy) { @@ -1183,7 +1192,6 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#setDescription(java.lang.Long, java.lang.String) */ - @Override @Transactional public void setDescription(final Long studyId, final String descriptionText) throws InvalidParameterException { @@ -1203,7 +1211,6 @@ public class StudyServiceImpl implements StudyService { * * @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long) */ - @Override @Transactional public boolean removeDescription(final Long studyId) throws InvalidParameterException { @@ -1346,10 +1353,73 @@ public class StudyServiceImpl implements StudyService { } catch (DocumentException e) { LOG.error("Sorry, the DocumentException is thrown.", e); } - + return resultPath; } + + /** + * {@inheritDoc} + * @see org.splat.service.StudyService#getReaders(long) + */ + @Transactional(readOnly = true) + public List getReaders(final long studyId) throws InvalidParameterException { + Study aStudy = selectStudy(studyId); + if(aStudy == null){ + throw new InvalidParameterException("studyId", String.valueOf(studyId)); + } + List relations = aStudy.getRelations(ReaderRelation.class); + List result = new ArrayList(); + for(Relation relation : relations){ + result.add(BeanHelper.copyBean(relation.getTo(), UserDTO.class)); + } + return Collections.unmodifiableList(result); + } + + /** + * {@inheritDoc} + * @see org.splat.service.StudyService#addReader(long, long) + */ + @Transactional + public boolean addReader(final long studyId, final long userId) throws InvalidParameterException { + Study aStudy = selectStudy(studyId); + if(aStudy == null){ + throw new InvalidParameterException("studyId", String.valueOf(studyId)); + } + User user = _userService.selectUser(userId); + if(user == null){ + throw new InvalidParameterException("userId", String.valueOf(userId)); + } + for(Relation relation : aStudy.getRelations(ReaderRelation.class)) { + if(user.equals(relation.getTo())) { + return false; + } + } + aStudy.addRelation(new ReaderRelation(aStudy, user)); + update(aStudy); + return true; + } + + /** + * {@inheritDoc} + * @see org.splat.service.StudyService#removeReader(long, long) + */ + @Transactional + public boolean removeReader(final long studyId, final long userId) throws InvalidParameterException { + Study aStudy = selectStudy(studyId); + if(aStudy == null){ + throw new InvalidParameterException("studyId", String.valueOf(studyId)); + } + User user = _userService.selectUser(userId); + if(user == null){ + throw new InvalidParameterException("userId", String.valueOf(userId)); + } + + Relation relation = aStudy.removeRelation(ReaderRelation.class, user); + update(aStudy); + return relation != null; + } + /** * Get project settings. * diff --git a/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java b/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java index 3776ef1..7cfb8aa 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestStudyService.java @@ -18,6 +18,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.splat.dal.bo.som.ReaderRelation; +import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.ContributorRelation; import org.splat.dal.bo.som.DescriptionAttribute; @@ -55,9 +57,11 @@ import org.splat.service.SimulationContextService; import org.splat.service.StepService; import org.splat.service.StudyService; import org.splat.service.dto.FileDTO; +import org.splat.service.dto.UserDTO; import org.splat.service.technical.ProjectSettingsService; import org.splat.service.technical.RepositoryService; import org.splat.service.technical.ProjectSettingsService.Step; +import org.splat.util.BeanHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.orm.hibernate3.HibernateTemplate; @@ -1014,4 +1018,144 @@ public class TestStudyService extends BaseTest { fw.close(); return new FileDTO(filePath); } + + @Test + public void testReaders() throws InvalidPropertyException, BusinessException { + LOG.debug(">>>>> BEGIN testReaders()"); + startNestedTransaction(); + + HibernateTemplate ht = getHibernateTemplate(); + + User user = TestEntitiesGenerator.getTestUser("GoodUser"); + _userDAO.create(user); + Study study = TestEntitiesGenerator.getTestStudy(user); + _studyDAO.create(study); + _studyDAO.flush(); + ht.clear(); + long studyId = study.getIndex(); + long userId = user.getIndex(); + + //get a non-existing user id + User nonExistingUser = TestEntitiesGenerator.getTestUser("nonExistingUser"); + _userDAO.create(nonExistingUser); + long nonExistingUserId = nonExistingUser.getIndex(); + _userDAO.delete(nonExistingUser); + _userDAO.flush(); + ht.clear(); + + //get a non-existing study id + Study nonExistingStudy = TestEntitiesGenerator.getTestStudy(user); + _studyDAO.create(nonExistingStudy); + long nonExistingStudyId = nonExistingStudy.getIndex(); + _studyDAO.delete(nonExistingStudy); + _userDAO.flush(); + ht.clear(); + + + // ============================================================================================================================== + // 1.Non-existing user and study ids + // ============================================================================================================================== + + //Test getReaders method with a non-existing study id + try { + _studyService.getReaders(nonExistingStudyId); + Assert.fail("retrieval of readers with non-existing study id " + + "must throw InvalidParameterException"); + } catch(InvalidParameterException e) { + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + //Test removeReader method with a non-existing study id + try { + _studyService.removeReader(nonExistingStudyId, userId); + Assert.fail("attempt to remove from readers with non-existing study id " + + "must throw InvalidParameterException"); + } catch(InvalidParameterException e) { + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + //Test removeReader method with an non-existing user id + try { + _studyService.removeReader(studyId, nonExistingUserId); + Assert.fail("attempt to remove from readers with non-existing user id " + + "must throw InvalidParameterException"); + } catch(InvalidParameterException e) { + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + //Test addReader method with a non-existing study id + try { + _studyService.addReader(nonExistingStudyId, userId); + Assert.fail("attempt to add a user to readers of a study with non-existing study id " + + "must throw InvalidParameterException"); + } catch(InvalidParameterException e) { + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + //Test addReader method with a non-existing user id + try { + _studyService.addReader(studyId, nonExistingUserId); + Assert.fail("attempt to add to readers a user with non-existing id " + + "must throw InvalidParameterException"); + } catch(InvalidParameterException e) { + LOG.debug("Expected exception is thrown: " + + e.getClass().getSimpleName() + ": " + e.getMessage()); + } + + // ============================================================================================================================== + // 2.Existing user who is not yet reader + // ============================================================================================================================== + + //Test getReaders method with no readers + Assert.assertTrue(_studyService.getReaders(studyId).isEmpty(), + "returned list for a study without readers must be empty"); + + //Test removeReader method with an existing user who is not reader + Assert.assertFalse(_studyService.removeReader(studyId, userId), + "attempt to remove from readers of a non-reader user must return false"); + + //ADD A READER: + //Test addReader method with an existing user who is not yet reader + Assert.assertTrue(_studyService.addReader(studyId, userId), + "addition of a user who is not yet reader must return true"); + + _studyDAO.flush(); + ht.clear(); + study = _studyDAO.get(studyId); + + List readerRelations = study.getRelations(ReaderRelation.class); + Assert.assertTrue(readerRelations.size() == 1, "The retrieved relations list has wrong size"); + Assert.assertEquals(readerRelations.get(0).getFrom(), study, + "the retrieved relation does not equal the one that has been added."); + Assert.assertEquals(readerRelations.get(0).getTo(), user, + "the retrieved relation does not equal the one that has been added."); + + + // ============================================================================================================================== + // 3.Existing reader + // ============================================================================================================================== + + //Test getReaders method with an existing reader + List readers = _studyService.getReaders(studyId); + Assert.assertTrue(readers.size() == 1, "The retrieved reader list has wrong size"); + Assert.assertEquals(readers.get(0), BeanHelper.copyBean(user, UserDTO.class), + "the retrieved user does not equal the one that has been added."); + + //Test addReader method with a user who is already reader + Assert.assertFalse(_studyService.addReader(studyId, userId), + "addition of a user who is already reader must return false"); + + //Test removeReader method with a user user who is already reader + Assert.assertTrue(_studyService.removeReader(studyId, userId), + "removal from readers of a user who is study reader must return true"); + Assert.assertTrue(study.getRelations(ReaderRelation.class).isEmpty(), + "a relation has not been properly removed"); + + rollbackNestedTransaction(); + LOG.debug(">>>>> END testReaders()"); + } } diff --git a/Workspace/Siman/WebContent/study/editStudyProperties.jsp b/Workspace/Siman/WebContent/study/editStudyProperties.jsp index b127c23..49cbda8 100644 --- a/Workspace/Siman/WebContent/study/editStudyProperties.jsp +++ b/Workspace/Siman/WebContent/study/editStudyProperties.jsp @@ -177,6 +177,84 @@ + + + + " border="none"/> + + + + + + + + " border="none" title=""/> + + + + + + + + + + + + + + + + + + + + +
+   + +
+ + + + + + + + + + + + + +
+   + +
+ + + +
+ + + + + " border="none" + title=""/> + + + + + + , + + + + + + " border="none"/> diff --git a/Workspace/Siman/src/labels.properties b/Workspace/Siman/src/labels.properties index 5e296bf..7c2ef9d 100644 --- a/Workspace/Siman/src/labels.properties +++ b/Workspace/Siman/src/labels.properties @@ -151,6 +151,9 @@ label.APPROVAL = Approuv label.skipped = Ne s'applique pas label.bytheauthor = Auteur du document label.me = Moi +label.readers = Reader(s) of the study +label.readers.present = Current reader(s) +label.readers.absents = Other possible readers field.username = Nom utilisateur @@ -247,6 +250,7 @@ tooltip.edit.study = Modifier cette tooltip.edit.document = Modifier ce document... tooltip.edit.context = Modifier ce contexte de simulation... tooltip.edit.members = Inscrire les contributeurs +tooltip.edit.readers = Register readers tooltip.version = Versionner ce document tooltip.refresh = Actualiser tooltip.close = Fermer diff --git a/Workspace/Siman/src/labels_en.properties b/Workspace/Siman/src/labels_en.properties index c17c89d..b073d13 100644 --- a/Workspace/Siman/src/labels_en.properties +++ b/Workspace/Siman/src/labels_en.properties @@ -152,6 +152,9 @@ label.APPROVAL = Approved by label.skipped = Not Applicable label.bytheauthor = Author of document label.me = Me +label.readers = Reader(s) of the study +label.readers.present = Current reader(s) +label.readers.absents = Other possible readers field.username = Username @@ -248,6 +251,7 @@ tooltip.edit.study = Edit this study... tooltip.edit.document = Edit this document... tooltip.edit.context = Edit this simulation context tooltip.edit.members = Register contributors +tooltip.edit.readers = Register readers tooltip.version = Version this document tooltip.refresh = Refresh tooltip.close = Close diff --git a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java index 3462674..fc016f3 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java @@ -9,12 +9,15 @@ 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.service.DocumentTypeService; import org.splat.service.UserService; +import org.splat.service.dto.UserDTO; import org.splat.som.ApplicationRights; import org.splat.som.StudyRights; +import org.splat.util.BeanHelper; import org.splat.wapp.Constants; /** @@ -70,6 +73,16 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { * Injected user service. */ private UserService _userService; + + /** + * Study readers list. + */ + List _readers; + + /** + * Study reader id list. + */ + List _readerIds; /** * Save operation type enumeration pointing which section of properties has been edited. @@ -86,7 +99,11 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { /** * Save validation cycle. */ - cycle + cycle, + /** + * Save study readers. + */ + readers } // ============================================================================================================================== @@ -137,6 +154,12 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { } else { res = "display"; } + + try { + _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue()); + } catch(InvalidParameterException e) { + LOG.error(e.getMessage(), e); + } return res; } @@ -171,8 +194,13 @@ 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); + } setActionType("edititle"); - return SUCCESS; } @@ -217,9 +245,43 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { 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(); + + _staff = getUserService().selectAllUsers(); + + //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() { @@ -269,12 +331,16 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { 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() { + public String doEdition() throws InvalidParameterException { Study study = getOpenStudy().getStudyObject(); if (_tosave == Save.title) { @@ -349,6 +415,41 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { 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 @@ -452,6 +553,14 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { _tosave = Save.cycle; } + /** + * Set tosave to readers. + * @param save the save + */ + public void setSaveReaders(final String save) { + _tosave = Save.readers; + } + /** * Get the documentTypeService. * @@ -490,4 +599,36 @@ public class StudyPropertiesAction extends DisplayStudyStepAction { public void setUserService(final UserService userService) { _userService = userService; } + + /** + * Get the readers. + * @return the readers + */ + public List getReaders() { + return _readers; + } + + /** + * Set the readers. + * @param readers the readers to set + */ + public void setReaders(final List readers) { + _readers = readers; + } + + /** + * Get the readerIds. + * @return the readerIds + */ + public List getReaderIds() { + return _readerIds; + } + + /** + * Set the readerIds. + * @param readerIds the readerIds to set + */ + public void setReaderIds(final List readerIds) { + this._readerIds = readerIds; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/struts.xml b/Workspace/Siman/src/struts.xml index 172ee38..23c10e3 100644 --- a/Workspace/Siman/src/struts.xml +++ b/Workspace/Siman/src/struts.xml @@ -424,6 +424,12 @@ page.editscenarioproperties + + + page.editstudyproperties + +