--- /dev/null
+/*****************************************************************************
+ * 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;
+ }
+}
<!-- <many-to-one cascade="all-delete-orphan" unique="true" name="refer" column="refer" access="field" not-null="true" />
-->
</union-subclass>
+
+<!-- Reader relation: Study to User
+ -->
+ <union-subclass name="org.splat.dal.bo.som.ReaderRelation" extends="org.splat.dal.bo.kernel.Relation" table="reader_rel">
+ <many-to-one name="refer" column="refer" access="field" not-null="true" />
+ </union-subclass>
<!-- ValidationCycle relation: Study to ValidationCycle
-->
package org.splat.service;
+import java.util.Date;
import java.util.List;
import org.splat.dal.bo.kernel.User;
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;
/**
*/
String compare(List<DocToCompareDTO> 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<UserDTO> 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;
}
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;
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;
*/
@Transactional
public boolean addContributor(final Study aStudy, final User user) {
- List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
- for (Iterator<User> i = contributor.iterator(); i.hasNext();) {
- User present = i.next();
- if (present.equals(user)) {
- return false;
+ List<User> contributors = getModifiableContributors(aStudy); // Initializes contributor
+
+ if(contributors.contains(user)) {
+ return false;
+ }
+
+ //Remove user from readers
+ try {
+ List<UserDTO> 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));
* @see #isPublic()
* @see Publication#approve(Date)
*/
+ @Transactional
public boolean moveToReference(final Study aStudy) {
if (aStudy.getProgressState() != ProgressState.APPROVED) {
return false;
*
* @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) {
*/
@Transactional
public boolean removeContributor(final Study aStudy, final User... users) {
- List<User> contributor = getModifiableContributors(aStudy); // Initializes contributor
+ List<User> contributors = getModifiableContributors(aStudy); // Initializes contributor
Boolean done = false;
- for (int i = 0; i < users.length; i++) {
- User user = users[i];
- for (Iterator<User> 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) {
*
* @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(
* 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);
* 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());
*
* @see org.splat.service.StudyService#markStudyAsReference(org.splat.dal.bo.som.Study)
*/
- @Override
@Transactional
public void markStudyAsReference(final Study aStudy) {
*
* @see org.splat.service.StudyService#removeStudyAsReference(org.splat.dal.bo.som.Study)
*/
- @Override
@Transactional
public void removeStudyAsReference(final Study aStudy) {
*
* @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 {
*
* @see org.splat.service.StudyService#removeStudyDescription(java.lang.Long)
*/
- @Override
@Transactional
public boolean removeDescription(final Long studyId)
throws InvalidParameterException {
} 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<UserDTO> getReaders(final long studyId) throws InvalidParameterException {
+ Study aStudy = selectStudy(studyId);
+ if(aStudy == null){
+ throw new InvalidParameterException("studyId", String.valueOf(studyId));
+ }
+ List<Relation> relations = aStudy.getRelations(ReaderRelation.class);
+ List<UserDTO> result = new ArrayList<UserDTO>();
+ 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.
*
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;
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;
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<Relation> 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<UserDTO> 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()");
+ }
}
</tr>
</s:else>
+ <!-- Readers functionality -->
+ <tr height=10><td width=20></td></tr>
+ <tr>
+ <td><img src="<s:url value="/skin/image.downarrow.png"/>" border="none"/></td>
+ <td><b><s:text name="label.readers"/></b></td>
+ </tr>
+ <tr height=5><td></td></tr>
+
+ <s:if test="actionType eq 'editReaders'">
+ <tr>
+ <td>
+ <s:a href="%{#undo}"><img src="<s:url value="/skin/icon.undo.png"/>" border="none" title="<s:text name="button.cancel"/>"/></s:a>
+ </td>
+
+ <td><s:text name="label.readers.present"/></td>
+ <td colspan=3><s:text name="label.readers.absents"/></td>
+ <td align=right>
+ <button type="submit" name="saveReaders" value=""
+ style="width:24px; height:16px; border:0; cursor:pointer; cursor:hand; background:transparent">
+ <img src="<s:url value="/skin/image.export.png"/>" title="<s:text name="button.save"/>"/>
+ </button>
+ </td>
+ </tr>
+ <tr height=1 bgcolor=#AAAAAA><td colspan=6></td></tr>
+
+
+ <tr>
+ <td></td>
+ <td>
+ <table border="0" cellpadding="0" cellspacing="0">
+ <s:iterator value="readers">
+ <tr>
+ <td>
+ <s:checkbox name="readerIds" fieldValue="%{index}" theme="simple" checked="checked" />
+ <s:property value="%{displayName}"/>
+ </td>
+ </tr>
+ </s:iterator>
+ </table>
+ </td>
+
+ <td colspan="3" valign="top">
+ <table border="0" cellpadding="0" cellspacing="0" width="100%">
+ <tr>
+ <s:iterator value="candidates" status="status">
+ <td>
+ <s:checkbox name="readerIds" fieldValue="%{index}" theme="simple"/>
+ <s:property value="%{displayName}"/>
+ </td>
+ <s:if test="%{(#status.index + 1) % 3 == 0}">
+ </tr>
+ <tr>
+ </s:if>
+ </s:iterator>
+ </tr>
+ </table>
+ </td>
+
+ </tr>
+ </s:if>
+ <s:else>
+ <tr>
+ <td>
+ <s:if test="#todo == 'display'"> <s:a namespace="/study" action="init-edit-readers" >
+ <img src="<s:url value="/skin/icon.ed.png"/>" border="none"
+ title="<s:text name="tooltip.edit.readers"/>"/>
+ </s:a> </s:if>
+ </td>
+ <td colspan="4">
+ <s:iterator value="readers" status="counter">
+ <s:if test="#counter.last"><s:property value="%{displayName}"/></s:if>
+ <s:else><s:property value="%{displayName}"/>,</s:else>
+ </s:iterator>
+ </td>
+ </tr>
+ </s:else>
+
+
<tr height=15><td width=20></td></tr>
<tr>
<td><img src="<s:url value="/skin/image.downarrow.png"/>" border="none"/></td>
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
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
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
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
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;
/**
* Injected user service.
*/
private UserService _userService;
+
+ /**
+ * Study readers list.
+ */
+ List<UserDTO> _readers;
+
+ /**
+ * Study reader id list.
+ */
+ List<Long > _readerIds;
/**
* Save operation type enumeration pointing which section of properties has been edited.
/**
* Save validation cycle.
*/
- cycle
+ cycle,
+ /**
+ * Save study readers.
+ */
+ readers
}
// ==============================================================================================================================
} else {
res = "display";
}
+
+ try {
+ _readers = getStudyService().getReaders(getOpenStudy().getIndex().longValue());
+ } catch(InvalidParameterException e) {
+ LOG.error(e.getMessage(), e);
+ }
return res;
}
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;
}
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<User> readers = new ArrayList<User>();
+ for(UserDTO userDTO : _readers) {
+ readers.add(BeanHelper.copyBean(userDTO, User.class));
+ }
+ _staff.removeAll(readers);
+
+ setActionType("editReaders");
+
+ return SUCCESS;
+ }
public String doEditCycle() {
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) {
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
_tosave = Save.cycle;
}
+ /**
+ * Set tosave to readers.
+ * @param save the save
+ */
+ public void setSaveReaders(final String save) {
+ _tosave = Save.readers;
+ }
+
/**
* Get the documentTypeService.
*
public void setUserService(final UserService userService) {
_userService = userService;
}
+
+ /**
+ * Get the readers.
+ * @return the readers
+ */
+ public List<UserDTO> getReaders() {
+ return _readers;
+ }
+
+ /**
+ * Set the readers.
+ * @param readers the readers to set
+ */
+ public void setReaders(final List<UserDTO> readers) {
+ _readers = readers;
+ }
+
+ /**
+ * Get the readerIds.
+ * @return the readerIds
+ */
+ public List<Long> getReaderIds() {
+ return _readerIds;
+ }
+
+ /**
+ * Set the readerIds.
+ * @param readerIds the readerIds to set
+ */
+ public void setReaderIds(final List<Long> readerIds) {
+ this._readerIds = readerIds;
+ }
}
\ No newline at end of file
page.editscenarioproperties
</result>
</action>
+ <action name="init-edit-readers" class="studyPropertiesAction"
+ method="initEditReaders">
+ <result name="success" type="tiles">
+ page.editstudyproperties
+ </result>
+ </action>
<!-- Edition of scenario
-->