use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class GroupBookmarkServiceImpl method getGroupsBookmarksPaginated.
@Override
public List<DataGridGroupBookmark> getGroupsBookmarksPaginated(String user, String additionalInfo, int offset, int limit, String searchString, String orderBy, String orderDir, boolean onlyCollections) throws DataGridConnectionRefusedException, DataNotFoundException, JargonException {
List<DataGridGroupBookmark> groupBookmarks = new ArrayList<DataGridGroupBookmark>();
if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) {
logger.error("Could not get groups bookmarks. Username or zone empty");
return groupBookmarks;
}
logger.info("Get groups bookmarks for {}", user);
UserAO userAO = adminServices.getUserAO();
User iRodsUser = userAO.findByName(user);
if (iRodsUser != null) {
String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo);
groupBookmarks = groupBookmarkDao.findGroupBookmarksByGroupsIds(groupIds, offset, limit, searchString, orderBy, orderDir, onlyCollections);
}
return groupBookmarks;
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class GroupBookmarkServiceImpl method getGroupsBookmarks.
@Override
public List<DataGridGroup> getGroupsBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, DataNotFoundException, JargonException {
List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) {
logger.error("Could not get groups bookmarks. Username or zone empty");
return groups;
}
logger.info("Get groups bookmarks for {}", user);
UserAO userAO = adminServices.getUserAO();
User iRodsUser = userAO.findByName(user);
if (iRodsUser != null) {
String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo);
groups = groupService.findByDataGridIdList(groupIds);
}
return groups;
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class GroupServiceImpl method updateMemberList.
@Override
public boolean updateMemberList(DataGridGroup group, List<DataGridUser> users) throws DataGridConnectionRefusedException {
try {
UserGroupAO groupAO = irodsServices.getGroupAO();
// Users that are currently on this group
List<User> usersFromIrods = groupAO.listUserGroupMembers(group.getGroupname());
// Building set with iRODS IDs already on this group
HashMap<Long, User> idsFromIrods = new HashMap<Long, User>();
for (User userFromIrods : usersFromIrods) {
idsFromIrods.put(Long.valueOf(userFromIrods.getId()), userFromIrods);
}
// Building set with iRODS IDs coming from UI
HashMap<Long, DataGridUser> idsFromUi = new HashMap<Long, DataGridUser>();
for (DataGridUser userFromUi : users) {
idsFromUi.put(userFromUi.getDataGridId(), userFromUi);
}
// Resolving differences from UI to iRODS
Set<Long> keysFromUi = idsFromUi.keySet();
Set<Long> keysFromIrods = idsFromIrods.keySet();
for (Long dataGridId : keysFromUi) {
if (!keysFromIrods.contains(dataGridId)) {
attachUserToGroup(idsFromUi.get(dataGridId), group);
}
}
for (Long dataGridId : keysFromIrods) {
if (!keysFromUi.contains(dataGridId)) {
DataGridUser user = new DataGridUser();
user.setUsername(idsFromIrods.get(dataGridId).getName());
removeUserFromGroup(user, group);
}
}
return true;
} catch (Exception e) {
logger.info("Could not update [" + group.getGroupname() + "]: ", e);
}
return false;
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class UserServiceImpl method createUser.
@Override
public boolean createUser(DataGridUser user, String password) throws JargonException, DataGridConnectionRefusedException {
logger.info("createUser()");
UserAO userAO = irodsServices.getUserAO();
// Translating to iRODS model format
User irodsUser = new User();
irodsUser.setName(user.getUsername());
irodsUser.setZone(user.getAdditionalInfo());
if (user.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
irodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
} else {
irodsUser.setUserType(UserTypeEnum.RODS_USER);
}
logger.debug("adding...");
// Creating user
irodsUser = userAO.addUser(irodsUser);
logger.debug("...added");
user.setDataGridId(Long.parseLong(irodsUser.getId()));
user.setEnabled(true);
userDao.save(user);
logger.info("setting password if provided (may be a PAM user!)");
if (password == null || password.isEmpty()) {
logger.info("no password, assume is not standard auth");
} else {
logger.info("password was provided, set in irods");
// Setting password
userAO.changeAUserPasswordByAnAdmin(user.getUsername(), password);
}
return true;
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class UserServiceImpl method modifyUser.
@Override
public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException {
UserAO userAO = irodsServices.getUserAO();
try {
User iRodsUser = userAO.findById(String.valueOf(modifyUser.getDataGridId()));
boolean iRodsFieldsModified = false;
// check which fields were modified (iRODS)
if (iRodsUser.getZone().compareTo(modifyUser.getAdditionalInfo()) != 0) {
iRodsUser.setZone(modifyUser.getAdditionalInfo());
iRodsFieldsModified = true;
}
if (!iRodsUser.getUserType().getTextValue().equals(modifyUser.getUserType())) {
if (modifyUser.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
iRodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
} else {
iRodsUser.setUserType(UserTypeEnum.RODS_USER);
}
iRodsFieldsModified = true;
}
// updating user in iRODS if any field was modified
if (iRodsFieldsModified) {
userAO.updateUser(iRodsUser);
}
DataGridUser applicationUser = userDao.findByUsernameAndZone(modifyUser.getUsername(), modifyUser.getAdditionalInfo());
// check which fields were modified (our database)
if (applicationUser.getAdditionalInfo() == null || applicationUser.getAdditionalInfo().compareTo(modifyUser.getAdditionalInfo()) != 0) {
applicationUser.setAdditionalInfo(modifyUser.getAdditionalInfo());
}
if (applicationUser.getFirstName() == null || applicationUser.getFirstName().compareTo(modifyUser.getFirstName()) != 0) {
applicationUser.setFirstName(modifyUser.getFirstName());
}
if (applicationUser.getLastName() == null || applicationUser.getLastName().compareTo(modifyUser.getLastName()) != 0) {
applicationUser.setLastName(modifyUser.getLastName());
}
if (applicationUser.getEmail() == null || applicationUser.getEmail().compareTo(modifyUser.getEmail()) != 0) {
applicationUser.setEmail(modifyUser.getEmail());
}
if (applicationUser.getCompany() == null || applicationUser.getCompany().compareTo(modifyUser.getCompany()) != 0) {
applicationUser.setCompany(modifyUser.getCompany());
}
if (applicationUser.getDepartment() == null || applicationUser.getDepartment().compareTo(modifyUser.getDepartment()) != 0) {
applicationUser.setDepartment(modifyUser.getDepartment());
}
applicationUser.setUserProfile(modifyUser.getUserProfile());
applicationUser.setLocale(modifyUser.getLocale());
applicationUser.setOrganizationalRole(modifyUser.getOrganizationalRole());
applicationUser.setUserType(modifyUser.getUserType());
applicationUser.setForceFileOverwriting(modifyUser.isForceFileOverwriting());
applicationUser.setAdvanceView(modifyUser.isAdvancedView());
userDao.merge(applicationUser);
// Changing password if a new password is set
String newPassword = modifyUser.getPassword();
if (newPassword != null && !newPassword.isEmpty()) {
userAO.changeAUserPasswordByAnAdmin(modifyUser.getUsername(), newPassword);
}
return true;
} catch (JargonException e) {
e.printStackTrace();
}
return false;
}
Aggregations