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 84a054359d6e29d3b48b116b56393e17f0772629 Author: Yannick Martel <martel@©odelutin.com> Date: Thu Jan 8 17:10:50 2015 +0100 add search by keywords for questions --- .../persistence/entity/QuestionTopiaDao.java | 13 +++++++++---- .../coselmar/services/v1/QuestionsWebService.java | 9 ++++++--- .../coselmar/services/QuestionsWebServiceTest.java | 22 +++++++++++----------- .../src/main/webapp/js/coselmar-controllers.js | 20 +++++++++++++++----- .../main/webapp/js/coselmar-questions-services.js | 14 ++++++++++++-- .../views/questions/modalQuestionSearch.html | 20 ++++++++++---------- .../src/main/webapp/views/questions/questions.html | 8 ++++++++ 7 files changed, 71 insertions(+), 35 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java index 389bfc9..23ff184 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java @@ -31,10 +31,15 @@ import java.util.Map; import fr.ifremer.coselmar.beans.QuestionSearchBean; import fr.ifremer.coselmar.persistence.DaoUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; +import static org.apache.commons.logging.LogFactory.getLog; + public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { + private static final Log log = getLog(QuestionTopiaDao.class); + public List<Question> findForExpert(CoselmarUser expert, QuestionSearchBean searchBean) { StringBuilder hqlBuilder = new StringBuilder("SELECT Q FROM " + Question.class.getName() + " Q " @@ -106,14 +111,14 @@ public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { String privateCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PRIVATE, ""); - hqlBuilder.append(" OR (" + privateCondition); + hqlBuilder.append(" OR (" + privateCondition + " AND ( 0 = 1 "); - String participantCondition = DaoUtils.andAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, expert); + String participantCondition = DaoUtils.orAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, expert); hqlBuilder.append(participantCondition); - String clientCondition = DaoUtils.andAttributeContains("Q", Question.PROPERTY_CLIENTS, args, topiaIds); + String clientCondition = DaoUtils.orAttributeContains("Q", Question.PROPERTY_CLIENTS, args, expert); - hqlBuilder.append(clientCondition + ") )"); + hqlBuilder.append(clientCondition + ") ) )"); String topiaIdsCondition = DaoUtils.andAttributeIn("Q", Question.PROPERTY_TOPIA_ID, args, topiaIds); hqlBuilder.append(topiaIdsCondition); diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java index 5092a89..1fa4241 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java @@ -220,7 +220,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { } } - public List<QuestionBean> getQuestions(QuestionSearchBean searchBean) throws InvalidCredentialException, UnauthorizedException { + public List<QuestionBean> getQuestions(QuestionSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { // Check authentication String authorization = getContext().getHeader("Authorization"); @@ -234,8 +234,8 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { List<Question> questionList; - if (searchBean != null) { - questionList = getAllFilteredQuestions(currentUser, searchBean); + if (searchOption != null) { + questionList = getAllFilteredQuestions(currentUser, searchOption); } else { questionList = getAllQuestions(currentUser); @@ -879,6 +879,9 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { try { List<String> questionIds = questionsIndexationService.searchQuestion(searchBean); fromIndexQuestionIds = getQuestionsFullId(questionIds); + if (log.isInfoEnabled()) { + log.info("Found " + fromIndexQuestionIds.size() + " questions from index."); + } } catch (IOException |ParseException e) { if (log.isErrorEnabled()) { diff --git a/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/QuestionsWebServiceTest.java b/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/QuestionsWebServiceTest.java index f47edc7..d579413 100644 --- a/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/QuestionsWebServiceTest.java +++ b/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/QuestionsWebServiceTest.java @@ -122,7 +122,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // First search : as supervisor, no search bean : retrieve the three documents Request searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{}") + .addParameter("searchOption", "{}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -139,7 +139,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Second search : as supervisor, searchBean only with public privacy : retrieve two documents (one and two) searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{privacy : 'public'}") + .addParameter("searchOption", "{privacy : 'public'}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -155,7 +155,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Third search : as supervisor, searchBean with public privacy and test keywords : retrieve documentOne searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{privacy : 'public', keywords : ['test']}") + .addParameter("searchOption", "{privacy : 'public', keywords : ['test']}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -169,7 +169,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Fourth search : as supervisor, searchBean with test and pandorica keywords : retrieve nothing searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{privacy : 'public', keywords : ['test', 'pandorica']}") + .addParameter("searchOption", "{privacy : 'public', keywords : ['test', 'pandorica']}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -182,7 +182,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Fifth search : as supervisor, searchBean with test keyword : retrieve documentOne and documentThree searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{keywords : ['test']}") + .addParameter("searchOption", "{keywords : ['test']}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -198,7 +198,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Sixth search : as supervisor, searchBean with test and universe keywords : retrieve documentThree searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{keywords : ['test', 'Universe']}") + .addParameter("searchOption", "{keywords : ['test', 'Universe']}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -228,7 +228,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Seventh search : as expert, no search bean : retrieve the two public documents searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{}") + .addParameter("searchOption", "{}") .Get() .addHeader("Authorization", "Bearer " + expertToken); @@ -243,7 +243,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Eighth search : as expert, searchBean only with public privacy : retrieve two documents (one and two) (same as seventh) searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{privacy : 'public'}") + .addParameter("searchOption", "{privacy : 'public'}") .Get() .addHeader("Authorization", "Bearer " + expertToken); @@ -259,7 +259,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Ninth search : as expert, searchBean with public privacy and test keywords : retrieve documentOne searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{privacy : 'public', keywords : ['test']}") + .addParameter("searchOption", "{privacy : 'public', keywords : ['test']}") .Get() .addHeader("Authorization", "Bearer " + expertToken); @@ -273,7 +273,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Tenth search : as supervisor, searchBean with test and pandorica keywords : retrieve nothing searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{privacy : 'public', keywords : ['test', 'pandorica']}") + .addParameter("searchOption", "{privacy : 'public', keywords : ['test', 'pandorica']}") .Get() .addHeader("Authorization", "Bearer " + expertToken); @@ -286,7 +286,7 @@ public class QuestionsWebServiceTest extends AbstractCoselmarWebServiceTest { // Eleventh search : as expert, searchBean with pandorica keyword : retrieve nothing (documentThree is private) searchRequest = createRequest("/v1/questions") - .addParameter("searchBean", "{keywords : ['zero']}") + .addParameter("searchOption", "{keywords : ['zero']}") .Get() .addHeader("Authorization", "Bearer " + expertToken); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 1e8572e..f2402cc 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -352,7 +352,9 @@ coselmarControllers.controller("UserViewCtrl", coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routeParams', '$location', 'questionsService', function($scope, $route, $routeParams, $location, questionsService){ - questionsService.getQuestions(function(questions) { + $scope.searchOptions = { 'privacy' : '', 'status' : '', 'keywords' : []}; + + questionsService.getQuestions($scope.searchOptions, function(questions) { // success : just get the questions $scope.questions = questions; @@ -361,6 +363,13 @@ coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routePara console.log(error); }); + $scope.searchQuestions = function() { + questionsService.getQuestions($scope.searchOptions, function(questions) { + $scope.questions = questions; + }); + + }; + $scope.deleteQuestion = function(questionId) { @@ -787,19 +796,20 @@ coselmarControllers.controller('ModalSearchDocumentsCtrl', function ($scope, $mo coselmarControllers.controller('ModalSearchQuestionsCtrl', function ($scope, $modalInstance, currentQuestionId, questionsService) { $scope.searchKeywords = []; + $scope.searchOptions = { 'privacy' : '', 'status' : '', 'keywords' : []}; $scope.currentQuestionId = currentQuestionId; - questionsService.getQuestions(function(questions) { + questionsService.getQuestions($scope.searchOptions, function(questions) { $scope.questions = questions; }); $scope.searchQuestions = function(searchKeywords) { - $scope.searchKeywords = searchKeywords; - questionsService.getQuestions(function(questions) { + $scope.searchOptions = { 'privacy' : '', 'status' : '', 'keywords' : searchKeywords}; + questionsService.getQuestions($scope.searchOptions, function(questions) { $scope.questions = questions; }); - } + }; $scope.select = function (question) { $modalInstance.close(question); 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 db19e3f..31a05ff 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-questions-services.js @@ -61,8 +61,18 @@ function Question(resource, config){ }; - this.getQuestions = function(successFunction, failFunction) { - var questionResource = resource(baseURL); + this.getQuestions = function(searchOptions, successFunction, failFunction) { + + if (searchOptions.privacy != "private" && searchOptions.privacy != "public" ) { + searchOptions.privacy = undefined; + } + + if (searchOptions.status != "open" && searchOptions.status != "close" + && searchOptions.status != "in_progress" && searchOptions.status != "adjourned") { + searchOptions.status = undefined; + } + + var questionResource = resource(baseURL, {'searchOption' : searchOptions}); questionResource.query().$promise.then(successFunction, failFunction); }; diff --git a/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html b/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html index 3b86fad..ba1a24b 100644 --- a/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html +++ b/coselmar-ui/src/main/webapp/views/questions/modalQuestionSearch.html @@ -7,16 +7,16 @@ </div> <div> - <!--<div>--> - <!--<form class="form-inline pull-right" role="questionOptions" ng-submit="searchQuestions(searchKeywords)">--> - <!--<div class="form-group">--> - <!--<input type="search" class="form-control" placeholder="word1,word2,..." ng-model="searchKeywords" ng-list />--> - <!--</div>--> - <!--<div class="form-group">--> - <!--<button type="submit" class="btn btn-default fa fa-search"></button>--> - <!--</div>--> - <!--</form>--> - <!--</div>--> + <div> + <form class="form-inline pull-right" role="questionOptions" ng-submit="searchQuestions(searchKeywords)"> + <div class="form-group"> + <input type="search" class="form-control" placeholder="word1,word2,..." ng-model="searchKeywords" ng-list /> + </div> + <div class="form-group"> + <button type="submit" class="btn btn-default fa fa-search"></button> + </div> + </form> + </div> <br/> <table class="table"> <tr> diff --git a/coselmar-ui/src/main/webapp/views/questions/questions.html b/coselmar-ui/src/main/webapp/views/questions/questions.html index 484dfac..4e0e31f 100644 --- a/coselmar-ui/src/main/webapp/views/questions/questions.html +++ b/coselmar-ui/src/main/webapp/views/questions/questions.html @@ -35,6 +35,14 @@ <div class="form-group" ng-if="currentUser.role == 'SUPERVISOR'"> <a href="#/questions/new" class="form-inline navbar-left btn btn-primary">Add a Question</a> </div> + <form class="form-inline pull-right" role="questionOptions" ng-submit="searchQuestions()"> + <div class="form-group"> + <input type="search" class="form-control" placeholder="word1,word2,..." ng-model="searchOptions.keywords" ng-list /> + </div> + <div class="form-group"> + <button type="submit" class="btn btn-default fa fa-search"></button> + </div> + </form> </div> <br/> <table class="table"> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.