use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class UserBookmarkController method addBookmarkToGroup.
@RequestMapping(value = "/addBookmarkToUser/")
@ResponseBody
public String addBookmarkToGroup(@RequestParam("username") final String username, @RequestParam("path") final String path) {
logger.info("addBookmarkToGroup()");
String zoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(username, zoneName);
if (user == null) {
return REQUEST_ERROR;
}
Set<String> toAdd = new HashSet<String>();
toAdd.add(path);
return userBookmarkService.updateBookmarks(user, toAdd, null) ? REQUEST_OK : REQUEST_ERROR;
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class SyncJobs method executeUsersSync.
private void executeUsersSync() {
try {
// Gets all users existing in iRODS
List<User> irodsUsers = this.findAllIRODSUsers();
HashMap<Long, User> hashMapIRodsUsers = new HashMap<Long, User>();
for (User user : irodsUsers) {
if (user.getUserType() != UserTypeEnum.RODS_GROUP) {
hashMapIRodsUsers.put(Long.valueOf(user.getId()), user);
}
}
// Gets all users existing in our database
List<DataGridUser> dbUsers = userDao.findAll(DataGridUser.class);
HashMap<Long, DataGridUser> hashMapDBUsers = new HashMap<Long, DataGridUser>();
for (DataGridUser dataGridUser : dbUsers) {
hashMapDBUsers.put(dataGridUser.getDataGridId(), dataGridUser);
}
Set<Long> irodsUserIDs = hashMapIRodsUsers.keySet();
Set<Long> dbDataGridUserIDs = hashMapDBUsers.keySet();
// action: remove this user from our database
for (Long id : dbDataGridUserIDs) {
if (!irodsUserIDs.contains(id)) {
String usernameDeleted = hashMapDBUsers.get(id).getUsername();
long userID = hashMapDBUsers.get(id).getId();
long dataGridID = hashMapDBUsers.get(id).getDataGridId();
userDao.deleteByDataGridId(id);
logger.info("[DELETE] User " + usernameDeleted + " (iRODS id: " + userID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
}
}
// action: add this user to our database
for (Long id : irodsUserIDs) {
if (!dbDataGridUserIDs.contains(id)) {
User irodsUserMissingInDB = hashMapIRodsUsers.get(id);
DataGridUser userMissingInDB = new DataGridUser();
userMissingInDB.setDataGridId(Long.valueOf(irodsUserMissingInDB.getId()));
userMissingInDB.setUsername(irodsUserMissingInDB.getName());
userMissingInDB.setAdditionalInfo(irodsUserMissingInDB.getZone());
userMissingInDB.setUserType(irodsUserMissingInDB.getUserType().getTextValue());
userMissingInDB.setEnabled(true);
userDao.save(userMissingInDB);
logger.info("[INSERT] User " + userMissingInDB.getUsername() + " (iRODS id: " + userMissingInDB.getDataGridId() + ") " + " was added to database.");
}
}
} catch (Exception e) {
logger.error("Could not synchronize database and iRODS (users): ", e);
}
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class GroupController method showAddGroupForm.
/**
* Responds the request for the url "add/". It adds a new GroupForm to the Model and sets the
* form's action to "add".
*
* @param model
* @return the userForm template
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "add/", method = RequestMethod.GET)
public String showAddGroupForm(Model model) throws DataGridConnectionRefusedException {
groupForm = new GroupForm();
model.addAttribute("groupForm", groupForm);
model.addAttribute("requestMapping", "/groups/add/action/");
// gets all users from iRODS to be attached to a group
List<DataGridUser> users = userService.findAll();
String[] membersList = new String[0];
usersToBeAdded = new ArrayList<String>(Arrays.asList(membersList));
model.addAttribute("addReadPermissionsOnDirs", addReadPermissionsOnDirs);
model.addAttribute("addWritePermissionsOnDirs", addWritePermissionsOnDirs);
model.addAttribute("addOwnerOnDirs", addOwnerOnDirs);
model.addAttribute("addInheritanceOnDirs", addInheritanceOnDirs);
model.addAttribute("users", users);
model.addAttribute("membersList", membersList);
model.addAttribute("resultSize", users.size());
model.addAttribute("foundUsers", users.size() > 0);
model.addAttribute("zones", zoneService.findAll());
model.addAttribute("groupZone", "");
return "groups/groupForm";
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class GroupController method addGroup.
/**
* Controller method that executes action 'create group'
*
* @param user
* @return the name of the template to render
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "add/action/", method = RequestMethod.POST)
public String addGroup(@ModelAttribute GroupForm groupForm, HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
DataGridGroup newGroup = new DataGridGroup();
newGroup.setGroupname(groupForm.getGroupname());
newGroup.setAdditionalInfo(groupForm.getAdditionalInfo());
// Get the list of users to be attached to the group
String[] idsList = usersToBeAdded.toArray(new String[usersToBeAdded.size()]);
List<DataGridUser> usersToBeAttached = new ArrayList<DataGridUser>();
if (idsList != null && idsList.length != 0) {
usersToBeAttached = userService.findByDataGridIds(idsList);
}
if (groupService.createGroup(newGroup, usersToBeAttached) == false) {
return "redirect:/groups/add/";
}
// Updating permissions on collections
// boolean recursive = false;
groupService.updateReadPermissions(newGroup, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
groupService.updateWritePermissions(newGroup, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
groupService.updateOwnership(newGroup, addOwnerOnDirs, removeOwnerOnDirs);
// Setting the Group's home collection as a bookmark by default
bookmarkController.addPathAsGroupBookmark(groupService.getGroupCollectionPath(newGroup.getGroupname()));
// Updating bookmarks
updateBookmarksList(newGroup.getGroupname());
redirectAttributes.addFlashAttribute("groupAddedSuccessfully", groupForm.getGroupname());
collectionService.updateInheritanceOptions(addInheritanceOnDirs, removeInheritanceOnDirs, newGroup.getAdditionalInfo());
cleanModificationSets();
currentGroup = null;
return "redirect:/groups/";
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class UserProfileServiceImpl method removeUserProfile.
@Override
public void removeUserProfile(UserProfile profile) {
profile = userProfileDao.findByID(UserProfile.class, profile.getProfileId());
for (DataGridUser user : profile.getUsers()) {
DataGridUser userToUpdate = userDao.findByID(DataGridUser.class, user.getId());
userToUpdate.setUserProfile(null);
userDao.merge(userToUpdate);
}
profile.getUsers().clear();
userProfileDao.delete(profile);
}
Aggregations