Search in sources :

Example 6 with DataGridUserFavorite

use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.

the class FavoriteDaoImpl method removeByPath.

@Override
public boolean removeByPath(String path) {
    logger.debug("Removing favorite by path: {} ", path);
    boolean removalSuccessful = false;
    try {
        List<DataGridUserFavorite> favorites = findFavoritesByPath(path);
        Iterator<DataGridUserFavorite> it = favorites.iterator();
        while (it.hasNext()) {
            DataGridUserFavorite favorite = it.next();
            logger.debug("Removing favorite {} from database", favorite.getPath());
            delete(favorite);
        }
        removalSuccessful = true;
    } catch (Exception e) {
        logger.error("Could not remove favorite for path {} ", path);
    }
    return removalSuccessful;
}
Also used : DataGridUserFavorite(com.emc.metalnx.core.domain.entity.DataGridUserFavorite)

Example 7 with DataGridUserFavorite

use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.

the class FavoriteDaoImpl method removeByUserAndPath.

@Override
public boolean removeByUserAndPath(DataGridUser user, String path) {
    boolean operationResult = true;
    logger.info("Attempting to remove favorite on {} from user {}", path, user.getUsername());
    try {
        DataGridUserFavorite favorite = findByUserAndPath(user, path);
        delete(favorite);
        logger.info("Successfully removed favorite {} from user{}", path, user.getUsername());
    } catch (Exception e) {
        operationResult = false;
        logger.error("Could not remove favorite on {} from user {}: {}", path, user.getUsername(), e.getMessage());
    }
    return operationResult;
}
Also used : DataGridUserFavorite(com.emc.metalnx.core.domain.entity.DataGridUserFavorite)

Example 8 with DataGridUserFavorite

use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.

the class FavoriteDaoImpl method addByUserAndPath.

@Override
public Long addByUserAndPath(DataGridUser user, String path, boolean isCollection) {
    String parentPath = path.substring(0, path.lastIndexOf("/"));
    if (parentPath.isEmpty()) {
        parentPath = "/";
    }
    String fileName = path != null ? path.substring(path.lastIndexOf("/") + 1, path.length()) : "";
    DataGridUserFavorite favorite = new DataGridUserFavorite();
    favorite.setUser(user);
    favorite.setPath(path);
    favorite.setPathHash(path.hashCode());
    favorite.setName(fileName);
    favorite.setCreateTs(new Date());
    favorite.setIsCollection(isCollection);
    return save(favorite);
}
Also used : DataGridUserFavorite(com.emc.metalnx.core.domain.entity.DataGridUserFavorite) Date(java.util.Date)

Example 9 with DataGridUserFavorite

use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.

the class FavoriteDaoImpl method findByUserAndPath.

@Override
public DataGridUserFavorite findByUserAndPath(DataGridUser user, String path) {
    if (user == null || path == null || path.isEmpty())
        return null;
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserFavorite where user_id = :user_id and path = :path");
    q.setLong("user_id", user.getId());
    q.setString("path", path);
    return (DataGridUserFavorite) q.uniqueResult();
}
Also used : Query(org.hibernate.Query) DataGridUserFavorite(com.emc.metalnx.core.domain.entity.DataGridUserFavorite)

Aggregations

DataGridUserFavorite (com.emc.metalnx.core.domain.entity.DataGridUserFavorite)9 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)2 Query (org.hibernate.Query)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1