public ModelAndView setupForm(@PathVariable Long studyId,
@PathVariable Long projectId,
ModelMap model) throws IOException {
try {
User user = securityManager.getUserByLoginName(SecurityContextHolder.getContext().getAuthentication().getName());
Study study = null;
if (studyId == AbstractStudy.UNSAVED_ID) {
study = dataObjectFactory.getStudy(user);
model.put("title", "New Study");
}
else {
study = requestManager.getStudyById(studyId);
model.put("title", "Study "+studyId);
}
Project project = requestManager.getProjectById(projectId);
model.addAttribute("project", project);
study.setProject(project);
if (Arrays.asList(user.getRoles()).contains("ROLE_TECH")) {
SecurityProfile sp = new SecurityProfile(user);
LimsUtils.inheritUsersAndGroups(study, project.getSecurityProfile());
study.setSecurityProfile(sp);
} else {
study.inheritPermissions(project);
}
if (!study.userCanWrite(user)) {
throw new SecurityException("Permission denied.");
}
model.put("formObj", study);
model.put("study", study);
model.put("owners", LimsSecurityUtils.getPotentialOwners(user, study, securityManager.listAllUsers()));