use of com.emc.metalnx.core.domain.entity.DataGridUser 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.DataGridUser in project metalnx-web by irods-contrib.
the class UserController method usersToCSVFile.
@RequestMapping(value = "/usersToCSVFile/")
public void usersToCSVFile(HttpServletResponse response) {
String loggedUser = loggedUserUtils.getLoggedDataGridUser().getUsername();
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String filename = String.format("users_%s_%s.csv", loggedUser, date);
// Setting CSV Mime type
response.setContentType("text/csv");
response.setHeader("Content-disposition", "attachment;filename=" + filename);
List<DataGridUser> users = userService.findAll();
List<String> rows = new ArrayList<String>();
rows.add("Username;Zone;FirstName;LastName;Email;UserType;UserProfile;Title;Company;Department;OrganizationalRole\n");
for (DataGridUser user : users) {
rows.add(user.getUsername() + ";");
rows.add(user.getAdditionalInfo() + ";");
rows.add((user.getFirstName() == null ? "" : user.getFirstName()) + ";");
rows.add((user.getLastName() == null ? "" : user.getLastName()) + ";");
rows.add((user.getEmail() == null ? "" : user.getEmail()) + ";");
rows.add(user.getUserType() + ";");
rows.add((user.getUserProfile() == null ? "" : user.getUserProfile()) + ";");
rows.add((user.getTitle() == null ? "" : user.getTitle()) + ";");
rows.add((user.getCompany() == null ? "" : user.getCompany()) + ";");
rows.add((user.getDepartment() == null ? "" : user.getDepartment()) + ";");
rows.add(user.getOrganizationalRole() == null ? "" : user.getOrganizationalRole());
rows.add("\n");
}
try {
ServletOutputStream outputStream = response.getOutputStream();
// Writing CSV file
Iterator<String> fileIterator = rows.iterator();
while (fileIterator.hasNext()) {
outputStream.print(fileIterator.next());
}
outputStream.flush();
} catch (IOException e) {
logger.error("Could not generate CSV file for users", e);
}
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class UserController method findUserByQueryy.
/**
* Queries the user DB to match users with the given query string. Returns JSON
* body.
*
* @param model
*/
@RequestMapping(value = "/query/{query}/")
@ResponseBody
public String findUserByQueryy(Model model, @PathVariable String query) {
ObjectMapper mapper = new ObjectMapper();
List<DataGridUser> users = userService.findByQueryString(query);
List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
for (DataGridUser user : users) {
Map<String, Object> userMap = new LinkedHashMap<String, Object>();
userMap.put("username", user.getUsername());
userMap.put("first_name", user.getFirstName());
userMap.put("last_name", user.getLastName());
userList.add(userMap);
}
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
resultMap.put("results", userList);
String resultJson = "";
try {
resultJson = mapper.writeValueAsString(resultMap);
} catch (JsonProcessingException e) {
logger.info("Could not parse Object to Json: ", e.getMessage());
}
return resultJson;
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class DataGridAuthenticationSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
logger.debug("Authentication successful!");
String username = (String) authentication.getPrincipal();
logger.debug("Applying user preferences to user [" + username + "]");
DataGridUser loggedUser = userService.findByUsernameAndAdditionalInfo(username, zoneName);
localeResolver.setLocale(request, response, StringUtils.parseLocaleString(loggedUser.getLocale()));
if (loggedUser.isAdmin()) {
response.sendRedirect("/emc-metalnx-web/dashboard/");
} else {
response.sendRedirect("/emc-metalnx-web/browse/home");
}
}
use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.
the class GroupController method showModifyGroupForm.
/**
* Controller that shows the modification of group view.
*
* @param username
* @param additionalInfo
* @param model
* @return
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "modify/{groupname}/{additionalInfo}/", method = RequestMethod.GET)
public String showModifyGroupForm(@PathVariable String groupname, @PathVariable String additionalInfo, Model model) throws DataGridConnectionRefusedException {
List<DataGridUser> users = userService.findAll();
currentGroup = groupService.findByGroupnameAndZone(groupname, additionalInfo);
String[] membersList;
if (currentGroup != null) {
membersList = groupService.getMemberList(currentGroup);
} else {
membersList = new String[0];
}
usersToBeAdded = new ArrayList<String>(Arrays.asList(membersList));
currentGroup = groupService.findByGroupnameAndZone(groupname, additionalInfo);
GroupForm groupForm = new GroupForm();
if (currentGroup != null) {
groupForm.setGroupname(groupname);
groupForm.setAdditionalInfo(currentGroup.getAdditionalInfo());
groupForm.setDataGridId(currentGroup.getDataGridId());
}
model.addAttribute("groupBookmarks", groupBookmarkService.findBookmarksForGroupAsString(currentGroup));
model.addAttribute("groupForm", groupForm);
model.addAttribute("requestMapping", "/groups/modify/action/");
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", additionalInfo);
return "groups/groupForm";
}
Aggregations