use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.
the class FavoriteDaoImpl method removeByUser.
@Override
public boolean removeByUser(DataGridUser user) {
logger.debug("Removing favorite by user: {} ", user.getUsername());
boolean removalSuccessful = false;
try {
List<DataGridUserFavorite> favorites = findByUser(user);
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 user {} ", user.getUsername());
}
return removalSuccessful;
}
use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.
the class FavoriteDaoImpl method removeByParentPath.
@Override
public boolean removeByParentPath(String parentPath) {
logger.debug("Removing favorite by relative path: {} ", parentPath);
boolean removalSuccessful = false;
try {
Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserFavorite where path LIKE :path");
q.setString("path", parentPath + "%");
List<DataGridUserFavorite> favorites = q.list();
Iterator<DataGridUserFavorite> favoritesIterator = favorites.iterator();
while (favoritesIterator.hasNext()) {
DataGridUserFavorite currFavorite = favoritesIterator.next();
logger.debug("Removing relative favorite {} from database", currFavorite.getPath());
delete(currFavorite);
}
} catch (Exception e) {
logger.error("Could not relative paths on favorite for path {} ", parentPath);
}
return removalSuccessful;
}
use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.
the class FavoritesController method favoritesPaginated.
@RequestMapping(value = "/favoritesPaginated")
@ResponseBody
public String favoritesPaginated(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" };
List<DataGridUserFavorite> userFavorites = favoritesService.findFavoritesPaginated(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)) {
totalFavorites = user.getFavorites().size();
totalFavoritesFiltered = user.getFavorites().size();
} else {
totalFavoritesFiltered = userFavorites.size();
}
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(totalFavorites));
jsonResponse.put("recordsFiltered", String.valueOf(totalFavoritesFiltered));
jsonResponse.put("data", userFavorites);
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (Exception e) {
logger.error("Could not parse hashmap in favorites to json", e.getMessage());
}
return jsonString;
}
use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.
the class FavoritesController method listfavorites.
/**
* Responds to the list favorites request
*
* @param model
* @return the template with a list of favorite items
*/
@RequestMapping(value = "/")
public String listfavorites(final Model model) {
String loggedUsername = irodsServices.getCurrentUser();
String loggedUserZoneName = irodsServices.getCurrentUserZone();
DataGridUser user = userService.findByUsernameAndAdditionalInfo(loggedUsername, loggedUserZoneName);
List<DataGridUserFavorite> userFavorites = user.getFavoritesSorted();
model.addAttribute("userFavorites", userFavorites);
model.addAttribute("topnavHeader", headerService.getheader("favorite"));
return "favorites/favorites";
}
use of com.emc.metalnx.core.domain.entity.DataGridUserFavorite in project metalnx-web by irods-contrib.
the class FavoritesServiceImpl method findFavoritesForUserAsString.
/**
* Returns a list of strings with each of them representing a path marked as
* favorite
*
* @param user
* @return List of paths marked as favorites by the user.
*/
@Override
public List<String> findFavoritesForUserAsString(DataGridUser user) {
List<DataGridUserFavorite> favorites = favoriteDao.findByUser(user);
List<String> strings = new ArrayList<String>();
for (DataGridUserFavorite favorite : favorites) {
strings.add(favorite.getPath());
}
return strings;
}
Aggregations