use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class UserServiceImpl method updateGroupList.
@Override
public boolean updateGroupList(DataGridUser user, List<DataGridGroup> groups) throws DataGridConnectionRefusedException {
UserGroupAO groupAO = irodsServices.getGroupAO();
try {
// List current groups for user
List<UserGroup> groupsFromIrods = groupAO.findUserGroupsForUser(user.getUsername());
// Building set with iRODS IDs already on this group
HashMap<Long, UserGroup> idsFromIrods = new HashMap<Long, UserGroup>();
for (UserGroup groupFromIrods : groupsFromIrods) {
idsFromIrods.put(Long.valueOf(groupFromIrods.getUserGroupId()), groupFromIrods);
}
// Building set with iRODS IDs coming from UI
HashMap<Long, DataGridGroup> idsFromUi = new HashMap<Long, DataGridGroup>();
for (DataGridGroup groupFromUi : groups) {
idsFromUi.put(groupFromUi.getDataGridId(), groupFromUi);
}
// Resolving differences from UI to iRODS
Set<Long> keysFromUi = idsFromUi.keySet();
Set<Long> keysFromIrods = idsFromIrods.keySet();
// Committing changes to iRODS
for (Long dataGridId : keysFromUi) {
if (!keysFromIrods.contains(dataGridId)) {
groupService.attachUserToGroup(user, idsFromUi.get(dataGridId));
}
}
for (Long dataGridId : keysFromIrods) {
if (!keysFromUi.contains(dataGridId)) {
DataGridGroup group = new DataGridGroup();
group.setGroupname(idsFromIrods.get(dataGridId).getUserGroupName());
if (group.getGroupname().compareTo("public") != 0) {
groupService.removeUserFromGroup(user, group);
}
}
}
return true;
} catch (Exception e) {
logger.info("Could not update [" + user.getUsername() + "] group list: ", e);
}
return false;
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class GroupDaoImpl method findByGroupname.
@Override
public List<DataGridGroup> findByGroupname(String groupname) {
List<DataGridGroup> dataGridGroups = null;
Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname = :groupname");
q.setString("groupname", groupname);
dataGridGroups = q.list();
return dataGridGroups;
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class GroupDaoImpl method findByGroupnameAndZone.
@Override
public DataGridGroup findByGroupnameAndZone(String groupname, String zone) {
Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname = :groupname and additional_info = :zone");
q.setString("groupname", groupname);
q.setParameter("zone", zone);
return (DataGridGroup) q.uniqueResult();
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class GroupDaoImpl method findByDataGridId.
@Override
public DataGridGroup findByDataGridId(long id) {
Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where data_grid_id=(:id)");
q.setParameter("id", id);
List<DataGridGroup> groups = q.list();
return groups.size() > 0 ? groups.get(0) : null;
}
use of com.emc.metalnx.core.domain.entity.DataGridGroup in project metalnx-web by irods-contrib.
the class UserController method modifyUser.
/**
* Updates the user on the current DB.
*
* @param userForm
* @return the users views template name
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "modify/action/", method = RequestMethod.POST)
public String modifyUser(@ModelAttribute UserForm userForm, HttpServletRequest request, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
String[] groupList = groupsToBeAdded.toArray(new String[groupsToBeAdded.size()]);
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (groupList != null && groupList.length != 0) {
groups = groupService.findByDataGridIdList(groupList);
}
DataGridUser user = userService.findByUsernameAndAdditionalInfo(userForm.getUsername(), userForm.getAdditionalInfo());
boolean modificationSucessful = false;
boolean updateGroupsSuccessful = false;
if (user != null) {
user.setAdditionalInfo(userForm.getAdditionalInfo());
user.setUsername(userForm.getUsername());
user.setPassword(userForm.getPassword());
user.setFirstName(userForm.getFirstName());
user.setLastName(userForm.getLastName());
user.setEmail(userForm.getEmail());
user.setOrganizationalRole(userForm.getOrganizationalRole() != null ? userForm.getOrganizationalRole() : "");
user.setUserType(userForm.getUserType());
user.setCompany(userForm.getCompany() != null ? userForm.getCompany() : "");
user.setDepartment(userForm.getDepartment() != null ? userForm.getDepartment() : "");
// User bookmarks
updateBookmarksList(user.getUsername(), user.getAdditionalInfo());
modificationSucessful = userService.modifyUser(user);
updateGroupsSuccessful = userService.updateGroupList(user, groups);
if (modificationSucessful && updateGroupsSuccessful) {
redirectAttributes.addFlashAttribute("userModifiedSuccessfully", userForm.getUsername());
// Updating permissions on collections
userService.updateOwnership(user, addOwnerOnDirs, removeOwnerOnDirs);
userService.updateWritePermissions(user, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
userService.updateReadPermissions(user, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
}
}
// Applying selected profile to the user
String selectedProfile = request.getParameter("selectedProfile");
if (selectedProfile != null && selectedProfile != "") {
UserProfile userProfile = userProfileService.findById(Long.valueOf(selectedProfile));
userService.applyProfileToUser(userProfile, user);
user.setUserProfile(userProfile);
} else {
user.setUserProfile(null);
}
userService.modifyUser(user);
cleanPermissionsSets();
return modificationSucessful && updateGroupsSuccessful ? "redirect:/users/" : "redirect:/users/modify/" + user.getUsername() + "/" + user.getAdditionalInfo() + "/";
}
Aggregations