This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit e3b0a235757decb746b3ff011c28d31b05d5a96d Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 10 17:42:47 2014 +0100 add filter on users during question edition --- .../coselmar/persistence/SearchRequestBean.java | 55 ++++++++++++++++ .../persistence/entity/CoselmarUserTopiaDao.java | 37 ++++++++++- .../fr/ifremer/coselmar/beans/UserSearchBean.java | 76 ++++++++++++++++++++++ .../services/CoselmarRestApplicationListener.java | 4 +- .../coselmar/services/v1/UsersWebService.java | 16 +++-- .../src/main/webapp/js/coselmar-controllers.js | 18 ++++- .../main/webapp/js/coselmar-questions-services.js | 4 +- 7 files changed, 198 insertions(+), 12 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/SearchRequestBean.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/SearchRequestBean.java new file mode 100644 index 0000000..6d38cc0 --- /dev/null +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/SearchRequestBean.java @@ -0,0 +1,55 @@ +package fr.ifremer.coselmar.persistence; + +import java.io.Serializable; +import java.util.List; + +/** + * @author ymartel <martel@codelutin.com> + */ +public class SearchRequestBean implements Serializable { + + private static final long serialVersionUID = -5556404267735629642L; + + // Pagination Parameters + protected int limit; + protected int page; + + // Global onFields request parameters + protected List<String> fullTextSearch;// if this is given, make fullText search for all given string + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public int getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + if (limit == null) { + this.limit = 10; + } else { + this.limit = limit; + } + } + + public int getPage() { + return page; + } + + public void setPage(Integer page) { + if (page == null) { + this.page = 0; + } else { + this.page = page; + } + } + + public List<String> getFullTextSearch() { + return fullTextSearch; + } + + public void setFullTextSearch(List<String> fullTextSearch) { + this.fullTextSearch = fullTextSearch; + } +} diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/CoselmarUserTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/CoselmarUserTopiaDao.java index 6bcfbbc..ddf63ca 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/CoselmarUserTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/CoselmarUserTopiaDao.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Map; import fr.ifremer.coselmar.persistence.DaoUtils; +import fr.ifremer.coselmar.persistence.SearchRequestBean; +import org.nuiton.util.pagination.PaginationParameter; public class CoselmarUserTopiaDao extends AbstractCoselmarUserTopiaDao<CoselmarUser> { @@ -117,7 +119,7 @@ public class CoselmarUserTopiaDao extends AbstractCoselmarUserTopiaDao<CoselmarU * @return Users thats contains in a property at least all given keywords * */ - public List<CoselmarUser> findAllByExample(CoselmarUser example, boolean onlyActive) { + public List<CoselmarUser> findAllByExample(CoselmarUser example, boolean onlyActive, SearchRequestBean searchRequest) { StringBuilder hqlBuilder = new StringBuilder("FROM " + CoselmarUser.class.getName() + " CU"); hqlBuilder.append(" WHERE 1=1 "); // Just because next clause will begin with operator @@ -177,7 +179,38 @@ public class CoselmarUserTopiaDao extends AbstractCoselmarUserTopiaDao<CoselmarU } - List<CoselmarUser> coselmarUsers = forHql(hqlBuilder.toString(), args).findAll(); + // Now lets start keywords on each text fields on User ! + List<String> keywords = searchRequest.getFullTextSearch(); + if (keywords != null) { + for (String keyword : keywords) { + // a keyword is an AND clause with lot of OR clauses inside ! + hqlBuilder.append(" AND ( 1=0 "); // Same as previously : need to have an insignificant clause to add all OR after + String orFirstname = DaoUtils.orAttributeLike("CU", CoselmarUser.PROPERTY_FIRSTNAME, args, keyword); + hqlBuilder.append(orFirstname); + + // Name + String orName = DaoUtils.orAttributeLike("CU", CoselmarUser.PROPERTY_NAME, args, keyword); + hqlBuilder.append(orName); + + // Name + String orMail = DaoUtils.orAttributeLike("CU", CoselmarUser.PROPERTY_MAIL, args, keyword); + hqlBuilder.append(orMail); + + // Name + String orOrganization = DaoUtils.orAttributeLike("CU", CoselmarUser.PROPERTY_ORGANIZATION, args, keyword); + hqlBuilder.append(orOrganization); + + // Name + String orQualification = DaoUtils.orAttributeLike("CU", CoselmarUser.PROPERTY_QUALIFICATION, args, keyword); + hqlBuilder.append(orQualification); + + hqlBuilder.append(" ) "); // Close this keywords clause + } + } + + PaginationParameter paginationParameter = PaginationParameter.of(searchRequest.getPage(), searchRequest.getLimit(), CoselmarUser.PROPERTY_MAIL, false); + + List<CoselmarUser> coselmarUsers = forHql(hqlBuilder.toString(), args).find(paginationParameter); return coselmarUsers; } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserSearchBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserSearchBean.java new file mode 100644 index 0000000..2604033 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/UserSearchBean.java @@ -0,0 +1,76 @@ +package fr.ifremer.coselmar.beans; + +/* + * #%L + * Coselmar :: Rest Services + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2014 Ifremer, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import java.util.List; + +/** + * @author ymartel <martel@codelutin.com> + */ +public class UserSearchBean extends UserBean { + + private static final long serialVersionUID = -2665085000774964576L; + + protected Integer limit; + protected Integer page; + protected List<String> fullTextSearch; + protected boolean onlyActive; + + public UserSearchBean(String id, String firstName, String name, String mail, String role, String qualification, String organization, boolean active) { + super(id, firstName, name, mail, role, qualification, organization, active); + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + this.limit = limit; + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + this.page = page; + } + + public List<String> getFullTextSearch() { + return fullTextSearch; + } + + public void setFullTextSearch(List<String> fullTextSearch) { + this.fullTextSearch = fullTextSearch; + } + + public boolean isOnlyActive() { + return onlyActive; + } + + public void setOnlyActive(boolean onlyActive) { + this.onlyActive = onlyActive; + } +} diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestApplicationListener.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestApplicationListener.java index 94799bc..8af741c 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestApplicationListener.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestApplicationListener.java @@ -31,6 +31,7 @@ import com.google.common.collect.Sets; import fr.ifremer.coselmar.beans.DocumentBean; import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.beans.UserBean; +import fr.ifremer.coselmar.beans.UserSearchBean; import fr.ifremer.coselmar.converter.DateConverter; import fr.ifremer.coselmar.converter.JsonArrayConverter; import fr.ifremer.coselmar.converter.JsonConverter; @@ -48,7 +49,8 @@ public class CoselmarRestApplicationListener implements WebMotionServerListener protected static final Set<Class<?>> BEAN_TYPES = Sets.<Class<?>>newHashSet( DocumentBean.class, UserBean.class, - QuestionBean.class + QuestionBean.class, + UserSearchBean.class ); @Override diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java index 6007e40..d9f9f98 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java @@ -41,8 +41,10 @@ import com.github.mustachejava.MustacheFactory; import com.google.common.base.Preconditions; import fr.ifremer.coselmar.beans.UserAccountCreatedMail; import fr.ifremer.coselmar.beans.UserBean; +import fr.ifremer.coselmar.beans.UserSearchBean; import fr.ifremer.coselmar.beans.UserWebToken; import fr.ifremer.coselmar.converter.BeanEntityConverter; +import fr.ifremer.coselmar.persistence.SearchRequestBean; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; import fr.ifremer.coselmar.services.CoselmarTechnicalException; @@ -92,16 +94,22 @@ public class UsersWebService extends CoselmarWebServiceSupport { return userBean; } - public List<UserBean> getUsers(String searchKeyword, UserBean like, boolean onlyActive) { + public List<UserBean> getUsers(String searchKeyword, UserSearchBean search, boolean onlyActive) { List<CoselmarUser> userList; if (StringUtils.isNotBlank(searchKeyword)) { userList = getCoselmarUserDao().findAllLikeKeywords(Arrays.asList(searchKeyword), onlyActive); - } else if (like != null) { - CoselmarUser example = BeanEntityConverter.fromBean(like); - userList = getCoselmarUserDao().findAllByExample(example, onlyActive); + } else if (search != null) { + // Search default parameter if not given + SearchRequestBean requestBean = new SearchRequestBean(); + requestBean.setLimit(search.getLimit()); + requestBean.setPage(search.getPage()); + requestBean.setFullTextSearch(search.getFullTextSearch()); + CoselmarUser example = BeanEntityConverter.fromBean(search); + + userList = getCoselmarUserDao().findAllByExample(example, search.isOnlyActive(), requestBean); } else { if (onlyActive) { diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index d063fac..e655776 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -343,8 +343,12 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam $scope.users = { 'participants' : [], 'clients': [], 'supervisors' : []}; $scope.refreshExperts = function(searchKeyword) { + var searchKeywords = []; + if (searchKeyword && searchKeyword.length > 0) { + searchKeywords.push(searchKeyword); + } - questionsService.findUsers({'role': 'EXPERT', 'active': 'true'}, searchKeyword, function(users) { + questionsService.findUsers({'role': 'EXPERT', 'active': true, 'fullTextSearch' : searchKeywords}, function(users) { $scope.users.participants = users; $scope.participantsIndex = {}; angular.forEach($scope.users.participants, function(participant) { @@ -355,8 +359,12 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam } $scope.refreshClients = function(searchKeyword) { + var searchKeywords = []; + if (searchKeyword && searchKeyword.length > 0) { + searchKeywords.push(searchKeyword); + } - questionsService.findUsers({'role': 'CLIENT', 'active': 'true'}, searchKeyword, function(users) { + questionsService.findUsers({'role': 'CLIENT', 'active': 'true', 'fullTextSearch' : searchKeywords}, function(users) { $scope.users.clients = users; $scope.clientsIndex = {}; angular.forEach($scope.users.clients, function(client) { @@ -367,8 +375,12 @@ coselmarControllers.controller("QuestionCtrl", ['$scope', '$route', '$routeParam } $scope.refreshSupervisors = function(searchKeyword) { + var searchKeywords = []; + if (searchKeyword && searchKeyword.length > 0) { + searchKeywords.push(searchKeyword); + } - questionsService.findUsers({'role': 'SUPERVISOR', 'active': 'true'}, searchKeyword, function(users) { + questionsService.findUsers({'role': 'SUPERVISOR', 'active': 'true', 'fullTextSearch' : searchKeywords}, function(users) { $scope.users.supervisors = users; $scope.supervisorsIndex = {}; angular.forEach($scope.users.supervisors, function(supervisor) { diff --git a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js index 873c215..8856a1f 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -32,8 +32,8 @@ function Question(resource, config){ questionResource.save(null, formData, successFunction, failFunction); }; - this.findUsers = function(example, searchKeyword, successFunction) { - var userResource = resource(usersURL, {'like': example, 'fullSearch': searchKeyword}); + this.findUsers = function(example, successFunction) { + var userResource = resource(usersURL, {'search': example}); userResource.query(successFunction); }; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.