use of org.irods.jargon.core.exception.DuplicateDataException 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 org.irods.jargon.core.exception.DuplicateDataException in project metalnx-web by irods-contrib.
the class GroupServiceImpl method createGroup.
@Override
public boolean createGroup(DataGridGroup newGroup, List<DataGridUser> usersToBeAttached) throws DataGridConnectionRefusedException {
UserGroupAO groupAO = irodsServices.getGroupAO();
// Translating to iRODS model format
UserGroup irodsGroup = new UserGroup();
irodsGroup.setUserGroupName(newGroup.getGroupname());
irodsGroup.setZone(newGroup.getAdditionalInfo());
try {
irodsGroup.setUserGroupName(newGroup.getGroupname());
irodsGroup.setZone(newGroup.getAdditionalInfo());
// creating group in iRODS
groupAO.addUserGroup(irodsGroup);
// Recovering the recently created group to get the data grid id.
irodsGroup = groupAO.findByName(irodsGroup.getUserGroupName());
newGroup.setDataGridId(Long.parseLong(irodsGroup.getUserGroupId()));
// Persisting the new group into our database
groupDao.save(newGroup);
// attaching users to this group
updateMemberList(newGroup, usersToBeAttached);
return true;
} catch (DuplicateDataException e) {
logger.error("UserGroup " + newGroup.getGroupname() + " already exists: ", e);
} catch (JargonException e) {
logger.error("Could not execute createGroup() on UserGroupAO class: ", e);
}
return false;
}
Aggregations