Salome HOME
Readers functionality is implemented.
authormka <mka@opencascade.com>
Wed, 27 Mar 2013 13:58:31 +0000 (13:58 +0000)
committermka <mka@opencascade.com>
Wed, 27 Mar 2013 13:58:31 +0000 (13:58 +0000)
Workspace/Siman-Common/src/org/splat/dal/bo/som/ReaderRelation.java [new file with mode: 0644]
Workspace/Siman-Common/src/org/splat/dal/bo/som/Relations.hbm.xml
Workspace/Siman-Common/src/org/splat/service/StudyService.java
Workspace/Siman-Common/src/org/splat/service/StudyServiceImpl.java
Workspace/Siman-Common/src/test/splat/service/TestStudyService.java
Workspace/Siman/WebContent/study/editStudyProperties.jsp
Workspace/Siman/src/labels.properties
Workspace/Siman/src/labels_en.properties
Workspace/Siman/src/org/splat/simer/StudyPropertiesAction.java
Workspace/Siman/src/struts.xml

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 (file)
index 0000000..672e793
--- /dev/null
@@ -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;
+       }
+}
index e9d2b570024e23bdd69f8aeac71315d4d5db68a5..f327a53c8ca32772483897514a09dc87a462e84a 100644 (file)
 <!--         <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
   -->
index 3e644a7d4283482f38a1c25ee579aefc79a574e4..507a5f3ff5244896b3d05df764685c8ee339dba7 100644 (file)
@@ -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<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;
 }
index 40f106cc693b870862e5d6e894f6c03bc39c9534..29a27d4cb891da5898b86c1dc75839d19f51a888 100644 (file)
@@ -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<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));
@@ -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<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) {
@@ -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<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.
         * 
index 3776ef1840289f3b7fe3f2c014a091f94e9c5fc8..7cfb8aaf232a79e4c7e604deb64cfdf3b4c6fa84 100644 (file)
@@ -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<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()");
+       }
 }
index b127c234f061ee00eb21586e2d83ba4decc5e4ab..49cbda8e2889ebb1e0071327ac84e34bc1ca651d 100644 (file)
             </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" /> &nbsp;
+                        <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"/> &nbsp;
+                          <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>
index 5e296bf6e63928db52b6cdf107741afc33bdb3c0..7c2ef9d324bc2c6a64df6aee135002e7a60ffc42 100644 (file)
@@ -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
index c17c89d4918ae60269801c38f6cee45a84b1fc5a..b073d13cedcf221722968f602383f58b2fdc2089 100644 (file)
@@ -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
index 3462674ad4452886d2394cc41ab7148e147b704d..fc016f30f00acc12b7038c833d30681274923ca7 100644 (file)
@@ -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<UserDTO> _readers;
+
+       /**
+        * Study reader id list.
+        */
+       List<Long > _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<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() {
 
@@ -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<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
index 172ee38e3a6edf933e4260018b0b6ccbf5b95445..23c10e367f9d112d2060f44d11a4072ee3850682 100644 (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
                -->