Salome HOME
Readers functionality is implemented.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / StudyPropertiesAction.java
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