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