use of com.emc.metalnx.core.domain.entity.DataGridUserBookmark in project metalnx-web by irods-contrib.
the class UserBookmarkController method bookmarksPaginated.
@RequestMapping(value = "/bookmarksPaginated")
@ResponseBody
public String bookmarksPaginated(final HttpServletRequest request) {
int draw = Integer.parseInt(request.getParameter("draw"));
int start = Integer.parseInt(request.getParameter("start"));
int length = Integer.parseInt(request.getParameter("length"));
String searchString = request.getParameter("search[value]");
int orderColumn = Integer.parseInt(request.getParameter("order[0][column]"));
String orderDir = request.getParameter("order[0][dir]");
boolean onlyCollections = Boolean.parseBoolean(request.getParameter("onlyCollections"));
String loggedUsername = irodsServices.getCurrentUser();
String loggedUserZoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(loggedUsername, loggedUserZoneName);
String[] orderBy = { "name", "path", "created_at", "is_collection" };
// checking if there is another column to order by
boolean has2ndColumnToOrderBy = request.getParameter("order[1][column]") != null;
List<DataGridUserBookmark> userBookmarks = null;
if (has2ndColumnToOrderBy) {
List<String> orderByList = new ArrayList<String>();
List<String> orderDirList = new ArrayList<String>();
int firstCol = Integer.parseInt(request.getParameter("order[0][column]"));
int secondCol = Integer.parseInt(request.getParameter("order[1][column]"));
orderByList.add(orderBy[firstCol]);
orderDirList.add(request.getParameter("order[0][dir]"));
orderByList.add(orderBy[secondCol]);
orderDirList.add(request.getParameter("order[1][dir]"));
userBookmarks = userBookmarkService.findBookmarksPaginated(user, start, length, searchString, orderByList, orderDirList, onlyCollections);
} else {
userBookmarks = userBookmarkService.findBookmarksPaginated(user, start, length, searchString, orderBy[orderColumn], orderDir, onlyCollections);
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
String jsonString = "";
if ("".equals(searchString)) {
totalUserBookmarks = user.getBookmarks().size();
totalUserBookmarksFiltered = user.getBookmarks().size();
} else {
totalUserBookmarksFiltered = userBookmarks.size();
}
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(totalUserBookmarks));
jsonResponse.put("recordsFiltered", String.valueOf(totalUserBookmarksFiltered));
jsonResponse.put("data", userBookmarks);
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (JsonProcessingException e) {
logger.error("Could not parse user bookmarks to json: {}", e.getMessage());
}
return jsonString;
}
use of com.emc.metalnx.core.domain.entity.DataGridUserBookmark in project metalnx-web by irods-contrib.
the class UserBookmarkDaoImpl method findByUserAndPath.
@Override
public DataGridUserBookmark findByUserAndPath(DataGridUser user, String path) {
Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark where user_id = :user_id and path = :path");
q.setLong("user_id", user.getId());
q.setString("path", path);
return (DataGridUserBookmark) q.uniqueResult();
}
use of com.emc.metalnx.core.domain.entity.DataGridUserBookmark in project metalnx-web by irods-contrib.
the class UserBookmarkDaoImpl method removeByUser.
@Override
public boolean removeByUser(DataGridUser user) {
boolean operationResult = true;
Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark where user_id = :user_id");
q.setLong("user_id", user.getId());
List<DataGridUserBookmark> bookmarks = q.list();
Iterator<DataGridUserBookmark> it = bookmarks.iterator();
try {
while (it.hasNext()) {
delete(it.next());
}
} catch (Exception e) {
operationResult = false;
}
return operationResult;
}
use of com.emc.metalnx.core.domain.entity.DataGridUserBookmark in project metalnx-web by irods-contrib.
the class PermissionsController method getPermissionDetails.
/**
* Gives permission details related to a collection or file that is passed as a
* parameter
*
* @param model
* @param path
* @return
* @throws DataGridConnectionRefusedException
* @throws JargonException
* @throws FileNotFoundException
*/
@RequestMapping(value = "/getPermissionDetails/", method = RequestMethod.POST)
public String getPermissionDetails(final Model model, @RequestParam("path") final String path) throws DataGridException {
logger.info("Getting permission info for {}", path);
DataGridCollectionAndDataObject obj = null;
List<DataGridFilePermission> permissions;
List<DataGridGroupPermission> groupPermissions;
List<DataGridUserPermission> userPermissions;
List<DataGridUserBookmark> userBookmarks;
Set<String> groupsWithBookmarks;
Set<String> usersWithBookmarks;
boolean userCanModify = false;
boolean isCollection = false;
try {
loggedUser = luu.getLoggedDataGridUser();
permissions = ps.getPathPermissionDetails(path);
groupPermissions = ps.getGroupsWithPermissions(permissions);
userPermissions = ps.getUsersWithPermissions(permissions);
userBookmarks = uBMS.findBookmarksOnPath(path);
userCanModify = loggedUser.isAdmin() || ps.canLoggedUserModifyPermissionOnPath(path);
groupsWithBookmarks = new HashSet<>();
usersWithBookmarks = new HashSet<>();
for (DataGridUserBookmark userBookmark : userBookmarks) {
usersWithBookmarks.add(userBookmark.getUser().getUsername());
}
obj = cs.findByName(path);
obj.setMostPermissiveAccessForCurrentUser(ps.resolveMostPermissiveAccessForUser(obj.getPath(), loggedUser.getUsername()));
} catch (Exception e) {
logger.error("Could not get permission details: {}", path, e);
throw new DataGridException("error getting permissions", e);
}
model.addAttribute("usersWithBookmarks", usersWithBookmarks);
model.addAttribute("groupsWithBookmark", groupsWithBookmarks);
model.addAttribute("groupPermissions", groupPermissions);
model.addAttribute("userPermissions", userPermissions);
model.addAttribute("userCanModify", userCanModify);
model.addAttribute("permissions", PERMISSIONS);
model.addAttribute("permissionsWithoutNone", PERMISSIONS_WITHOUT_NONE);
model.addAttribute("collectionAndDataObject", obj);
model.addAttribute("isCollection", isCollection);
model.addAttribute("permissionOnCurrentPath", cs.getPermissionsForPath(path));
model.addAttribute("permissionFlag", true);
logger.debug("------Permission Conroller - /getPermissionDetail/ ends------");
return "permissions/permissionDetails :: permissionDetails";
}
use of com.emc.metalnx.core.domain.entity.DataGridUserBookmark in project metalnx-web by irods-contrib.
the class UserBookmarkController method listBookmarks.
@RequestMapping(value = "/")
public String listBookmarks(final Model model) {
String loggedUsername = irodsServices.getCurrentUser();
String loggedUserZoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(loggedUsername, loggedUserZoneName);
List<DataGridUserBookmark> userBookmakrs = user.getBookmarksSorted();
logger.info("userBookmarks found....");
logger.info(userBookmakrs.toString());
model.addAttribute("userBookmarks", userBookmakrs);
model.addAttribute("foundUserBookmarks", !userBookmakrs.isEmpty());
return "bookmarks/userBookmarks";
}
Aggregations