use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class UserController method addUser.
/**
* Controller method that executes action 'create user'
*
* @param user
* @return the name of the template to render
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "add/action/", method = RequestMethod.POST)
public String addUser(@ModelAttribute UserForm user, HttpServletRequest request, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
logger.info("addUser()");
if (user == null) {
throw new IllegalArgumentException("null user");
}
DataGridUser newUser = new DataGridUser();
newUser.setAdditionalInfo(user.getAdditionalInfo());
newUser.setUsername(user.getUsername());
newUser.setFirstName(user.getFirstName());
newUser.setLastName(user.getLastName());
newUser.setEmail(user.getEmail());
newUser.setUserType(user.getUserType());
newUser.setOrganizationalRole(user.getOrganizationalRole() != null ? user.getOrganizationalRole() : "");
newUser.setCompany(user.getCompany() != null ? user.getCompany() : "");
newUser.setDepartment(user.getDepartment() != null ? user.getDepartment() : "");
logger.info("adding user:{}", newUser);
String selectedProfile = request.getParameter("selectedProfile");
String[] groupList = groupsToBeAdded.toArray(new String[groupsToBeAdded.size()]);
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (groupList != null && groupList.length != 0) {
groups = groupService.findByDataGridIdList(groupList);
}
boolean groupsUpdateSuccessful = false;
boolean creationSucessful = false;
try {
logger.info("creating the user...");
creationSucessful = userService.createUser(newUser, user.getPassword());
logger.info("creation successful? {}", creationSucessful);
// Updating the group list for the recently-created user
if (creationSucessful) {
// adding read, write and ownership permissions to a set of collections
userService.updateReadPermissions(newUser, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
userService.updateWritePermissions(newUser, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
userService.updateOwnership(newUser, addOwnerOnDirs, removeOwnerOnDirs);
cleanPermissionsSets();
DataGridUser userForGroups = userService.findByUsernameAndAdditionalInfo(newUser.getUsername(), newUser.getAdditionalInfo());
groupsUpdateSuccessful = userService.updateGroupList(userForGroups, groups);
if (selectedProfile != null && selectedProfile != "") {
UserProfile userProfile = userProfileService.findById(Long.valueOf(selectedProfile));
userService.applyProfileToUser(userProfile, userForGroups);
userForGroups.setUserProfile(userProfile);
} else {
user.setUserProfile(null);
}
// User bookmarks
updateBookmarksList(newUser.getUsername(), newUser.getAdditionalInfo());
userService.modifyUser(userForGroups);
redirectAttributes.addFlashAttribute("userAddedSuccessfully", user.getUsername());
}
} catch (DuplicateDataException e) {
redirectAttributes.addFlashAttribute("duplicateUser", ExceptionEnum.USERS_DATA_DUPLICATE_EXCEPTION.getCode());
logger.error("Could not create user: ", e);
} catch (JargonException e) {
redirectAttributes.addFlashAttribute("error", ExceptionEnum.JARGON_EXCEPTION.getCode());
logger.error("Could not create user: ", e);
}
return creationSucessful && groupsUpdateSuccessful ? "redirect:/users/" : "redirect:/users/add/";
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class UserProfileController method createUserProfile.
@RequestMapping(value = "/create/action/")
public String createUserProfile(@ModelAttribute UserProfileForm userProfileForm, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
UserProfile newUserProfile = new UserProfile();
newUserProfile.setProfileName(userProfileForm.getProfileName());
newUserProfile.setDescription(userProfileForm.getDescription());
// Getting group list from UI
// String[] groupList = request.getParameterValues("groupIdsList");
String[] groupList = groupIdsList.toArray(new String[groupIdsList.size()]);
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (groupList != null && groupList.length != 0) {
groups = groupService.findByIdList(groupList);
}
Set<DataGridGroup> groupSet = new HashSet<DataGridGroup>(groups);
Long userProfileId = userProfileService.createUserProfile(newUserProfile);
newUserProfile = userProfileService.findById(userProfileId);
newUserProfile.setGroups(groupSet);
userProfileService.modifyUserProfile(newUserProfile);
if (newUserProfile != null) {
redirectAttributes.addFlashAttribute("userProfileAddedSuccessfully", newUserProfile.getProfileName());
}
return "redirect:/users/profile/";
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class UserProfileController method showModifyForm.
@RequestMapping(value = "/modify/{profileId}/")
public String showModifyForm(Model model, @PathVariable String profileId) {
UserProfile userProfile = userProfileService.findById(Long.valueOf(profileId));
List<DataGridGroup> groups = groupService.findAll();
UserProfileForm userProfileForm = new UserProfileForm();
if (userProfile != null) {
userProfileForm.setProfileId(String.valueOf(userProfile.getProfileId()));
userProfileForm.setProfileName(userProfile.getProfileName());
userProfileForm.setDescription(userProfile.getDescription());
int groupsQuantity = userProfile.getGroups().size(), i = 0;
String[] groupsOnProfileList = new String[groupsQuantity];
for (DataGridGroup group : userProfile.getGroups()) {
groupsOnProfileList[i++] = String.valueOf(group.getId());
}
model.addAttribute("groupsOnProfileList", groupsOnProfileList);
groupIdsList = new ArrayList<String>(Arrays.asList(groupsOnProfileList));
}
model.addAttribute("userProfileForm", userProfileForm);
model.addAttribute("groups", groups);
model.addAttribute("resultSize", groups.size());
model.addAttribute("foundGroups", groups.size() > 0);
model.addAttribute("requestMapping", "/users/profile/modify/action/");
return "userProfile/userProfileForm";
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class UserProfileController method modifyUserProfile.
@RequestMapping(value = "/modify/action/")
public String modifyUserProfile(@ModelAttribute UserProfileForm userProfileForm, HttpServletRequest request, RedirectAttributes redirectAttributes) {
// Getting group list from UI
// String[] groupList = request.getParameterValues("groupIdsList");
String[] groupList = groupIdsList.toArray(new String[groupIdsList.size()]);
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (groupList != null && groupList.length != 0) {
groups = groupService.findByIdList(groupList);
}
Set<DataGridGroup> groupSet = new HashSet<DataGridGroup>(groups);
// Updating the UserProfile entity
UserProfile userProfile = userProfileService.findById(Long.valueOf(userProfileForm.getProfileId()));
userProfile.setProfileName(userProfileForm.getProfileName());
userProfile.setDescription(userProfileForm.getDescription());
userProfile.setGroups(groupSet);
userProfileService.modifyUserProfile(userProfile);
if (userProfile != null) {
redirectAttributes.addFlashAttribute("userProfileModifiedSuccessfully", userProfile.getProfileName());
}
return "redirect:/users/profile/";
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class GroupController method updateBookmarksList.
/*
* ********************************************************************************************
* ******************************** PRIVATE ***************************************
* ********************************************************************************************
*/
/**
* Persists the changes on the bookmarks lists for the given group on the database
*
* @param groupName
*/
private void updateBookmarksList(String groupName) {
DataGridGroup group = groupService.findByGroupname(groupName).get(0);
Set<String> bookmarksToAdd = bookmarkController.getAddBookmark();
Set<String> bookmarksToRemove = bookmarkController.getRemoveBookmark();
groupBookmarkService.updateBookmarks(group, bookmarksToAdd, bookmarksToRemove);
bookmarkController.clearBookmarksLists();
}
Aggregations