Search in sources :

Example 6 with DataGridUserBookmark

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;
}
Also used : HashMap(java.util.HashMap) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) ArrayList(java.util.ArrayList) DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with DataGridUserBookmark

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();
}
Also used : DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) Query(org.hibernate.Query)

Example 8 with DataGridUserBookmark

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;
}
Also used : DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) Query(org.hibernate.Query)

Example 9 with DataGridUserBookmark

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";
}
Also used : DataGridGroupPermission(com.emc.metalnx.core.domain.entity.DataGridGroupPermission) DataGridUserPermission(com.emc.metalnx.core.domain.entity.DataGridUserPermission) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) DataGridFilePermission(com.emc.metalnx.core.domain.entity.DataGridFilePermission) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with DataGridUserBookmark

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";
}
Also used : DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)10 Query (org.hibernate.Query)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)2 ArrayList (java.util.ArrayList)2 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridFilePermission (com.emc.metalnx.core.domain.entity.DataGridFilePermission)1 DataGridGroupPermission (com.emc.metalnx.core.domain.entity.DataGridGroupPermission)1 DataGridUserPermission (com.emc.metalnx.core.domain.entity.DataGridUserPermission)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1