diff --git a/emc-metalnx-core/pom.xml b/emc-metalnx-core/pom.xml index d58a658..3b01aef 100755 --- a/emc-metalnx-core/pom.xml +++ b/emc-metalnx-core/pom.xml @@ -25,8 +25,6 @@ org.hibernate hibernate-core - org.hibernate @@ -37,8 +35,6 @@ org.hibernate hibernate-envers ${hibernate.version} - org.springframework @@ -90,7 +86,6 @@ dom4j - @@ -281,8 +276,6 @@ - - diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/GroupBookmarkDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/GroupBookmarkDao.java deleted file mode 100755 index 3ed1b1a..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/GroupBookmarkDao.java +++ /dev/null @@ -1,115 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.dao; - -import com.emc.metalnx.core.domain.dao.generic.GenericDao; -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import com.emc.metalnx.core.domain.entity.DataGridGroupBookmark; - -import java.util.List; - -public interface GroupBookmarkDao extends GenericDao { - - /** - * Add a bookmark to a group using the path and group entity - * - * @param group - * @param path - * @param isCollection - * @return a confirmation that the insertion has been successfully - */ - public Long addByGroupAndPath(DataGridGroup group, String path, boolean isCollection); - - /** - * Removes a bookmark based on the path and the group - * - * @param group - * @param path - * @return a confirmation that the deletion has been successfully - */ - public boolean removeByGroupAndPath(DataGridGroup group, String path); - - /** - * Removes a bookmark based on the group - * - * @param group - * @return a confirmation that the deletion has been successfully - */ - public boolean removeByGroup(DataGridGroup group); - - /** - * Retrieve a given GroupBookmark based on the group - * - * @param group - * @return a {@link DataGridGroupBookmark} - */ - public List findByGroup(DataGridGroup group); - - /** - * Retrieves all the bookmarks on a given path - * - * @param path - * @return list of {@link DataGridGroupBookmark} - */ - public List findBookmarksByPath(String path); - - /** - * Removes a bookmark based on the given path - * - * @param path - * path to remove any bookmark - * @return a confirmation that the deletion has been successful - */ - public boolean removeByPath(String path); - - /** - * Removes all existing bookmarks whose parent path is the given path. Basically, if the - * following bookmarks exist: - * a/b/c - * a/b/c/d - * x/y/z/a/b/c - * and the directory "a" gets deleted. Both "a/b/c" and "a/b/c/d" should be removed from - * bookmarks since they no longer exist. But "x/y/z/a/b/c" should be kept. - * - * @param parentPath - * path to remove any bookmark - * @return a confirmation that the deletion has been successful - */ - public boolean removeByParentPath(String parentPath); - - /** - * Find group bookmarks with limits and filter for pagination - * - * @param groupIds - * @param offset - * @param limit - * @param searchString - * @param orderBy - * @param orderDir - * @param onlyCollections - * @return - */ - public List findGroupBookmarksByGroupsIds(String[] groupIds, int offset, int limit, String searchString, String orderBy, - String orderDir, boolean onlyCollections); - - /** - * Gives the total number of group bookmarks for a list of groups - * - * @param groupIds - * @return - */ - public Long countGroupBookmarksByGroupsIds(String[] groupIds); - - /** - * Changes an existing bookmark to a new value. - * - * @param oldPath - * existing path that will be updated - * @param newPath - * new path - * @return True, if oldePath was successfully changed to newPath. False, otherwise. - */ - boolean updateBookmark(String oldPath, String newPath); -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/GroupDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/GroupDao.java deleted file mode 100755 index c5d0397..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/GroupDao.java +++ /dev/null @@ -1,77 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.dao; - -import com.emc.metalnx.core.domain.dao.generic.GenericDao; -import com.emc.metalnx.core.domain.entity.DataGridGroup; - -import java.util.List; - -public interface GroupDao extends GenericDao { - - /** - * Find a group by its name - * @param groupname - * @return List of groups - */ - List findByGroupname(String groupname); - - /** - * Find group by group and zone - * @param groupname - * @param zone - * @return - */ - DataGridGroup findByGroupnameAndZone(String groupname, String zone); - - /** - * Deletes a group by its group - * @param groupname - * @return - */ - boolean deleteByGroupname(String groupname); - - /** - * Deletes a group by its id - * @param id - * @return true if a group whose id matches with the id parameter - */ - boolean deleteByDataGridGroupId(long id); - - /** - * Finds groups that match the specified query - * @param query - * @return list of groups - */ - public List findByQueryString(String query); - - /** - * Finds all groups that match the input Data Grid IDs. - * @param ids - * @return list of groups - */ - public List findByDataGridIdList(String[] ids); - - /** - * Finds all groups that match the input Data Grid Group names. - * @param ids - * @return list of group names - */ - public List findByGroupNameList(String[] groupNames); - - /** - * Finds all groups that match the input Data Grid IDs. - * @param ids - * @return list of groups - */ - public List findByIdList(Long[] ids); - - /** - * Finds a group that matches the input Data Grid ID. - * @param id - * @return DataGridGroup - */ - public DataGridGroup findByDataGridId(long id); -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserProfileDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserProfileDao.java deleted file mode 100755 index 15658ea..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserProfileDao.java +++ /dev/null @@ -1,21 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.dao; - -import com.emc.metalnx.core.domain.dao.generic.GenericDao; -import com.emc.metalnx.core.domain.entity.UserProfile; - -import java.util.List; - -public interface UserProfileDao extends GenericDao { - - /** - * Returns the list of UserProfiles matching the input string. - * @param query - * @return - */ - List findByQueryString(String query); - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/GroupBookmarkDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/GroupBookmarkDaoImpl.java deleted file mode 100755 index 08d2158..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/GroupBookmarkDaoImpl.java +++ /dev/null @@ -1,239 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.dao.impl; - -import com.emc.metalnx.core.domain.dao.GroupBookmarkDao; -import com.emc.metalnx.core.domain.dao.GroupDao; -import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import com.emc.metalnx.core.domain.entity.DataGridGroupBookmark; -import org.hibernate.Query; -import org.hibernate.SessionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -@Repository -@SuppressWarnings("unchecked") -public class GroupBookmarkDaoImpl extends GenericDaoImpl implements GroupBookmarkDao { - - private static final Logger logger = LoggerFactory.getLogger(GroupBookmarkDaoImpl.class); - - @Autowired - private SessionFactory sessionFactory; - - @Autowired - GroupDao groupDao; - - @Override - public Long addByGroupAndPath(DataGridGroup group, String path, boolean isCollection) { - - String parentPath = path.substring(0, path.lastIndexOf("/")); - if (parentPath.isEmpty()) { - parentPath = "/"; - } - - DataGridGroupBookmark bookmark = new DataGridGroupBookmark(); - bookmark.setGroup(group); - bookmark.setPath(path); - bookmark.setIsCollection(isCollection); - bookmark.setCreateTs(new Date()); - bookmark.setIsNotified(false); - return save(bookmark); - } - - @Override - public boolean removeByGroupAndPath(DataGridGroup group, String path) { - - boolean madeModifications = false; - boolean operationResult = true; - - logger.info("Attempting to remove bookmark on {} from group {}", path, group.getGroupname()); - try { - Iterator it = group.getGroupBookmarks().iterator(); - while (it.hasNext()) { - DataGridGroupBookmark bk = it.next(); - if (bk.getPath().compareTo(path) == 0) { - madeModifications = true; - it.remove(); - } - } - - if (madeModifications) { - logger.debug("Attempting to merge group entity [{}]", group.getId()); - groupDao.merge(group); - logger.info("Successfully removed bookmark {} from group{}", path, group.getGroupname()); - } - } - catch (Exception e) { - operationResult = false; - logger.error("Could not remove bookmark on {} from group {}", path, group.getGroupname(), e); - } - - return operationResult; - } - - @Override - public List findByGroup(DataGridGroup group) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroupBookmark where group_id = :group_id"); - q.setLong("group_id", group.getId()); - return q.list(); - } - - @Override - public List findBookmarksByPath(String path) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroupBookmark where path = :path"); - q.setString("path", path); - return q.list(); - } - - @Override - public boolean removeByPath(String path) { - logger.debug("Removing bookmarks by path: {} ", path); - boolean removalSuccessful = false; - - try { - List bookmarks = findBookmarksByPath(path); - Iterator it = bookmarks.iterator(); - while (it.hasNext()) { - DataGridGroupBookmark bookmark = it.next(); - logger.debug("Removing bookmark {} from database", bookmark.getPath()); - delete(bookmark); - } - - removalSuccessful = true; - } - catch (Exception e) { - logger.error("Could not remove bookmark for path {} ", path); - } - - return removalSuccessful; - } - - @Override - public boolean removeByParentPath(String parentPath) { - logger.debug("Removing bookmarks by relative path: {} ", parentPath); - boolean removalSuccessful = false; - - try { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark where path LIKE :path"); - q.setString("path", parentPath + "%"); - - List bookmarks = q.list(); - - Iterator bookmarksIterator = bookmarks.iterator(); - while (bookmarksIterator.hasNext()) { - DataGridGroupBookmark currBookmark = bookmarksIterator.next(); - logger.debug("Removing relative bookmark {} from database", currBookmark.getPath()); - delete(currBookmark); - } - } - catch (Exception e) { - logger.error("Could not relative paths on bookmarks for path {} ", parentPath); - } - - return removalSuccessful; - } - - @Override - public boolean removeByGroup(DataGridGroup group) { - boolean operationResult = true; - - List bookmarks = findByGroup(group); - Iterator it = bookmarks.iterator(); - while (it.hasNext()) { - try { - delete(it.next()); - } - catch (Exception e) { - operationResult = false; - } - } - - return operationResult; - } - - @Override - public List findGroupBookmarksByGroupsIds(String[] groupIds, int offset, int limit, String searchString, String orderBy, - String orderDir, boolean onlyCollections) { - if (groupIds != null && groupIds.length > 0) { - Long[] groupIdsLong = convertStringsToLongs(groupIds); - String queryString = "select Dggb from DataGridGroupBookmark Dggb left join Dggb.group Dgg where Dgg.dataGridId in (:groupIds) and (Dggb.path LIKE :path or Dgg.groupname LIKE :groupname) "; - if (onlyCollections) { - queryString += "and Dggb.isCollection = true "; - } - queryString += "order by " + orderBy + " " + orderDir; - Query q = sessionFactory.getCurrentSession().createQuery(queryString); - q.setParameterList("groupIds", groupIdsLong); - q.setString("path", '%' + searchString + '%'); - q.setString("groupname", '%' + searchString + '%'); - q.setFirstResult(offset); - q.setMaxResults(limit); - - return q.list(); - } - - // If the input list is null, the method returns null - return new ArrayList(); - } - - @Override - public Long countGroupBookmarksByGroupsIds(String[] groupIds) { - if (groupIds != null && groupIds.length > 0) { - Long[] groupIdsLong = convertStringsToLongs(groupIds); - Query q = sessionFactory.getCurrentSession().createQuery( - "select count(*) from DataGridGroupBookmark Dggb left join Dggb.group Dgg where Dgg.dataGridId in (:groupIds)"); - q.setParameterList("groupIds", groupIdsLong); - - return (Long) q.uniqueResult(); - } - return (long) 0; - } - - @Override - public boolean updateBookmark(String oldPath, String newPath) { - logger.info("Updating bookmark for group"); - - if (oldPath == null || newPath == null) { - logger.info("Could not update bookmark for group. Null values provided"); - return false; - } - - if (oldPath.equals(newPath)) { - logger.info("Old bookmark is the same as the new one. No need for an update."); - return false; - } - - Query q = sessionFactory.getCurrentSession().createQuery("update DataGridGroupBookmark set path = :newPath where path = :oldPath"); - q.setString("newPath", newPath); - q.setString("oldPath", oldPath); - logger.info("update query for group: " + q); - return q.executeUpdate() > 0; - } - - /** - * Converts an array of strings into an array of longs. - * - * @param strArray - * array of strings to be converted - * @return array of longs - */ - private Long[] convertStringsToLongs(String[] strArray) { - Long[] intArray = new Long[strArray.length]; - - for (int i = 0; i < strArray.length; i++) { - intArray[i] = Long.valueOf(strArray[i]); - } - - return intArray; - } - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/GroupDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/GroupDaoImpl.java deleted file mode 100755 index d647008..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/GroupDaoImpl.java +++ /dev/null @@ -1,156 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.dao.impl; - -import com.emc.metalnx.core.domain.dao.GroupDao; -import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import org.hibernate.Query; -import org.hibernate.SessionFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("unchecked") -@Repository -public class GroupDaoImpl extends GenericDaoImpl implements GroupDao { - - @Autowired - private SessionFactory sessionFactory; - - @Override - public List findByGroupname(String groupname) { - - List dataGridGroups = null; - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname = :groupname"); - q.setString("groupname", groupname); - - dataGridGroups = q.list(); - - return dataGridGroups; - } - - @Override - public DataGridGroup findByGroupnameAndZone(String groupname, String zone) { - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname = :groupname and additional_info = :zone"); - q.setString("groupname", groupname); - q.setParameter("zone", zone); - - return (DataGridGroup) q.uniqueResult(); - } - - @Override - public boolean deleteByGroupname(String groupname) { - - boolean operationResult = true; - - try { - List dataGridGroups = findByGroupname(groupname); - - for (DataGridGroup dataGridGroup : dataGridGroups) { - delete(dataGridGroup); - } - } - catch (Exception e) { - operationResult = false; - } - - return operationResult; - } - - @Override - public List findByQueryString(String query) { - Query q = sessionFactory.getCurrentSession().createQuery( - "from DataGridGroup where groupname like :groupname or additional_info like :additional_info"); - - q.setParameter("groupname", "%" + query + "%"); - q.setParameter("additional_info", "%" + query + "%"); - - // Returning results - return q.list(); - } - - @Override - public List findByDataGridIdList(String[] ids) { - // Checking if the input ID list is empty - if (ids == null || ids.length == 0) { - return new ArrayList(); - } - - Long[] idsLong = convertStringsToLongs(ids); - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where data_grid_id in (:ids)"); - q.setParameterList("ids", idsLong); - - return q.list(); - - } - - @Override - public List findByGroupNameList(String[] groupNames) { - // Checking if the input ID list is empty - if (groupNames == null || groupNames.length == 0) { - return new ArrayList(); - } - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where groupname in (:groupNames)"); - q.setParameterList("groupNames", groupNames); - - return q.list(); - } - - @Override - public boolean deleteByDataGridGroupId(long id) { - DataGridGroup dataGridGroup = findByDataGridId(id); - - if (dataGridGroup != null) { - delete(dataGridGroup); - return true; - } - - return false; - } - - @Override - public DataGridGroup findByDataGridId(long id) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where data_grid_id=(:id)"); - q.setParameter("id", id); - - List groups = q.list(); - return groups.size() > 0 ? groups.get(0) : null; - } - - @Override - public List findByIdList(Long[] ids) { - if (ids == null || ids.length == 0) { - return new ArrayList(); - } - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridGroup where id in (:ids)"); - q.setParameterList("ids", ids); - - return q.list(); - } - - /** - * Converts an array of strings into an array of longs. - * - * @param strArray - * array of strings to be converted - * @return array of longs - */ - private Long[] convertStringsToLongs(String[] strArray) { - Long[] intArray = new Long[strArray.length]; - - for (int i = 0; i < strArray.length; i++) { - intArray[i] = Long.valueOf(strArray[i]); - } - - return intArray; - } - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java index abc2a96..e96855e 100755 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java +++ b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java @@ -1,121 +1,129 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.core.domain.dao.impl; -import com.emc.metalnx.core.domain.dao.UserDao; -import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; -import com.emc.metalnx.core.domain.entity.DataGridUser; +import java.util.ArrayList; +import java.util.List; + import org.hibernate.Query; import org.hibernate.SessionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; +import com.emc.metalnx.core.domain.dao.UserDao; +import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; +import com.emc.metalnx.core.domain.entity.DataGridUser; @SuppressWarnings("unchecked") @Repository @Transactional public class UserDaoImpl extends GenericDaoImpl implements UserDao { - @Autowired - private SessionFactory sessionFactory; - - @Override - public List findByUsername(String username) { - - List users = null; - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where username = :username"); - q.setString("username", username); - - users = q.list(); - - return users; - } - - @Override - public DataGridUser findByUsernameAndZone(String username, String zone) { - - List users = null; - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where username = :username and additional_info = :zone"); - q.setString("username", username); - q.setString("zone", zone); - - users = q.list(); - return users.size() > 0 ? users.get(0) : null; - } - - @Override - public boolean deleteByUsername(String username) { - List users = findByUsername(username); - for (DataGridUser user : users) { - delete(user); - } - return true; - } - - @Override - public List findByQueryString(String query) { - Query q = sessionFactory.getCurrentSession().createQuery( - "from DataGridUser where username like :username or additional_info like :additional_info " - + "or first_name like :first_name or last_name like :last_name " + "or email like :email order by username"); - - q.setParameter("username", "%" + query + "%"); - q.setParameter("additional_info", "%" + query + "%"); - q.setParameter("first_name", "%" + query + "%"); - q.setParameter("last_name", "%" + query + "%"); - q.setParameter("email", "%" + query + "%"); - - // Returning results - return q.list(); - } - - @Override - public List findByDataGridIdList(String[] ids) { - List result = new ArrayList(); - - if (ids != null) { - int i = 0; - Integer ids_int[] = new Integer[ids.length]; - - for (String id_str : ids) { - ids_int[i++] = Integer.parseInt(id_str); - } - - // Checking if the input ID list is empty - if (ids_int != null) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where data_grid_id in (:ids)"); - q.setParameterList("ids", ids_int); - result = q.list(); - } - } - - // If the input list is null, the method returns null - return result; - } - - @Override - public DataGridUser findByDataGridId(long id) { - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where data_grid_id=(:id)"); - q.setParameter("id", id); - - List users = q.list(); - - return users.size() > 0 ? users.get(0) : null; - } - - @Override - public boolean deleteByDataGridId(long id) { - DataGridUser user = findByDataGridId(id); - if (user != null) { - delete(user); - } - return false; - } + private static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class); + + @Autowired + private SessionFactory sessionFactory; + + @Override + public List findByUsername(String username) { + + List users = null; + Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where username = :username"); + q.setString("username", username); + + users = q.list(); + + return users; + } + + @Override + public DataGridUser findByUsernameAndZone(String username, String zone) { + + List users = null; + + Query q = sessionFactory.getCurrentSession() + .createQuery("from DataGridUser where username = :username and additional_info = :zone"); + q.setString("username", username); + q.setString("zone", zone); + + users = q.list(); + return users.size() > 0 ? users.get(0) : null; + } + + @Override + public boolean deleteByUsername(String username) { + List users = findByUsername(username); + for (DataGridUser user : users) { + delete(user); + } + return true; + } + + @Override + public List findByQueryString(String query) { + Query q = sessionFactory.getCurrentSession() + .createQuery("from DataGridUser where username like :username or additional_info like :additional_info " + + "or first_name like :first_name or last_name like :last_name " + + "or email like :email order by username"); + + q.setParameter("username", "%" + query + "%"); + q.setParameter("additional_info", "%" + query + "%"); + q.setParameter("first_name", "%" + query + "%"); + q.setParameter("last_name", "%" + query + "%"); + q.setParameter("email", "%" + query + "%"); + + // Returning results + return q.list(); + } + + @Override + public List findByDataGridIdList(String[] ids) { + logger.info("findByDataGridIdList()"); + List result = new ArrayList(); + + if (ids != null) { + int i = 0; + Integer ids_int[] = new Integer[ids.length]; + + for (String id_str : ids) { + ids_int[i++] = Integer.parseInt(id_str); + } + + // Checking if the input ID list is empty + if (ids_int != null) { + Query q = sessionFactory.getCurrentSession() + .createQuery("from DataGridUser where data_grid_id in (:ids)"); + q.setParameterList("ids", ids_int); + result = q.list(); + } + } + + // If the input list is null, the method returns null + return result; + } + + @Override + public DataGridUser findByDataGridId(long id) { + + Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where data_grid_id=(:id)"); + q.setParameter("id", id); + + List users = q.list(); + + return users.size() > 0 ? users.get(0) : null; + } + + @Override + public boolean deleteByDataGridId(long id) { + DataGridUser user = findByDataGridId(id); + if (user != null) { + delete(user); + } + return false; + } } diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserProfileDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserProfileDaoImpl.java deleted file mode 100755 index fc7b6ac..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserProfileDaoImpl.java +++ /dev/null @@ -1,41 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.dao.impl; - -import com.emc.metalnx.core.domain.dao.UserProfileDao; -import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; -import com.emc.metalnx.core.domain.entity.UserProfile; -import org.hibernate.Query; -import org.hibernate.SessionFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@SuppressWarnings("unchecked") -@Repository -@Transactional -public class UserProfileDaoImpl extends GenericDaoImpl - implements UserProfileDao { - - @Autowired - private SessionFactory sessionFactory; - - @Override - public List findByQueryString(String query) { - Query q = sessionFactory - .getCurrentSession() - .createQuery( - "from UserProfile where profile_name like :name or description like :description "); - - q.setParameter("name", "%" + query + "%"); - q.setParameter("description", "%" + query + "%"); - - // Returning results - return q.list(); - } - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridGroup.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridGroup.java deleted file mode 100755 index c39d517..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridGroup.java +++ /dev/null @@ -1,193 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.entity; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -import org.hibernate.envers.Audited; -import org.hibernate.envers.NotAudited; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -@Entity -//@Audited -@Table(name = "groups") -public class DataGridGroup implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @NotAudited - @Column(name = "id", unique = true, nullable = false) - private Long id; - - @Column(name = "data_grid_id", unique = true, nullable = false) - private long dataGridId; - - @Column(name = "groupname", unique = true, nullable = false, length = 60) - private String groupname; - - @Column(name = "additional_info", nullable = true, length = 60) - private String additional_info; - - @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST }) - @JoinTable(name = "user_profile_groups", joinColumns = { @JoinColumn(name = "group_id") }, inverseJoinColumns = { - @JoinColumn(name = "profile_id") }) - private Set userProfiles; - - @JsonIgnore - @OneToMany(mappedBy = "group", fetch = FetchType.EAGER, cascade = CascadeType.DETACH, orphanRemoval = true) - private Set groupBookmarks; - - public DataGridGroup() { - - } - - public DataGridGroup(String groupname, String additional_info) { - this.groupname = groupname; - this.additional_info = additional_info; - } - - public String getDisplayName() { - - return groupname; - } - - /** - * @return the id - */ - public long getId() { - return id; - } - - /** - * @return the dataGridId - */ - public long getDataGridId() { - return dataGridId; - } - - /** - * @param id - * the id to set - */ - public void setId(long id) { - this.id = id; - } - - /** - * @param dataGridId - * the dataGridId to set - */ - public void setDataGridId(long dataGridId) { - this.dataGridId = dataGridId; - } - - /** - * @return the groupName - */ - public String getGroupname() { - return groupname; - } - - /** - * @param the - * groupName to set - */ - public void setGroupname(String groupName) { - groupname = groupName; - } - - /** - * @return group's zone - */ - public String getAdditionalInfo() { - return additional_info; - } - - /** - * @param the - * zone to set - */ - public void setAdditionalInfo(String additional_info) { - this.additional_info = additional_info; - } - - /** - * @return the groupBookmarks - */ - public Set getGroupBookmarks() { - return groupBookmarks; - } - - /** - * @param groupBookmarks - * the groupBookmarks to set - */ - public void setGroupBookmarks(Set groupBookmarks) { - this.groupBookmarks = groupBookmarks; - } - - @Override - public int compareTo(DataGridGroup dgg) { - return groupname.compareTo(dgg.getGroupname()); - } - - @Override - public String toString() { - final int maxLen = 10; - StringBuilder builder = new StringBuilder(); - builder.append("DataGridGroup ["); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - builder.append("dataGridId=").append(dataGridId).append(", "); - if (groupname != null) { - builder.append("groupname=").append(groupname).append(", "); - } - if (additional_info != null) { - builder.append("additional_info=").append(additional_info).append(", "); - } - if (userProfiles != null) { - builder.append("userProfiles=").append(toString(userProfiles, maxLen)).append(", "); - } - if (groupBookmarks != null) { - builder.append("groupBookmarks=").append(toString(groupBookmarks, maxLen)); - } - builder.append("]"); - return builder.toString(); - } - - private String toString(Collection collection, int maxLen) { - StringBuilder builder = new StringBuilder(); - builder.append("["); - int i = 0; - for (Iterator iterator = collection.iterator(); iterator.hasNext() && i < maxLen; i++) { - if (i > 0) { - builder.append(", "); - } - builder.append(iterator.next()); - } - builder.append("]"); - return builder.toString(); - } -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridGroupBookmark.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridGroupBookmark.java deleted file mode 100755 index 25678f1..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridGroupBookmark.java +++ /dev/null @@ -1,209 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - -package com.emc.metalnx.core.domain.entity; - -import java.io.Serializable; -import java.text.SimpleDateFormat; -import java.util.Date; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -import org.hibernate.envers.Audited; -import org.hibernate.envers.NotAudited; - -import com.emc.metalnx.core.domain.utils.DataGridCoreUtils; - -@Entity -//@Audited -@Table(name = "group_bookmarks") -public class DataGridGroupBookmark implements Serializable, Comparable { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @NotAudited - @Column(name = "id", unique = true, nullable = false) - private Long id; - - @ManyToOne(fetch = FetchType.EAGER, optional = true) - @JoinColumn(name = "group_id", nullable = false, updatable = true) - private DataGridGroup group; - - @Column(name = "path", nullable = false, length = 512) - private String path; - - @Column(name = "is_notified", nullable = true) - private Boolean isNotified; - - @Column(name = "is_collection", nullable = true) - private Boolean isCollection; - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "created_at", nullable = false, length = 60, updatable = false) - private Date createTs; - - private static final long serialVersionUID = -229875209906357557L; - - /** - * @return the id - */ - public Long getId() { - return id; - } - - /** - * @return the group - */ - public DataGridGroup getGroup() { - return group; - } - - /** - * @return the path - */ - public String getPath() { - return path; - } - - /** - * @return the isNotified - */ - public Boolean getIsNotified() { - return isNotified; - } - - /** - * @return the createTs - */ - public Date getCreateTs() { - return createTs; - } - - /** - * @param id - * the id to set - */ - public void setId(Long id) { - this.id = id; - } - - /** - * @param group - * the group to set - */ - public void setGroup(DataGridGroup group) { - this.group = group; - } - - /** - * @param path - * the path to set - */ - public void setPath(String path) { - this.path = path; - } - - /** - * @param isNotified - * the isNotified to set - */ - public void setIsNotified(Boolean isNotified) { - this.isNotified = isNotified; - } - - /** - * @return the isCollection - */ - public Boolean getIsCollection() { - return isCollection; - } - - /** - * @param isCollection - * the isCollection to set - */ - public void setIsCollection(Boolean isCollection) { - this.isCollection = isCollection; - } - - /** - * @param createTs - * the createTs to set - */ - public void setCreateTs(Date createTs) { - this.createTs = createTs; - } - - /** - * Finds the file name based on its path - * - * @return file name - */ - public String getFileName() { - if (getPath() == null) { - return new String(); - } - - String fileName = getPath() != null ? getPath() : ""; - fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); - return fileName; - } - - /** - * Gets the icon to be displayed for a bookmarks based on its extension - * - * @return String containing the icon name to be displayed - */ - public String getDisplayIcon() { - return DataGridCoreUtils.getIconToDisplay(getPath()); - } - - /** - * Formats the date when a collection/data object was modified - * - * @return String in the format MM/DD/YYYY HH:MM - */ - public String getCreatedAtFormatted() { - return new SimpleDateFormat("MMM dd yyyy, HH:mm").format(createTs); - } - - @Override - public int compareTo(DataGridGroupBookmark dgub) { - return getFileName().compareTo(dgub.getFileName()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DataGridGroupBookmark ["); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - if (path != null) { - builder.append("path=").append(path).append(", "); - } - if (isNotified != null) { - builder.append("isNotified=").append(isNotified).append(", "); - } - if (isCollection != null) { - builder.append("isCollection=").append(isCollection).append(", "); - } - if (createTs != null) { - builder.append("createTs=").append(createTs); - } - builder.append("]"); - return builder.toString(); - } - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/UserProfile.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/UserProfile.java index 6a626f0..df2d641 100755 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/UserProfile.java +++ b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/UserProfile.java @@ -1,6 +1,5 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.core.domain.entity; @@ -8,19 +7,14 @@ import java.util.Iterator; import java.util.Set; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.Table; -import org.hibernate.envers.Audited; import org.hibernate.envers.NotAudited; @Entity @@ -40,11 +34,6 @@ public class UserProfile { @Column(name = "description", nullable = false, length = 512) private String description; - @ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST }) - @JoinTable(name = "user_profile_groups", joinColumns = { @JoinColumn(name = "profile_id") }, inverseJoinColumns = { - @JoinColumn(name = "group_id") }) - private Set groups; - @OneToMany(mappedBy = "userProfile", fetch = FetchType.EAGER) private Set users; @@ -57,10 +46,9 @@ public UserProfile(String profileName, String description) { this.description = description; } - public UserProfile(String profileName, String description, Set groups, Set users) { + public UserProfile(String profileName, String description, Set users) { this.profileName = profileName; this.description = description; - this.groups = groups; this.users = users; } @@ -72,8 +60,7 @@ public Long getProfileId() { } /** - * @param profileId - * the profileId to set + * @param profileId the profileId to set */ public void setProfileId(Long profileId) { this.profileId = profileId; @@ -87,8 +74,7 @@ public String getProfileName() { } /** - * @param profileName - * the profileName to set + * @param profileName the profileName to set */ public void setProfileName(String profileName) { this.profileName = profileName; @@ -102,28 +88,12 @@ public String getDescription() { } /** - * @param description - * the description to set + * @param description the description to set */ public void setDescription(String description) { this.description = description; } - /** - * @return the groups - */ - public Set getGroups() { - return groups; - } - - /** - * @param groups - * the groups to set - */ - public void setGroups(Set groups) { - this.groups = groups; - } - /** * @return the users */ @@ -132,8 +102,7 @@ public Set getUsers() { } /** - * @param users - * the users to set + * @param users the users to set */ public void setUsers(Set users) { this.users = users; @@ -153,9 +122,7 @@ public String toString() { if (description != null) { builder.append("description=").append(description).append(", "); } - if (groups != null) { - builder.append("groups=").append(toString(groups, maxLen)).append(", "); - } + if (users != null) { builder.append("users=").append(toString(users, maxLen)); } diff --git a/emc-metalnx-core/src/test/java/META-INF/MANIFEST.MF b/emc-metalnx-core/src/test/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/emc-metalnx-core/src/test/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/CollectionServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/CollectionServiceImpl.java index 1b70b0b..c5db4d5 100644 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/CollectionServiceImpl.java +++ b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/CollectionServiceImpl.java @@ -629,7 +629,7 @@ public Set listOwnershipForPathAndGroup(String path, String groupName) } @Override - public Set listInheritanceForPath(String path) throws DataGridConnectionRefusedException { + public Set listInheritanceForPath(String path) throws DataGridException { logger.info("listInheritanceForPath()"); @@ -651,8 +651,8 @@ public Set listInheritanceForPath(String path) throws DataGridConnection return collections; } catch (JargonException e) { logger.error("Could not get collections with inheritance option enabled: ", e); + throw new DataGridException("exception getting inheritance", e); } - return null; } @Override diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FileOperationServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FileOperationServiceImpl.java index f7906fc..df7c37b 100755 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FileOperationServiceImpl.java +++ b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FileOperationServiceImpl.java @@ -1,7 +1,5 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.services.irods; @@ -33,7 +31,6 @@ import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; import com.emc.metalnx.core.domain.exceptions.DataGridException; import com.emc.metalnx.services.interfaces.FileOperationService; -import com.emc.metalnx.services.interfaces.GroupBookmarkService; import com.emc.metalnx.services.interfaces.IRODSServices; import com.emc.metalnx.services.interfaces.MetadataService; import com.emc.metalnx.services.interfaces.RuleService; @@ -53,9 +50,6 @@ public class FileOperationServiceImpl implements FileOperationService { @Autowired private UserBookmarkService userBookmarkService; - @Autowired - private GroupBookmarkService groupBookmarkService; - @Autowired private FavoritesService favoritesService; @@ -144,9 +138,6 @@ public boolean deleteItem(String path, boolean force) throws DataGridConnectionR userBookmarkService.removeBookmarkBasedOnPath(path); userBookmarkService.removeBookmarkBasedOnRelativePath(path); - groupBookmarkService.removeBookmarkBasedOnPath(path); - groupBookmarkService.removeBookmarkBasedOnRelativePath(path); - favoritesService.removeFavoriteBasedOnPath(path); favoritesService.removeFavoriteBasedOnRelativePath(path); @@ -351,14 +342,12 @@ public void computeChecksum(String path, String filename) * Copies a buffered input stream from a file to a HTTP response for * downloading. * - * @param path - * path to the file in iRODS to be added to the HTTP response - * @param response - * HTTP response to let the user download the file + * @param path path to the file in iRODS to be added to the HTTP response + * @param response HTTP response to let the user download the file * @return True, if the file was successfully added to the HTTP response. False, * otherwise. - * @throws DataGridConnectionRefusedException - * is Metalnx cannot connect to the data grid + * @throws DataGridConnectionRefusedException is Metalnx cannot connect to the + * data grid */ private boolean copyFileIntoHttpResponse(String path, HttpServletResponse response) throws DataGridConnectionRefusedException { diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupBookmarkServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupBookmarkServiceImpl.java deleted file mode 100755 index 3dbdcc6..0000000 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupBookmarkServiceImpl.java +++ /dev/null @@ -1,194 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - - -package com.emc.metalnx.services.irods; - -import com.emc.metalnx.core.domain.dao.GroupBookmarkDao; -import com.emc.metalnx.core.domain.dao.GroupDao; -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import com.emc.metalnx.core.domain.entity.DataGridGroupBookmark; -import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; -import com.emc.metalnx.services.interfaces.*; -import org.irods.jargon.core.exception.DataNotFoundException; -import org.irods.jargon.core.exception.JargonException; -import org.irods.jargon.core.pub.UserAO; -import org.irods.jargon.core.pub.domain.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -@Service -@Transactional -public class GroupBookmarkServiceImpl implements GroupBookmarkService { - - @Autowired - GroupDao groupDao; - - @Autowired - GroupBookmarkDao groupBookmarkDao; - - @Autowired - IRODSServices irodsServices; - - @Autowired - AdminServices adminServices; - - @Autowired - UserService userService; - - @Autowired - GroupService groupService; - - @Autowired - CollectionService collectionService; - - private static final Logger logger = LoggerFactory.getLogger(GroupBookmarkServiceImpl.class); - - @Override - public List getGroupsBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, - DataNotFoundException, JargonException { - - List groups = new ArrayList(); - - if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) { - logger.error("Could not get groups bookmarks. Username or zone empty"); - return groups; - } - - logger.info("Get groups bookmarks for {}", user); - - UserAO userAO = adminServices.getUserAO(); - User iRodsUser = userAO.findByName(user); - - if (iRodsUser != null) { - String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo); - groups = groupService.findByDataGridIdList(groupIds); - } - - return groups; - } - - @Override - public boolean updateBookmarks(DataGridGroup group, Set toAdd, Set toRemove) { - - boolean operationResult = true; - - try { - if (toAdd != null) { - for (String path : toAdd) { - if (!findBookmarksForGroupAsString(group).contains(path)) { - groupBookmarkDao.addByGroupAndPath(group, path, collectionService.isCollection(path)); - } - } - } - - if (toRemove != null) { - for (String path : toRemove) { - groupBookmarkDao.removeByGroupAndPath(group, path); - } - } - } - catch (Exception e) { - operationResult = false; - logger.error("Could not modify group bookmark for {}", group.getGroupname(), e); - } - - return operationResult; - } - - @Override - public List findBookmarksForGroupAsString(DataGridGroup group) { - List bookmarks = groupBookmarkDao.findByGroup(group); - List strings = new ArrayList(); - - for (DataGridGroupBookmark bookmark : bookmarks) { - strings.add(bookmark.getPath()); - } - - Collections.sort(strings); - - return strings; - } - - @Override - public List getGroupsBookmarksPaginated(String user, String additionalInfo, int offset, int limit, String searchString, - String orderBy, String orderDir, boolean onlyCollections) throws DataGridConnectionRefusedException, DataNotFoundException, - JargonException { - - List groupBookmarks = new ArrayList(); - - if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) { - logger.error("Could not get groups bookmarks. Username or zone empty"); - return groupBookmarks; - } - - logger.info("Get groups bookmarks for {}", user); - - UserAO userAO = adminServices.getUserAO(); - User iRodsUser = userAO.findByName(user); - - if (iRodsUser != null) { - String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo); - groupBookmarks = groupBookmarkDao - .findGroupBookmarksByGroupsIds(groupIds, offset, limit, searchString, orderBy, orderDir, onlyCollections); - } - - return groupBookmarks; - } - - @Override - public Integer countTotalGroupBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, DataNotFoundException, - JargonException { - Integer totalGroupBookmarks = 0; - if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) { - logger.error("Could not get groups bookmarks. Username or zone empty"); - return 0; - } - - logger.info("Get groups bookmarks for {}", user); - - UserAO userAO = adminServices.getUserAO(); - User iRodsUser = userAO.findByName(user); - - if (iRodsUser != null) { - String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo); - totalGroupBookmarks = groupBookmarkDao.countGroupBookmarksByGroupsIds(groupIds).intValue(); - } - return totalGroupBookmarks; - } - - @Override - public List findBookmarksOnPath(String path) { - return groupBookmarkDao.findBookmarksByPath(path); - } - - @Override - public boolean removeBookmarkBasedOnPath(String path) { - return groupBookmarkDao.removeByPath(path); - } - - @Override - public boolean removeBookmarkBasedOnRelativePath(String path) { - return groupBookmarkDao.removeByParentPath(path); - } - - @Override - public boolean removeBookmarkBasedOnGroup(DataGridGroup group) { - return groupBookmarkDao.removeByGroup(group); - } - - @Override - public boolean updateBookmark(String oldPath, String newPath) { - return groupBookmarkDao.updateBookmark(oldPath, newPath); - } - -} diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupServiceImpl.java index 636e7aa..06608a4 100755 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupServiceImpl.java +++ b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/GroupServiceImpl.java @@ -1,18 +1,16 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.services.irods; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.irods.jargon.core.exception.DuplicateDataException; +import org.irods.jargon.core.exception.InvalidGroupException; +import org.irods.jargon.core.exception.InvalidUserException; import org.irods.jargon.core.exception.JargonException; import org.irods.jargon.core.pub.CollectionAO; import org.irods.jargon.core.pub.DataObjectAO; @@ -25,13 +23,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.emc.metalnx.core.domain.dao.GroupDao; -import com.emc.metalnx.core.domain.entity.DataGridGroup; import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; +import com.emc.metalnx.core.domain.exceptions.DataGridException; import com.emc.metalnx.services.interfaces.CollectionService; import com.emc.metalnx.services.interfaces.ConfigService; -import com.emc.metalnx.services.interfaces.GroupBookmarkService; import com.emc.metalnx.services.interfaces.GroupService; import com.emc.metalnx.services.interfaces.IRODSServices; import com.emc.metalnx.services.interfaces.UserBookmarkService; @@ -46,154 +41,206 @@ public class GroupServiceImpl implements GroupService { @Autowired UserBookmarkService userBookmarkService; - @Autowired - GroupBookmarkService groupBookmarkService; - @Autowired IRODSServices irodsServices; - @Autowired - GroupDao groupDao; - @Autowired private ConfigService configService; - private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); + private static final Logger logger = LoggerFactory.getLogger(GroupServiceImpl.class); @Override - public List findAll() { - List groups = groupDao.findAll(DataGridGroup.class); - Collections.sort(groups); - return groups; + public List findAll() throws DataGridException { + try { + UserGroupAO groupAO = irodsServices.getGroupAO(); + List groups = groupAO.findAll(); + return groups; + } catch (JargonException e) { + logger.error("error finding groups", e); + throw new DataGridException(e); + } } @Override - public List findByGroupname(String groupname) { - List groups = groupDao.findByGroupname(groupname); - Collections.sort(groups); - return groups; + public UserGroup findById(String groupId) throws DataGridException { + logger.info("findById()"); + if (groupId == null || groupId.isEmpty()) { + throw new IllegalArgumentException("null groupId"); + } + UserGroupAO userGroupAO = irodsServices.getGroupAO(); + try { + return userGroupAO.find(groupId); + } catch (JargonException e) { + logger.error("error finding group by id:{}", groupId, e); + throw new DataGridException("error finding group", e); + } } @Override - public DataGridGroup findByGroupnameAndZone(String groupname, String zone) { - return groupDao.findByGroupnameAndZone(groupname, zone); + public List findByGroupname(String groupname) throws DataGridException { + try { + UserGroupAO userGroupAO = irodsServices.getGroupAO(); + List groups = userGroupAO.findUserGroups(groupname); + return groups; + } catch (JargonException e) { + logger.error("error finding groups", e); + throw new DataGridException(e); + } } @Override - public boolean createGroup(DataGridGroup newGroup, List usersToBeAttached) - throws DataGridConnectionRefusedException { + public UserGroup findByGroupnameAndZone(String groupname, String zone) throws DataGridException { - UserGroupAO groupAO = irodsServices.getGroupAO(); + logger.info("findByGroupnameAndZone()"); + if (groupname == null || groupname.isEmpty()) { + throw new IllegalArgumentException("null or empty groupname"); + } - // Translating to iRODS model format - UserGroup irodsGroup = new UserGroup(); + if (zone == null) { + throw new IllegalArgumentException("null zone"); + } - irodsGroup.setUserGroupName(newGroup.getGroupname()); - irodsGroup.setZone(newGroup.getAdditionalInfo()); + logger.info("groupname:{}", groupname); + logger.info("zone:{}", zone); + + UserGroupAO userGroupAO = irodsServices.getGroupAO(); + StringBuilder sb = new StringBuilder(); + sb.append(groupname); + if (!zone.isEmpty()) { + if (!zone.equals(userGroupAO.getIRODSAccount().getZone())) { + sb.append('#'); + sb.append(zone); + } + } try { + UserGroup group = userGroupAO.findByName(sb.toString()); - irodsGroup.setUserGroupName(newGroup.getGroupname()); - irodsGroup.setZone(newGroup.getAdditionalInfo()); + return group; + } catch (JargonException e) { + logger.error("error finding groups", e); + throw new DataGridException(e); + } + } - // creating group in iRODS - groupAO.addUserGroup(irodsGroup); + @Override + public boolean createGroup(UserGroup newGroup, List usersToBeAttached) throws DataGridException { - // Recovering the recently created group to get the data grid id. - irodsGroup = groupAO.findByName(irodsGroup.getUserGroupName()); - newGroup.setDataGridId(Long.parseLong(irodsGroup.getUserGroupId())); + UserGroupAO groupAO = irodsServices.getGroupAO(); + + try { - // Persisting the new group into our database - groupDao.save(newGroup); + // creating group in iRODS + groupAO.addUserGroup(newGroup); // attaching users to this group updateMemberList(newGroup, usersToBeAttached); return true; } catch (DuplicateDataException e) { - logger.error("UserGroup " + newGroup.getGroupname() + " already exists: ", e); + logger.error("UserGroup " + newGroup.getUserGroupName() + " already exists: ", e); + return false; } catch (JargonException e) { logger.error("Could not execute createGroup() on UserGroupAO class: ", e); + throw new DataGridException("error creating group", e); } - return false; } @Override - public boolean deleteGroupByGroupname(String groupname) throws DataGridConnectionRefusedException { - boolean groupDeleted = false; - - UserGroupAO groupAO = irodsServices.getGroupAO(); - - try { + public void deleteGroup(UserGroup userGroup) throws DataGridException { - DataGridGroup group = groupDao.findByGroupnameAndZone(groupname, configService.getIrodsZone()); + logger.info("deleteGroup()"); - // remove group from the data grid - groupAO.removeUserGroup(groupname); + if (userGroup == null) { + throw new IllegalArgumentException("null userGroup"); + } - // Removing group bookmarks associated to this group - userBookmarkService - .removeBookmarkBasedOnPath(String.format("/%s/home/%s", configService.getIrodsZone(), groupname)); - groupBookmarkService.removeBookmarkBasedOnGroup(group); + logger.info("userGroup:{}", userGroup); - // remove user from the Mlx database - groupDeleted = groupDao.deleteByGroupname(groupname); + UserGroupAO groupAO = irodsServices.getGroupAO(); + try { + groupAO.removeUserGroup(userGroup); } catch (JargonException e) { - logger.error("Could not execute removeUserGroup(String groupname)/" - + "deleteByGroupname(groupname) on UserGroupAO/GroupDao class(es): ", e); - } catch (Exception e) { - logger.error("Could not execute delete group (dao)"); + logger.error("exception removing user group", e); + throw new DataGridException("error removing user group", e); } - return groupDeleted; } @Override - public boolean attachUserToGroup(DataGridUser user, DataGridGroup group) throws DataGridConnectionRefusedException { + public void attachUserToGroup(String userName, String userZone, UserGroup userGroup) throws DataGridException { + + logger.info("attachUserToGroup()"); + + if (userName == null || userName.isEmpty()) { + throw new IllegalArgumentException("null or empty userName"); + } + + if (userZone == null) { + throw new IllegalArgumentException("null userZone"); + } + + if (userGroup == null) { + throw new IllegalArgumentException("null userGroup"); + } + + logger.info("userName:{}", userName); + logger.info("userZone:{}", userZone); + logger.info("userGroup:{}", userGroup); UserGroupAO groupAO = irodsServices.getGroupAO(); + try { - groupAO.addUserToGroup(group.getGroupname(), user.getUsername(), group.getAdditionalInfo()); - return true; + groupAO.addUserToGroup(userGroup.getUserGroupName(), userName, userZone); // FIXME: needs support for user + // zone and group zone } catch (Exception e) { - logger.info("Could not attach user [" + user.getUsername() + "] to group [" + group.getGroupname() + "]: ", - e); + logger.error("unable to add user to group", e); + throw new DataGridException("unable to add user to group", e); } - return false; } @Override - public boolean removeUserFromGroup(DataGridUser user, DataGridGroup group) - throws DataGridConnectionRefusedException { + public void removeUserFromGroup(String userName, String userZone, UserGroup userGroup) throws DataGridException { - UserGroupAO groupAO = irodsServices.getGroupAO(); + UserGroupAO groupAO = irodsServices.getGroupAO(); // FIXME: user#zone and group#zone support try { - groupAO.removeUserFromGroup(group.getGroupname(), user.getUsername(), group.getAdditionalInfo()); - return true; + groupAO.removeUserFromGroup(userGroup.getUserGroupName(), userName, userZone); } catch (Exception e) { - logger.info( - "Could not remove user [" + user.getUsername() + "] from group [" + group.getGroupname() + "]: ", - e); + logger.info("Could not remove user [" + userName + "] from group [" + userGroup + "]: ", e); } - return false; } + // FIXME: why is this done this way? Why not just track new users added? + @Override - public boolean updateMemberList(DataGridGroup group, List users) - throws DataGridConnectionRefusedException { + public void updateMemberList(UserGroup group, List users) throws DataGridException { + + logger.info("updateMemberList()"); + + if (group == null) { + throw new IllegalArgumentException("null group"); + } + + if (users == null) { + throw new IllegalArgumentException("null users"); + } + + logger.info("group:{}", group); + logger.info("users:{}", users); try { UserGroupAO groupAO = irodsServices.getGroupAO(); - + // FIXME: incorporate user and group zone, include changes to userGroupAO // Users that are currently on this group - List usersFromIrods = groupAO.listUserGroupMembers(group.getGroupname()); + List usersFromIrods = groupAO.listUserGroupMembers(group.getUserGroupName()); // Building set with iRODS IDs already on this group - HashMap idsFromIrods = new HashMap(); + HashMap idsFromIrods = new HashMap<>(); for (User userFromIrods : usersFromIrods) { - idsFromIrods.put(Long.valueOf(userFromIrods.getId()), userFromIrods); + idsFromIrods.put(Long.decode(userFromIrods.getId()), userFromIrods); + logger.info("userFromIrods:{}", userFromIrods); } // Building set with iRODS IDs coming from UI @@ -203,85 +250,147 @@ public boolean updateMemberList(DataGridGroup group, List users) } // Resolving differences from UI to iRODS + // keysFromUi = irods user ids from iCAT Set keysFromUi = idsFromUi.keySet(); + // keysFromIrods = irods user ids from web page Set keysFromIrods = idsFromIrods.keySet(); - for (Long dataGridId : keysFromUi) { - if (!keysFromIrods.contains(dataGridId)) { - attachUserToGroup(idsFromUi.get(dataGridId), group); + // for each iRODS user in the group from web page + for (Long keyFromUi : keysFromUi) { + // if not in irods add it + if (!keysFromIrods.contains(keyFromUi)) { + logger.info("adding user:{}", keyFromUi); + attachUserToGroup(idsFromUi.get(keyFromUi), group); } } - for (Long dataGridId : keysFromIrods) { - if (!keysFromUi.contains(dataGridId)) { + for (Long keyFromIrods : keysFromIrods) { + // if the UI does not have the user from iRODS, remove it from iRODS + if (!keysFromUi.contains(keyFromIrods)) { DataGridUser user = new DataGridUser(); - user.setUsername(idsFromIrods.get(dataGridId).getName()); + user.setUsername(idsFromIrods.get(keyFromIrods).getName()); + user.setAdditionalInfo(idsFromIrods.get(keyFromIrods).getZone()); removeUserFromGroup(user, group); + logger.info("removing user:{}", user); } } - return true; } catch (Exception e) { - logger.info("Could not update [" + group.getGroupname() + "]: ", e); + logger.info("error updating user group membership", e); + throw new DataGridException("error adding group membership", e); } - return false; } - @Override - public List findByQueryString(String query) { - List groups = groupDao.findByQueryString(query); - Collections.sort(groups); - return groups; + /** + * Remove the given user from the group + * + * @param user {@link DataGridUser} to remove + * @param group {@link UserGroup} from which the user will be removed + */ + private void removeUserFromGroup(DataGridUser user, UserGroup group) throws DataGridException { + logger.info("removeUserFromGroup()"); + logger.info("user:{}", user); + logger.info("group:{}", group); + UserGroupAO groupAO = irodsServices.getGroupAO(); + try { + groupAO.removeUserFromGroup(group.getUserGroupName(), user.getUsername(), user.getAdditionalInfo()); + } catch (InvalidUserException e) { + logger.warn("invalid user, ignored", e); + } catch (InvalidGroupException e) { + logger.warn("invalid group, ignored", e); + } catch (JargonException e) { + logger.error("error adding user to group", e); + throw new DataGridException("error removing user from group", e); + } + } + + /** + * Attach the data grid user to the given UserGroup in iRODS + * + * @param dataGridUser {@link DataGridUser} to add to group + * @param group {@link UserGroup} to add user to + */ + private void attachUserToGroup(DataGridUser dataGridUser, UserGroup group) throws DataGridException { + logger.info("attachUserToGroup()"); + logger.info("dataGridUser:{}", dataGridUser); + logger.info("group:{}", group); + UserGroupAO groupAO = irodsServices.getGroupAO(); + try { + groupAO.addUserToGroup(group.getUserGroupName(), dataGridUser.getUsername(), + dataGridUser.getAdditionalInfo()); + } catch (JargonException e) { + logger.error("error adding user to group", e); + throw new DataGridException("error adding user to group", e); + } } @Override - public String[] getMemberList(DataGridGroup group) throws DataGridConnectionRefusedException { + public String[] getMemberList(String groupName, String groupZone) throws DataGridException { + + logger.info("getMemberList()"); + + if (groupName == null || groupName.isEmpty()) { + throw new IllegalArgumentException("null or empty groupName"); + } + + if (groupZone == null) { + throw new IllegalArgumentException("null groupZone"); + } + + logger.info("groupName:{}", groupName); + logger.info("groupZone:{}", groupZone); + UserGroupAO userGroupAO = irodsServices.getGroupAO(); + + String queryGroupName; + if (groupZone.isEmpty()) { + queryGroupName = groupName; + } else if (groupZone.equals(userGroupAO.getIRODSAccount().getZone())) { + queryGroupName = groupName; + } else { + StringBuilder sb = new StringBuilder(); + sb.append(groupName); + sb.append('#'); + sb.append(groupZone); + queryGroupName = sb.toString(); + } + + logger.info("queryGroupName:{}", queryGroupName); + try { - List groupMembers = userGroupAO.listUserGroupMembers(group.getGroupname()); + List groupMembers = userGroupAO.listUserGroupMembers(queryGroupName); String[] dataGridIds = new String[groupMembers.size()]; for (int i = 0; i < groupMembers.size(); i++) { dataGridIds[i] = groupMembers.get(i).getId(); } return dataGridIds; } catch (JargonException e) { - logger.error("Could not get members list for group [" + group.getGroupname() + "]: ", e); + logger.error("Could not get members list for group ", e); + throw new DataGridException("error listing group members", e); } - return new String[0]; } @Override - public List findByDataGridIdList(String[] ids) { - List groups = groupDao.findByDataGridIdList(ids); - Collections.sort(groups); - return groups; - } + public void updateReadPermissions(UserGroup group, Map addCollectionsToRead, + Map removeCollectionsToRead) throws DataGridException { - @Override - public List findByGroupNameList(String[] groupNames) { - List groups = groupDao.findByGroupNameList(groupNames); - Collections.sort(groups); - return groups; - } + logger.info("updateReadPermissions()"); - @Override - public List findByIdList(String[] ids) { + if (group == null) { + throw new IllegalArgumentException("null group"); + } - if (ids != null) { - Long[] longIds = new Long[ids.length]; - for (int i = 0; i < ids.length; i++) { - longIds[i] = Long.valueOf(ids[i]); - } - List groups = groupDao.findByIdList(longIds); - Collections.sort(groups); - return groups; + if (addCollectionsToRead == null) { + throw new IllegalArgumentException("null addCollectionsToRead"); } - return new ArrayList(); - } - @Override - public boolean updateReadPermissions(DataGridGroup group, Map addCollectionsToRead, - Map removeCollectionsToRead) throws DataGridConnectionRefusedException { + if (removeCollectionsToRead == null) { + throw new IllegalArgumentException("null removeCollectionsToRead"); + } + + logger.info("group:{}", group); + logger.info("addCollectionsToRead:{}", addCollectionsToRead); + logger.info("removeCollectionsToRead:{}", removeCollectionsToRead); CollectionAO collectionAO = irodsServices.getCollectionAO(); DataObjectAO dataObjectAO = irodsServices.getDataObjectAO(); @@ -289,32 +398,47 @@ public boolean updateReadPermissions(DataGridGroup group, Map a try { for (String path : addCollectionsToRead.keySet()) { if (collectionService.isCollection(path)) { - collectionAO.setAccessPermissionReadAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), + collectionAO.setAccessPermissionReadAsAdmin(group.getZone(), path, group.getUserGroupName(), addCollectionsToRead.get(path)); } else { - dataObjectAO.setAccessPermissionReadInAdminMode(group.getAdditionalInfo(), path, - group.getGroupname()); + dataObjectAO.setAccessPermissionReadInAdminMode(group.getZone(), path, group.getUserGroupName()); } } for (String path : removeCollectionsToRead.keySet()) { if (collectionService.isCollection(path)) { - collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, - group.getGroupname(), removeCollectionsToRead.get(path)); + collectionAO.removeAccessPermissionForUserAsAdmin(group.getZone(), path, group.getUserGroupName(), + removeCollectionsToRead.get(path)); } else { - dataObjectAO.setAccessPermissionReadInAdminMode(group.getAdditionalInfo(), path, - group.getGroupname()); + dataObjectAO.setAccessPermissionReadInAdminMode(group.getZone(), path, group.getUserGroupName()); } } - return true; } catch (JargonException e) { logger.error("Could not set read permission:", e); + throw new DataGridException("exception setting permission", e); } - return false; } @Override - public boolean updateWritePermissions(DataGridGroup group, Map addCollectionsToWrite, - Map removeCollectionsToWrite) throws DataGridConnectionRefusedException { + public void updateWritePermissions(UserGroup group, Map addCollectionsToWrite, + Map removeCollectionsToWrite) throws DataGridException { + + logger.info("updateWritePermissions()"); + + if (group == null) { + throw new IllegalArgumentException("null group"); + } + + if (addCollectionsToWrite == null) { + throw new IllegalArgumentException("null addCollectionsToWrite"); + } + + if (removeCollectionsToWrite == null) { + throw new IllegalArgumentException("null removeCollectionsToWrite"); + } + + logger.info("group:{}", group); + logger.info("addCollectionsToWrite:{}", addCollectionsToWrite); + logger.info("removeCollectionsToWrite:{}", removeCollectionsToWrite); DataObjectAO dataObjectAO = irodsServices.getDataObjectAO(); CollectionAO collectionAO = irodsServices.getCollectionAO(); @@ -322,64 +446,75 @@ public boolean updateWritePermissions(DataGridGroup group, Map try { for (String path : addCollectionsToWrite.keySet()) { if (collectionService.isCollection(path)) { - collectionAO.setAccessPermissionWriteAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), + collectionAO.setAccessPermissionWriteAsAdmin(group.getZone(), path, group.getUserGroupName(), addCollectionsToWrite.get(path)); } else { - dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, - group.getGroupname()); + dataObjectAO.setAccessPermissionWriteInAdminMode(group.getZone(), path, group.getUserGroupName()); } } for (String path : removeCollectionsToWrite.keySet()) { if (collectionService.isCollection(path)) { - collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, - group.getGroupname(), removeCollectionsToWrite.get(path)); + collectionAO.removeAccessPermissionForUserAsAdmin(group.getZone(), path, group.getUserGroupName(), + removeCollectionsToWrite.get(path)); } else { - dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, - group.getGroupname()); + dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getZone(), path, + group.getUserGroupName()); } } - return true; } catch (JargonException e) { logger.error("Could not set read permission:", e); + throw new DataGridException("error setting read permission", e); } - return false; } @Override - public boolean updateOwnership(DataGridGroup group, Map addCollectionsToOwn, - Map removeCollectionsToOwn) throws DataGridConnectionRefusedException { + public void updateOwnership(UserGroup group, Map addCollectionsToOwn, + Map removeCollectionsToOwn) throws DataGridException { + + logger.info("updateOwnership()"); + + if (group == null) { + throw new IllegalArgumentException("null group"); + } + + if (addCollectionsToOwn == null) { + throw new IllegalArgumentException("null addCollectionsToOwn"); + } + + if (removeCollectionsToOwn == null) { + throw new IllegalArgumentException("null removeCollectionsToOwn"); + } + + logger.info("group:{}", group); + logger.info("addCollectionsToOwn:{}", addCollectionsToOwn); + logger.info("removeCollectionsToOwn:{}", removeCollectionsToOwn); DataObjectAO dataObjectAO = irodsServices.getDataObjectAO(); CollectionAO collectionAO = irodsServices.getCollectionAO(); try { for (String path : addCollectionsToOwn.keySet()) { if (collectionService.isCollection(path)) { - collectionAO.setAccessPermissionOwnAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), + collectionAO.setAccessPermissionOwnAsAdmin(group.getZone(), path, group.getUserGroupName(), addCollectionsToOwn.get(path)); } else { - dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, - group.getGroupname()); + dataObjectAO.setAccessPermissionWriteInAdminMode(group.getZone(), path, group.getUserGroupName()); } } for (String path : removeCollectionsToOwn.keySet()) { if (collectionService.isCollection(path)) { - collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, - group.getGroupname(), removeCollectionsToOwn.get(path)); + collectionAO.removeAccessPermissionForUserAsAdmin(group.getZone(), path, group.getUserGroupName(), + removeCollectionsToOwn.get(path)); } else { - dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, - group.getGroupname()); + dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getZone(), path, + group.getUserGroupName()); } } - return true; + } catch (JargonException e) { logger.error("Could not set ownership:", e); - } - return false; - } + throw new DataGridException("error setting own permission", e); - @Override - public int countAll() { - return groupDao.findAll(DataGridGroup.class).size(); + } } @Override diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/PermissionsServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/PermissionsServiceImpl.java index c9d5131..8352438 100644 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/PermissionsServiceImpl.java +++ b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/PermissionsServiceImpl.java @@ -4,7 +4,6 @@ package com.emc.metalnx.services.irods; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -26,11 +25,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.emc.metalnx.core.domain.dao.GroupBookmarkDao; -import com.emc.metalnx.core.domain.dao.GroupDao; import com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject; import com.emc.metalnx.core.domain.entity.DataGridFilePermission; -import com.emc.metalnx.core.domain.entity.DataGridGroup; import com.emc.metalnx.core.domain.entity.DataGridGroupPermission; import com.emc.metalnx.core.domain.entity.DataGridUser; import com.emc.metalnx.core.domain.entity.DataGridUserPermission; @@ -54,12 +50,6 @@ public class PermissionsServiceImpl implements PermissionsService { @Autowired private IRODSServices irodsServices; - @Autowired - private GroupBookmarkDao groupBookmarkDao; - - @Autowired - private GroupDao groupDao; - @Autowired private CollectionService collectionService; @@ -152,47 +142,23 @@ public List getGroupsWithPermissions(List idGroupsPermissions = new HashMap(); + List groupPermissions = new ArrayList<>(); for (DataGridFilePermission ufp : ufps) { // Getting only the groups, ignoring users if (ufp.getUserType().compareTo(RODS_GROUP) == 0) { + DataGridGroupPermission groupPermission = new DataGridGroupPermission(); + groupPermission.setDataGridId(0); + groupPermission.setGroupName(ufp.getUsername()); + groupPermission.setPermission(ufp.getPermission()); + groupPermissions.add(groupPermission); - String groupDataGridId = ufp.getUserId(); - if (groupDataGridId.isEmpty()) { - groupDataGridId = "0"; - } - - // If the ID is not known yet, we need to create a new entry for it - if (!idGroupsPermissions.containsKey(groupDataGridId)) { - DataGridGroupPermission dggp = new DataGridGroupPermission(); - dggp.setDataGridId(Integer.parseInt(groupDataGridId)); - dggp.setPermission(ufp.getPermission()); - - // Creating new entry for group - idGroupsPermissions.put(groupDataGridId, dggp); - } } } - // Making sure we have groups to query for - if (idGroupsPermissions.size() > 0) { + return groupPermissions; - // Getting list of unique IDs on an array - String[] groupIds = idGroupsPermissions.keySet().toArray(new String[idGroupsPermissions.size()]); - - // One single DB query to get group names - List groupObjects = groupDao.findByDataGridIdList(groupIds); - - // Setting group names to the elements on the hash map - for (DataGridGroup group : groupObjects) { - idGroupsPermissions.get(String.valueOf(group.getDataGridId())).setGroupName(group.getGroupname()); - } - } - - // Casting hash map values list to array list and returning - return new ArrayList(idGroupsPermissions.values()); } /***********************************************************************************/ @@ -242,15 +208,6 @@ public boolean setPermissionOnPath(DataGridPermType permType, String uName, bool } else { operationResult = chmodDataObject(permType, path, uName, inAdminMode); } - - // If the permissions is NONE, remove all bookmarks associated to the group and - // the path - if (permType.equals(DataGridPermType.NONE)) { - DataGridGroup group = groupDao.findByGroupnameAndZone(uName, irodsServices.getCurrentUserZone()); - if (group != null) - groupBookmarkDao.removeByGroupAndPath(group, path); - } - logger.info("Permission {} for user {} on path {} set successfully", permType, uName, paths); } catch (JargonException e) { logger.error("Could not set {} permission on path {} for user/group {}", permType, path, uName, e); @@ -492,6 +449,7 @@ private List mapListToListDataGridFilePermission( DataGridFilePermission dgfp = mapToDataGridFilePermission(ufp); dgFilePermissionList.add(dgfp); } + logger.debug("mapped permission list:{}", dgFilePermissionList); return dgFilePermissionList; } } diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserProfileServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserProfileServiceImpl.java deleted file mode 100755 index 113fbfc..0000000 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserProfileServiceImpl.java +++ /dev/null @@ -1,70 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - - -package com.emc.metalnx.services.irods; - -import com.emc.metalnx.core.domain.dao.UserDao; -import com.emc.metalnx.core.domain.dao.UserProfileDao; -import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.UserProfile; -import com.emc.metalnx.services.interfaces.UserProfileService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -public class UserProfileServiceImpl implements UserProfileService { - - @Autowired - UserDao userDao; - - @Autowired - UserProfileDao userProfileDao; - - @Override - public List findAll() { - return userProfileDao.findAll(UserProfile.class); - } - - @Override - public List findByQueryString(String query) { - return userProfileDao.findByQueryString(query); - } - - @Override - public UserProfile findById(Long id) { - return userProfileDao.findByID(UserProfile.class, id); - } - - @Override - public void modifyUserProfile(UserProfile profile) { - userProfileDao.merge(profile); - } - - @Override - public Long createUserProfile(UserProfile userProfile) { - return userProfileDao.save(userProfile); - } - - @Override - public void removeUserProfile(UserProfile profile) { - profile = userProfileDao.findByID(UserProfile.class, profile.getProfileId()); - for (DataGridUser user : profile.getUsers()) { - DataGridUser userToUpdate = userDao.findByID(DataGridUser.class, user.getId()); - userToUpdate.setUserProfile(null); - userDao.merge(userToUpdate); - } - profile.getUsers().clear(); - userProfileDao.delete(profile); - } - - @Override - public int countAll() { - return userProfileDao.findAll(UserProfile.class).size(); - } -} diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserServiceImpl.java index 0a4dce5..66b4dce 100755 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserServiceImpl.java +++ b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserServiceImpl.java @@ -1,7 +1,5 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.services.irods; @@ -10,7 +8,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.irods.jargon.core.exception.JargonException; import org.irods.jargon.core.protovalues.UserTypeEnum; @@ -30,9 +27,7 @@ import org.springframework.transaction.annotation.Transactional; import com.emc.metalnx.core.domain.dao.UserDao; -import com.emc.metalnx.core.domain.entity.DataGridGroup; import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.UserProfile; import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; import com.emc.metalnx.services.interfaces.ConfigService; import com.emc.metalnx.services.interfaces.GroupService; @@ -64,6 +59,32 @@ public class UserServiceImpl implements UserService { private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); + /** + * Compare the data grid user to the current zone and build a proper fully + * qualified user name where indicated + * + * @param dataGridUser {@link DataGridUser} to build the full user name + * @return {@code String} with the full user name including #zone where needed + */ + public String buildConcatUserName(final DataGridUser dataGridUser) { + logger.info("buildConcatUserName()"); + StringBuilder sb = new StringBuilder(); + sb.append(dataGridUser.getUsername()); + + if (dataGridUser.getAdditionalInfo().isEmpty()) { + // no zone info + } else if (dataGridUser.getAdditionalInfo().equals(irodsServices.getCurrentUserZone())) { + // no need for zone, same zone + } else { + logger.debug("adding zone"); + sb.append("#"); + sb.append(dataGridUser.getAdditionalInfo()); + } + + return sb.toString(); + + } + @Override public List findAll() { List users = userDao.findAll(DataGridUser.class); @@ -230,6 +251,7 @@ public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefu @Override public List findByDataGridIds(String[] ids) { + logger.info("findByDataGridIds()"); List users = userDao.findByDataGridIdList(ids); Collections.sort(users); return users; @@ -297,7 +319,7 @@ public String[] getGroupIdsForUser(String username, String additionalInfo) } @Override - public boolean updateGroupList(DataGridUser user, List groups) + public boolean updateGroupList(DataGridUser user, List groups) throws DataGridConnectionRefusedException { UserGroupAO groupAO = irodsServices.getGroupAO(); @@ -307,40 +329,40 @@ public boolean updateGroupList(DataGridUser user, List groups) // List current groups for user List groupsFromIrods = groupAO.findUserGroupsForUser(user.getUsername()); - // Building set with iRODS IDs already on this group - HashMap idsFromIrods = new HashMap(); - for (UserGroup groupFromIrods : groupsFromIrods) { - idsFromIrods.put(Long.valueOf(groupFromIrods.getUserGroupId()), groupFromIrods); - } + Map groupsFromUiMap = new HashMap<>(); + Map groupsFromIrodsMap = new HashMap<>(); - // Building set with iRODS IDs coming from UI - HashMap idsFromUi = new HashMap(); - for (DataGridGroup groupFromUi : groups) { - idsFromUi.put(groupFromUi.getDataGridId(), groupFromUi); + for (UserGroup userGroup : groups) { + groupsFromUiMap.put(userGroup.getUserGroupName(), userGroup); } - // Resolving differences from UI to iRODS - Set keysFromUi = idsFromUi.keySet(); - Set keysFromIrods = idsFromIrods.keySet(); + for (UserGroup userGroup : groupsFromIrods) { + groupsFromIrodsMap.put(userGroup.getUserGroupName(), userGroup); + } // Committing changes to iRODS - for (Long dataGridId : keysFromUi) { - if (!keysFromIrods.contains(dataGridId)) { - groupService.attachUserToGroup(user, idsFromUi.get(dataGridId)); + + // for every ui key not in irods put the user in that group + + for (String key : groupsFromUiMap.keySet()) { + if (groupsFromIrodsMap.get(key) == null) { + logger.info("adding group:{}", key); + // groupAO.addUserToGroup(key, this.buildConcatUserName(user), ""); + groupAO.addUserToGroup(key, user.getUsername(), user.getAdditionalInfo()); } } - for (Long dataGridId : keysFromIrods) { - if (!keysFromUi.contains(dataGridId)) { - DataGridGroup group = new DataGridGroup(); - group.setGroupname(idsFromIrods.get(dataGridId).getUserGroupName()); + // for every irods key not in ui remove from irods - if (group.getGroupname().compareTo("public") != 0) { - groupService.removeUserFromGroup(user, group); - } + for (String key : groupsFromIrodsMap.keySet()) { + if (groupsFromUiMap.get(key) == null) { + logger.info("removing group:{}", key); + groupAO.removeUserFromGroup(key, user.getUsername(), user.getAdditionalInfo()); } } + logger.info("done!"); + return true; } catch (Exception e) { logger.info("Could not update [" + user.getUsername() + "] group list: ", e); @@ -348,20 +370,6 @@ public boolean updateGroupList(DataGridUser user, List groups) return false; } - @Override - public boolean applyProfileToUser(UserProfile profile, DataGridUser user) { - Set profileGroups = profile.getGroups(); - for (DataGridGroup dataGridGroup : profileGroups) { - try { - groupService.attachUserToGroup(user, dataGridGroup); - } catch (Exception e) { - logger.info("iCAT already contain the user [" + user.getUsername() + "] on group [" - + dataGridGroup.getGroupname() + "] :", e); - } - } - return true; - } - @Override public boolean updateReadPermissions(DataGridUser user, Map addCollectionsToRead, Map removeCollectionsToRead) throws DataGridConnectionRefusedException { diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/CollectionService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/CollectionService.java index 2044c3a..9c57f43 100755 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/CollectionService.java +++ b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/CollectionService.java @@ -30,14 +30,13 @@ public interface CollectionService { /** * Verifies whether or not a file already exists in a collection * - * @param filename - * name of the file to be checked - * @param collectionPath - * path to the collection where the file may or may not exist + * @param filename name of the file to be checked + * @param collectionPath path to the collection where the file may or may not + * exist * @return True, if a file with the exact same name is found in the collection. * False, otherwise. - * @throws DataGridConnectionRefusedException - * if Metalnx cannot connect to the data grid. + * @throws DataGridConnectionRefusedException if Metalnx cannot connect to the + * data grid. * @throws JargonException */ boolean isFileInCollection(String filename, String collectionPath) @@ -46,8 +45,7 @@ boolean isFileInCollection(String filename, String collectionPath) /** * Checks whether a path is valid in the grid or not. * - * @param path - * file or collection path to be validated + * @param path file or collection path to be validated * @return True, if the path exists in the grid (path is a file or collection). * False, otherwise. * @throws JargonException @@ -80,18 +78,13 @@ boolean isFileInCollection(String filename, String collectionPath) * results are paginated. Any collection or data object where the term appears * in the beginning, middle, and the end of its name will be retrieved. * - * @param path - * path that we will be looking for collections and data objects that - * match the search term - * @param searchText - * term to be matched - * @param pageNum - * the page the user is currently seeing - * @param pageSize - * number of items shown by page - * @param pageContext - * object that contains information about the number of items - * diplayed and the total number of items found + * @param path path that we will be looking for collections and data + * objects that match the search term + * @param searchText term to be matched + * @param pageNum the page the user is currently seeing + * @param pageSize number of items shown by page + * @param pageContext object that contains information about the number of items + * diplayed and the total number of items found * @return List of collections and data objects where the term appears. * @throws DataGridDataNotFoundException * @throws DataGridQueryException @@ -105,8 +98,7 @@ List getSubCollectionsAndDataObjectsUnderPathTh /** * Gets what kind of permission(s) the logged user has on a certain path * - * @param path - * path to collection or data object in the data grid + * @param path path to collection or data object in the data grid * @return permission type (read, write, own) * @throws DataGridConnectionRefusedException */ @@ -117,8 +109,7 @@ List getSubCollectionsAndDataObjectsUnderPathTh /** * Gets the total number of replicas for a specific data object * - * @param path - * path to the data object + * @param path path to the data object * @return the total number of replicas for the data object given as a parameter * @throws DataGridConnectionRefusedException * @throws DataGridException @@ -128,8 +119,7 @@ List getSubCollectionsAndDataObjectsUnderPathTh /** * Lists all replicas of a data object by resource. * - * @param path - * path to the data object + * @param path path to the data object * @return Map, containing the replica of the given path * and the resource where this replica is located * @throws DataGridConnectionRefusedException @@ -148,9 +138,8 @@ Map listReplicasByResource(St /** * Gets all collections and data objects existing under a specific path * - * @param path - * path to the collection where we will retrieve sub collections and - * data objects + * @param path path to the collection where we will retrieve sub collections and + * data objects * @return list of collections and data objects existing under a path * @throws DataGridConnectionRefusedException * @throws FileNotFoundException @@ -170,8 +159,7 @@ List getSubCollectionsAndDataObjectsUnderPath(S /** * Find collections that match the parameter name * - * @param name - * name that will be looked for in the grid + * @param name name that will be looked for in the grid * @return CollectionAndDataObjectListingEntry List list of collections that * match a given name * @throws DataGridConnectionRefusedException @@ -182,8 +170,7 @@ List searchCollectionAndDataObjectsByName(Strin /** * Find collections and data objects that match the parameter name * - * @param path - * path that will be looked for in the grid + * @param path path that will be looked for in the grid * @return DataGridCollectionAndDataObject of the given path null if no * collections or data objects were found * @throws DataGridException @@ -194,14 +181,11 @@ List searchCollectionAndDataObjectsByName(Strin /** * Changes collection's name * - * @param previousPath - * collection path that will be modified - * @param newPath - * new collection path where the previous collection path will be - * moved to - * @param inheritOption - * boolean that says if we need to enable inheritance on a collection - * or not + * @param previousPath collection path that will be modified + * @param newPath new collection path where the previous collection path + * will be moved to + * @param inheritOption boolean that says if we need to enable inheritance on a + * collection or not * @throws DataGridConnectionRefusedException */ boolean modifyCollectionAndDataObject(String previousPath, String newPath, boolean inheritOption) @@ -280,25 +264,21 @@ Set listWritePermissionsForPathAndGroup(String path, String groupName) /** * List the collections that have inheritance enabled * - * @param path - * the parent path + * @param path the parent path * @return list of collections that have the inheritance option enabled - * @throws DataGridConnectionRefusedException + * @throws DataGridException {@link DataGridException} */ - Set listInheritanceForPath(String path) throws DataGridConnectionRefusedException; + Set listInheritanceForPath(String path) throws DataGridConnectionRefusedException, DataGridException; /** * Update the inheritance options on collections * - * @param toAdd - * {@code Map} with the inheritance paths and options to add - * @param toRemove - * {@code Map} with the inheritance paths and options to remove - * @param zoneName - * {@code String} (blank if default} for which the operation is done + * @param toAdd {@code Map} with the inheritance paths and options to add + * @param toRemove {@code Map} with the inheritance paths and options to remove + * @param zoneName {@code String} (blank if default} for which the operation is + * done * @return confirmation {@code boolean} with the confirmation - * @throws DataGridConnectionRefusedException - * {@link DataGridConnectionRefusedException} + * @throws DataGridConnectionRefusedException {@link DataGridConnectionRefusedException} */ boolean updateInheritanceOptions(Map toAdd, Map toRemove, String zoneName) throws DataGridConnectionRefusedException; @@ -307,8 +287,7 @@ boolean updateInheritanceOptions(Map toAdd, Map toAdd, Map listWritePermissionsForPathAndGroupRecursive(String path, String groupName) throws DataGridConnectionRefusedException, JargonException; @@ -332,32 +307,25 @@ Set listWritePermissionsForPathAndGroupRecursive(String path, String gro /** * Prepares files to be downloaded by compressing them into a single file. * - * @param paths - * array of strings that represent all paths that will be downloaded + * @param paths array of strings that represent all paths that will be + * downloaded * @return Path to the compressed file, if any. Empty string, otherwise. - * @throws DataGridException - * {@link DataGridException} - * @throws JargonException - * {@link JargonException} + * @throws DataGridException {@link DataGridException} + * @throws JargonException {@link JargonException} */ String prepareFilesForDownload(String[] paths) throws IOException, DataGridException, JargonException; /** * Prepares files to be downloaded by compressing them into a single file. * - * @param sourcePaths - * list of files to compress into a single file + * @param sourcePaths list of files to compress into a single file * @return Path to the compressed file, if any. Empty string, otherwise. - * @throws FileSizeTooLargeException - * {@link FileSizeTooLargeException} when bundle size exceeds max - * @throws IOException - * {@link IOException} - * @throws DataGridException - * {@link DataGridException} - * @throws ZipServiceException - * {@link ZipServiceException} - * @throws JargonException - * {@link JargonException} + * @throws FileSizeTooLargeException {@link FileSizeTooLargeException} when + * bundle size exceeds max + * @throws IOException {@link IOException} + * @throws DataGridException {@link DataGridException} + * @throws ZipServiceException {@link ZipServiceException} + * @throws JargonException {@link JargonException} * */ String prepareFilesForDownload(List sourcePaths) @@ -368,10 +336,8 @@ String prepareFilesForDownload(List sourcePaths) * * @param collPath * @return the boolean - * @throws DataGridConnectionRefusedException - * {@link DataGridConnectionRefusedException} - * @throws JargonException - * {@link JargonException} + * @throws DataGridConnectionRefusedException {@link DataGridConnectionRefusedException} + * @throws JargonException {@link JargonException} */ boolean getInheritanceOptionForCollection(String collPath) throws DataGridConnectionRefusedException, JargonException; @@ -379,22 +345,18 @@ boolean getInheritanceOptionForCollection(String collPath) /** * Gets the replica number of a collection or data object in the grid. * - * @param path - * path to the collection/object + * @param path path to the collection/object * @return int with the replica number 0, if path does not exist - * @throws DataGridConnectionRefusedException - * {@link DataGridConnectionRefusedException} + * @throws DataGridConnectionRefusedException {@link DataGridConnectionRefusedException} */ int getReplicationNumber(String path) throws DataGridConnectionRefusedException; /** * Gets the data grid checksum for a given path. * - * @param path - * path to the collection/object in the grid + * @param path path to the collection/object in the grid * @return String with the checksum - * @throws DataGridConnectionRefusedException - * {@link DataGridConnectionRefusedException} + * @throws DataGridConnectionRefusedException {@link DataGridConnectionRefusedException} */ String getChecksum(String path) throws DataGridConnectionRefusedException; @@ -402,8 +364,7 @@ boolean getInheritanceOptionForCollection(String collPath) * Maps a CollectionAndDataObjectListingEntry list into a * DataGridCollectionAndDataObject list * - * @param entries - * CollectionAndDataObjectListingEntry objects to map + * @param entries CollectionAndDataObjectListingEntry objects to map * @return list of DataGridCollectionAndDataObject objects */ List mapListingEntryToDataGridCollectionAndDataObject( @@ -413,8 +374,7 @@ List mapListingEntryToDataGridCollectionAndData * Maps a CollectionAndDataObjectListingEntry object into a * DataGridCollectionAndDataObject object * - * @param entry - * CollectionAndDataObjectListingEntry objects to map + * @param entry CollectionAndDataObjectListingEntry objects to map * @return instance of {@link DataGridCollectionAndDataObject} */ DataGridCollectionAndDataObject mapListingEntryToDataGridCollectionAndDataObject( @@ -430,11 +390,9 @@ DataGridCollectionAndDataObject mapListingEntryToDataGridCollectionAndDataObject /** * Retrieve only the collections under a parent collection * - * @param parent - * {@code String} with the parent path + * @param parent {@code String} with the parent path * @return {@code List} of {@link DataGridCollectionAndDataObject} - * @throws DataGridConnectionRefusedException - * {@link DataGridConnectionRefusedException} + * @throws DataGridConnectionRefusedException {@link DataGridConnectionRefusedException} */ List getSubCollectionsUnderPath(String parent) throws DataGridConnectionRefusedException; @@ -442,8 +400,7 @@ List getSubCollectionsUnderPath(String parent) /** * Get trash path related to the current path * - * @param path - * {@code String} with the path + * @param path {@code String} with the path * @return correspondent trash for given path */ String getTrashForPath(String path); @@ -453,13 +410,10 @@ List getSubCollectionsUnderPath(String parent) /** * Retrieve a data profile for the path * - * @param path - * {@code String} with the path + * @param path {@code String} with the path * @return {@link DataProfile} - * @throws DataGridException - * {@link DataGridException} - * @throws FileNotFoundException - * {@link FileNotFoundException} + * @throws DataGridException {@link DataGridException} + * @throws FileNotFoundException {@link FileNotFoundException} */ DataProfile getCollectionDataProfile(String path) throws DataGridException, FileNotFoundException; @@ -467,26 +421,20 @@ DataProfile getCollectionDataProfile(String path) /** * Update the collection inheritance value * - * @param path - * {@code String} with the collection path - * @param inheritOption - * {@code boolean} with the inheritance setting - * @param recursive - * {@code boolean} indicating whether to apply the setting - * recursively - * @throws DataGridException - * {@link DataGridException} + * @param path {@code String} with the collection path + * @param inheritOption {@code boolean} with the inheritance setting + * @param recursive {@code boolean} indicating whether to apply the setting + * recursively + * @throws DataGridException {@link DataGridException} */ void modifyInheritance(String path, boolean inheritOption, boolean recursive) throws DataGridException; /** * Handy method probes user access to a path * - * @param path - * {@code String} with the path to check access on + * @param path {@code String} with the path to check access on * @return {@code boolean} of {@code true} if the user has access - * @throws DataGridException - * {@link DataGridException} + * @throws DataGridException {@link DataGridException} */ boolean canUserAccessThisPath(String path) throws DataGridException; @@ -494,11 +442,9 @@ DataProfile getCollectionDataProfile(String path) * Retrieve a data profile for the path using the admin account to serve as a * metadata only proxy * - * @param path - * {@code String} with the path + * @param path {@code String} with the path * @return {@link DataProfile} - * @throws DataGridException - * {@link DataGridException} + * @throws DataGridException {@link DataGridException} */ DataProfile getCollectionDataProfileAsProxyAdmin(String path) throws FileNotFoundException, DataGridException; diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupBookmarkService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupBookmarkService.java deleted file mode 100755 index 79a84ec..0000000 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupBookmarkService.java +++ /dev/null @@ -1,110 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - - -package com.emc.metalnx.services.interfaces; - -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import com.emc.metalnx.core.domain.entity.DataGridGroupBookmark; -import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; -import org.irods.jargon.core.exception.DataNotFoundException; -import org.irods.jargon.core.exception.JargonException; - -import java.util.List; -import java.util.Set; - -public interface GroupBookmarkService { - - /** - * Finds all groups a user belongs to and all bookmarks set for this group to have access to. - * - * @param user - * name of the user - * @param additionalInfo - * zone name where the user is - * @return true if the group was created successfully, false otherwise - * @throws DataGridConnectionRefusedException - * @throws JargonException - * @throws DataNotFoundException - */ - public List getGroupsBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, - DataNotFoundException, JargonException; - - /** - * Updates the list of bookmarks on a group - * - * @param group - * @param toAdd - * @param toRemove - * @return a confirmation that the operation has been successful - */ - public boolean updateBookmarks(DataGridGroup group, Set toAdd, Set toRemove); - - /** - * Lists all the bookmarks on a given path - * - * @param path - * @return - */ - public List findBookmarksOnPath(String path); - - /** - * Lists all the bookmarks on a given path for a given group as Strings - * - * @param group - * @param parentPath - * @return - */ - public List findBookmarksForGroupAsString(DataGridGroup group); - - /** - * Remove any bookmark associated with the given path. - * - * @param path - * @return True, if there was one or more bookmarks mathching the given path and they were - * removed successfully. False, - * otherwise. - */ - public boolean removeBookmarkBasedOnPath(String path); - - /** - * Remove any bookmark associated with the given user. - * - * @param {@link DataGridGroup} group - * @return True, if there was one or more bookmarks mathching the given path and they were - * removed successfully. False, - * otherwise. - */ - public boolean removeBookmarkBasedOnGroup(DataGridGroup group); - - /** - * Remove all bookmarks based on relative paths. - * - * @param path - * @return True, if there was one or more bookmarks mathching the given path and they were - * removed successfully. False, - * otherwise. - */ - public boolean removeBookmarkBasedOnRelativePath(String path); - - public List getGroupsBookmarksPaginated(String user, String additionalInfo, int offset, int limit, String searchString, - String orderBy, String orderDir, boolean onlyCollections) throws DataGridConnectionRefusedException, DataNotFoundException, - JargonException; - - public Integer countTotalGroupBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, DataNotFoundException, - JargonException; - - - /** - * Changes an existing bookmark to a new value. - * - * @param oldPath - * existing path that will be updated - * @param newPath - * new path - * @return True, if oldePath was successfully changed to newPath. False, otherwise. - */ - public boolean updateBookmark(String oldPath, String newPath); - -} diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupService.java index 7594917..05df953 100755 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupService.java +++ b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/GroupService.java @@ -1,175 +1,145 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.services.interfaces; -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; - import java.util.List; import java.util.Map; +import org.irods.jargon.core.pub.domain.UserGroup; + +import com.emc.metalnx.core.domain.entity.DataGridUser; +import com.emc.metalnx.core.domain.exceptions.DataGridException; + public interface GroupService { - /** - * Lists all groups existing on iRODS - * - * @return all groups existing in iRODS - */ - public List findAll(); - - /** - * Find an specific group whose name is equal to groupname - * - * @return all groups existing in iRODS - */ - public List findByGroupname(String groupname); - - /** - * Find an specific group whose name is equal to groupname and zone - * - * @return - */ - public DataGridGroup findByGroupnameAndZone(String groupname, String zone); - - /** - * Creates a group in iRODS - * - * @param newGroup - * @return true if the group was created successfully, false otherwise - * @throws DataGridConnectionRefusedException - */ - public boolean createGroup(DataGridGroup newGroup, List usersToBeAttached) throws DataGridConnectionRefusedException; - - /** - * Removes a group from iRODS - * - * @param groupname - * @return True, if the group was successfully deleted. False, otherwise. - * @throws DataGridConnectionRefusedException - */ - public boolean deleteGroupByGroupname(String groupname) throws DataGridConnectionRefusedException; - - /** - * Attach the user to the group - * - * @param user - * @param group - * @return - * @throws DataGridConnectionRefusedException - */ - public boolean attachUserToGroup(DataGridUser user, DataGridGroup group) throws DataGridConnectionRefusedException; - - /** - * Remove the user from the group - * - * @param user - * @param group - * @return - * @throws DataGridConnectionRefusedException - */ - public boolean removeUserFromGroup(DataGridUser user, DataGridGroup group) throws DataGridConnectionRefusedException; - - /** - * Updates the list of users belonging to a given group - * - * @param user - * @param group - * @return the confirmation - * @throws DataGridConnectionRefusedException - */ - public boolean updateMemberList(DataGridGroup group, List users) throws DataGridConnectionRefusedException; - - /** - * Updates the list of collections the group has read permission - * - * @return the confirmation - * @throws DataGridConnectionRefusedException - */ - public boolean updateReadPermissions(DataGridGroup group, Map addCollectionsToRead, Map removeCollectionsToRead) - throws DataGridConnectionRefusedException; - - /** - * Updates the list of collections the group has write permission - * - * @return the confirmation - * @throws DataGridConnectionRefusedException - */ - public boolean updateWritePermissions(DataGridGroup group, Map addCollectionsToWrite, - Map removeCollectionsToWrite) throws DataGridConnectionRefusedException; - - /** - * Updates the list of collections the group owns - * - * @return the confirmation - * @throws DataGridConnectionRefusedException - */ - public boolean updateOwnership(DataGridGroup group, Map addCollectionsToOwn, Map removeCollectionsToOwn) - throws DataGridConnectionRefusedException; - - /** - * Returns the list of Data Grid IDs for the members of the group. - * - * @param group - * @return list of Data Grid IDs of members - * @throws DataGridConnectionRefusedException - */ - public String[] getMemberList(DataGridGroup group) throws DataGridConnectionRefusedException; - - /** - * Finds users matching the specified query. - * - * @param query - * @param page - * @return list of users - */ - public List findByQueryString(String query); - - /** - * Finds users whose ids match the list of ids. - * - * @param ids - * @return list of users - */ - public List findByDataGridIdList(String[] ids); - - /** - * Finds groups whose names match the list of names. - * - * @param groupNames - * @return list of users - */ - public List findByGroupNameList(String[] groupNames); - - /** - * Finds users whose ids match the list of ids. - * - * @param ids - * @return list of users - */ - public List findByIdList(String[] ids); - - /** - * Calculates the number of existing groups - * - * @return the number of groups - */ - public int countAll(); - - /** - * Gets the group's home collection path in the grid. - * - * Be aware that this method, for performance issues, does not call the data grid - * to verify whether or not the group exists. - * - * @param groupName - * name of the group to find the home path - * @return - * path to the group's home collection - */ - public String getGroupCollectionPath(String groupName); + /** + * Lists all groups existing on iRODS + * + * @return all groups existing in iRODS + * @throws DataGridException + */ + public List findAll() throws DataGridException; + + /** + * Find an specific group whose name is equal to groupname + * + * @return all groups existing in iRODS + * @throws DataGridException + */ + public List findByGroupname(String groupname) throws DataGridException; + + /** + * Find an specific group whose name is equal to groupname and zone + * + * @return + * @throws DataGridException {@link DataGridException} + */ + public UserGroup findByGroupnameAndZone(String groupname, String zone) throws DataGridException; + + /** + * Creates a group in iRODS + * + * @param newGroup + * @return true if the group was created successfully, false otherwise + * @throws DataGridException {@link DataGridException} + */ + public boolean createGroup(UserGroup newGroup, List usersToBeAttached) throws DataGridException; + + /** + * Gets the group's home collection path in the grid. + * + * Be aware that this method, for performance issues, does not call the data + * grid to verify whether or not the group exists. + * + * @param groupName name of the group to find the home path + * @return path to the group's home collection + */ + public String getGroupCollectionPath(String groupName); + + /** + * Delete the group from the connected zone + * + * @param userGroup {@link UserGroup} to be deleted + * @throws DataGridException {@link DataGridException} + */ + void deleteGroup(UserGroup userGroup) throws DataGridException; + + /** + * Attach a user to a group. This group is local to the logged-in iRODS zone. + * The user can be a cross-zone user as denoted by the {@code zoneName} + * + * + * @throws DataGridException {@code DataGridException} + */ + void attachUserToGroup(String userName, String userZone, UserGroup userGroup) throws DataGridException; + + /** + * Remove the given user from the group + * + * @param userName {@code String} with the user to add + * @param userZone {@code String} with the name of the user zone + * @param userGroup {@code userGroup} with the group#zone + * @throws DataGridException + */ + void removeUserFromGroup(String userName, String userZone, UserGroup userGroup) throws DataGridException; + + /** + * Given the users in the UI and in iRODS compare the delta and apply changes + * FIXME: this is dumb + * + * @param group {@link UserGroup} being operated on + * @param users {@code List} of {@link DataGridUsers} to compute + * @throws DataGridException {@link DataGridException} + */ + void updateMemberList(UserGroup group, List users) throws DataGridException; + + /** + * Get a list of members for the given group and optional zone + * + * @param groupName {@code String} with the name of the group + * @param groupZone {@code String} with an optional zone + * @return {@code List[String]} with the name of the members + * @throws DataGridException {@link DataGridException} + */ + String[] getMemberList(String groupName, String groupZone) throws DataGridException; + + /** + * Update permissions with a set of deltas to add and remove + * + * @param group {@link UserGroup} + * @param addCollectionsToRead {@code List} of collections to add read + * permissions + * @param removeCollectionsToRead {@code List} of collections to remove read + * permissions + * @throws DataGridException {@link DataGridException} + */ + void updateReadPermissions(UserGroup group, Map addCollectionsToRead, + Map removeCollectionsToRead) throws DataGridException; + + /** + * Updates the list of collections the group has write permission + * + * @param group {@link UserGroup} + * @param addCollectionsToWrite {@code List} of collections to add write + * permissions + * @param removeCollectionsToWrite {@code List} of collections to remove write + * permissions + * @throws DataGridException {@link DataGridException} + */ + void updateWritePermissions(UserGroup group, Map addCollectionsToWrite, + Map removeCollectionsToWrite) throws DataGridException; + + void updateOwnership(UserGroup group, Map addCollectionsToOwn, + Map removeCollectionsToOwn) throws DataGridException; + + /** + * Locate a user group based on its iCAT id + * + * @param groupId {@code String} with the group id + * @return {@link UserGroup} associated with the id, or {@code null} + * @throws DataGridException {@link DataGridException} + */ + UserGroup findById(String groupId) throws DataGridException; } diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserService.java index 00e72e8..9f742b2 100755 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserService.java +++ b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserService.java @@ -1,199 +1,187 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - +/* Copyright (c) 2018, University of North Carolina at Chapel Hill */ +/* Copyright (c) 2015-2017, Dell EMC */ package com.emc.metalnx.services.interfaces; -import com.emc.metalnx.core.domain.entity.DataGridGroup; -import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.UserProfile; -import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; -import org.irods.jargon.core.exception.JargonException; - import java.util.List; import java.util.Map; +import org.irods.jargon.core.exception.JargonException; +import org.irods.jargon.core.pub.domain.UserGroup; + +import com.emc.metalnx.core.domain.entity.DataGridUser; +import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; + public interface UserService { - /** - * Returns all the users existing on iRODS - * - * @return - */ - public List findAll(); - - /** - * Returns the list of DataGridUsers matching data grid ID. - * - * @param ids - * @return - */ - List findByDataGridIds(String[] ids); - - /** - * Create the user on local DB and on iRODS - * - * @param user - * @return confirmation - * @throws DataGridConnectionRefusedException - */ - public boolean createUser(DataGridUser user, String password) throws JargonException, DataGridConnectionRefusedException; - - /** - * Delete user by username - * - * @param username - * @return a confirmation that the user has been removed - * @throws DataGridConnectionRefusedException - */ - public boolean deleteUserByUsername(String username) throws DataGridConnectionRefusedException; - - /** - * Modify user by username - * - * @param username - * @return a confirmation that the user has been modified - * @throws DataGridConnectionRefusedException - */ - public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException; - - /** - * Finds users by username - * - * @param username - * name of the user(s) to be found - * @return List of users matching {@code username} - */ - public List findByUsername(String username); - - /** - * Return a user whose name is 'username' and additional info is 'additionalInfo' - * - * @param username - * @param additionalInfo - * @return - */ - public DataGridUser findByUsernameAndAdditionalInfo(String username, String additionalInfo); - - /** - * Returns the quantity of users persisted on our database. - * - * @return - */ - public int countAll(); - - /** - * Finds users matching the specified query. - * - * @param query - * @param page - * @return list of users - */ - public List findByQueryString(String query); - - /** - * Returns the list of IDs of each group the user belongs to. - * - * @param user - * @return list of data grid IDs - * @throws DataGridConnectionRefusedException - */ - public String[] getGroupIdsForUser(DataGridUser user) throws DataGridConnectionRefusedException; - - /** - * Returns the list of IDs of each group the user belongs to. - * - * @param username - * name of the user - * @param additionalInfo - * zone name where the user is - * @return list of data grid IDs - * @throws DataGridConnectionRefusedException - */ - public String[] getGroupIdsForUser(String username, String additionalInfo) throws DataGridConnectionRefusedException; - - /** - * Updates the list of groups the user belongs to. - * - * @param user - * @param groups - * @return the confirmation of the update. - * @throws DataGridConnectionRefusedException - */ - public boolean updateGroupList(DataGridUser user, List groups) throws DataGridConnectionRefusedException; - - /** - * Applies a profile to a user - * - * @param profile - * @param user - * @return - */ - public boolean applyProfileToUser(UserProfile profile, DataGridUser user); - - /** - * Updates the list of collections the user has read permission - * - * @param group - * @param addCollectionsToRead - * @param removeCollectionsToRead - * @param recursive - * flag that says whether or not the permission is applied recursively - * @return True, if permissions were updated. False, otherwise. - * @throws DataGridConnectionRefusedException - */ - public boolean updateReadPermissions(DataGridUser group, Map addCollectionsToRead, Map removeCollectionsToRead) - throws DataGridConnectionRefusedException; - - /** - * Updates the list of collections the user has write permission - * - * @param group - * @param addCollectionsToWrite - * @param removeCollectionsToWrite - * @param recursive - * flag that says whether or not the permission is applied recursively - * @return True, if permissions were updated. False, otherwise. - * @throws DataGridConnectionRefusedException - */ - public boolean updateWritePermissions(DataGridUser group, Map addCollectionsToWrite, - Map removeCollectionsToWrite) throws DataGridConnectionRefusedException; - - /** - * Updates the list of collections the user owns - * - * @param group - * @param addCollectionsToOwn - * @param removeCollectionsToOwn - * @param recursive - * flag that says whether or not the permission is applied recursively - * @return True, if permissions were updated. False, otherwise. - * @throws DataGridConnectionRefusedException - */ - public boolean updateOwnership(DataGridUser group, Map addCollectionsToOwn, Map removeCollectionsToOwn) - throws DataGridConnectionRefusedException; - - /** - * Lists all user types available in the data grid - * - * @return List of all user types - */ - public List listUserTypes(); - - /** - * Removes access permission on a set of paths for a particular user. - * - * @param user - * user who permission will be removed - * @param paths - * paths to collections/data objects on which the user will lose access - * @param recursive - * flag that says whether or not the permission is applied recursively - * @throws JargonException - * @throws DataGridConnectionRefusedException - */ - void removeAccessPermissionForUserAsAdmin(DataGridUser user, Map paths) throws JargonException, - DataGridConnectionRefusedException; + /** + * Returns all the users existing on iRODS + * + * @return + */ + public List findAll(); + + /** + * Returns the list of DataGridUsers matching data grid ID. + * + * @param ids + * @return + */ + List findByDataGridIds(String[] ids); + + /** + * Create the user on local DB and on iRODS + * + * @param user + * @return confirmation + * @throws DataGridConnectionRefusedException + */ + public boolean createUser(DataGridUser user, String password) + throws JargonException, DataGridConnectionRefusedException; + + /** + * Delete user by username + * + * @param username + * @return a confirmation that the user has been removed + * @throws DataGridConnectionRefusedException + */ + public boolean deleteUserByUsername(String username) throws DataGridConnectionRefusedException; + + /** + * Modify user by username + * + * @param username + * @return a confirmation that the user has been modified + * @throws DataGridConnectionRefusedException + */ + public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException; + + /** + * Finds users by username + * + * @param username name of the user(s) to be found + * @return List of users matching {@code username} + */ + public List findByUsername(String username); + + /** + * Return a user whose name is 'username' and additional info is + * 'additionalInfo' + * + * @param username + * @param additionalInfo + * @return + */ + public DataGridUser findByUsernameAndAdditionalInfo(String username, String additionalInfo); + + /** + * Returns the quantity of users persisted on our database. + * + * @return + */ + public int countAll(); + + /** + * Finds users matching the specified query. + * + * @param query + * @param page + * @return list of users + */ + public List findByQueryString(String query); + + /** + * Returns the list of IDs of each group the user belongs to. + * + * @param user + * @return list of data grid IDs + * @throws DataGridConnectionRefusedException + */ + public String[] getGroupIdsForUser(DataGridUser user) throws DataGridConnectionRefusedException; + + /** + * Returns the list of IDs of each group the user belongs to. + * + * @param username name of the user + * @param additionalInfo zone name where the user is + * @return list of data grid IDs + * @throws DataGridConnectionRefusedException + */ + public String[] getGroupIdsForUser(String username, String additionalInfo) + throws DataGridConnectionRefusedException; + + /** + * Updates the list of groups the user belongs to. + * + * @param user + * @param groups + * @return the confirmation of the update. + * @throws DataGridConnectionRefusedException + */ + public boolean updateGroupList(DataGridUser user, List groups) throws DataGridConnectionRefusedException; + + /** + * Updates the list of collections the user has read permission + * + * @param group + * @param addCollectionsToRead + * @param removeCollectionsToRead + * @param recursive flag that says whether or not the permission + * is applied recursively + * @return True, if permissions were updated. False, otherwise. + * @throws DataGridConnectionRefusedException + */ + public boolean updateReadPermissions(DataGridUser group, Map addCollectionsToRead, + Map removeCollectionsToRead) throws DataGridConnectionRefusedException; + + /** + * Updates the list of collections the user has write permission + * + * @param group + * @param addCollectionsToWrite + * @param removeCollectionsToWrite + * @param recursive flag that says whether or not the permission + * is applied recursively + * @return True, if permissions were updated. False, otherwise. + * @throws DataGridConnectionRefusedException + */ + public boolean updateWritePermissions(DataGridUser group, Map addCollectionsToWrite, + Map removeCollectionsToWrite) throws DataGridConnectionRefusedException; + + /** + * Updates the list of collections the user owns + * + * @param group + * @param addCollectionsToOwn + * @param removeCollectionsToOwn + * @param recursive flag that says whether or not the permission is + * applied recursively + * @return True, if permissions were updated. False, otherwise. + * @throws DataGridConnectionRefusedException + */ + public boolean updateOwnership(DataGridUser group, Map addCollectionsToOwn, + Map removeCollectionsToOwn) throws DataGridConnectionRefusedException; + + /** + * Lists all user types available in the data grid + * + * @return List of all user types + */ + public List listUserTypes(); + + /** + * Removes access permission on a set of paths for a particular user. + * + * @param user user who permission will be removed + * @param paths paths to collections/data objects on which the user will + * lose access + * @param recursive flag that says whether or not the permission is applied + * recursively + * @throws JargonException + * @throws DataGridConnectionRefusedException + */ + void removeAccessPermissionForUserAsAdmin(DataGridUser user, Map paths) + throws JargonException, DataGridConnectionRefusedException; }