diff --git a/emc-metalnx-core/pom.xml b/emc-metalnx-core/pom.xml index 0c62c50..200688c 100755 --- a/emc-metalnx-core/pom.xml +++ b/emc-metalnx-core/pom.xml @@ -22,20 +22,6 @@ javassist ${javassist.version} - - org.hibernate - hibernate-core - - - org.hibernate - hibernate-validator - ${hibernate.validator.version} - - - org.hibernate - hibernate-envers - ${hibernate.version} - org.springframework spring-orm @@ -91,6 +77,16 @@ jaxb-api 2.3.1 + + org.irods.jargon + jargon-zipservice + ${project.version} + + + org.irods.jargon + jargon-ticket + ${project.version} + @@ -130,7 +126,7 @@ 0 validate - + - + run @@ -204,7 +200,7 @@ 2 validate - + - + run diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/FavoriteDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/FavoriteDao.java deleted file mode 100755 index 36bffd1..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/FavoriteDao.java +++ /dev/null @@ -1,114 +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.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.DataGridUserFavorite; - -import java.util.List; - -public interface FavoriteDao { - - /** - * Retrieve a given Favorite based on the user and path - * - * @param user - * @param path - * @return a {@link DataGridUserFavorite} - */ - DataGridUserFavorite findByUserAndPath(DataGridUser user, String path); - - /** - * Add a favorite to a user using the path and user entity - * - * @param user - * data grid user to add the favorite to - * @param path - * path to the collection/data object to be added as a favorite - * @param isCollection - * indicates whether a path is a collection or a file - * @return a confirmation that the insertion has been successfully - */ - Long addByUserAndPath(DataGridUser user, String path, boolean isCollection); - - /** - * Removes a favorite based on the path and the user - * - * @param user - * @param path - * @return a confirmation that the deletion has been successful - */ - boolean removeByUserAndPath(DataGridUser user, String path); - - /** - * Removes a favorite based on the user - * - * @param {@link DataGridUser} user - * @return a confirmation that the deletion has been successful - */ - boolean removeByUser(DataGridUser user); - - /** - * Retrieve a given Favorite based on the user - * - * @param user - * @return list of {@link DataGridUserFavorite} - */ - List findByUser(DataGridUser user); - - /** - * Retrieves all the favorites on a given path - * - * @param path - * @return list of {@link DataGridUserFavorite} - */ - List findFavoritesByPath(String path); - - /** - * Removes a favorite based on the given path - * - * @param path - * path to remove any favorite - * @return a confirmation that the deletion has been successful - */ - boolean removeByPath(String path); - - /** - * Removes all existing favorites whose parent path is the given path. Basically, if the - * following favorites 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 - * favorites since they no longer exist. But "x/y/z/a/b/c" should be kept. - * - * @param parentPath - * path to remove any favorite - * @return a confirmation that the deletion has been successful - */ - boolean removeByParentPath(String parentPath); - - /** - * Find list of favorites paginated - * - * @param user - * @param offset - * represents the starting row in the query - * @param limit - * how many elements will have the result - * @param searchString - * is different from null if filter is used - * @param orderBy - * order by a column - * @param orderDir - * the direction of the order can be 'desc' or 'asc' - * @param onlyCollections - * indicates if results should contain only collections - * @return list of {@link DataGridUserFavorite} - */ - List findByUserPaginated(DataGridUser user, int offset, int limit, String searchString, String orderBy, String orderDir, - boolean onlyCollections); - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/TemplateDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/TemplateDao.java deleted file mode 100755 index 2d45f58..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/TemplateDao.java +++ /dev/null @@ -1,99 +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.DataGridTemplate; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; - -import java.util.List; - -public interface TemplateDao extends GenericDao { - - /** - * Gets the template id based on its name (the template name given has to - * match exactly the template name existing in the database). - * - * @param templateName - * name of the template - * @return the template id if the template is found. Null, otherwise. - */ - long getTemplateId(String templateName); - - /** - * Find a template by its name - * - * @param templateName - * name of the template - * @return Template matching the name - */ - DataGridTemplate findByName(String templateName); - - /** - * Find a template by its id - * - * @param id - * template id - * @return Template if the id exists. Null, if the id was not found. - */ - DataGridTemplate findById(long id); - - /** - * Deletes a template by its id - * - * @param id - * id of the template to be removed - * @return true if the template was successfully removed. False, otherwise. - */ - boolean deleteById(long id); - - /** - * Finds templates by a query string - * - * @param query - * string containing the search term to match template names - * @return list of templates - */ - List findByQueryString(String query); - - /** - * Lists all fields existing in a template - * - * @param template - * name of the template - * @return List of template fields, if any - */ - List listTemplateFields(String template); - - /** - * Lists all fields existing in a template - * - * @param id - * id of the template - * @return List of template fields, if any - */ - List listTemplateFields(Long id); - - /** - * Returns all the public metadata templates - * - * @return List of template fields, if any - */ - List listPublicTemplates(); - - /** - * Returns all the private metadata templates - * - * @return List of template fields, if any - */ - List listPrivateTemplatesByUser(String user); - - @Override - /** - * Overrides the merge method in order to handle the version number of the - * current template. - */ - void merge(DataGridTemplate template); -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/TemplateFieldDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/TemplateFieldDao.java deleted file mode 100755 index e63534a..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/TemplateFieldDao.java +++ /dev/null @@ -1,36 +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.DataGridTemplateField; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException; - -public interface TemplateFieldDao extends GenericDao { - - /** - * Find a template field by its id - * - * @param id - * template field id - * @return Template if the id exists. Null, if the id was not found. - */ - DataGridTemplateField findById(long id); - - /** - * Modify a template field by its id - * - * @param id - * id of the template field to be removed - * @return true if the template field was successfully modified. False, otherwise. - * @throws DataGridTemplateAttrException - * @throws DataGridTemplateValueException - * @throws DataGridTemplateUnitException - */ - boolean modifyById(long id, String attribute, String value, String unit) throws DataGridTemplateAttrException, DataGridTemplateValueException, - DataGridTemplateUnitException; -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserBookmarkDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserBookmarkDao.java deleted file mode 100755 index b1d416e..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserBookmarkDao.java +++ /dev/null @@ -1,148 +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.DataGridUser; -import com.emc.metalnx.core.domain.entity.DataGridUserBookmark; - -import java.util.List; - -public interface UserBookmarkDao extends GenericDao { - - /** - * Add a bookmark to a user using the path and user entity - * - * @param user - * data grid user to add the bookmark to - * @param path - * path to the collection/data object to be added as a bookmark - * @param isCollection - * indicates whether a path is a collection or a file - * @return a confirmation that the insertion has been successfully - */ - public Long addByUserAndPath(DataGridUser user, String path, boolean isCollection); - - /** - * Removes a bookmark based on the path and the user - * - * @param user - * @param path - * @return a confirmation that the deletion has been successful - */ - public boolean removeByUserAndPath(DataGridUser user, 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 a bookmark based on the given user - * - * @param path - * path to remove any bookmark - * @return a confirmation that the deletion has been successful - */ - public boolean removeByUser(DataGridUser user); - - /** - * 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); - - /** - * Retrieve a given UserBookmark based on the user and path - * - * @param user - * @param path - * @return a {@link DataGridUserBookmark} - */ - public DataGridUserBookmark findByUserAndPath(DataGridUser user, String path); - - /** - * Retrieve a given UserBookmark based on the user - * - * @param user - * @return a {@link DataGridUserBookmark} - */ - public List findByUser(DataGridUser user); - - /** - * Retrieves all the bookmarks on a given path - * - * @param path - * @return list of {@link DataGridUserBookmark} - */ - public List findBookmarksByPath(String path); - - /** - * Find list of bookmarks paginated - * - * @param user - * @param start - * represents the starting row in the query - * @param length - * how many elements will have the result - * @param searchString - * is different from null if filter is used - * @param orderBy - * order by a column - * @param orderDir - * the direction of the order can be 'desc' or 'asc' - * @param onlyCollections - * indicates if the results should contain only collections - * @return list of {@link DataGridUserBookmark} - */ - public List findByUserPaginated(DataGridUser user, int start, int length, String searchString, String orderBy, - String orderDir, boolean onlyCollections); - - /** - * Find list of bookmarks paginated - * - * @param user - * @param start - * represents the starting row in the query - * @param length - * how many elements will have the result - * @param searchString - * is different from null if filter is used - * @param orderBy - * list of columns the database will order the results by - * @param orderDir - * list of directions (ASC or DESC) that will applied to the columns in the order by - * clause - * @param onlyCollections - * indicates if the results should contain only collections - * @return list of {@link DataGridUserBookmark} - */ - public List findByUserPaginated(DataGridUser user, int start, int length, String searchString, List orderBy, - List orderDir, boolean onlyCollections); - - /** - * 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/UserDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserDao.java index c2dd739..254dcdc 100755 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserDao.java +++ b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/UserDao.java @@ -4,12 +4,11 @@ package com.emc.metalnx.core.domain.dao; -import com.emc.metalnx.core.domain.dao.generic.GenericDao; import com.emc.metalnx.core.domain.entity.DataGridUser; import java.util.List; -public interface UserDao extends GenericDao { +public interface UserDao { /** * Find a user by his ID @@ -61,5 +60,7 @@ public interface UserDao extends GenericDao { * @param query * @return list of users */ - public List findByQueryString(String query); + public List findByQueryString(String query); + + List findAll(); } diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/generic/GenericDao.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/generic/GenericDao.java deleted file mode 100755 index 34643b7..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/generic/GenericDao.java +++ /dev/null @@ -1,61 +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.generic; - -import org.hibernate.Query; - -import java.io.Serializable; -import java.util.List; - -@SuppressWarnings("rawtypes") -public interface GenericDao { - - /** - * Persists a new entry on the database. - * @param entity - */ - public id save(T entity); - - /** - * Updates an existing entry on the database. - * @param entity - */ - public void merge(T entity); - - /** - * Deletes an entry from the database. - * @param entity - */ - public void delete(T entity); - - /** - * Returns a list of entities of class T matching the query. - * @param query - * @return - */ - public List findMany(Query query); - - /** - * Returns one single entity of class T matching the query. - * @param query - * @return - */ - public T findOne(Query query); - - /** - * Returns all the entries for the class. - * @param clazz - * @return - */ - public List findAll(Class clazz); - - /** - * Find an entry by its ID. - * @param clazz - * @param id - * @return - */ - public T findByID(Class clazz, Long id); -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/generic/GenericDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/generic/GenericDaoImpl.java deleted file mode 100755 index 305d9a3..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/generic/GenericDaoImpl.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.core.domain.dao.generic; - -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.io.Serializable; -import java.util.List; - -@Component -@Transactional -@SuppressWarnings({ "rawtypes", "unchecked" }) -public abstract class GenericDaoImpl implements GenericDao { - - @Resource(name = "sessionFactory") - private SessionFactory sessionFactory; - - protected Session getSession() { - return sessionFactory.getCurrentSession(); - } - - public id save(T entity) { - Session hibernateSession = this.getSession(); - return (id) hibernateSession.save(entity); - } - - public void merge(T entity) { - Session hibernateSession = this.getSession(); - hibernateSession.merge(entity); - } - - public void delete(T entity) { - Session hibernateSession = this.getSession(); - hibernateSession.delete(entity); - } - - public List findMany(Query query) { - List t; - t = (List) query.list(); - return t; - } - - public T findOne(Query query) { - T t; - t = (T) query.uniqueResult(); - return t; - } - - public T findByID(Class clazz, Long id) { - Session hibernateSession = this.getSession(); - T t = null; - t = (T) hibernateSession.get(clazz, id); - return t; - } - - public List findAll(Class clazz) { - Session hibernateSession = this.getSession(); - List T = null; - Query query = hibernateSession.createQuery("from " + clazz.getName()); - T = query.list(); - return T; - } -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/FavoriteDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/FavoriteDaoImpl.java deleted file mode 100755 index 5116dd3..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/FavoriteDaoImpl.java +++ /dev/null @@ -1,184 +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.FavoriteDao; -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 com.emc.metalnx.core.domain.entity.DataGridUserFavorite; -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.Date; -import java.util.Iterator; -import java.util.List; - -@Repository -@SuppressWarnings("unchecked") -public class FavoriteDaoImpl extends GenericDaoImpl implements FavoriteDao { - - private static final Logger logger = LoggerFactory.getLogger(FavoriteDaoImpl.class); - - @Autowired - private SessionFactory sessionFactory; - - @Autowired - UserDao userDao; - - @Override - public DataGridUserFavorite findByUserAndPath(DataGridUser user, String path) { - if(user == null || path == null || path.isEmpty()) return null; - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserFavorite where user_id = :user_id and path = :path"); - q.setLong("user_id", user.getId()); - q.setString("path", path); - return (DataGridUserFavorite) q.uniqueResult(); - } - - @Override - public Long addByUserAndPath(DataGridUser user, String path, boolean isCollection) { - - String parentPath = path.substring(0, path.lastIndexOf("/")); - if (parentPath.isEmpty()) { - parentPath = "/"; - } - String fileName = path != null ? path.substring(path.lastIndexOf("/") + 1, path.length()) : ""; - - DataGridUserFavorite favorite = new DataGridUserFavorite(); - favorite.setUser(user); - favorite.setPath(path); - favorite.setPathHash(path.hashCode()); - favorite.setName(fileName); - favorite.setCreateTs(new Date()); - favorite.setIsCollection(isCollection); - return save(favorite); - } - - @Override - public boolean removeByUserAndPath(DataGridUser user, String path) { - - boolean operationResult = true; - - logger.info("Attempting to remove favorite on {} from user {}", path, user.getUsername()); - try { - DataGridUserFavorite favorite = findByUserAndPath(user, path); - delete(favorite); - logger.info("Successfully removed favorite {} from user{}", path, user.getUsername()); - } - catch (Exception e) { - operationResult = false; - logger.error("Could not remove favorite on {} from user {}: {}", path, user.getUsername(), e.getMessage()); - } - - return operationResult; - } - - @Override - public List findByUser(DataGridUser user) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserFavorite where user_id = :user_id"); - q.setLong("user_id", user.getId()); - return q.list(); - } - - @Override - public List findByUserPaginated(DataGridUser user, int offset, int limit, String searchString, String orderBy, - String orderDir, boolean onlyCollections) { - String queryString = "from DataGridUserFavorite where user_id = :user_id and path like :path "; - if (onlyCollections) { - queryString += " and is_collection = true "; - } - queryString += " order by " + orderBy + " " + orderDir; - Query q = sessionFactory.getCurrentSession().createQuery(queryString); - q.setLong("user_id", user.getId()); - q.setString("path", '%' + searchString + '%'); - q.setFirstResult(offset); - q.setMaxResults(limit); - return q.list(); - } - - @Override - public List findFavoritesByPath(String path) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserFavorite where path = :path"); - q.setString("path", path); - return q.list(); - } - - @Override - public boolean removeByPath(String path) { - logger.debug("Removing favorite by path: {} ", path); - boolean removalSuccessful = false; - - try { - List favorites = findFavoritesByPath(path); - Iterator it = favorites.iterator(); - while (it.hasNext()) { - DataGridUserFavorite favorite = it.next(); - logger.debug("Removing favorite {} from database", favorite.getPath()); - delete(favorite); - } - - removalSuccessful = true; - } - catch (Exception e) { - logger.error("Could not remove favorite for path {} ", path); - } - - return removalSuccessful; - } - - @Override - public boolean removeByParentPath(String parentPath) { - logger.debug("Removing favorite by relative path: {} ", parentPath); - boolean removalSuccessful = false; - - try { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserFavorite where path LIKE :path"); - q.setString("path", parentPath + "%"); - - List favorites = q.list(); - - Iterator favoritesIterator = favorites.iterator(); - while (favoritesIterator.hasNext()) { - DataGridUserFavorite currFavorite = favoritesIterator.next(); - logger.debug("Removing relative favorite {} from database", currFavorite.getPath()); - delete(currFavorite); - } - } - catch (Exception e) { - logger.error("Could not relative paths on favorite for path {} ", parentPath); - } - - return removalSuccessful; - } - - @Override - public boolean removeByUser(DataGridUser user) { - logger.debug("Removing favorite by user: {} ", user.getUsername()); - boolean removalSuccessful = false; - - try { - List favorites = findByUser(user); - Iterator it = favorites.iterator(); - while (it.hasNext()) { - DataGridUserFavorite favorite = it.next(); - logger.debug("Removing favorite {} from database", favorite.getPath()); - delete(favorite); - } - - removalSuccessful = true; - } - catch (Exception e) { - logger.error("Could not remove favorite for user {} ", user.getUsername()); - } - - return removalSuccessful; - } - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/TemplateDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/TemplateDaoImpl.java deleted file mode 100755 index 8a2d5d8..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/TemplateDaoImpl.java +++ /dev/null @@ -1,133 +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.TemplateDao; -import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; -import com.emc.metalnx.core.domain.entity.DataGridTemplate; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; -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 TemplateDaoImpl extends GenericDaoImplimplements TemplateDao { - - @Autowired - private SessionFactory sessionFactory; - - @Override - public long getTemplateId(String templateName) { - DataGridTemplate dataGridTemplate = this.findByName(templateName); - - if (dataGridTemplate == null) { - return -1; - } - - return dataGridTemplate.getId(); - } - - @Override - public DataGridTemplate findById(long id) { - - Query q = this.sessionFactory.getCurrentSession().createQuery("from DataGridTemplate where template_id=(:id)"); - q.setParameter("id", id); - - return (DataGridTemplate) q.uniqueResult(); - } - - @Override - public DataGridTemplate findByName(String templateName) { - - Query q = this.sessionFactory.getCurrentSession() - .createQuery("from DataGridTemplate where template_name = :templateName"); - q.setString("templateName", templateName); - - return (DataGridTemplate) q.uniqueResult(); - } - - @Override - public boolean deleteById(long id) { - DataGridTemplate dataGridTemplate = this.findById(id); - - if (dataGridTemplate == null) { - return false; - } - - this.delete(dataGridTemplate); - - return true; - } - - @Override - public List findByQueryString(String query) { - Query q = this.sessionFactory.getCurrentSession() - .createQuery("from DataGridTemplate where template_name like :templateName"); - - q.setParameter("templateName", "%" + query + "%"); - - // Returning results - return q.list(); - } - - @Override - public List listTemplateFields(Long id) { - Query q = this.sessionFactory.getCurrentSession() - .createQuery("from DataGridTemplateField where template_id = :templateID"); - - q.setParameter("templateID", id); - - // Returning results - return q.list(); - } - - @Override - public List listTemplateFields(String template) { - long id = this.getTemplateId(template); - - if (id > 0) { - return this.listTemplateFields(id); - } - - return new ArrayList(); - } - - @Override - public List listPublicTemplates() { - Query q = this.sessionFactory.getCurrentSession() - .createQuery("from DataGridTemplate where access_type = :accessType"); - - q.setParameter("accessType", "system"); - - // Returning results - return q.list(); - } - - @Override - public List listPrivateTemplatesByUser(String user) { - Query q = this.sessionFactory.getCurrentSession() - .createQuery("from DataGridTemplate where access_type = :accessType and owner = :owner"); - - q.setParameter("accessType", "private"); - q.setParameter("owner", user); - - // Returning results - return q.list(); - } - - @Override - public void merge(DataGridTemplate template) { - if (template.isModified()) { - template.setVersion(template.getVersion() + 1); - } - - super.merge(template); - } -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/TemplateFieldsDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/TemplateFieldsDaoImpl.java deleted file mode 100755 index 5179cea..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/TemplateFieldsDaoImpl.java +++ /dev/null @@ -1,50 +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.TemplateFieldDao; -import com.emc.metalnx.core.domain.dao.generic.GenericDaoImpl; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException; -import org.hibernate.Query; -import org.hibernate.SessionFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -@SuppressWarnings("unchecked") -@Repository -public class TemplateFieldsDaoImpl extends GenericDaoImpl implements TemplateFieldDao { - - @Autowired - private SessionFactory sessionFactory; - - @Override - public DataGridTemplateField findById(long id) { - - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridTemplateField where template_field_id=(:id)"); - q.setParameter("id", id); - - return (DataGridTemplateField) q.uniqueResult(); - } - - @Override - public boolean modifyById(long id, String attribute, String value, String unit) throws DataGridTemplateAttrException, - DataGridTemplateValueException, DataGridTemplateUnitException { - DataGridTemplateField templateField = findById(id); - - if (templateField == null) { - return false; - } - - templateField.setAttribute(attribute); - templateField.setValue(value); - templateField.setUnit(unit); - merge(templateField); - - return true; - } -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserBookmarkDaoImpl.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserBookmarkDaoImpl.java deleted file mode 100755 index 25fa820..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserBookmarkDaoImpl.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.UserBookmarkDao; -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 com.emc.metalnx.core.domain.entity.DataGridUserBookmark; -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 UserBookmarkDaoImpl extends GenericDaoImpl implements UserBookmarkDao { - - private static final Logger logger = LoggerFactory.getLogger(UserBookmarkDaoImpl.class); - - @Autowired - private SessionFactory sessionFactory; - - @Autowired - UserDao userDao; - - @Override - public DataGridUserBookmark findByUserAndPath(DataGridUser user, String path) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark where user_id = :user_id and path = :path"); - q.setLong("user_id", user.getId()); - q.setString("path", path); - return (DataGridUserBookmark) q.uniqueResult(); - } - - @Override - public Long addByUserAndPath(DataGridUser user, String path, boolean isCollection) { - - String parentPath = path.substring(0, path.lastIndexOf("/")); - if (parentPath.isEmpty()) { - parentPath = "/"; - } - - String fileName = path != null ? path : ""; - fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); - - DataGridUserBookmark bookmark = new DataGridUserBookmark(); - bookmark.setUser(user); - bookmark.setPath(path); - bookmark.setName(fileName); - bookmark.setCreateTs(new Date()); - bookmark.setIsNotified(false); - bookmark.setIsCollection(isCollection); - return save(bookmark); - } - - @Override - public boolean removeByUserAndPath(DataGridUser user, String path) { - - boolean operationResult = true; - - logger.info("Attempting to remove bookmark on {} from user {}", path, user.getUsername()); - try { - DataGridUserBookmark bookmark = findByUserAndPath(user, path); - delete(bookmark); - logger.info("Successfully removed bookmark {} from user{}", path, user.getUsername()); - } - catch (Exception e) { - operationResult = false; - logger.error("Could not remove bookmark on {} from user {}: {}", path, user.getUsername(), e.getMessage()); - } - - return operationResult; - } - - @Override - public List findByUser(DataGridUser user) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark where user_id = :user_id"); - q.setLong("user_id", user.getId()); - return q.list(); - } - - @Override - public List findBookmarksByPath(String path) { - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark 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()) { - DataGridUserBookmark 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()) { - DataGridUserBookmark 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 List findByUserPaginated(DataGridUser user, int start, int length, String searchString, String orderBy, - String orderDir, boolean onlyCollections) { - List orderByList = new ArrayList(); - orderByList.add(orderBy); - - List orderDirList = new ArrayList(); - orderDirList.add(orderDir); - - return this.findByUserPaginated(user, start, length, searchString, orderByList, orderDirList, onlyCollections); - } - - @Override - public List findByUserPaginated(DataGridUser user, int start, int length, String searchString, List orderBy, - List orderDir, boolean onlyCollections) { - - if (orderBy.size() != orderDir.size()) { - return null; - } - - StringBuilder query = new StringBuilder(); - query.append("from DataGridUserBookmark "); - query.append("where "); - query.append("user_id = :user_id "); - query.append("and "); - query.append("path like :path "); - if (onlyCollections) { - query.append("and is_collection = true "); - } - query.append("order by "); - - for (int i = 0; i < orderBy.size(); i++) { - query.append(orderBy.get(i)); - query.append(" "); - query.append(orderDir.get(i)); - query.append(" "); - if (i + 1 < orderBy.size()) { - query.append(","); - } - } - - Query q = sessionFactory.getCurrentSession().createQuery(query.toString()); - q.setLong("user_id", user.getId()); - q.setString("path", '%' + searchString + '%'); - q.setFirstResult(start); - q.setMaxResults(length); - return q.list(); - } - - @Override - public boolean removeByUser(DataGridUser user) { - - boolean operationResult = true; - Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUserBookmark where user_id = :user_id"); - q.setLong("user_id", user.getId()); - List bookmarks = q.list(); - Iterator it = bookmarks.iterator(); - - try { - while (it.hasNext()) { - delete(it.next()); - } - } - catch (Exception e) { - operationResult = false; - } - - return operationResult; - } - - @Override - public boolean updateBookmark(String oldPath, String newPath) { - logger.info("Updating bookmark for user"); - - if (oldPath == null || newPath == null) { - logger.info("Could not update bookmark for user. 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; - } - - String newBookmarkName = newPath.substring(newPath.lastIndexOf("/") + 1, newPath.length()); - - Query q = sessionFactory.getCurrentSession().createQuery("update DataGridUserBookmark set path = :newPath, name = :name where path = :oldPath"); - q.setString("newPath", newPath); - q.setString("name", newBookmarkName); - q.setString("oldPath", oldPath); - logger.info("update query for user: " + q); - return q.executeUpdate() > 0; - } -} 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 deleted file mode 100755 index e96855e..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java +++ /dev/null @@ -1,129 +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 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 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 { - - 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/entity/DataGridMetadataFields.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridMetadataFields.java deleted file mode 100755 index d30d46a..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridMetadataFields.java +++ /dev/null @@ -1,157 +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 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 org.hibernate.envers.Audited; -import org.hibernate.envers.NotAudited; - -@Entity -//@Audited -@Table(name = "metadata_fields") -public class DataGridMetadataFields implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - @Id - @NotAudited - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id", unique = true, nullable = false) - private Long id; - - @Column(name = "attribute", length = 60) - private String attribute; - - @Column(name = "attribute_value", length = 60) - private String attributeValue; - - @Column(name = "attribute_unit", length = 60) - private String attributeUnit; - - @Column(name = "start_range") - private float startRange; - - @Column(name = "end_range") - private float endRange; - - @Column(name = "field_order") - private int order; - - @ManyToOne(fetch = FetchType.EAGER, optional = true) - @JoinColumn(name = "template_id", nullable = false, updatable = true) - private DataGridTemplate template; - - public DataGridMetadataFields() { - - } - - public DataGridMetadataFields(String attribute, String value, String unit) { - this.attribute = attribute; - this.attributeValue = value; - this.attributeUnit = unit; - } - - /** - * @return the id - */ - public long getId() { - return id; - } - - /** - * @param id - * the id to set - */ - public void setId(long id) { - this.id = id; - } - - /** - * @return the attribute - */ - public String getAttribute() { - return attribute; - } - - /** - * @param attribute - * the attribute to set - */ - public void setAttribute(String attribute) { - this.attribute = attribute; - } - - /** - * @return the value - */ - public String getValue() { - return attributeValue; - } - - /** - * @param value - * the value to set - */ - public void setValue(String value) { - this.attributeValue = value; - } - - /** - * @return the unit - */ - public String getUnit() { - return attributeUnit; - } - - /** - * @param unit - * the unit to set - */ - public void setUnit(String unit) { - this.attributeUnit = unit; - } - - @Override - public int compareTo(DataGridMetadataFields dgmf) { - return this.attributeValue.compareTo(dgmf.getValue()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DataGridMetadataFields ["); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - if (attribute != null) { - builder.append("attribute=").append(attribute).append(", "); - } - if (attributeValue != null) { - builder.append("attributeValue=").append(attributeValue).append(", "); - } - if (attributeUnit != null) { - builder.append("attributeUnit=").append(attributeUnit).append(", "); - } - builder.append("startRange=").append(startRange).append(", endRange=").append(endRange).append(", order=") - .append(order).append(", "); - if (template != null) { - builder.append("template=").append(template); - } - builder.append("]"); - return builder.toString(); - } - -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridTemplate.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridTemplate.java deleted file mode 100755 index 7f3d298..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridTemplate.java +++ /dev/null @@ -1,311 +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.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -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.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -import org.hibernate.envers.NotAudited; - -import com.emc.metalnx.core.domain.exceptions.DataGridTooLongTemplateNameException; - -@Entity -//@Audited -@Table(name = "templates") -public class DataGridTemplate implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - @Id - @NotAudited - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "template_id", unique = true, nullable = false) - private Long id; - - @Column(name = "template_name", unique = true, nullable = false, length = 100) - private String templateName; - - @Column(name = "owner", nullable = false, length = 100) - private String owner; - - @Column(name = "description", nullable = false, length = 512) - private String description; - - @Column(name = "usage_info", length = 100) - private String usageInformation; - - @Column(name = "access_type", length = 32) - private String accessType; - - @Column(name = "version") - private Integer version; - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "create_ts", nullable = false, length = 60, updatable = false) - private Date createTs; - - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "modify_ts", nullable = false, length = 60) - private Date modifyTs; - - @OneToMany(mappedBy = "template", fetch = FetchType.EAGER) - private Set fields = new HashSet<>(); - - private static final int TEMPLATE_NAME_MAX_LENGTH = 100; - private static final int TEMPLATE_DESC_MAX_LENGTH = 100; - - private boolean isModified = false; - - public DataGridTemplate() { - // empty constructor - } - - public DataGridTemplate(String templateName) throws DataGridTooLongTemplateNameException { - if (templateName.length() > TEMPLATE_NAME_MAX_LENGTH) { - throw new DataGridTooLongTemplateNameException( - "Template name exceeded " + TEMPLATE_NAME_MAX_LENGTH + " characters."); - } - - this.templateName = templateName; - } - - /** - * @return the owner - */ - public String getOwner() { - return owner; - } - - /** - * @param owner the owner to set - */ - public void setOwner(String owner) { - this.owner = owner; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - * @throws DataGridTooLongTemplateNameException - */ - public void setDescription(String description) throws DataGridTooLongTemplateNameException { - if (description.length() > TEMPLATE_NAME_MAX_LENGTH) { - throw new DataGridTooLongTemplateNameException( - "Template description exceeded " + TEMPLATE_DESC_MAX_LENGTH + " characters."); - } - this.description = description; - } - - /** - * @return the createTs - */ - public Date getCreateTs() { - return createTs; - } - - /** - * @param createTs the createTs to set - */ - public void setCreateTs(Date createTs) { - this.createTs = createTs; - } - - /** - * @return the modifyTs - */ - public Date getModifyTs() { - return modifyTs; - } - - /** - * @param modifyTs the modifyTs to set - */ - public void setModifyTs(Date modifyTs) { - this.modifyTs = modifyTs; - } - - /** - * @return the id - */ - public long getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(long id) { - this.id = id; - } - - /** - * @return the templateName - */ - public String getTemplateName() { - return templateName; - } - - /** - * @param the templateName to set - * @throws DataGridTooLongTemplateNameException - */ - public void setTemplateName(String templateName) throws DataGridTooLongTemplateNameException { - if (templateName.length() > TEMPLATE_NAME_MAX_LENGTH) { - throw new DataGridTooLongTemplateNameException( - "Template name exceeded " + TEMPLATE_NAME_MAX_LENGTH + " characters."); - } - - this.templateName = templateName; - } - - /** - * @return the usageInformation - */ - public String getUsageInformation() { - return usageInformation; - } - - /** - * @param usageInformation the usageInformation to set - */ - public void setUsageInformation(String usageInformation) { - this.usageInformation = usageInformation; - } - - /** - * @return the accessType - */ - public String getAccessType() { - return accessType; - } - - /** - * @param accessType the accessType to set - */ - public void setAccessType(String accessType) { - this.accessType = accessType; - } - - /** - * @return the fields - */ - public Set getFields() { - return fields; - } - - /** - * @param fields the fields to set - */ - public void setFields(Set fields) { - this.fields = fields; - } - - /** - * @return the version - */ - public Integer getVersion() { - return version; - } - - /** - * @param version the version to set - */ - public void setVersion(Integer version) { - this.version = version; - } - - /** - * @return the isModified - */ - public boolean isModified() { - return isModified; - } - - /** - * @param isModified the isModified to set - */ - public void setModified(boolean isModified) { - this.isModified = isModified; - } - - @Override - public int compareTo(DataGridTemplate dgt) { - return templateName.compareTo(dgt.getTemplateName()); - } - - @Override - public String toString() { - final int maxLen = 10; - StringBuilder builder = new StringBuilder(); - builder.append("DataGridTemplate ["); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - if (templateName != null) { - builder.append("templateName=").append(templateName).append(", "); - } - if (owner != null) { - builder.append("owner=").append(owner).append(", "); - } - if (description != null) { - builder.append("description=").append(description).append(", "); - } - if (usageInformation != null) { - builder.append("usageInformation=").append(usageInformation).append(", "); - } - if (accessType != null) { - builder.append("accessType=").append(accessType).append(", "); - } - if (version != null) { - builder.append("version=").append(version).append(", "); - } - if (createTs != null) { - builder.append("createTs=").append(createTs).append(", "); - } - if (modifyTs != null) { - builder.append("modifyTs=").append(modifyTs).append(", "); - } - if (fields != null) { - builder.append("fields=").append(toString(fields, maxLen)).append(", "); - } - builder.append("isModified=").append(isModified).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/DataGridTemplateField.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridTemplateField.java deleted file mode 100755 index b0d193e..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridTemplateField.java +++ /dev/null @@ -1,290 +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 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 org.hibernate.envers.NotAudited; - -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException; - -@Entity -//@Audited -@Table(name = "template_fields") -public class DataGridTemplateField implements Serializable, Comparable { - - private static final long serialVersionUID = 1L; - - private final int MAX_ATTR_LENGTH = 100; - private final int MAX_VAL_LENGTH = 100; - private final int MAX_UNT_LENGTH = 100; - - @Id - @NotAudited - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "template_field_id", unique = true, nullable = false) - private Long id; - - @Column(name = "attribute", length = MAX_ATTR_LENGTH) - private String attribute; - - @Column(name = "attribute_value", length = MAX_VAL_LENGTH) - private String attributeValue; - - @Column(name = "attribute_unit", length = MAX_UNT_LENGTH) - private String attributeUnit; - - @Column(name = "start_range") - private float startRange; - - @Column(name = "end_range") - private float endRange; - - @Column(name = "field_order") - private int order; - - @ManyToOne(fetch = FetchType.EAGER, optional = true) - @JoinColumn(name = "template_id", nullable = false, updatable = true) - private DataGridTemplate template; - - public DataGridTemplateField() { - - } - - public DataGridTemplateField(String attribute, String value, String unit, DataGridTemplate template) - throws DataGridTemplateAttrException, DataGridTemplateValueException, DataGridTemplateUnitException { - if (attribute == null || attribute.length() > MAX_ATTR_LENGTH) { - throw new DataGridTemplateAttrException( - "Template attribute is null or exceed " + MAX_ATTR_LENGTH + " characters."); - } - - if (value == null || value.length() > MAX_VAL_LENGTH) { - throw new DataGridTemplateValueException( - "Template attribute is null or exceed " + MAX_ATTR_LENGTH + " characters."); - } - - if (unit == null || unit.length() > MAX_UNT_LENGTH) { - throw new DataGridTemplateUnitException( - "Template attribute is null or exceed " + MAX_ATTR_LENGTH + " characters."); - } - - this.attribute = attribute; - attributeValue = value; - attributeUnit = unit; - this.template = template; - } - - public DataGridTemplateField(String attribute, String value, String unit) - throws DataGridTemplateAttrException, DataGridTemplateValueException, DataGridTemplateUnitException { - this(attribute, value, unit, null); - } - - /** - * @return the id - */ - public Long getId() { - return id; - } - - /** - * @param id the id to set - */ - public void setId(long id) { - this.id = id; - } - - /** - * @return the attribute - */ - public String getAttribute() { - return attribute; - } - - /** - * @param attribute the attribute to set - * @throws DataGridTemplateAttrException - */ - public void setAttribute(String attribute) throws DataGridTemplateAttrException { - if (attribute == null || attribute.length() > MAX_ATTR_LENGTH) { - throw new DataGridTemplateAttrException( - "Template attribute is null or exceed " + MAX_ATTR_LENGTH + " characters."); - } - - this.attribute = attribute; - } - - /** - * @return the value - */ - public String getValue() { - return attributeValue; - } - - /** - * @param value the value to set - * @throws DataGridTemplateValueException - */ - public void setValue(String value) throws DataGridTemplateValueException { - if (value == null || value.length() > MAX_VAL_LENGTH) { - throw new DataGridTemplateValueException( - "Template attribute is null or exceed " + MAX_ATTR_LENGTH + " characters."); - } - - attributeValue = value; - } - - /** - * @return the unit - */ - public String getUnit() { - return attributeUnit; - } - - /** - * @param unit the unit to set - * @throws DataGridTemplateUnitException - */ - public void setUnit(String unit) throws DataGridTemplateUnitException { - if (unit == null || unit.length() > MAX_UNT_LENGTH) { - throw new DataGridTemplateUnitException( - "Template attribute is null or exceed " + MAX_ATTR_LENGTH + " characters."); - } - - attributeUnit = unit; - } - - /** - * @return the template - */ - public DataGridTemplate getTemplate() { - return template; - } - - /** - * @param template the template to set - */ - public void setTemplate(DataGridTemplate template) { - this.template = template; - } - - /** - * @return the startRange - */ - public float getStartRange() { - return startRange; - } - - /** - * @param startRange the startRange to set - */ - public void setStartRange(float startRange) { - this.startRange = startRange; - } - - /** - * @return the endRange - */ - public float getEndRange() { - return endRange; - } - - /** - * @param endRange the endRange to set - */ - public void setEndRange(float endRange) { - this.endRange = endRange; - } - - /** - * @return the order - */ - public int getOrder() { - return order; - } - - /** - * @param order the order to set - */ - public void setOrder(int order) { - this.order = order; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DataGridTemplateField [MAX_ATTR_LENGTH=").append(MAX_ATTR_LENGTH).append(", MAX_VAL_LENGTH=") - .append(MAX_VAL_LENGTH).append(", MAX_UNT_LENGTH=").append(MAX_UNT_LENGTH).append(", "); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - if (attribute != null) { - builder.append("attribute=").append(attribute).append(", "); - } - if (attributeValue != null) { - builder.append("attributeValue=").append(attributeValue).append(", "); - } - if (attributeUnit != null) { - builder.append("attributeUnit=").append(attributeUnit).append(", "); - } - builder.append("startRange=").append(startRange).append(", endRange=").append(endRange).append(", order=") - .append(order).append(", "); - - builder.append("]"); - return builder.toString(); - } - - @Override - public int compareTo(DataGridTemplateField dgmf) { - if (attribute != null) { - return attribute.compareTo(dgmf.getAttribute()); - } else if (attributeValue != null) { - return attributeValue.compareTo(dgmf.getValue()); - } else if (attributeUnit != null) { - return attributeUnit.compareTo(dgmf.getUnit()); - } - - return 0; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - - if (obj instanceof DataGridTemplateField) { - DataGridTemplateField dgmf = (DataGridTemplateField) obj; - - if (dgmf.getAttribute() == null || dgmf.getValue() == null) { - return false; - } - - boolean areAttributesEqual = getAttribute().equals(dgmf.getAttribute()); - boolean areValuesEqual = getValue().equals(dgmf.getValue()); - - if (areAttributesEqual && areValuesEqual) { - return true; - } - } - - return false; - } - - @Override - public int hashCode() { - return (getAttribute() + getValue()).hashCode(); - } -} diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUser.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUser.java index 4f3cbe3..9abb5ea 100755 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUser.java +++ b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUser.java @@ -9,91 +9,31 @@ import java.util.List; 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.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import org.hibernate.envers.NotAudited; - -@Entity -// @Audited -@Table(name = "users", uniqueConstraints = @UniqueConstraint(columnNames = { "username", "additional_info" })) + public class DataGridUser implements Serializable, Comparable { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @NotAudited private Long id; - @Column(name = "data_grid_id", unique = true, nullable = false) private long dataGridId; - @Column(name = "username", nullable = false, length = 60, unique = true) private String username; private String password; - @Column(name = "additional_info", nullable = true, length = 128) private String additionalInfo; - @Column(name = "enabled", nullable = false) private boolean enabled; - @Column(name = "first_name") - private String firstName; - - @Column(name = "last_name") - private String lastName; - - @Column(name = "email", nullable = true) - private String email; - - @Column(name = "locale") private String locale = "en"; - @Column(name = "forceFileOverwriting", nullable = false) private boolean forceFileOverwriting = false; - @Column(name = "user_type", nullable = false, length = 60) private String userType; - @Column(name = "organizational_role", nullable = true, length = 60) - private String organizationalRole; - - @ManyToOne(fetch = FetchType.EAGER, optional = true) - @JoinColumn(name = "userProfile_id", nullable = true, updatable = true) - private UserProfile userProfile; - - @Column(name = "user_company", nullable = true, length = 60) - private String company; - - @Column(name = "user_department", nullable = true, length = 60) - private String department; - - @Column(name = "user_title", nullable = true, length = 60) - private String title; - - @Column(name = "advanced_view", nullable = false) private boolean advancedView; - @Column(name = "metadata_unit_view", nullable = false) private boolean metadataUnitView; - @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.DETACH, orphanRemoval = true) - private Set bookmarks; - - @OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.DETACH, orphanRemoval = true) - private Set favorites; - private static final long serialVersionUID = -500578459147421831L; public DataGridUser() { @@ -106,63 +46,9 @@ public DataGridUser(String username, String password, boolean enabled) { } public String getDisplayName() { - if (firstName != null && !firstName.isEmpty()) { - return firstName; - } - return username; } - /** - * Gets the user bookmarks sorted in ascending order - * - * @return the userBookmarks - */ - public List getBookmarksSorted() { - List bookmarksSorted = new ArrayList(bookmarks); - Collections.sort(bookmarksSorted); - return bookmarksSorted; - } - - /** - * @return the userBookmarks - */ - public Set getBookmarks() { - return bookmarks; - } - - /** - * @param userBookmarks the userBookmarks to set - */ - public void setUserBookmarks(Set userBookmarks) { - bookmarks = userBookmarks; - } - - /** - * Gets the user favorites sorted in ascending order - * - * @return the userFavorites - */ - public List getFavoritesSorted() { - List favoritesSorted = new ArrayList(favorites); - Collections.sort(favoritesSorted); - return favoritesSorted; - } - - /** - * @return the userFavorites - */ - public Set getFavorites() { - return favorites; - } - - /** - * @param userFavorites the userFavorites to set - */ - public void setUserFavorites(Set userFavorites) { - favorites = userFavorites; - } - /** * @return the id */ @@ -261,62 +147,6 @@ public void setMetadataUnitView(boolean metadataUnitView) { this.metadataUnitView = metadataUnitView; } - /** - * @return the firstName - */ - public String getFirstName() { - return firstName; - } - - /** - * @return the lastName - */ - public String getLastName() { - return lastName; - } - - /** - * @param firstName the firstName to set - */ - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - /** - * @param lastName the lastName to set - */ - public void setLastName(String lastName) { - this.lastName = lastName; - } - - /** - * @return the email - */ - public String getEmail() { - return email; - } - - /** - * @param email the email to set - */ - public void setEmail(String email) { - this.email = email; - } - - /** - * @return the userProfile - */ - public UserProfile getUserProfile() { - return userProfile; - } - - /** - * @param userProfile the userProfile to set - */ - public void setUserProfile(UserProfile userProfile) { - this.userProfile = userProfile; - } - /** * @return the locale */ @@ -339,62 +169,6 @@ public void setUserType(String userType) { this.userType = userType; } - /** - * @return the organizationalRole - */ - public String getOrganizationalRole() { - return organizationalRole; - } - - /** - * @param organizationalRole the organizationalRole to set - */ - public void setOrganizationalRole(String organizationalRole) { - this.organizationalRole = organizationalRole; - } - - /** - * @return the company - */ - public String getCompany() { - return company; - } - - /** - * @return the department - */ - public String getDepartment() { - return department; - } - - /** - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * @param company the company to set - */ - public void setCompany(String company) { - this.company = company; - } - - /** - * @param department the department to set - */ - public void setDepartment(String department) { - this.department = department; - } - - /** - * @param title the title to set - */ - public void setTitle(String title) { - this.title = title; - } - @Override public int compareTo(DataGridUser o) { return username.compareTo(o.getUsername()); @@ -454,15 +228,6 @@ public String toString() { builder.append("additionalInfo=").append(additionalInfo).append(", "); } builder.append("enabled=").append(enabled).append(", "); - if (firstName != null) { - builder.append("firstName=").append(firstName).append(", "); - } - if (lastName != null) { - builder.append("lastName=").append(lastName).append(", "); - } - if (email != null) { - builder.append("email=").append(email).append(", "); - } if (locale != null) { builder.append("locale=").append(locale).append(", "); } @@ -470,32 +235,8 @@ public String toString() { if (userType != null) { builder.append("userType=").append(userType).append(", "); } - if (organizationalRole != null) { - builder.append("organizationalRole=").append(organizationalRole).append(", "); - } - if (userProfile != null) { - builder.append("userProfile=").append(userProfile).append(", "); - } - if (company != null) { - builder.append("company=").append(company).append(", "); - } - if (department != null) { - builder.append("department=").append(department).append(", "); - } - if (title != null) { - builder.append("title=").append(title).append(", "); - } builder.append("advancedView=").append(advancedView).append(", "); - if (bookmarks != null) { - builder.append("bookmarks=").append(bookmarks).append(", "); - } builder.append("metadataUnitView=").append(metadataUnitView).append(", "); - if (bookmarks != null) { - builder.append("bookmarks=").append(bookmarks).append(", "); - } - if (favorites != null) { - builder.append("favorites=").append(favorites); - } builder.append("]"); return builder.toString(); } diff --git a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUserBookmark.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUserBookmark.java deleted file mode 100755 index ed5b699..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUserBookmark.java +++ /dev/null @@ -1,211 +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; -import com.fasterxml.jackson.annotation.JsonIgnore; - -@Entity -//@Audited -@Table(name = "user_bookmarks") -public class DataGridUserBookmark 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 = "user_id", nullable = false, updatable = true) - private DataGridUser user; - - @Column(name = "path", nullable = false, length = 512) - private String path; - - @Column(name = "name", nullable = false, length = 512) - private String name; - - @Column(name = "is_notified", nullable = true) - private Boolean isNotified; - - @Column(name = "is_collection", nullable = false) - 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 user - */ - @JsonIgnore - public DataGridUser getUser() { - return user; - } - - /** - * @return the path - */ - public String getPath() { - return path; - } - - /** - * @return the isNotified - */ - public Boolean getIsNotified() { - return isNotified; - } - - /** - * @return the createTs - */ - public Date getCreateTs() { - return createTs; - } - - public String getCreateTsFormatted() { - return new SimpleDateFormat("MMM dd yyyy, HH:mm").format(createTs); - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the isCollection - */ - public Boolean getIsCollection() { - return isCollection; - } - - /** - * @param isCollection - * the isCollection to set - */ - public void setIsCollection(Boolean isCollection) { - this.isCollection = isCollection; - } - - /** - * @param id - * the id to set - */ - public void setId(Long id) { - this.id = id; - } - - /** - * @param user - * the user to set - */ - public void setUser(DataGridUser user) { - this.user = user; - } - - /** - * @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; - } - - /** - * @param createTs - * the createTs to set - */ - public void setCreateTs(Date createTs) { - this.createTs = createTs; - } - - /** - * 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(this.getPath()); - } - - @Override - public int compareTo(DataGridUserBookmark dgub) { - return this.getName().compareTo(dgub.getName()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DataGridUserBookmark ["); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - if (path != null) { - builder.append("path=").append(path).append(", "); - } - if (name != null) { - builder.append("name=").append(name).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/DataGridUserFavorite.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUserFavorite.java deleted file mode 100755 index 3610ac4..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/DataGridUserFavorite.java +++ /dev/null @@ -1,214 +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 javax.persistence.UniqueConstraint; - -import org.hibernate.envers.Audited; -import org.hibernate.envers.NotAudited; - -import com.emc.metalnx.core.domain.utils.DataGridCoreUtils; -import com.fasterxml.jackson.annotation.JsonIgnore; - -@Entity -//@Audited -@Table(name = "user_favorites", uniqueConstraints = @UniqueConstraint(columnNames = { "user_id", "path_hash" })) -public class DataGridUserFavorite 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 = "user_id", nullable = false, updatable = true) - private DataGridUser user; - - @Column(name = "path", nullable = false, length = 512) - private String path; - - @Column(name = "name", nullable = false, length = 512) - private String name; - - @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; - - @Column(name = "path_hash", nullable = false) - private int pathHash; - - private static final long serialVersionUID = -7923823760209937080L; - - /** - * @return the id - */ - @JsonIgnore - public Long getId() { - return id; - } - - /** - * @return the user - */ - @JsonIgnore - public DataGridUser getUser() { - return user; - } - - /** - * @return the path - */ - public String getPath() { - return path; - } - - /** - * @return the isCollection - */ - public boolean getIsCollection() { - return isCollection; - } - - /** - * @return the createTs - */ - @JsonIgnore - public Date getCreateTs() { - return createTs; - } - - public String getCreateTsFormatted() { - return new SimpleDateFormat("MMM dd yyyy, HH:mm").format(createTs); - } - - /** - * @param id - * the id to set - */ - public void setId(Long id) { - this.id = id; - } - - /** - * @param user - * the user to set - */ - public void setUser(DataGridUser user) { - this.user = user; - } - - /** - * @param path - * the path to set - */ - public void setPath(String path) { - this.path = path; - } - - /** - * @param fileName - * the fileName to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @param isNotified - * 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 getName() { - return this.name; - } - - /** - * @return the pathHash - */ - public int getPathHash() { - return pathHash; - } - - /** - * @param pathHash - * the pathHash to set - */ - public void setPathHash(int pathHash) { - this.pathHash = pathHash; - } - - /** - * 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(this.getPath()); - } - - @Override - public int compareTo(DataGridUserFavorite dgub) { - return this.getName().compareTo(dgub.getName()); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DataGridUserFavorite ["); - if (id != null) { - builder.append("id=").append(id).append(", "); - } - if (path != null) { - builder.append("path=").append(path).append(", "); - } - if (name != null) { - builder.append("name=").append(name).append(", "); - } - if (isCollection != null) { - builder.append("isCollection=").append(isCollection).append(", "); - } - if (createTs != null) { - builder.append("createTs=").append(createTs).append(", "); - } - builder.append("pathHash=").append(pathHash).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 deleted file mode 100755 index df2d641..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/entity/UserProfile.java +++ /dev/null @@ -1,146 +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.util.Collection; -import java.util.Iterator; -import java.util.Set; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -import org.hibernate.envers.NotAudited; - -@Entity -//@Audited -@Table(name = "user_profile") -public class UserProfile { - - @Id - @Column(name = "id") - @NotAudited - @GeneratedValue - private Long profileId; - - @Column(name = "profile_name", nullable = false, length = 64) - private String profileName; - - @Column(name = "description", nullable = false, length = 512) - private String description; - - @OneToMany(mappedBy = "userProfile", fetch = FetchType.EAGER) - private Set users; - - public UserProfile() { - - } - - public UserProfile(String profileName, String description) { - this.profileName = profileName; - this.description = description; - } - - public UserProfile(String profileName, String description, Set users) { - this.profileName = profileName; - this.description = description; - this.users = users; - } - - /** - * @return the profileId - */ - public Long getProfileId() { - return profileId; - } - - /** - * @param profileId the profileId to set - */ - public void setProfileId(Long profileId) { - this.profileId = profileId; - } - - /** - * @return the profileName - */ - public String getProfileName() { - return profileName; - } - - /** - * @param profileName the profileName to set - */ - public void setProfileName(String profileName) { - this.profileName = profileName; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the users - */ - public Set getUsers() { - return users; - } - - /** - * @param users the users to set - */ - public void setUsers(Set users) { - this.users = users; - } - - @Override - public String toString() { - final int maxLen = 10; - StringBuilder builder = new StringBuilder(); - builder.append("UserProfile ["); - if (profileId != null) { - builder.append("profileId=").append(profileId).append(", "); - } - if (profileName != null) { - builder.append("profileName=").append(profileName).append(", "); - } - if (description != null) { - builder.append("description=").append(description).append(", "); - } - - if (users != null) { - builder.append("users=").append(toString(users, 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/utils/DataGridTemplateFieldComparator.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/utils/DataGridTemplateFieldComparator.java deleted file mode 100755 index 7904355..0000000 --- a/emc-metalnx-core/src/main/java/com/emc/metalnx/core/domain/utils/DataGridTemplateFieldComparator.java +++ /dev/null @@ -1,31 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - - -package com.emc.metalnx.core.domain.utils; - -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; - -import java.util.Comparator; - -public class DataGridTemplateFieldComparator implements Comparator { - - @Override - public int compare(DataGridTemplateField o1, DataGridTemplateField o2) { - if (o1.getAttribute().compareTo(o2.getAttribute()) != 0) { - return o1.getAttribute().compareTo(o2.getAttribute()); - } - - else if (o1.getValue().compareTo(o2.getValue()) != 0) { - return o1.getValue().compareTo(o2.getValue()); - } - - else if (o1.getUnit().compareTo(o2.getUnit()) != 0) { - return o1.getUnit().compareTo(o2.getUnit()); - } - - return 0; - } - -} diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/IRODSServices.java b/emc-metalnx-core/src/main/java/com/emc/metalnx/services/interfaces/IRODSServices.java similarity index 100% rename from irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/IRODSServices.java rename to emc-metalnx-core/src/main/java/com/emc/metalnx/services/interfaces/IRODSServices.java diff --git a/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-context.xml b/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-context.xml index 0a6bec9..ef0f6a3 100755 --- a/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-context.xml +++ b/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-context.xml @@ -17,6 +17,4 @@ - - - \ No newline at end of file + diff --git a/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-jpa.xml b/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-jpa.xml deleted file mode 100755 index a922781..0000000 --- a/emc-metalnx-core/src/main/resources/META-INF/emc-metalnx-core/emc-metalnx-core-jpa.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - ${hibernate.dialect} - ${hibernate.format_sql} - ${hibernate.show_sql} - ${hibernate.hbm2ddl.auto} - - - - - - - - - - - - \ No newline at end of file diff --git a/emc-metalnx-services/pom.xml b/emc-metalnx-services/pom.xml index 9b40b16..9dc4b46 100755 --- a/emc-metalnx-services/pom.xml +++ b/emc-metalnx-services/pom.xml @@ -125,7 +125,7 @@ 0 validate - + - + run @@ -199,7 +199,7 @@ 2 validate - + - + run diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/auth/IRODSAuthenticationProvider.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/auth/IRODSAuthenticationProvider.java index 2d79488..718ba09 100755 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/auth/IRODSAuthenticationProvider.java +++ b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/auth/IRODSAuthenticationProvider.java @@ -215,8 +215,6 @@ private AuthResponse authenticateAgainstIRODS(String username, String password, user.setAdditionalInfo(irodsUser.getZone()); user.setDataGridId(Long.parseLong(irodsUser.getId())); user.setEnabled(true); - user.setFirstName(""); - user.setLastName(""); if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) { logger.debug("setting user type admin:{}", irodsUser.getUserType()); user.setUserType(UserTypeEnum.RODS_ADMIN.getTextValue()); @@ -227,15 +225,12 @@ private AuthResponse authenticateAgainstIRODS(String username, String password, logger.debug("setting user type rodsuser:{}", irodsUser.getUserType()); user.setUserType(UserTypeEnum.RODS_USER.getTextValue()); } - this.userDao.save(user); } else { // check for an update of user type if (user.getUserType() != irodsUser.getUserType().getTextValue()) { logger.info("updating user type based on iRODS current value"); user.setUserType(irodsUser.getUserType().getTextValue()); - this.userDao.merge(user); - logger.info("updated user type in db"); } } diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FavoritesServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FavoritesServiceImpl.java deleted file mode 100755 index 1c59819..0000000 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/FavoritesServiceImpl.java +++ /dev/null @@ -1,145 +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 java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.irodsext.dataprofiler.favorites.FavoritesService; -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 com.emc.metalnx.core.domain.dao.FavoriteDao; -import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.DataGridUserFavorite; -import com.emc.metalnx.services.interfaces.CollectionService; -import com.emc.metalnx.services.interfaces.IRODSServices; - -@Service("favoritesService") -@Transactional -public class FavoritesServiceImpl implements FavoritesService { - - @Autowired - IRODSServices irodsServices; - - @Autowired - CollectionService collectionService; - - @Autowired - FavoriteDao favoriteDao; - - private static final Logger logger = LoggerFactory.getLogger(FavoritesServiceImpl.class); - - /** - * Updates the favorites table for a user, whether be it to remove or add a path - * - * @param user - * @param set - * of paths to be added - * @param set - * of paths to be removed - * @return True, if operation is successful. False, otherwise. - */ - @Override - public boolean updateFavorites(DataGridUser user, Set toAdd, Set toRemove) { - - boolean operationResult = true; - - try { - if (toAdd != null) { - for (String path : toAdd) { - if (!findFavoritesForUserAsString(user).contains(path)) { - favoriteDao.addByUserAndPath(user, path, collectionService.isCollection(path)); - } - } - } - - if (toRemove != null) { - for (String path : toRemove) { - favoriteDao.removeByUserAndPath(user, path); - } - } - } catch (Exception e) { - operationResult = false; - logger.error("Could not modify favorite for {}", user.getUsername(), e); - } - - return operationResult; - } - - /** - * Returns a list of strings with each of them representing a path marked as - * favorite - * - * @param user - * @return List of paths marked as favorites by the user. - */ - @Override - public List findFavoritesForUserAsString(DataGridUser user) { - List favorites = favoriteDao.findByUser(user); - List strings = new ArrayList(); - - for (DataGridUserFavorite favorite : favorites) { - strings.add(favorite.getPath()); - } - - return strings; - } - - @Override - public List findFavoritesPaginated(DataGridUser user, int offset, int limit, - String searchString, String orderBy, String orderDir, boolean onlyCollections) { - List favorites = favoriteDao.findByUserPaginated(user, offset, limit, searchString, - orderBy, orderDir, onlyCollections); - return favorites; - } - - /** - * Removes path from database. This operation is used when the corresponding - * collection or file is deleted from the grid - * - * @param path - * @return True, if operation is successful. False, otherwise. - */ - @Override - public boolean removeFavoriteBasedOnPath(String path) { - return favoriteDao.removeByPath(path); - } - - /** - * Removes path from database. This operation is used when the corresponding - * collection or file is deleted from the grid - * - * @param path - * @return True, if operation is successful. False, otherwise. - */ - @Override - public boolean removeFavoriteBasedOnRelativePath(String path) { - return favoriteDao.removeByParentPath(path); - } - - /** - * Checks whether the parameter path is a favorite for parameter user - * - * @param user - * @param path - * @return True, if path is a favorite for user. False, otherwise. - */ - @Override - public boolean isPathFavoriteForUser(DataGridUser user, String path) { - return favoriteDao.findByUserAndPath(user, path) != null; - } - - @Override - public boolean removeFavoriteBasedOnUser(DataGridUser user) { - return favoriteDao.removeByUser(user); - } - -} 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 a297512..b19d96a 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 @@ -18,7 +18,6 @@ import org.irods.jargon.core.pub.io.IRODSFile; import org.irods.jargon.core.pub.io.IRODSFileFactory; import org.irods.jargon.core.pub.io.IRODSFileInputStream; -import org.irodsext.dataprofiler.favorites.FavoritesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +33,6 @@ import com.emc.metalnx.services.interfaces.IRODSServices; import com.emc.metalnx.services.interfaces.MetadataService; import com.emc.metalnx.services.interfaces.RuleService; -import com.emc.metalnx.services.interfaces.UserBookmarkService; @Service @Transactional @@ -47,12 +45,6 @@ public class FileOperationServiceImpl implements FileOperationService { @Autowired private IRODSServices irodsServices; - @Autowired - private UserBookmarkService userBookmarkService; - - @Autowired - private FavoritesService favoritesService; - @Autowired private MetadataService metadataService; @@ -134,13 +126,6 @@ public boolean deleteItem(String path, boolean force) throws DataGridConnectionR itemDeleted = true; - // item deleted, we need to delete any bookmarks related to it - userBookmarkService.removeBookmarkBasedOnPath(path); - userBookmarkService.removeBookmarkBasedOnRelativePath(path); - - favoritesService.removeFavoriteBasedOnPath(path); - favoritesService.removeFavoriteBasedOnRelativePath(path); - } catch (JargonException e) { logger.error("Could not delete item " + path + ": ", e); } 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 06608a4..b6a1107 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 @@ -29,7 +29,6 @@ import com.emc.metalnx.services.interfaces.ConfigService; import com.emc.metalnx.services.interfaces.GroupService; import com.emc.metalnx.services.interfaces.IRODSServices; -import com.emc.metalnx.services.interfaces.UserBookmarkService; @Service @Transactional @@ -38,9 +37,6 @@ public class GroupServiceImpl implements GroupService { @Autowired CollectionService collectionService; - @Autowired - UserBookmarkService userBookmarkService; - @Autowired IRODSServices irodsServices; diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/TemplateFieldServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/TemplateFieldServiceImpl.java deleted file mode 100755 index 0ec5dad..0000000 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/TemplateFieldServiceImpl.java +++ /dev/null @@ -1,75 +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.TemplateFieldDao; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException; -import com.emc.metalnx.services.interfaces.TemplateFieldService; -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.List; - -@Service -@Transactional -public class TemplateFieldServiceImpl implements TemplateFieldService { - - @Autowired - private TemplateFieldDao templateFieldDao; - - private static final Logger logger = LoggerFactory.getLogger(TemplateFieldServiceImpl.class); - - @Override - public DataGridTemplateField findById(long id) { - logger.info("Find template field by ID {}", id); - return templateFieldDao.findById(id); - } - - @Override - public long createTemplateField(DataGridTemplateField dataGridTemplateField) { - if (dataGridTemplateField == null) { - return 0; - } - - logger.info("Creating template field {}, {}, {} for template {}", dataGridTemplateField.getAttribute(), dataGridTemplateField.getValue(), - dataGridTemplateField.getUnit(), dataGridTemplateField.getTemplate().getTemplateName()); - - return templateFieldDao.save(dataGridTemplateField); - } - - @Override - public List findAll() { - logger.info("Find all template fields."); - return templateFieldDao.findAll(DataGridTemplateField.class); - } - - @Override - public boolean deleteTemplateField(DataGridTemplateField dataGridTemplateField) { - if (dataGridTemplateField == null) { - return false; - } - - logger.info("Delete template field {}", dataGridTemplateField.getAttribute(), dataGridTemplateField.getValue(), - dataGridTemplateField.getUnit(), dataGridTemplateField.getTemplate().getTemplateName()); - - templateFieldDao.delete(dataGridTemplateField); - - return true; - } - - @Override - public boolean modifyTemplateField(long id, String attribute, String value, String unit) throws DataGridTemplateAttrException, - DataGridTemplateValueException, DataGridTemplateUnitException { - logger.info("Modify template field by id {}", id); - return templateFieldDao.modifyById(id, attribute, value, unit); - } -} diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/TemplateServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/TemplateServiceImpl.java deleted file mode 100755 index e01686a..0000000 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/TemplateServiceImpl.java +++ /dev/null @@ -1,289 +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 java.io.IOException; -import java.io.InputStream; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; - -import org.irods.jargon.core.exception.DataNotFoundException; -import org.joda.time.format.ISODateTimeFormat; -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 com.emc.metalnx.core.domain.dao.TemplateDao; -import com.emc.metalnx.core.domain.dao.TemplateFieldDao; -import com.emc.metalnx.core.domain.entity.DataGridTemplate; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; -import com.emc.metalnx.core.domain.exceptions.DataGridException; -import com.emc.metalnx.services.interfaces.MetadataTemplateException; -import com.emc.metalnx.services.interfaces.TemplateService; -import com.emc.metalnx.services.irods.template.SerializedMetadataTemplate; -import com.emc.metalnx.services.irods.template.SerializedTemplateField; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Service -@Transactional -public class TemplateServiceImpl implements TemplateService { - - @Autowired - private TemplateDao templateDao; - - @Autowired - private TemplateFieldDao templateFieldDao; - - private ObjectMapper objectMapper = new ObjectMapper(); - org.joda.time.format.DateTimeFormatter dateParser = ISODateTimeFormat.dateTimeNoMillis(); - - private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); // Quoted "Z" to indicate UTC, no timezone - // offset - - private static final Logger logger = LoggerFactory.getLogger(TemplateServiceImpl.class); - - @Override - public boolean modifyTemplate(DataGridTemplate template) { - if (template == null) { - return false; - } - - templateDao.merge(template); - - return true; - } - - @Override - public DataGridTemplate findById(long id) { - return templateDao.findById(id); - } - - @Override - public DataGridTemplate findByName(String templateName) { - return templateDao.findByName(templateName); - } - - @Override - public long createTemplate(DataGridTemplate dataGridTemplate) { - Date today = new Date(); - - dataGridTemplate.setVersion(1); - dataGridTemplate.setCreateTs(today); - dataGridTemplate.setModifyTs(today); - - long id = templateDao.save(dataGridTemplate); - - return id; - } - - @Override - public List findAll() { - List dataGridTemplates = templateDao.findAll(DataGridTemplate.class); - - Collections.sort(dataGridTemplates); - - return dataGridTemplates; - } - - @Override - public boolean deleteTemplate(long id) { - /* - * we need to remove all template fields existing in a template before removing - * the Template itself - */ - List templateFields = this.listTemplateFields(id); - for (DataGridTemplateField templateField : templateFields) { - templateFieldDao.delete(templateField); - } - - return templateDao.deleteById(id); - } - - @Override - public List findByQueryString(String queryString) { - List templates = templateDao.findByQueryString(queryString); - Collections.sort(templates); - return templates; - } - - @Override - public List listTemplateFields(String template) { - List templateFields = templateDao.listTemplateFields(template); - Collections.sort(templateFields); - return templateFields; - } - - @Override - public List listTemplateFields(Long id) { - List templateFields = templateDao.listTemplateFields(id); - Collections.sort(templateFields); - return templateFields; - } - - @Override - public List listPublicTemplates() { - return templateDao.listPublicTemplates(); - } - - @Override - public List listPrivateTemplatesByUser(String user) { - return templateDao.listPrivateTemplatesByUser(user); - } - - @Override - public boolean importMetadataTemplate(InputStream inStream, String owner, String prefix, String suffix) - throws MetadataTemplateException, DataGridException { - logger.info("importMetadataTemplate()"); - - if (inStream == null) { - throw new IllegalArgumentException("null inStream"); - } - - if (owner == null || owner.isEmpty()) { - throw new IllegalArgumentException("null owner"); - } - - if (prefix == null) { - prefix = ""; - } - - if (suffix == null) { - suffix = ""; - } - - SerializedMetadataTemplate template; - try { - template = objectMapper.readValue(inStream, SerializedMetadataTemplate.class); - } catch (IOException e) { - logger.error("error parsing metadata template", e); - throw new MetadataTemplateException("error parsing template from JSON", e); - } - - String newTemplateName = String.format("%s%s%s", prefix, template.getTemplateName(), suffix); - logger.info("newTemplateName:{}", newTemplateName); - - DataGridTemplate dataGridTemplate = new DataGridTemplate(); - dataGridTemplate.setAccessType(template.getAccessType()); - - /* - * if dates are provided, use those, otherwise init with current timestamp. - * Dates are in ISO data format - */ - - if (template.getIso8601CreateDate() != null && !template.getIso8601CreateDate().isEmpty()) { - dataGridTemplate.setCreateTs(dateParser.parseDateTime(template.getIso8601CreateDate()).toDate()); - } else { - dataGridTemplate.setCreateTs(new Date()); - } - - if (template.getIso8601ModifyDate() != null && !template.getIso8601ModifyDate().isEmpty()) { - dataGridTemplate.setModifyTs(dateParser.parseDateTime(template.getIso8601ModifyDate()).toDate()); - } - - dataGridTemplate.setDescription(template.getDescription()); - dataGridTemplate.setOwner(owner); - dataGridTemplate.setTemplateName(newTemplateName); - dataGridTemplate.setVersion(template.getVersion()); - long templateId = this.createTemplate(dataGridTemplate); - dataGridTemplate.setId(templateId); - for (SerializedTemplateField field : template.getTemplateFields()) { - DataGridTemplateField templateField = new DataGridTemplateField(); - templateField.setTemplate(dataGridTemplate); - templateField.setAttribute(field.getAttribute()); - templateField.setOrder(field.getFieldOrder()); - templateField.setTemplate(dataGridTemplate); - templateField.setUnit(field.getUnit()); - templateField.setValue(field.getValue()); - templateFieldDao.save(templateField); - } - - return true; - } - - @Override - public String exportMetadataTemplateAsJsonString(long id) - throws DataNotFoundException, MetadataTemplateException, DataGridException { - logger.info("exportMetadataTemplateAsJsonString()"); - - DataGridTemplate template = this.findById(id); - if (template == null) { - logger.warn("no data found for template with id:{}", id); - throw new DataNotFoundException("no template found"); - } - - logger.info("template:{}", template); - TimeZone tz = TimeZone.getTimeZone("UTC"); - df.setTimeZone(tz); - String nowAsISO = df.format(new Date()); - - SerializedMetadataTemplate serialized = new SerializedMetadataTemplate(); - serialized.setAccessType(template.getAccessType()); - serialized.setDescription(template.getDescription()); - serialized.setIdentifier(String.valueOf(template.getId())); - - if (template.getCreateTs() != null) { - serialized.setIso8601CreateDate(df.format(template.getCreateTs())); - } - - if (template.getModifyTs() != null) { - serialized.setIso8601ModifyDate(df.format(template.getModifyTs())); - } - - serialized.setTemplateName(template.getTemplateName()); - serialized.setTemplateOwner(template.getOwner()); - serialized.setVersion(template.getVersion()); - - SerializedTemplateField serializedField; - for (DataGridTemplateField field : template.getFields()) { - logger.info("field:{}", field); - serializedField = new SerializedTemplateField(); - serializedField.setAttribute(field.getAttribute()); - serializedField.setFieldOrder(field.getOrder()); - serializedField.setIdentifier(String.valueOf(field.getId())); - serializedField.setUnit(field.getUnit()); - serializedField.setValue(field.getValue()); - serialized.getTemplateFields().add(serializedField); - - } - - logger.info("build serialized template:{}", serialized); - try { - return objectMapper.writeValueAsString(serialized); - } catch (JsonProcessingException e) { - logger.error("error serializig metadata template to json", e); - throw new MetadataTemplateException("error serializing metadata template", e); - } - - } - - @Override - public int countAll() { - int count = templateDao.findAll(DataGridTemplate.class).size(); - - return count; - } - - public TemplateDao getTemplateDao() { - return templateDao; - } - - public void setTemplateDao(TemplateDao templateDao) { - this.templateDao = templateDao; - } - - public TemplateFieldDao getTemplateFieldDao() { - return templateFieldDao; - } - - public void setTemplateFieldDao(TemplateFieldDao templateFieldDao) { - this.templateFieldDao = templateFieldDao; - } -} diff --git a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserBookmarkServiceImpl.java b/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserBookmarkServiceImpl.java deleted file mode 100755 index 18b1b6c..0000000 --- a/emc-metalnx-services/src/main/java/com/emc/metalnx/services/irods/UserBookmarkServiceImpl.java +++ /dev/null @@ -1,124 +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.UserBookmarkDao; -import com.emc.metalnx.core.domain.dao.UserDao; -import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.DataGridUserBookmark; -import com.emc.metalnx.services.interfaces.*; -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.List; -import java.util.Set; - -@Service -@Transactional -public class UserBookmarkServiceImpl implements UserBookmarkService { - - @Autowired - UserDao userDao; - - @Autowired - UserBookmarkDao userBookmarkDao; - - @Autowired - IRODSServices irodsServices; - - @Autowired - AdminServices adminServices; - - @Autowired - UserService userService; - - @Autowired - CollectionService collectionService; - - private static final Logger logger = LoggerFactory.getLogger(UserBookmarkServiceImpl.class); - - @Override - public boolean updateBookmarks(DataGridUser user, Set toAdd, Set toRemove) { - - boolean operationResult = true; - - try { - if (toAdd != null) { - for (String path : toAdd) { - if (!findBookmarksForUserAsString(user).contains(path)) { - userBookmarkDao.addByUserAndPath(user, path, collectionService.isCollection(path)); - } - } - } - - if (toRemove != null) { - for (String path : toRemove) { - userBookmarkDao.removeByUserAndPath(user, path); - } - } - } - catch (Exception e) { - operationResult = false; - logger.error("Could not modify user bookmark for {}", user.getUsername(), e); - } - - return operationResult; - } - - @Override - public List findBookmarksForUserAsString(DataGridUser user) { - List bookmarks = userBookmarkDao.findByUser(user); - List strings = new ArrayList(); - - for (DataGridUserBookmark bookmark : bookmarks) { - strings.add(bookmark.getPath()); - } - - return strings; - } - - @Override - public List findBookmarksOnPath(String path) { - return userBookmarkDao.findBookmarksByPath(path); - } - - @Override - public boolean removeBookmarkBasedOnPath(String path) { - return userBookmarkDao.removeByPath(path); - } - - @Override - public boolean removeBookmarkBasedOnRelativePath(String path) { - return userBookmarkDao.removeByParentPath(path); - } - - @Override - public List findBookmarksPaginated(DataGridUser user, int start, int length, String searchString, String orderBy, - String orderDir, boolean onlyCollections) { - return userBookmarkDao.findByUserPaginated(user, start, length, searchString, orderBy, orderDir, onlyCollections); - } - - @Override - public List findBookmarksPaginated(DataGridUser user, int start, int length, String searchString, List orderBy, - List orderDir, boolean onlyCollections) { - return userBookmarkDao.findByUserPaginated(user, start, length, searchString, orderBy, orderDir, onlyCollections); - } - - @Override - public boolean removeBookmarkBasedOnUser(DataGridUser user) { - return userBookmarkDao.removeByUser(user); - } - - @Override - public boolean updateBookmark(String oldPath, String newPath) { - return userBookmarkDao.updateBookmark(oldPath, newPath); - } - -} 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 104c46b..0f51c07 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 @@ -13,13 +13,13 @@ import org.irods.jargon.core.protovalues.UserTypeEnum; import org.irods.jargon.core.pub.CollectionAO; import org.irods.jargon.core.pub.DataObjectAO; +import org.irods.jargon.core.pub.IRODSAccessObjectFactory; import org.irods.jargon.core.pub.UserAO; import org.irods.jargon.core.pub.UserGroupAO; import org.irods.jargon.core.pub.domain.User; import org.irods.jargon.core.pub.domain.UserGroup; import org.irods.jargon.core.pub.io.IRODSFile; import org.irods.jargon.core.pub.io.IRODSFileFactory; -import org.irodsext.dataprofiler.favorites.FavoritesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +33,6 @@ import com.emc.metalnx.services.interfaces.ConfigService; import com.emc.metalnx.services.interfaces.GroupService; import com.emc.metalnx.services.interfaces.IRODSServices; -import com.emc.metalnx.services.interfaces.UserBookmarkService; import com.emc.metalnx.services.interfaces.UserService; @Service("userService") @@ -46,14 +45,11 @@ public class UserServiceImpl implements UserService { @Autowired GroupService groupService; - @Autowired - UserBookmarkService userBookmarkService; - - @Autowired - FavoritesService favoritesService; - @Autowired private IRODSServices irodsServices; + + @Autowired + IRODSAccessObjectFactory irodsAccessObjectFactory; @Autowired private ConfigService configService; @@ -88,7 +84,7 @@ public String buildConcatUserName(final DataGridUser dataGridUser) { @Override public List findAll() { - List users = userDao.findAll(DataGridUser.class); + List users = userDao.findAll(); Collections.sort(users); return users; } @@ -121,7 +117,6 @@ public boolean createUser(DataGridUser user, String password) user.setDataGridId(Long.parseLong(irodsUser.getId())); user.setEnabled(true); - userDao.save(user); logger.info("setting password if provided (may be a PAM user!)"); if (password == null || password.isEmpty()) { @@ -150,13 +145,6 @@ public boolean deleteUserByUsername(String username) throws DataGridConnectionRe userAO.deleteUser(username); userDao.deleteByUsername(username); - // Removing favorites and user bookmarks before removing user - userBookmarkService.removeBookmarkBasedOnUser(user); - userBookmarkService.removeBookmarkBasedOnPath(userHomeFolder); - - favoritesService.removeFavoriteBasedOnUser(user); - favoritesService.removeFavoriteBasedOnPath(userHomeFolder); - return true; } catch (Exception e) { logger.error("Could not delete user with username [" + username + "]"); @@ -198,49 +186,6 @@ public boolean modifyUser(DataGridUser modifyUser) throws DataGridException { userAO.updateUser(iRodsUser); } - DataGridUser applicationUser = userDao.findByUsernameAndZone(modifyUser.getUsername(), - modifyUser.getAdditionalInfo()); - - // check which fields were modified (our database) - if (applicationUser.getAdditionalInfo() == null - || applicationUser.getAdditionalInfo().compareTo(modifyUser.getAdditionalInfo()) != 0) { - applicationUser.setAdditionalInfo(modifyUser.getAdditionalInfo()); - } - - if (applicationUser.getFirstName() == null - || applicationUser.getFirstName().compareTo(modifyUser.getFirstName()) != 0) { - applicationUser.setFirstName(modifyUser.getFirstName()); - } - - if (applicationUser.getLastName() == null - || applicationUser.getLastName().compareTo(modifyUser.getLastName()) != 0) { - applicationUser.setLastName(modifyUser.getLastName()); - } - - if (applicationUser.getEmail() == null - || applicationUser.getEmail().compareTo(modifyUser.getEmail()) != 0) { - applicationUser.setEmail(modifyUser.getEmail()); - } - - if (applicationUser.getCompany() == null - || applicationUser.getCompany().compareTo(modifyUser.getCompany()) != 0) { - applicationUser.setCompany(modifyUser.getCompany()); - } - - if (applicationUser.getDepartment() == null - || applicationUser.getDepartment().compareTo(modifyUser.getDepartment()) != 0) { - applicationUser.setDepartment(modifyUser.getDepartment()); - } - - applicationUser.setUserProfile(modifyUser.getUserProfile()); - applicationUser.setLocale(modifyUser.getLocale()); - applicationUser.setOrganizationalRole(modifyUser.getOrganizationalRole()); - applicationUser.setUserType(modifyUser.getUserType()); - applicationUser.setForceFileOverwriting(modifyUser.isForceFileOverwriting()); - applicationUser.setAdvanceView(modifyUser.isAdvancedView()); - applicationUser.setMetadataUnitView(modifyUser.isMetadataUnitView()); - userDao.merge(applicationUser); - // Changing password if a new password is set String newPassword = modifyUser.getPassword(); if (newPassword != null && !newPassword.isEmpty()) { @@ -276,7 +221,7 @@ public DataGridUser findByUsernameAndAdditionalInfo(String username, String addi @Override public int countAll() { - return userDao.findAll(DataGridUser.class).size(); + return userDao.findAll().size(); } @Override diff --git a/emc-metalnx-services/src/main/resources/META-INF/emc-metalnx-services/emc-metalnx-services-context.xml b/emc-metalnx-services/src/main/resources/META-INF/emc-metalnx-services/emc-metalnx-services-context.xml index 75436c4..f60b71b 100755 --- a/emc-metalnx-services/src/main/resources/META-INF/emc-metalnx-services/emc-metalnx-services-context.xml +++ b/emc-metalnx-services/src/main/resources/META-INF/emc-metalnx-services/emc-metalnx-services-context.xml @@ -122,7 +122,6 @@ ref="dataProfilerSettings" /> - diff --git a/emc-metalnx-services/src/test/java/com/emc/metalnx/services/irods/TemplateServiceImplTest.java b/emc-metalnx-services/src/test/java/com/emc/metalnx/services/irods/TemplateServiceImplTest.java deleted file mode 100644 index 1fa8ee5..0000000 --- a/emc-metalnx-services/src/test/java/com/emc/metalnx/services/irods/TemplateServiceImplTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.emc.metalnx.services.irods; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Date; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mockito; - -import com.emc.metalnx.core.domain.dao.TemplateDao; -import com.emc.metalnx.core.domain.dao.TemplateFieldDao; -import com.emc.metalnx.core.domain.entity.DataGridTemplate; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; -import com.emc.metalnx.services.irods.template.SerializedMetadataTemplate; -import com.emc.metalnx.services.irods.template.SerializedTemplateField; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class TemplateServiceImplTest { - - @Test - public void testExportMetadataTemplate() throws Exception { - DataGridTemplate dataGridTemplate = new DataGridTemplate(); - dataGridTemplate.setAccessType("PUBLIC"); - dataGridTemplate.setCreateTs(new Date()); - dataGridTemplate.setDescription("boo"); - dataGridTemplate.setId(1L); - dataGridTemplate.setOwner("joe"); - dataGridTemplate.setTemplateName("mytemplate"); - dataGridTemplate.setVersion(1); - - DataGridTemplateField field = new DataGridTemplateField(); - field.setAttribute("attr"); - field.setId(1); - field.setOrder(0); - field.setTemplate(dataGridTemplate); - field.setValue("val"); - dataGridTemplate.getFields().add(field); - TemplateDao templateDao = Mockito.mock(TemplateDao.class); - Mockito.when(templateDao.findById(1)).thenReturn(dataGridTemplate); - - TemplateFieldDao templateFieldDao = Mockito.mock(TemplateFieldDao.class); - - TemplateServiceImpl impl = new TemplateServiceImpl(); - impl.setTemplateDao(templateDao); - impl.setTemplateFieldDao(templateFieldDao); - - String json = impl.exportMetadataTemplateAsJsonString(1L); - Assert.assertNotNull("no json returned", json); - - } - - @Test - public void testImportMetadataTemplate() throws Exception { - ObjectMapper objectMapper = new ObjectMapper(); - SerializedMetadataTemplate metadataTemplate = new SerializedMetadataTemplate(); - metadataTemplate.setAccessType("PUBLIC"); - metadataTemplate.setDescription("desc"); - metadataTemplate.setIdentifier("0"); - metadataTemplate.setTemplateName("boo"); - metadataTemplate.setTemplateOwner("me"); - metadataTemplate.setVersion(0); - - SerializedTemplateField field1 = new SerializedTemplateField(); - field1.setAttribute("a1"); - field1.setValue("foo"); - field1.setFieldOrder(0); - - metadataTemplate.getTemplateFields().add(field1); - - SerializedTemplateField field2 = new SerializedTemplateField(); - field1.setAttribute("a2"); - field1.setFieldOrder(1); - - metadataTemplate.getTemplateFields().add(field2); - - String json = objectMapper.writeValueAsString(metadataTemplate); - InputStream jsonStream = new ByteArrayInputStream(json.getBytes()); - - TemplateDao templateDao = Mockito.mock(TemplateDao.class); - Mockito.when(templateDao.save(Mockito.any(DataGridTemplate.class))).thenReturn(1L); - - TemplateFieldDao templateFieldDao = Mockito.mock(TemplateFieldDao.class); - Mockito.when(templateFieldDao.save(Mockito.any(DataGridTemplateField.class))).thenReturn(1L); - - TemplateServiceImpl impl = new TemplateServiceImpl(); - impl.setTemplateDao(templateDao); - impl.setTemplateFieldDao(templateFieldDao); - String testPrefix = "pre"; - String testSuffix = "post"; - String owner = "me"; - - impl.importMetadataTemplate(jsonStream, owner, testPrefix, testSuffix); - // no error means success - - } - -} diff --git a/emc-metalnx-services/src/test/resources/test-core-jpa.xml b/emc-metalnx-services/src/test/resources/test-core-jpa.xml deleted file mode 100755 index 751eeeb..0000000 --- a/emc-metalnx-services/src/test/resources/test-core-jpa.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - ${hibernate.dialect} - ${hibernate.format_sql} - ${hibernate.show_sql} - ${hibernate.hbm2ddl.auto} - - - - - - - - - - - - \ No newline at end of file diff --git a/emc-metalnx-services/src/test/resources/test-services-context.xml b/emc-metalnx-services/src/test/resources/test-services-context.xml index 70162d3..c357483 100755 --- a/emc-metalnx-services/src/test/resources/test-services-context.xml +++ b/emc-metalnx-services/src/test/resources/test-services-context.xml @@ -100,7 +100,6 @@ - @@ -119,4 +118,4 @@ - \ No newline at end of file + diff --git a/irodsext-data-profiler/pom.xml b/irodsext-data-profiler/pom.xml index 1258d0e..ad94a8e 100755 --- a/irodsext-data-profiler/pom.xml +++ b/irodsext-data-profiler/pom.xml @@ -62,7 +62,7 @@ 0 validate - + @@ -89,7 +89,7 @@ test.irods.scratch.subdir=${jargon.test.irods.scratch.subdir} test.option.exercise.remoteexecstream=${jargon.test.option.exercise.remoteexecstream} - + run @@ -100,7 +100,7 @@ 2 validate - + @@ -178,7 +178,7 @@ resource.location.i18-users=classpath:i18n-users/messages - + run diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java new file mode 100755 index 0000000..927ec45 --- /dev/null +++ b/irodsext-data-profiler/src/main/java/com/emc/metalnx/core/domain/dao/impl/UserDaoImpl.java @@ -0,0 +1,415 @@ +/* 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 java.util.ArrayList; +import java.util.List; + +import org.irods.jargon.core.connection.IRODSAccount; +import org.irods.jargon.core.exception.DataNotFoundException; +import org.irods.jargon.core.exception.InvalidUserException; +import org.irods.jargon.core.exception.JargonException; +import org.irods.jargon.core.pub.IRODSAccessObjectFactory; +import org.irods.jargon.core.pub.IRODSGenQueryExecutor; +import org.irods.jargon.core.pub.IRODSGenQueryExecutorImpl; +import org.irods.jargon.core.pub.UserAO; +import org.irods.jargon.core.pub.aohelper.UserAOHelper; +import org.irods.jargon.core.pub.domain.User; +import org.irods.jargon.core.query.IRODSGenQuery; +import org.irods.jargon.core.query.IRODSQueryResultRow; +import org.irods.jargon.core.query.IRODSQueryResultSetInterface; +import org.irods.jargon.core.query.JargonQueryException; +import org.irods.jargon.core.query.RodsGenQueryEnum; +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 com.emc.metalnx.core.domain.dao.UserDao; +import com.emc.metalnx.core.domain.entity.DataGridUser; +import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException; +import com.emc.metalnx.services.interfaces.AdminServices; +import com.emc.metalnx.services.interfaces.IRODSServices; + +@SuppressWarnings("unchecked") +@Repository +@Transactional +public class UserDaoImpl implements UserDao { + + @Autowired + private AdminServices adminServices; + + final int DEFAULT_REC_COUNT = 500; + + private static final Logger logger = LoggerFactory.getLogger(UserDaoImpl.class); + + @Override + public List findByUsername(String username) { + + List userList = new ArrayList(); + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to find user {}: {}", username, e); + return userList; + } + User u; + try { + u = userAO.findByName(username); + } catch (DataNotFoundException e) { + // not found - return empty list + return userList; + } catch (JargonException e) { + logger.error("JargonException when attempting to find user {}: {}", username, e); + return userList; + } + + // translate User to DataGridUser + DataGridUser dataGridUser = new DataGridUser(); + dataGridUser.setUsername(u.getName()); + dataGridUser.setId(Integer.parseInt(u.getId())); + dataGridUser.setDataGridId(dataGridUser.getId()); + dataGridUser.setUserType(u.getUserType().getTextValue()); + dataGridUser.setAdditionalInfo(u.getZone()); + + // add user to list + userList.add(dataGridUser); + return userList; + } + + @Override + public DataGridUser findByUsernameAndZone(String username, String zone) { + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to find by user name and zone - username=[{}] zone=[{}]: {}", username, zone, e); + return null; + } + + // This uses a modified copy of the code from Jargon UserAOImpl.findByIdInZone + + IRODSGenQueryExecutorImpl irodsGenQueryExecutorImpl = null; + IRODSAccount irodsAccount = null; + try { + irodsAccount = userAO.getIRODSAccount(); + irodsGenQueryExecutorImpl = new IRODSGenQueryExecutorImpl(userAO.getIRODSSession(), irodsAccount); + StringBuilder userQuery = new StringBuilder(); + + userQuery.append(UserAOHelper.buildUserSelects()); + userQuery.append(" where "); + userQuery.append(RodsGenQueryEnum.COL_USER_NAME.getName()); + userQuery.append(" = '"); + userQuery.append(username); + userQuery.append("'"); + + String userQueryString = userQuery.toString(); + + IRODSGenQuery irodsQuery; + irodsQuery = IRODSGenQuery.instance(userQueryString, DEFAULT_REC_COUNT); + + + IRODSQueryResultSetInterface resultSet; + try { + resultSet = irodsGenQueryExecutorImpl.executeIRODSQueryAndCloseResultInZone(irodsQuery, 0, zone); + } catch (JargonQueryException e) { + logger.error("query exception for user query:{}", userQueryString, e); + return null; + } + + if (resultSet.getResults().size() == 0) { + StringBuilder messageBuilder = new StringBuilder(); + messageBuilder.append("user not found for username:"); + messageBuilder.append(username); + String message = messageBuilder.toString(); + logger.warn(message); + return null; + } + + if (resultSet.getResults().size() > 1) { + StringBuilder messageBuilder = new StringBuilder(); + messageBuilder.append("more than one user found for username:"); + messageBuilder.append(username); + String message = messageBuilder.toString(); + logger.error(message); + return null; + } + + // I know I have just one user + + IRODSQueryResultRow row; + try { + row = resultSet.getFirstResult(); + } catch (DataNotFoundException e) { + return null; + } + IRODSAccessObjectFactory aof = adminServices.getIrodsAccessObjectFactory(); + IRODSGenQueryExecutor irodsGenQueryExecutor = aof.getIRODSGenQueryExecutor(userAO.getIRODSAccount()); + User u = UserAOHelper.buildUserFromResultSet(row, irodsGenQueryExecutor, true); + + // translate User to DataGridUser + DataGridUser dataGridUser = new DataGridUser(); + dataGridUser.setUsername(u.getName()); + dataGridUser.setId(Integer.parseInt(u.getId())); + dataGridUser.setDataGridId(dataGridUser.getId()); + dataGridUser.setUserType(u.getUserType().getTextValue()); + dataGridUser.setAdditionalInfo(u.getZone()); + logger.info("findByUsernameAndZone: dataGridUser.id=[{}] dataGridUser.dataGridId=[{}]", dataGridUser.getId(), dataGridUser.getDataGridId()); + return dataGridUser; + } catch (JargonException e) { + logger.error("JargonException encounted when attempting to find by user name and zone - username=[{}] zone=[{}]: {}", username, zone, e); + e.printStackTrace(); + return null; + } + } + + @Override + public boolean deleteByUsername(String username) { + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to delete user {}: {}", username, e); + return false; + } + + try { + userAO.deleteUser(username); + } catch (InvalidUserException e) { + return false; + } catch (JargonException e) { + logger.error("JargonException when attempting to delete user {}: {}", username, e); + return false; + } + + return true; + } + + @Override + public List findByQueryString(String query) { + + // TODO this needs testing as I am not sure what the intent is + + List userList = new ArrayList(); + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when finding users by query string {}: {}", query, e); + return userList; + } + + IRODSGenQueryExecutorImpl irodsGenQueryExecutorImpl = null; + IRODSAccount irodsAccount = null; + try { + irodsAccount = userAO.getIRODSAccount(); + irodsGenQueryExecutorImpl = new IRODSGenQueryExecutorImpl(userAO.getIRODSSession(), irodsAccount); + StringBuilder userQuery = new StringBuilder(); + + // original code searched for matches to either username, first name, last name, + // email, additional info but I think only username applies here since we are using + // the iRODS database + userQuery.append(UserAOHelper.buildUserSelects()); + userQuery.append(" where "); + userQuery.append(RodsGenQueryEnum.COL_USER_NAME.getName()); + userQuery.append(" = '"); + userQuery.append("%" + query + "%"); + userQuery.append("'"); + + String userQueryString = userQuery.toString(); + + IRODSGenQuery irodsQuery; + irodsQuery = IRODSGenQuery.instance(userQueryString, DEFAULT_REC_COUNT); + + IRODSQueryResultSetInterface resultSet; + try { + resultSet = irodsGenQueryExecutorImpl.executeIRODSQueryAndCloseResult(irodsQuery, 0); + } catch (JargonQueryException e) { + logger.error("query exception for user query:{}", userQueryString, e); + return userList; + } + + if (resultSet.getResults().size() == 0) { + // nothing found - just return empty userList + return userList; + } + + List results = resultSet.getResults(); + + for (IRODSQueryResultRow row : results) { + IRODSAccessObjectFactory aof = adminServices.getIrodsAccessObjectFactory(); + IRODSGenQueryExecutor irodsGenQueryExecutor = aof.getIRODSGenQueryExecutor(userAO.getIRODSAccount()); + User u = UserAOHelper.buildUserFromResultSet(row, irodsGenQueryExecutor, true); + + // translate User to DataGridUser + DataGridUser dataGridUser = new DataGridUser(); + dataGridUser.setUsername(u.getName()); + dataGridUser.setId(Integer.parseInt(u.getId())); + dataGridUser.setDataGridId(dataGridUser.getId()); + dataGridUser.setUserType(u.getUserType().getTextValue()); + dataGridUser.setAdditionalInfo(u.getZone()); + userList.add(dataGridUser); + } + return userList; + } catch (JargonException e) { + logger.error("JargonException encountered when finding users by query string {}: {}", query, e); + e.printStackTrace(); + return userList; + } + } + + @Override + public List findByDataGridIdList(String[] ids) { + + logger.info("findByDataGridIdList()"); + List result = new ArrayList(); + + if (ids == null) { + return result; + } + + for (String id : ids) { + DataGridUser dataGridUser = new DataGridUser(); + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to find user by id {}: {}", id, e); + return result; + } + User u; + try { + u = userAO.findById(id); + } catch (DataNotFoundException e) { + // not found - return empty list + continue; + } catch (JargonException e) { + logger.error("JargonException when attempting to find user by id {}: {}", id, e); + continue; + } + + // translate User to DataGridUser + dataGridUser.setUsername(u.getName()); + dataGridUser.setId(Integer.parseInt(u.getId())); + dataGridUser.setDataGridId(dataGridUser.getId()); + dataGridUser.setUserType(u.getUserType().getTextValue()); + dataGridUser.setAdditionalInfo(u.getZone()); + + result.add(dataGridUser); + } + + return result; + } + + @Override + public DataGridUser findByDataGridId(long id) { + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to find user by id {}: {}", id, e); + return null; + } + User u; + try { + u = userAO.findById(Long.toString(id)); + } catch (DataNotFoundException e) { + // not found - return null; + return null; + } catch (JargonException e) { + logger.error("JargonException when attempting to find user by id {}: {}", id, e); + return null; + } + + // translate User to DataGridUser + DataGridUser dataGridUser = new DataGridUser(); + dataGridUser.setUsername(u.getName()); + dataGridUser.setId(Integer.parseInt(u.getId())); + dataGridUser.setDataGridId(dataGridUser.getId()); + dataGridUser.setUserType(u.getUserType().getTextValue()); + dataGridUser.setAdditionalInfo(u.getZone()); + + return dataGridUser; + } + + @Override + public boolean deleteByDataGridId(long id) { + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to delete user by id {}: {}", id, e); + return false; + } + User u; + try { + u = userAO.findById(Long.toString(id)); + } catch (DataNotFoundException e) { + // not found - return empty list + return false; + } catch (JargonException e) { + logger.error("JargonException when attempting to delete user by id {}: {}", id, e); + return false; + } + try { + userAO.deleteUser(u.getName()); + } catch (InvalidUserException e) { + return false; + } catch (JargonException e) { + logger.error("JargonException when attempting to delete user by id {}: {}", id, e); + return false; + } + + return true; + + } + + @Override + public List findAll() { + + List dataGridUserList = new ArrayList(); + + UserAO userAO = null; + try { + userAO = adminServices.getUserAO(); + } catch (DataGridConnectionRefusedException e) { + logger.error("Connection refused when attempting to find all users: {}", e); + return dataGridUserList; + } + + List userList; + try { + userList = userAO.findAll(); + } catch (JargonException e) { + logger.error("JargonException when attempting to find all users: {}", e); + e.printStackTrace(); + return dataGridUserList; + } + + // Iterate, convert from User to DataGridUser, and insert into dataGridUserList + for (User u : userList) { + // translate User to DataGridUser + DataGridUser dataGridUser = new DataGridUser(); + dataGridUser.setUsername(u.getName()); + dataGridUser.setId(Integer.parseInt(u.getId())); + dataGridUser.setDataGridId(dataGridUser.getId()); + dataGridUser.setUserType(u.getUserType().getTextValue()); + dataGridUser.setAdditionalInfo(u.getZone()); + + // add user to list + dataGridUserList.add(dataGridUser); + } + return dataGridUserList; + } + +} diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/TemplateFieldService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/TemplateFieldService.java deleted file mode 100755 index b3dfedc..0000000 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/TemplateFieldService.java +++ /dev/null @@ -1,64 +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.DataGridTemplateField; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateAttrException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateUnitException; -import com.emc.metalnx.core.domain.exceptions.DataGridTemplateValueException; - -import java.util.List; - -public interface TemplateFieldService { - - /** - * Finds a template field by id - * - * @param id - * id of the template field to be found - * @return DataGridTemplateField object if found. Null, otherwise. - */ - public DataGridTemplateField findById(long id); - - /** - * Creates a template field into the database - * - * @param dataGridTemplateField - * template field to be saved into the database - * @return The id of the template field just created - */ - public long createTemplateField(DataGridTemplateField dataGridTemplateField); - - /** - * Lists all template fields existing in the database. - * - * @return List of template fields - */ - public List findAll(); - - /** - * Deletes a template field from the database - * - * @param dataGridTemplate - * template field object to be removed - * @return True, if the template field was successfully removed. False, otherwise. - */ - public boolean deleteTemplateField(DataGridTemplateField dataGridTemplateField); - - /** - * Modifies a template field from the database based on its id - * - * @param id - * id of the template field to be removed - * @return True, if the template field was successfully modified. False, otherwise. - * @throws DataGridTemplateUnitException - * @throws DataGridTemplateValueException - * @throws DataGridTemplateAttrException - */ - boolean modifyTemplateField(long id, String attribute, String value, String unit) throws DataGridTemplateAttrException, - DataGridTemplateValueException, DataGridTemplateUnitException; - -} diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/TemplateService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/TemplateService.java deleted file mode 100755 index 60b1427..0000000 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/TemplateService.java +++ /dev/null @@ -1,140 +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 java.io.InputStream; -import java.util.List; - -import org.irods.jargon.core.exception.DataNotFoundException; - -import com.emc.metalnx.core.domain.entity.DataGridTemplate; -import com.emc.metalnx.core.domain.entity.DataGridTemplateField; -import com.emc.metalnx.core.domain.exceptions.DataGridException; - -public interface TemplateService { - - /** - * Modifies an existing template - * - * @param template template object to persist in the database - * @return True, if the template was successfully modified. False, otherwise. - */ - public boolean modifyTemplate(DataGridTemplate template); - - /** - * Finds a template by id - * - * @param id id of the template to be found - * @return DataGridTemplate object if found. Null, otherwise. - */ - public DataGridTemplate findById(long id); - - /** - * Finds a template by a given name - * - * @param templateName name of the template to be found - * @return DataGridTemplate object if found. Null, otherwise. - */ - public DataGridTemplate findByName(String templateName); - - /** - * Creates a template into the database - * - * @param dataGridTemplate template to be saved into the database - * @return The id of the template just created - */ - public long createTemplate(DataGridTemplate dataGridTemplate); - - /** - * Lists all templates existing in the database. - * - * @return List of templates - */ - public List findAll(); - - /** - * Deletes a template from the database based on its id - * - * @param id id of the template to be removed - * @return True, if the template was successfully removed. False, otherwise. - */ - public boolean deleteTemplate(long id); - - /** - * Find templates by a query string - * - * @param queryString string containing the search term to match template names - * @return list of templates - */ - public List findByQueryString(String queryString); - - /** - * Lists all fields of a template by its name - * - * @param template name of the template - * @return List of template fields, if any. - */ - public List listTemplateFields(String template); - - /** - * Lists all fields of a template by its id - * - * @param id name of the template - * @return List of template fields, if any. - */ - public List listTemplateFields(Long id); - - /** - * Lists all the system-wide metadata templates - * - * @return List of template fields, if any. - */ - public List listPublicTemplates(); - - /** - * Returns all the privates templates owned by a given user - * - * @param user - * @return List of template fields, if any. - */ - public List listPrivateTemplatesByUser(String user); - - /** - * Returns the number of all templates existing in the database. - * - * @return number of templates - */ - int countAll(); - - /** - * Upload a JSON metadata template into the Metalnx environment. Warning: this - * functionality is transitional as the metadata template working group works to - * define a final templating spec - * - * @param inStream {@link InputStream} that contains a JSON template document - * @param owner {@code String} with the owner of the template - * @param prefix {@code String} with template name prefix - * @param suffix {@code String} with the template name suffix - * @return {@code boolean} indicating success - * @throws MetadataTemplateException {@link MetadataTemplateException} - * @throws DataGridException {@link DataGridException} - */ - boolean importMetadataTemplate(InputStream inStream, String owner, String prefix, String suffix) - throws MetadataTemplateException, DataGridException; - - /** - * Given an id of a metadata template in the irods-ext data store, retrieve the - * JSON string that is the serialized format of the template - * - * @param id {@code long} with a valid id of a metadata template - * @return {@code String} with the serialized JSON string representing the - * template - * @throws DataNotFoundException {@link DataNotFoundException} - * @throws MetadataTemplateException {@link MetadataTemplateException} - * @throws DataGridException {@link DataGridException} - */ - String exportMetadataTemplateAsJsonString(long id) - throws DataNotFoundException, MetadataTemplateException, DataGridException; - -} diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserBookmarkService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserBookmarkService.java deleted file mode 100755 index 8d9a85a..0000000 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserBookmarkService.java +++ /dev/null @@ -1,125 +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.DataGridUser; -import com.emc.metalnx.core.domain.entity.DataGridUserBookmark; - -import java.util.List; -import java.util.Set; - -public interface UserBookmarkService { - - /** - * Updates the list of bookmarks on a user - * - * @param user - * @param toAdd - * @param toRemove - * @return a confirmation that the operation has been successful - */ - public boolean updateBookmarks(DataGridUser user, 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 user as Strings - * - * @param user - * @param parentPath - * @return - */ - public List findBookmarksForUserAsString(DataGridUser user); - - /** - * 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 DataGridUser} user - * @return True, if there was one or more bookmarks mathching the given user and they were - * removed successfully. False, otherwise. - */ - public boolean removeBookmarkBasedOnUser(DataGridUser user); - - /** - * 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); - - /** - * Find list of bookmarks paginated - * - * @param user - * @param start - * represents the starting row in the query - * @param length - * how many elements will have the result - * @param searchString - * is different from null if filter is used - * @param orderBy - * order by a column - * @param orderDir - * the direction of the order can be 'desc' or 'asc' - * @param onlyCollections - * indicates if the results should contain only collections - * @return list of {@link DataGridUserBookmark} - */ - public List findBookmarksPaginated(DataGridUser user, int start, int length, String searchString, String orderBy, - String orderDir, boolean onlyCollections); - - /** - * Find list of bookmarks paginated - * - * @param user - * @param start - * represents the starting row in the query - * @param length - * how many elements will have the result - * @param searchString - * is different from null if filter is used - * @param orderBy - * list of columns the database will order the results by - * @param orderDir - * list of directions to be applied to the columns in the order by clause (DESC or - * ASC) - * @param onlyCollections - * indicates if the results should contain only collections - * @return list of {@link DataGridUserBookmark} - */ - public List findBookmarksPaginated(DataGridUser user, int start, int length, String searchString, List orderBy, - List orderDir, boolean onlyCollections); - - /** - * Updates an existing bookmark path to a new one. - * - * @param oldPath - * old path to be updated - * @param newPath - * new path value - * @return True, if oldPath was successfully set to newPath. False, otherwise. - */ - boolean updateBookmark(String oldPath, String newPath); -} diff --git a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserProfileService.java b/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserProfileService.java deleted file mode 100755 index 08b2f66..0000000 --- a/irodsext-data-profiler/src/main/java/com/emc/metalnx/services/interfaces/UserProfileService.java +++ /dev/null @@ -1,65 +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.UserProfile; - -import java.util.List; - -public interface UserProfileService { - - /** - * Returns the list of all existing profiles on the local DB. - * - * @return - */ - List findAll(); - - /** - * Finds a UserProfile object by its id. - * - * @param id - * @return - */ - UserProfile findById(Long id); - - /** - * Returns the list of UserProfiles matching the input string. - * - * @param query - * @return - */ - List findByQueryString(String query); - - /** - * Creates a new user profile on the DB. - * - * @param userProfile - */ - Long createUserProfile(UserProfile userProfile); - - /** - * Updates the UserProfile entity on DB. - * - * @param profile - * @return - */ - void modifyUserProfile(UserProfile profile); - - /** - * Removes a user profile from DB. - * - * @param profile - */ - void removeUserProfile(UserProfile profile); - - /** - * Returns the size of the list of all existing profiles on the local DB. - * - * @return - */ - int countAll(); -} diff --git a/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerFactoryImpl.java b/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerFactoryImpl.java index d4992e9..843bced 100755 --- a/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerFactoryImpl.java +++ b/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerFactoryImpl.java @@ -10,7 +10,6 @@ import org.irods.jargon.extensions.dataprofiler.DataProfilerService; import org.irods.jargon.extensions.dataprofiler.DataProfilerSettings; import org.irods.jargon.extensions.datatyper.DataTypeResolutionServiceFactory; -import org.irodsext.dataprofiler.favorites.FavoritesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,13 +32,6 @@ public class IrodsextDataProfilerFactoryImpl implements DataProfilerFactory { private DataTypeResolutionServiceFactory dataTypeResolutionServiceFactory; - /** - * MetaLnx favorites service is current source of 'favorites' and bookmarks, - * this comes from the irods-ext database at moment. This is provided to the - * data profiler service instance during factory creation - */ - private FavoritesService favoritesService; - /** * MetaLnx service to map user/zone accounts to the MetaLnx {@link DataGridUser} */ @@ -59,7 +51,6 @@ public DataProfilerService instanceDataProfilerService(final IRODSAccount irodsA irodsAccessObjectFactory, irodsAccount); dataProfilerService.setDataTypeResolutionService( dataTypeResolutionServiceFactory.instanceDataTypeResolutionService(irodsAccount)); - dataProfilerService.setFavoritesService(getFavoritesService()); dataProfilerService.setDataGridUser(resolveDataGridUser(irodsAccount)); return dataProfilerService; } @@ -106,14 +97,6 @@ private void validateContext() { } - public FavoritesService getFavoritesService() { - return favoritesService; - } - - public void setFavoritesService(FavoritesService favoritesService) { - this.favoritesService = favoritesService; - } - public UserService getUserService() { return userService; } @@ -149,7 +132,6 @@ public DataProfilerService instanceDataProfilerService(IRODSAccount irodsAccount irodsAccessObjectFactory, irodsAccount); dataProfilerService.setDataTypeResolutionService( dataTypeResolutionServiceFactory.instanceDataTypeResolutionService(irodsAccount)); - dataProfilerService.setFavoritesService(getFavoritesService()); dataProfilerService.setDataGridUser(resolveDataGridUser(irodsAccount)); return dataProfilerService; } diff --git a/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerService.java b/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerService.java index 1996e88..1b39b69 100755 --- a/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerService.java +++ b/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/IrodsextDataProfilerService.java @@ -12,7 +12,6 @@ import org.irods.jargon.extensions.dataprofiler.DataProfile; import org.irods.jargon.extensions.dataprofiler.DataProfilerService; import org.irods.jargon.extensions.dataprofiler.DataProfilerSettings; -import org.irodsext.dataprofiler.favorites.FavoritesService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,11 +26,6 @@ */ public class IrodsextDataProfilerService extends DataProfilerService { - /** - * This will be provided by the factory - */ - private FavoritesService favoritesService; - /** * logged in user identity */ @@ -47,21 +41,11 @@ public IrodsextDataProfilerService(DataProfilerSettings defaultDataProfilerSetti @Override protected void addStarringDataToDataObject(DataProfile dataProfile, DataProfilerSettings dataProfilerSettings) throws JargonException { - validateContext(); - boolean isStarred = favoritesService.isPathFavoriteForUser(dataGridUser, - dataProfile.getDomainObject().getAbsolutePath()); - dataProfile.setStarred(isStarred); - log.debug("starring set to:{}", isStarred); } @Override protected void addStarringDataToCollection(DataProfile dataProfile, DataProfilerSettings dataProfilerSettings) throws JargonException { - validateContext(); - boolean isStarred = favoritesService.isPathFavoriteForUser(dataGridUser, - dataProfile.getDomainObject().getAbsolutePath()); - dataProfile.setStarred(isStarred); - log.debug("starring set to:{}", isStarred); } @Override @@ -120,24 +104,6 @@ protected void addMetadataTemplatesToCollection(DataProfile dataProf } - public FavoritesService getFavoritesService() { - return favoritesService; - } - - public void setFavoritesService(FavoritesService favoritesService) { - this.favoritesService = favoritesService; - } - - /** - * Check for any missing dependencies or misconfiguration - */ - private void validateContext() { - if (favoritesService == null) { - log.error("favoritesService not configured"); - throw new JargonRuntimeException("favoritesService not configured"); - } - - } public DataGridUser getDataGridUser() { return dataGridUser; diff --git a/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/favorites/FavoritesService.java b/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/favorites/FavoritesService.java deleted file mode 100755 index 97ea4e5..0000000 --- a/irodsext-data-profiler/src/main/java/org/irodsext/dataprofiler/favorites/FavoritesService.java +++ /dev/null @@ -1,93 +0,0 @@ - /* Copyright (c) 2018, University of North Carolina at Chapel Hill */ - /* Copyright (c) 2015-2017, Dell EMC */ - - - -package org.irodsext.dataprofiler.favorites; - -import com.emc.metalnx.core.domain.entity.DataGridUser; -import com.emc.metalnx.core.domain.entity.DataGridUserFavorite; - -import java.util.List; -import java.util.Set; - -public interface FavoritesService { - - /** - * Updates the favorites table for a user, whether be it to remove or add a path - * - * @param user - * @param set - * of paths to be added - * @param set - * of paths to be removed - * @return True, if operation is successful. False, otherwise. - */ - boolean updateFavorites(DataGridUser user, Set toAdd, Set toRemove); - - /** - * Returns a list of strings with each of them representing a path marked as favorite - * - * @param user - * @return List of paths marked as favorites by the user. - */ - List findFavoritesForUserAsString(DataGridUser user); - - /** - * Removes path from database. This operation is used when the corresponding collection or file - * is deleted from the grid - * - * @param path - * @return True, if operation is successful. False, otherwise. - */ - boolean removeFavoriteBasedOnPath(String path); - - /** - * Removes path from database. This operation is used when the corresponding collection or file - * is deleted from the grid - * - * @param {@link DataGridUser} user - * @return True, if operation is successful. False, otherwise. - */ - boolean removeFavoriteBasedOnUser(DataGridUser user); - - /** - * Removes path from database. This operation is used when the corresponding collection or file - * is deleted from the grid - * - * @param path - * @return True, if operation is successful. False, otherwise. - */ - boolean removeFavoriteBasedOnRelativePath(String path); - - /** - * Checks whether the parameter path is a favorite for parameter user - * - * @param user - * @param path - * @return True, if path is a favorite for user. False, otherwise. - */ - boolean isPathFavoriteForUser(DataGridUser user, String path); - - /** - * Find list of favorites paginated - * - * @param user - * @param offset - * represents the starting row in the query - * @param limit - * how many elements will have the result - * @param searchString - * is different from null if filter is used - * @param orderBy - * order by a column - * @param orderDir - * the direction of the order can be 'desc' or 'asc' - * @param onlyCollections - * indicates if the results should contain only collections - * @return list of {@link DataGridUserFavorite} - */ - List findFavoritesPaginated(DataGridUser user, int offset, int limit, String searchString, String orderBy, String orderDir, - boolean onlyCollections); - -} diff --git a/irodsext-data-profiler/src/test/java/org/irodsext/dataprofiler/IrodsextDataProfilerServiceTest.java b/irodsext-data-profiler/src/test/java/org/irodsext/dataprofiler/IrodsextDataProfilerServiceTest.java index 0652c60..97cbeeb 100755 --- a/irodsext-data-profiler/src/test/java/org/irodsext/dataprofiler/IrodsextDataProfilerServiceTest.java +++ b/irodsext-data-profiler/src/test/java/org/irodsext/dataprofiler/IrodsextDataProfilerServiceTest.java @@ -23,7 +23,6 @@ import org.irods.jargon.testutils.TestingPropertiesHelper; import org.irods.jargon.testutils.filemanip.FileGenerator; import org.irods.jargon.testutils.filemanip.ScratchFileUtils; -import org.irodsext.dataprofiler.favorites.FavoritesService; import org.irodsext.datatyper.IrodsextDataTypeResolutionService; import org.irodsext.datatyper.IrodsextDataTypeResolutionServiceFactoryImpl; import org.junit.After; @@ -108,12 +107,8 @@ public void testProfileWithCollectionWithStar() throws Exception { DataGridUser dataGridUser = new DataGridUser(); dataGridUser.setUsername(irodsAccount.getUserName()); - FavoritesService favoritesService = Mockito.mock(FavoritesService.class); - Mockito.when(favoritesService.isPathFavoriteForUser(dataGridUser, targetIrodsCollection)).thenReturn(true); - IrodsextDataProfilerService dataProfilerService = new IrodsextDataProfilerService(dataProfilerSettings, accessObjectFactory, irodsAccount); - dataProfilerService.setFavoritesService(favoritesService); dataProfilerService.setDataTypeResolutionService(dataTyperService); dataProfilerService.setDataGridUser(dataGridUser); @SuppressWarnings("rawtypes") @@ -200,14 +195,10 @@ public void testStarDataObject() throws Exception { DataGridUser dataGridUser = new DataGridUser(); dataGridUser.setUsername(irodsAccount.getUserName()); - FavoritesService favoritesService = Mockito.mock(FavoritesService.class); - Mockito.when(favoritesService.isPathFavoriteForUser(dataGridUser, dataName)).thenReturn(true); - IrodsextDataProfilerService dataProfilerService = new IrodsextDataProfilerService(dataProfilerSettings, accessObjectFactory, irodsAccount); dataProfilerService.setDataTypeResolutionService(dataTyperService); dataProfilerService.setDataGridUser(dataGridUser); - dataProfilerService.setFavoritesService(favoritesService); @SuppressWarnings("rawtypes") DataProfile dataProfile = dataProfilerService.retrieveDataProfile(dataName); Assert.assertTrue("should be starred", dataProfile.isStarred()); diff --git a/irodsext-data-typer/pom.xml b/irodsext-data-typer/pom.xml index 23874c2..88f79a3 100755 --- a/irodsext-data-typer/pom.xml +++ b/irodsext-data-typer/pom.xml @@ -36,7 +36,7 @@ 0 validate - + @@ -64,7 +64,7 @@ test.mac.icommand.path=${jargon.test.mac.icommand.path} test.option.exercise.remoteexecstream=${jargon.test.option.exercise.remoteexecstream} - + run diff --git a/pom.xml b/pom.xml index b0b3eb8..5bccd86 100755 --- a/pom.xml +++ b/pom.xml @@ -9,9 +9,7 @@ 4.3.4.0-RELEASE - 4.3.11.Final 3.12.1.GA - 5.1.2.Final 4.3.18.RELEASE 3.2.10.RELEASE