This is an automated email from the git hooks/post-receive script. New change to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git from 0bbe39e fixes #7648 finish projects export new 5555369 refs-10 #7778 Prepare la recherche avancée sur les documents new 4eca421 refs-20 #7778 Premier jet pour l'ecran de recherche avancée sur les documents et preparation côté service new fe40b40 refs-30 #7778 Revue de la couche DAO pour la recherche de documents new cc162cf refs-90 #7778 Revue avancée de documents new baed38f refs-90 #7778 Ajout d'un filtre de recherche sur la date de dépot d'un document The 5 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit baed38f0b722af0a54163c6c9d452e4875f9e04c Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 11 11:12:08 2015 +0100 refs-90 #7778 Ajout d'un filtre de recherche sur la date de dépot d'un document commit cc162cf7afc3aa2cc10727be2fa9cbddf59b106f Author: Yannick Martel <martel@©odelutin.com> Date: Thu Dec 10 18:28:17 2015 +0100 refs-90 #7778 Revue avancée de documents commit fe40b40b0246dbd1d96678d25243b790443c985c Author: Yannick Martel <martel@©odelutin.com> Date: Thu Dec 10 12:26:14 2015 +0100 refs-30 #7778 Revue de la couche DAO pour la recherche de documents commit 4eca42112887da49b1834363f93827aa7238b48d Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 9 17:56:41 2015 +0100 refs-20 #7778 Premier jet pour l'ecran de recherche avancée sur les documents et preparation côté service commit 55553699ca5bdbf1aa41bb00f32a3a2950830651 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 9 13:05:51 2015 +0100 refs-10 #7778 Prepare la recherche avancée sur les documents Summary of changes: .../coselmar/beans/DocumentSearchExample.java | 69 +++++++++ .../ifremer/coselmar/beans/QuestionSearchBean.java | 30 +--- .../fr/ifremer/coselmar/beans/SearchExample.java | 65 +++++++++ .../fr/ifremer/coselmar/persistence/DaoUtils.java | 34 +++++ .../coselmar/persistence/SearchRequestBean.java | 14 +- .../persistence/entity/DocumentTopiaDao.java | 137 +++++++++++++++++ .../persistence/entity/QuestionTopiaDao.java | 2 +- ...UserSearchBean.java => DocumentSearchBean.java} | 35 ++++- .../coselmar/converter/BeanEntityConverter.java | 60 ++++++++ .../services/CoselmarRestApplicationListener.java | 4 +- .../indexation/QuestionsIndexationService.java | 2 +- .../coselmar/services/v1/DocumentsWebService.java | 48 ++++-- .../coselmar/services/v1/UsersWebService.java | 2 +- .../coselmar/services/QuestionsWebServiceTest.java | 14 +- .../indexation/QuestionsIndexationServiceTest.java | 54 +++---- coselmar-ui/src/main/webapp/i18n/en.js | 3 + coselmar-ui/src/main/webapp/i18n/fr.js | 3 + .../src/main/webapp/js/coselmar-controllers.js | 36 +++-- .../src/main/webapp/js/coselmar-services.js | 9 +- .../src/main/webapp/views/documents/documents.html | 17 +-- .../main/webapp/views/documents/editDocument.html | 2 +- .../main/webapp/views/documents/newdocument.html | 2 +- .../src/main/webapp/views/documents/toolsPart.html | 162 +++++++++++++++++++++ .../src/main/webapp/views/questions/questions.html | 2 +- 24 files changed, 690 insertions(+), 116 deletions(-) create mode 100644 coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java create mode 100644 coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/SearchExample.java copy coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/{UserSearchBean.java => DocumentSearchBean.java} (55%) create mode 100644 coselmar-ui/src/main/webapp/views/documents/toolsPart.html -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 55553699ca5bdbf1aa41bb00f32a3a2950830651 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 9 13:05:51 2015 +0100 refs-10 #7778 Prepare la recherche avancée sur les documents --- .../src/main/webapp/js/coselmar-controllers.js | 13 +++-- .../src/main/webapp/views/documents/documents.html | 17 +----- .../src/main/webapp/views/documents/toolsPart.html | 65 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index b690efe..2426648 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -156,15 +156,17 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara function($scope, $route, $routeParams, $location, notify, documentService, errorService){ //manage keywords if given - $scope.searchKeywords = []; + $scope.search = { searchKeywords : []}; + $scope.example = { active : "true", role : 'ALL'}; + var keywords = $routeParams.keywords; if (Array.isArray(keywords)) { - $scope.searchKeywords = keywords; + $scope.search.searchKeywords = keywords; } else if (keywords) { - $scope.searchKeywords.push(keywords); + $scope.search.searchKeywords.push(keywords); } - documentService.getDocuments($scope.searchKeywords, function(documents) { + documentService.getDocuments($scope.search.searchKeywords, function(documents) { $scope.documents = documents; }, errorService.defaultFailOnCall); @@ -185,7 +187,7 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara }; $scope.searchDocuments = function(){ - $location.search('keywords', $scope.searchKeywords); + $location.search('keywords', $scope.search.searchKeywords); }; }]); @@ -574,7 +576,6 @@ coselmarControllers.controller("UsersCtrl", ['$scope', '$route', '$routeParams', }; $scope.searchUsers = function(){ - console.log("launch search"); $location.search('keywords', $scope.search.searchKeyword); $location.search('showDisable', $scope.search.showDisable); }; diff --git a/coselmar-ui/src/main/webapp/views/documents/documents.html b/coselmar-ui/src/main/webapp/views/documents/documents.html index a42e6ed..5578226 100644 --- a/coselmar-ui/src/main/webapp/views/documents/documents.html +++ b/coselmar-ui/src/main/webapp/views/documents/documents.html @@ -29,22 +29,9 @@ </h1> </div> + <div> - <div> - <div class="form-group" ng-if="context.currentUser.role == 'EXPERT' || context.currentUser.role == 'SUPERVISOR'"> - <a href="#/documents/new" class="form-inline navbar-left btn btn-primary">{{ 'document.button.add' | translate}}</a> - </div> - <form class="form-inline pull-right search-zone" role="documentOptions" ng-submit="searchDocuments()"> - <div class="form-group"> - <span class="fa fa-info-circle" tooltip-placement="bottom" tooltip-html-unsafe="{{ 'common.message.info.searchKeywords' | translate }}"></span> - <input type="search" class="form-control" placeholder="keyword1,keyword2,..." ng-model="searchKeywords" ng-list /> - </div> - <div class="form-group"> - <button type="submit" class="btn btn-primary glyphicon glyphicon-search"></button> - </div> - </form> - </div> - <br/> + <div ng-include="src='views/documents/toolsPart.html'"></div> <table class="table"> <thead> <tr> diff --git a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html new file mode 100644 index 0000000..aba3898 --- /dev/null +++ b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html @@ -0,0 +1,65 @@ +<!-- + #%L + Coselmar :: UI + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2014 - 2015 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% + --> + +<div> + <!-- New Document --> + <div class="form-group"> + <div class="form-group" ng-if="context.currentUser.role == 'EXPERT' || context.currentUser.role == 'SUPERVISOR'"> + <a href="#/documents/new" class="form-inline navbar-left btn btn-primary">{{ 'document.button.add' | translate}}</a> + </div> + + <!-- Simple search part --> + + <form class="form-inline pull-right search-zone" role="documentOptions" ng-submit="searchDocuments()" ng-show="!advanced"> + <div class="form-group"> + <span class="fa fa-info-circle" tooltip-placement="bottom" + tooltip-html-unsafe="{{ 'common.message.info.searchKeywords' | translate }}"></span> + <input type="search" class="form-control" placeholder="keyword1,keyword2,..." ng-model="search.searchKeywords" ng-list /> + </div> + <div class="form-group"> + <button type="submit" class="btn btn-primary fa fa-search"></button> + </div> + <div class="form-group" ng-show="!advanced"> + <a ng-click="advanced=true" class="btn btn-action"> + <span class="fa fa-expand" aria-hidden="true"></span> + {{'common.button.advanceSearch' | translate }} + </a> + </div> + </form> + + </div> +</div> + +<div class="text-right clear"> +</div> + +<!-- Advanced Search part --> +<div ng-show="advanced" class="search-zone marginVertical20"> + <div class="form-group text-right"> + <a ng-click="advanced=false" class="btn btn-action"><span class="fa fa-compress" aria-hidden="true"></span> {{ 'common.button.simpleSearch' | translate }}</a> + </div> + <form class="form-horizontal" name="userFullOption" role="userFullOptions" ng-submit="advancedSearchDocuments()"> + + </form> +</div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 4eca42112887da49b1834363f93827aa7238b48d Author: Yannick Martel <martel@©odelutin.com> Date: Wed Dec 9 17:56:41 2015 +0100 refs-20 #7778 Premier jet pour l'ecran de recherche avancée sur les documents et preparation côté service --- .../ifremer/coselmar/beans/DocumentSearchBean.java | 76 ++++++++++++++++++++++ .../services/CoselmarRestApplicationListener.java | 4 +- .../coselmar/services/v1/DocumentsWebService.java | 19 +++--- .../coselmar/services/v1/UsersWebService.java | 2 +- .../src/main/webapp/js/coselmar-controllers.js | 9 ++- .../src/main/webapp/js/coselmar-services.js | 9 ++- .../main/webapp/views/documents/editDocument.html | 2 +- .../main/webapp/views/documents/newdocument.html | 2 +- .../src/main/webapp/views/documents/toolsPart.html | 68 +++++++++++++++++++ 9 files changed, 175 insertions(+), 16 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.java new file mode 100644 index 0000000..107aea3 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.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.Collection; +import java.util.Date; +import java.util.List; + +/** + * @author ymartel <martel@codelutin.com> + */ +public class DocumentSearchBean extends DocumentBean { + + private static final long serialVersionUID = -2665085000774964576L; + + protected Integer limit; + protected Integer page; + protected List<String> fullTextSearch; + + + public DocumentSearchBean(String id, String name, String ownerName, String ownerId, String privacy, + Date depositDate, Collection<String> keywords, + String type, String summary, String language, Date publicationDate, + String authors, String license, String copyright, + boolean withFile, String mimeType, String externalUrl, + String comment, String fileName) { + super(id, name, ownerName, ownerId, privacy, depositDate, keywords, type, summary, language, publicationDate, authors, license, copyright, withFile, mimeType, externalUrl, comment, fileName); + } + + 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; + } + +} 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 5715dd0..58b4b23 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 @@ -29,6 +29,7 @@ import java.util.Set; import com.google.common.collect.Sets; import fr.ifremer.coselmar.beans.DocumentBean; +import fr.ifremer.coselmar.beans.DocumentSearchBean; import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.beans.QuestionSearchBean; import fr.ifremer.coselmar.beans.UserBean; @@ -52,7 +53,8 @@ public class CoselmarRestApplicationListener implements WebMotionServerListener UserBean.class, QuestionBean.class, UserSearchBean.class, - QuestionSearchBean.class + QuestionSearchBean.class, + DocumentSearchBean.class ); @Override diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 6c058a9..482ae7c 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -41,11 +41,15 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import fr.ifremer.coselmar.beans.DocumentBean; +import fr.ifremer.coselmar.beans.DocumentSearchBean; import fr.ifremer.coselmar.beans.QuestionBean; +import fr.ifremer.coselmar.beans.QuestionSearchBean; 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.exceptions.CoselmarTechnicalException; +import fr.ifremer.coselmar.persistence.SearchRequestBean; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroup; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; @@ -142,22 +146,19 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { return documentBean; } - public List<DocumentBean> getDocuments(List<String> searchKeywords) throws InvalidCredentialException { + public List<DocumentBean> getDocuments(DocumentSearchBean searchBean) throws InvalidCredentialException { // Check authentication String authorization = getContext().getHeader("Authorization"); - UserWebToken userWebToken = checkAuthentication(authorization); - - // Retrieve current user - String fullCurrentUserId = getFullUserIdFromShort(userWebToken.getUserId()); - CoselmarUser currentUser = getCoselmarUserDao().forTopiaIdEquals(fullCurrentUserId).findAnyOrNull(); + CoselmarUser currentUser = checkUserAuthentication(authorization); - String currentUserRole = userWebToken.getRole().toUpperCase(); + CoselmarUserRole currentUserRole = currentUser.getRole(); List<Document> documentList; // Admin and Supervisor can see all documents (public, private and restricted) - if (Lists.newArrayList(CoselmarUserRole.ADMIN.name(), CoselmarUserRole.SUPERVISOR.name()).contains(currentUserRole)) { + if (Lists.newArrayList(CoselmarUserRole.ADMIN, CoselmarUserRole.SUPERVISOR).contains(currentUserRole)) { + List<String> searchKeywords = searchBean.getFullTextSearch(); if (searchKeywords != null && !searchKeywords.isEmpty()) { DocumentsIndexationService documentsIndexationService = getServicesContext().newService(DocumentsIndexationService.class); @@ -180,7 +181,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } else { //Other can only see public, his own private and restricted for which he is allowed - documentList = getDocumentDao().findAllFilterByUser(currentUser, searchKeywords); + documentList = getDocumentDao().findAllFilterByUser(currentUser, searchBean.getFullTextSearch()); } List<DocumentBean> result = new ArrayList<>(documentList.size()); 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 d3fb0d6..63746ea 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 @@ -160,7 +160,7 @@ public class UsersWebService extends CoselmarWebServiceSupport { String authorization = getContext().getHeader("Authorization"); CoselmarUser currentUser = checkUserAuthentication(authorization); - // Who is allowed here ? Admin and user himself + // Who is allowed here ? Admin, Supervisor, Expert if (currentUser.getRole() != CoselmarUserRole.ADMIN && currentUser.getRole() != CoselmarUserRole.SUPERVISOR && currentUser.getRole() != CoselmarUserRole.EXPERT) { diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 2426648..cd2e0ad 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -157,7 +157,7 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara //manage keywords if given $scope.search = { searchKeywords : []}; - $scope.example = { active : "true", role : 'ALL'}; + $scope.example = { keywords: []}; var keywords = $routeParams.keywords; if (Array.isArray(keywords)) { @@ -189,6 +189,13 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara $scope.searchDocuments = function(){ $location.search('keywords', $scope.search.searchKeywords); }; + + $scope.advancedSearchDocuments = function() { + + documentService.getAdvancedUsers($scope.example, function(documents){ + $scope.documents = documents; + }); + }; }]); // Controller for new document View diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index 0dc895b..b145c11 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -115,8 +115,7 @@ function Document(resource, config){ this.getDocuments = function(searchKeywords, successFunction, failFunction){ // Load all documents - - var docResource = resource(baseURL, {searchKeywords : searchKeywords}); + var docResource = resource(baseURL, {'searchBean' : {'fullTextSearch' : searchKeywords}}); docResource.query(successFunction, failFunction); }; @@ -136,4 +135,10 @@ function Document(resource, config){ }; + this.getAdvancedDocuments = function(searchExample, successFunction){ + // Load documents with search example + var docResource = resource(baseURL, {'searchBean' : searchExample}); + userResource.query(successFunction); + }; + }; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/documents/editDocument.html b/coselmar-ui/src/main/webapp/views/documents/editDocument.html index 4b73fa5..b6588ec 100644 --- a/coselmar-ui/src/main/webapp/views/documents/editDocument.html +++ b/coselmar-ui/src/main/webapp/views/documents/editDocument.html @@ -118,7 +118,7 @@ </ui-select-match> <ui-select-choices - repeat="user in users track by user.id | propsFilter: {name: $select.search, firstName: $select.search, organization: $select.search}" + repeat="user in (users | propsFilter: {name: $select.search, firstName: $select.search, organization: $select.search}) track by user.id" refresh="refreshUsers($select.search)" refresh-delay="500"> {{user.firstName}} {{user.name}} ({{user.organization}}) diff --git a/coselmar-ui/src/main/webapp/views/documents/newdocument.html b/coselmar-ui/src/main/webapp/views/documents/newdocument.html index 7e29535..7209af4 100644 --- a/coselmar-ui/src/main/webapp/views/documents/newdocument.html +++ b/coselmar-ui/src/main/webapp/views/documents/newdocument.html @@ -127,7 +127,7 @@ </ui-select-match> <ui-select-choices - repeat="user in users track by user.id | propsFilter: {name: $select.search, firstName: $select.search, organization: $select.search}" + repeat="user in (users | propsFilter: {name: $select.search, firstName: $select.search, organization: $select.search}) track by user.id" refresh="refreshUsers($select.search)" refresh-delay="500"> {{user.firstName}} {{user.name}} ({{user.organization}}) diff --git a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html index aba3898..410533b 100644 --- a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html +++ b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html @@ -61,5 +61,73 @@ </div> <form class="form-horizontal" name="userFullOption" role="userFullOptions" ng-submit="advancedSearchDocuments()"> + <div class="form-group row"> + + <label class="col-md-1 control-label">{{ 'document.metadata.name' | translate }}</label> + <div class="col-md-2"> + <input class="form-control" type="search" class="form-control" placeholder="Titre" ng-model="example.title" /> + </div> + + <label class="col-md-1 control-label">{{ 'document.metadata.authors' | translate }}</label> + <div class="col-md-2"> + <input class="form-control" type="search" class="form-control" placeholder="Nom et/ou Prénom" ng-model="example.authors" /> + </div> + + <label class="col-md-1 control-label">{{ 'document.metadata.type' | translate }}</label> + <div class="col-md-2"> + <select class="form-control" name="type" ng-model="example.type" required> + <option value="PERIODICAL_PUBLICATION">{{ 'document.metadata.type.periodicalPublication' | translate }}</option> + <option value="MEETING_PUBLICATION">{{ 'document.metadata.type.meetingPublication' | translate }}</option> + <option value="THESIS">{{ 'document.metadata.type.thesis' | translate }}</option> + <option value="REPORT">{{ 'document.metadata.type.report' | translate }}</option> + <option value="SCIENTIFIC_REPORT">{{ 'document.metadata.type.scientificReport' | translate }}</option> + <option value="SCIENTIFIC_WORK">{{ 'document.metadata.type.scientificWork' | translate }}</option> + <option value="CHAPTER_WORK">{{ 'document.metadata.type.chapterWork' | translate }}</option> + <option value="CONTRACT_REPORT">{{ 'document.metadata.type.contractReport' | translate }}</option> + <option value="EXPERTISE">{{ 'document.metadata.type.expertise' | translate }}</option> + <option value="POSTER">{{ 'document.metadata.type.poster' | translate }}</option> + <option value="CONFERENCE_ARTICLE">{{ 'document.metadata.type.conferenceArticle' | translate }}</option> + <option value="CONFERENCE_SUMMARY">{{ 'document.metadata.type.conferenceSummary' | translate }}</option> + <option value="DATA">{{ 'document.metadata.type.data' | translate }}</option> + <option value="OTHER">{{ 'document.metadata.type.other' | translate }}</option> + </select> + </div> + + <label class="col-md-1 control-label">{{ 'document.metadata.privacy' | translate }}</label> + <div class="col-md-2"> + <select class="form-control" name="privacy" + ng-model="example.privacy"> + <option value="PRIVATE">{{ 'common.privacy.private' | translate }}</option> + <option value="PUBLIC">{{ 'common.privacy.public' | translate }}</option> + <option value="RESTRICTED">{{ 'common.privacy.restricted' | translate }}</option> + </select> + </div> + + </div> + + <div class="form-group row"> + + <label class="col-md-1 control-label">{{ 'document.metadata.depositor' | translate }}</label> + <div class="col-md-2"> + <input type="search" class="form-control" placeholder="Prénom Nom" ng-model="example.depositor" ng-list /> + + </div> + + <label class="col-md-1 control-label">{{ 'document.metadata.keywords' | translate }}</label> + <div class="col-md-2"> + <input type="search" class="form-control" placeholder="keyword1,keyword2,..." ng-model="example.keywords" ng-list /> + </div> + + <label class="col-md-1 control-label">{{ 'document.metadata.licence' | translate }}</label> + <div class="col-md-2"> + <input type="text" class="form-control" name="licence" + placeholder="Licence" ng-model="example.licence"/> + </div> + + <div class="col-md-3 text-right"> + <button type="submit" class="btn btn-primary fa fa-search" ng-click="advancedSearchDocuments()"><span class="paddingLeft10">Search</span></button> + </div> + + </div> </form> </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 fe40b40b0246dbd1d96678d25243b790443c985c Author: Yannick Martel <martel@©odelutin.com> Date: Thu Dec 10 12:26:14 2015 +0100 refs-30 #7778 Revue de la couche DAO pour la recherche de documents --- .../coselmar/persistence/SearchRequestBean.java | 14 +++- .../persistence/entity/DocumentTopiaDao.java | 94 ++++++++++++++++++++++ .../coselmar/services/v1/DocumentsWebService.java | 13 ++- 3 files changed, 116 insertions(+), 5 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 index 28d0243..927293a 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/SearchRequestBean.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/SearchRequestBean.java @@ -34,6 +34,9 @@ public class SearchRequestBean implements Serializable { private static final long serialVersionUID = -5556404267735629642L; + public static final int DEFAULT_PAGE_SIZE = -1; + public static final int DEFAULT_PAGE = 0; + // Pagination Parameters protected int limit; protected int page; @@ -41,8 +44,11 @@ public class SearchRequestBean implements Serializable { // 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 static final SearchRequestBean newDefaultSearchRequestBean() { + SearchRequestBean searchRequestBean = new SearchRequestBean(); + searchRequestBean.setPage(DEFAULT_PAGE); + searchRequestBean.setLimit(DEFAULT_PAGE_SIZE); + return searchRequestBean; } public int getLimit() { @@ -51,7 +57,7 @@ public class SearchRequestBean implements Serializable { public void setLimit(Integer limit) { if (limit == null) { - this.limit = 10; + this.limit = DEFAULT_PAGE_SIZE; } else { this.limit = limit; } @@ -63,7 +69,7 @@ public class SearchRequestBean implements Serializable { public void setPage(Integer page) { if (page == null) { - this.page = 0; + this.page = DEFAULT_PAGE; } else { this.page = page; } diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java index 4a0bb09..c5b691d 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.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.apache.commons.lang3.StringUtils; public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { @@ -100,6 +102,98 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { return documents; } + public List<Document> findAllByExample(CoselmarUser userFilter, Document example, SearchRequestBean requestBean) { + + StringBuilder hqlBuilder = new StringBuilder("SELECT DISTINCT(D) FROM " + Document.class.getName() + " D" + + " LEFT OUTER JOIN D." + Document.PROPERTY_RESTRICTED_LIST + " CUG "); + hqlBuilder.append(" WHERE 1=1 "); // Just because next clause will begin with operator + + Map<String, Object> args = new HashMap<>(); + + // If there is a filter on User : list public, owned and ones he is on restricted list. + if (userFilter != null) { + // can list all public document + String privacyPublicCondition = DaoUtils.getQueryForAttributeEquals("D", Document.PROPERTY_PRIVACY, args, Privacy.PUBLIC, ""); + hqlBuilder.append(" AND ( " + privacyPublicCondition); + + // Can list his own document + String ownerCondition = DaoUtils.orAttributeEquals("D", Document.PROPERTY_OWNER, args, userFilter); + hqlBuilder.append(ownerCondition); + + // For limited access, check if user is in a restricted list + String participantCondition = DaoUtils.orAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, userFilter); + hqlBuilder.append(participantCondition + ")"); + } + + + // Manage example + if (example != null) { + hqlBuilder.append(" AND ( 1 = 1 "); + + if (StringUtils.isNotBlank(example.getName())) { + String nameCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_NAME, args, example.getName()); + hqlBuilder.append(nameCondition); + } + + if (StringUtils.isNotBlank(example.getAuthors())) { + String authorsCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_AUTHORS, args, example.getAuthors()); + hqlBuilder.append(authorsCondition); + } + + if (StringUtils.isNotBlank(example.getLicense())) { + String licenseCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_LICENSE, args, example.getLicense()); + hqlBuilder.append(licenseCondition); + } + + if (StringUtils.isNotBlank(example.getType())) { + String typeCondition = DaoUtils.andAttributeLike("D", Document.PROPERTY_TYPE, args, example.getType()); + hqlBuilder.append(typeCondition); + } + + if (example.getPrivacy() != null ) { + String privacyCondition = DaoUtils.andAttributeEquals("D", Document.PROPERTY_PRIVACY, args, example.getPrivacy()); + hqlBuilder.append(privacyCondition); + } + + if (example.getKeywords() != null && !example.getKeywords().isEmpty()) { + for (String keyword : example.getKeywords()) { + String keywordCondition = DaoUtils.andAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); + hqlBuilder.append(keywordCondition); + } + } + + if (example.getOwner() != null) { + String ownerCondition = DaoUtils.andAttributeEquals("D", Document.PROPERTY_OWNER, args, example.getOwner()); + hqlBuilder.append(ownerCondition); + } + + hqlBuilder.append(" ) "); + } + + + // Manage keywords search in : title, summary, authors and keywords + if (requestBean.getFullTextSearch() != null && !requestBean.getFullTextSearch().isEmpty()) { + hqlBuilder.append(" AND ( 1 = 0 "); + for (String keyword : requestBean.getFullTextSearch()) { + String nameClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_NAME, args, keyword); + String summaryClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_SUMMARY, args, keyword); + String authorsClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_AUTHORS, args, keyword); + String containsKeyword = DaoUtils.orAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); + + hqlBuilder.append(nameClause); + hqlBuilder.append(summaryClause); + hqlBuilder.append(authorsClause); + hqlBuilder.append(containsKeyword); + } + hqlBuilder.append(" )"); + } + + + List<Document> documents = forHql(hqlBuilder.toString(), args).findAll(); + + return documents; + } + public List<String> findAllKeywords() { StringBuilder hqlBuilder = diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 482ae7c..6dd657f 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -154,6 +154,17 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { CoselmarUserRole currentUserRole = currentUser.getRole(); + SearchRequestBean requestBean = SearchRequestBean.newDefaultSearchRequestBean(); + if (searchBean != null) { + if (searchBean.getPage() != null) { + requestBean.setPage(searchBean.getPage()); + } + if (searchBean.getLimit() != null) { + requestBean.setLimit(searchBean.getLimit()); + } + requestBean.setFullTextSearch(searchBean.getFullTextSearch()); + } + List<Document> documentList; // Admin and Supervisor can see all documents (public, private and restricted) @@ -181,7 +192,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } else { //Other can only see public, his own private and restricted for which he is allowed - documentList = getDocumentDao().findAllFilterByUser(currentUser, searchBean.getFullTextSearch()); + documentList = getDocumentDao().findAllByExample(currentUser, null, requestBean); } List<DocumentBean> result = new ArrayList<>(documentList.size()); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 cc162cf7afc3aa2cc10727be2fa9cbddf59b106f Author: Yannick Martel <martel@©odelutin.com> Date: Thu Dec 10 18:28:17 2015 +0100 refs-90 #7778 Revue avancée de documents --- .../coselmar/beans/DocumentSearchExample.java | 69 ++++++++++++++++++++++ .../ifremer/coselmar/beans/QuestionSearchBean.java | 30 +--------- .../fr/ifremer/coselmar/beans/SearchExample.java | 65 ++++++++++++++++++++ .../persistence/entity/DocumentTopiaDao.java | 30 ++++++++-- .../persistence/entity/QuestionTopiaDao.java | 2 +- .../coselmar/converter/BeanEntityConverter.java | 60 +++++++++++++++++++ .../indexation/QuestionsIndexationService.java | 2 +- .../coselmar/services/v1/DocumentsWebService.java | 20 +++++-- .../coselmar/services/QuestionsWebServiceTest.java | 14 ++--- .../indexation/QuestionsIndexationServiceTest.java | 54 ++++++++--------- .../src/main/webapp/js/coselmar-controllers.js | 10 ++-- .../src/main/webapp/js/coselmar-services.js | 2 +- .../src/main/webapp/views/documents/toolsPart.html | 8 +-- .../src/main/webapp/views/questions/questions.html | 2 +- 14 files changed, 284 insertions(+), 84 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java new file mode 100644 index 0000000..7c72c61 --- /dev/null +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java @@ -0,0 +1,69 @@ +package fr.ifremer.coselmar.beans; + +import fr.ifremer.coselmar.persistence.SearchRequestBean; +import fr.ifremer.coselmar.persistence.entity.Document; + +import java.util.Date; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class DocumentSearchExample extends SearchExample<Document> { + + public static final DocumentSearchExample newDefaultSearchExample() { + DocumentSearchExample searchExample = new DocumentSearchExample(); + searchExample.setPage(DEFAULT_PAGE); + searchExample.setLimit(DEFAULT_PAGE_SIZE); + return searchExample; + } + + protected Date publicationAfterDate; + + protected Date publicationBeforeDate; + + protected Date depositAfterDate; + + protected Date depositBeforeDate; + + protected String ownerName; + + public Date getPublicationAfterDate() { + return publicationAfterDate; + } + + public void setPublicationAfterDate(Date publicationAfterDate) { + this.publicationAfterDate = publicationAfterDate; + } + + public Date getPublicationBeforeDate() { + return publicationBeforeDate; + } + + public void setPublicationBeforeDate(Date publicationBeforeDate) { + this.publicationBeforeDate = publicationBeforeDate; + } + + public Date getDepositAfterDate() { + return depositAfterDate; + } + + public void setDepositAfterDate(Date depositAfterDate) { + this.depositAfterDate = depositAfterDate; + } + + public Date getDepositBeforeDate() { + return depositBeforeDate; + } + + public void setDepositBeforeDate(Date depositBeforeDate) { + this.depositBeforeDate = depositBeforeDate; + } + + public String getOwnerName() { + return ownerName; + } + + public void setOwnerName(String ownerName) { + this.ownerName = ownerName; + } +} diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchBean.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchBean.java index 12d9a82..656fb3e 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchBean.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchBean.java @@ -24,30 +24,21 @@ package fr.ifremer.coselmar.beans; * #L% */ +import fr.ifremer.coselmar.persistence.entity.Question; + import java.io.Serializable; import java.util.List; /** * @author ymartel <martel@codelutin.com> */ -public class QuestionSearchBean implements Serializable { +public class QuestionSearchBean extends SearchExample<Question> { private static final long serialVersionUID = -3318003570685481073L; - protected List<String> keywords; protected String status; protected String privacy; - protected Integer limit; - protected Integer page; - - public List<String> getKeywords() { - return keywords; - } - - public void setKeywords(List<String> keywords) { - this.keywords = keywords; - } public String getStatus() { return status; @@ -65,19 +56,4 @@ public class QuestionSearchBean implements Serializable { this.privacy = privacy; } - 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; - } } diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/SearchExample.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/SearchExample.java new file mode 100644 index 0000000..c8548d3 --- /dev/null +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/SearchExample.java @@ -0,0 +1,65 @@ +package fr.ifremer.coselmar.beans; + +import org.nuiton.topia.persistence.TopiaEntity; + +import java.io.Serializable; +import java.util.List; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class SearchExample<E extends TopiaEntity> implements Serializable { + + private static final long serialVersionUID = 4024861043438299258L; + + public static final int DEFAULT_PAGE_SIZE = -1; + public static final int DEFAULT_PAGE = 0; + + protected E example; + + protected List<String> fullTextSearch; + + // Pagination Parameters + protected Integer limit; + protected Integer page; + + public E getExample() { + return example; + } + + public void setExample(E example) { + this.example = example; + } + + public List<String> getFullTextSearch() { + return fullTextSearch; + } + + public void setFullTextSearch(List<String> fullTextSearch) { + this.fullTextSearch = fullTextSearch; + } + + public Integer getLimit() { + return limit; + } + + public void setLimit(Integer limit) { + if (limit == null) { + this.limit = DEFAULT_PAGE_SIZE; + } else { + this.limit = limit; + } + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + if (page == null) { + this.page = DEFAULT_PAGE; + } else { + this.page = page; + } + } +} diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java index c5b691d..aec17d4 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import fr.ifremer.coselmar.beans.DocumentSearchExample; import fr.ifremer.coselmar.persistence.DaoUtils; import fr.ifremer.coselmar.persistence.SearchRequestBean; import org.apache.commons.lang3.StringUtils; @@ -102,10 +103,11 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { return documents; } - public List<Document> findAllByExample(CoselmarUser userFilter, Document example, SearchRequestBean requestBean) { + public List<Document> findAllByExample(CoselmarUser userFilter, DocumentSearchExample searchExample) { StringBuilder hqlBuilder = new StringBuilder("SELECT DISTINCT(D) FROM " + Document.class.getName() + " D" - + " LEFT OUTER JOIN D." + Document.PROPERTY_RESTRICTED_LIST + " CUG "); + + " LEFT OUTER JOIN D." + Document.PROPERTY_RESTRICTED_LIST + " CUG " + + " LEFT OUTER JOIN D." + Document.PROPERTY_OWNER + " DO "); hqlBuilder.append(" WHERE 1=1 "); // Just because next clause will begin with operator Map<String, Object> args = new HashMap<>(); @@ -127,6 +129,7 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { // Manage example + Document example = searchExample.getExample(); if (example != null) { hqlBuilder.append(" AND ( 1 = 1 "); @@ -167,14 +170,33 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { hqlBuilder.append(ownerCondition); } + + // Now lets start keywords on each text fields on User ! + if (StringUtils.isNotBlank(searchExample.getOwnerName())) { + + String activeCondition = DaoUtils.andAttributeEquals("DO", CoselmarUser.PROPERTY_ACTIVE, args, true); + hqlBuilder.append(activeCondition); + + // try to find name in user#firstName or user#name! + hqlBuilder.append(" AND ( 1=0 "); // Same as previously : need to have an insignificant clause to add all OR after + String orFirstname = DaoUtils.orAttributeLike("DO", CoselmarUser.PROPERTY_FIRSTNAME, args, searchExample.getOwnerName()); + hqlBuilder.append(orFirstname); + + // Name + String orName = DaoUtils.orAttributeLike("DO", CoselmarUser.PROPERTY_NAME, args, searchExample.getOwnerName()); + hqlBuilder.append(orName); + + hqlBuilder.append(" ) "); // Close this keywords clause + } + hqlBuilder.append(" ) "); } // Manage keywords search in : title, summary, authors and keywords - if (requestBean.getFullTextSearch() != null && !requestBean.getFullTextSearch().isEmpty()) { + if (searchExample.getFullTextSearch() != null && !searchExample.getFullTextSearch().isEmpty()) { hqlBuilder.append(" AND ( 1 = 0 "); - for (String keyword : requestBean.getFullTextSearch()) { + for (String keyword : searchExample.getFullTextSearch()) { String nameClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_NAME, args, keyword); String summaryClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_SUMMARY, args, keyword); String authorsClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_AUTHORS, args, keyword); 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 bc02716..9983f18 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 @@ -237,7 +237,7 @@ public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { finerHqlBuilder.append(statusHql); } - List<String> keywords = searchBean.getKeywords(); + List<String> keywords = searchBean.getFullTextSearch(); if (keywords != null && !keywords.isEmpty()) { // should be like : """ ( (1=1) // AND ( 1=0 OR title like keyword1 OR summary like keyword1 OR theme contains keyword1 ) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java index 5e2bc97..25914fe 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java @@ -27,6 +27,7 @@ package fr.ifremer.coselmar.converter; import java.util.Collection; import java.util.Date; import java.util.HashSet; +import java.util.LinkedList; import java.util.Set; import com.google.common.collect.Sets; @@ -38,6 +39,8 @@ import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroup; import fr.ifremer.coselmar.persistence.entity.CoselmarUserImpl; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; import fr.ifremer.coselmar.persistence.entity.Document; +import fr.ifremer.coselmar.persistence.entity.DocumentImpl; +import fr.ifremer.coselmar.persistence.entity.Privacy; import fr.ifremer.coselmar.persistence.entity.Question; import org.apache.commons.lang3.StringUtils; import org.nuiton.topia.persistence.TopiaIdFactory; @@ -263,4 +266,61 @@ public class BeanEntityConverter { return result; } + /** + * Convert simple fields from {@link DocumentBean} into a {@link Document}. + * So, this does not convert : + * <ul> + * <li>Document#owner</li> + * <li>Document#restrictedList</li> + * </ul> + * If documentBean is null, simply return null Document. + */ + public static Document fromBean(DocumentBean documentBean) { + if (documentBean == null) { + return null; + } + + Document document = new DocumentImpl(); + + document.setName(documentBean.getName()); + + Date depositDate = documentBean.getDepositDate(); + if (depositDate != null) { + document.setDepositDate(new Date(depositDate.getTime())); + } + + Set<String> keywords = documentBean.getKeywords(); + if (keywords != null) { + document.setKeywords(new LinkedList(keywords)); + } + + document.setMimeType(documentBean.getMimeType()); + document.setCopyright(documentBean.getCopyright()); + document.setAuthors(documentBean.getAuthors()); + document.setLicense(documentBean.getLicense()); + document.setLanguage(documentBean.getLanguage()); + document.setType(documentBean.getType()); + String privacy = documentBean.getPrivacy(); + + if (StringUtils.isNotBlank(privacy)) { + document.setPrivacy(Privacy.valueOf(privacy)); + } + + Date publicationDate = documentBean.getPublicationDate(); + if (publicationDate != null) { + document.setPublicationDate(new Date(publicationDate.getTime())); + } else { + document.setPublicationDate(null); + } + + document.setSummary(documentBean.getSummary()); + document.setWithFile(documentBean.isWithFile()); + document.setExternalUrl(documentBean.getExternalUrl()); + document.setComment(documentBean.getComment()); + document.setFileName(documentBean.getFileName()); + + return document; + } + + } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java index 36bffef..70d2469 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java @@ -156,7 +156,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { } // Keywords part - List<String> keywords = searchBean.getKeywords(); + List<String> keywords = searchBean.getFullTextSearch(); if (keywords != null && !keywords.isEmpty()) { BooleanQuery keywordsQuery = new BooleanQuery(); diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 6dd657f..3eba6e1 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -42,6 +42,7 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import fr.ifremer.coselmar.beans.DocumentBean; import fr.ifremer.coselmar.beans.DocumentSearchBean; +import fr.ifremer.coselmar.beans.DocumentSearchExample; import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.beans.QuestionSearchBean; import fr.ifremer.coselmar.beans.UserBean; @@ -154,17 +155,24 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { CoselmarUserRole currentUserRole = currentUser.getRole(); - SearchRequestBean requestBean = SearchRequestBean.newDefaultSearchRequestBean(); + DocumentSearchExample searchExample = DocumentSearchExample.newDefaultSearchExample(); if (searchBean != null) { if (searchBean.getPage() != null) { - requestBean.setPage(searchBean.getPage()); + searchExample.setPage(searchBean.getPage()); } if (searchBean.getLimit() != null) { - requestBean.setLimit(searchBean.getLimit()); + searchExample.setLimit(searchBean.getLimit()); } - requestBean.setFullTextSearch(searchBean.getFullTextSearch()); + searchExample.setFullTextSearch(searchBean.getFullTextSearch()); + + Document example = BeanEntityConverter.fromBean(searchBean); + searchExample.setExample(example); + + searchExample.setOwnerName(searchBean.getOwnerName()); + } + List<Document> documentList; // Admin and Supervisor can see all documents (public, private and restricted) @@ -187,12 +195,12 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } } else { - documentList = getDocumentDao().findAll(); + documentList = getDocumentDao().findAllByExample(null, searchExample); } } else { //Other can only see public, his own private and restricted for which he is allowed - documentList = getDocumentDao().findAllByExample(currentUser, null, requestBean); + documentList = getDocumentDao().findAllByExample(currentUser, searchExample); } List<DocumentBean> result = new ArrayList<>(documentList.size()); 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 d579413..1d8903f 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 @@ -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("searchOption", "{privacy : 'public', keywords : ['test']}") + .addParameter("searchOption", "{privacy : 'public', fullTextSearch : ['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("searchOption", "{privacy : 'public', keywords : ['test', 'pandorica']}") + .addParameter("searchOption", "{privacy : 'public', fullTextSearch : ['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("searchOption", "{keywords : ['test']}") + .addParameter("searchOption", "{fullTextSearch : ['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("searchOption", "{keywords : ['test', 'Universe']}") + .addParameter("searchOption", "{fullTextSearch : ['test', 'Universe']}") .Get() .addHeader("Authorization", "Bearer " + supervisorToken); @@ -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("searchOption", "{privacy : 'public', keywords : ['test']}") + .addParameter("searchOption", "{privacy : 'public', fullTextSearch : ['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("searchOption", "{privacy : 'public', keywords : ['test', 'pandorica']}") + .addParameter("searchOption", "{privacy : 'public', fullTextSearch : ['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("searchOption", "{keywords : ['zero']}") + .addParameter("searchOption", "{fullTextSearch : ['zero']}") .Get() .addHeader("Authorization", "Bearer " + expertToken); diff --git a/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationServiceTest.java b/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationServiceTest.java index 99755bb..b71bb04 100644 --- a/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationServiceTest.java +++ b/coselmar-rest/src/test/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationServiceTest.java @@ -127,76 +127,76 @@ public class QuestionsIndexationServiceTest extends AbstractCoselmarServiceTest // Ok, let's search now ! QuestionSearchBean searchBean = new QuestionSearchBean(); - searchBean.setKeywords(Arrays.asList("ultimate")); + searchBean.setFullTextSearch(Arrays.asList("ultimate")); List<String> questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); Assert.assertEquals(questionTwoId, questionMatchingTitleIds.get(0)); - searchBean.setKeywords(Arrays.asList("amy")); + searchBean.setFullTextSearch(Arrays.asList("amy")); List<String> questionMatchingAmyIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertTrue(questionMatchingAmyIds.isEmpty()); - searchBean.setKeywords(Arrays.asList("Pandorica")); + searchBean.setFullTextSearch(Arrays.asList("Pandorica")); List<String> questionMatchingPandoricaIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingPandoricaIds.size()); Assert.assertEquals(questionThreeId, questionMatchingPandoricaIds.get(0)); - searchBean.setKeywords(Arrays.asList("universe")); + searchBean.setFullTextSearch(Arrays.asList("universe")); List<String> questionMatchingUniverseIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(2, questionMatchingUniverseIds.size()); Assert.assertTrue(questionMatchingUniverseIds.contains(questionThreeId)); Assert.assertTrue(questionMatchingUniverseIds.contains(questionOneId)); - searchBean.setKeywords(Arrays.asList("universe", "someone")); + searchBean.setFullTextSearch(Arrays.asList("universe", "someone")); List<String> questionMatchingUniverseAndSomeoneIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingUniverseAndSomeoneIds.size()); Assert.assertEquals(questionThreeId, questionMatchingUniverseAndSomeoneIds.get(0)); - searchBean.setKeywords(Arrays.asList("Unknown")); + searchBean.setFullTextSearch(Arrays.asList("Unknown")); List<String> documentMatchingUnknownIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertTrue(documentMatchingUnknownIds.isEmpty()); - searchBean.setKeywords(Arrays.asList("Something blue")); + searchBean.setFullTextSearch(Arrays.asList("Something blue")); List<String> documentMatchingPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPartOfSummaryIds.size()); Assert.assertEquals(questionThreeId, documentMatchingPartOfSummaryIds.get(0)); - searchBean.setKeywords(Arrays.asList("Something borrowed,")); + searchBean.setFullTextSearch(Arrays.asList("Something borrowed,")); documentMatchingPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPartOfSummaryIds.size()); Assert.assertEquals(questionThreeId, documentMatchingPartOfSummaryIds.get(0)); - searchBean.setKeywords(Arrays.asList("can we")); + searchBean.setFullTextSearch(Arrays.asList("can we")); documentMatchingPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPartOfSummaryIds.size()); Assert.assertEquals(questionOneId, documentMatchingPartOfSummaryIds.get(0)); - searchBean.setKeywords(null); + searchBean.setFullTextSearch(null); searchBean.setPrivacy(Privacy.PUBLIC.name()); List<String> documentMatchingPrivacyIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(2, documentMatchingPrivacyIds.size()); Assert.assertTrue(documentMatchingPrivacyIds.contains(questionOneId)); Assert.assertTrue(documentMatchingPrivacyIds.contains(questionTwoId)); - searchBean.setKeywords(null); + searchBean.setFullTextSearch(null); searchBean.setPrivacy(Privacy.PRIVATE.name()); documentMatchingPrivacyIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPrivacyIds.size()); Assert.assertEquals(questionThreeId, documentMatchingPrivacyIds.get(0)); - searchBean.setKeywords(Arrays.asList("Universe")); + searchBean.setFullTextSearch(Arrays.asList("Universe")); searchBean.setPrivacy(Privacy.PUBLIC.name()); List<String> documentMatchingPrivacyAndUniverseKeywordIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPrivacyAndUniverseKeywordIds.size()); Assert.assertEquals(questionOneId, documentMatchingPrivacyAndUniverseKeywordIds.get(0)); - searchBean.setKeywords(Arrays.asList("Something blue")); + searchBean.setFullTextSearch(Arrays.asList("Something blue")); searchBean.setPrivacy(Privacy.PRIVATE.name()); List<String> documentMatchingPrivacyAndPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPrivacyAndPartOfSummaryIds.size()); Assert.assertEquals(questionThreeId, documentMatchingPrivacyAndPartOfSummaryIds.get(0)); - searchBean.setKeywords(Arrays.asList("Something blue")); + searchBean.setFullTextSearch(Arrays.asList("Something blue")); searchBean.setPrivacy(Privacy.PUBLIC.name()); documentMatchingPrivacyAndPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertTrue(documentMatchingPrivacyAndPartOfSummaryIds.isEmpty()); @@ -243,22 +243,22 @@ public class QuestionsIndexationServiceTest extends AbstractCoselmarServiceTest // Ok, let's search now ! QuestionSearchBean searchBean = new QuestionSearchBean(); - searchBean.setKeywords(Arrays.asList("awesome")); + searchBean.setFullTextSearch(Arrays.asList("awesome")); List<String> questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertTrue(questionMatchingTitleIds.isEmpty()); - searchBean.setKeywords(Arrays.asList("who")); + searchBean.setFullTextSearch(Arrays.asList("who")); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(2, questionMatchingTitleIds.size()); Assert.assertTrue(questionMatchingTitleIds.contains(questionOneId)); Assert.assertTrue(questionMatchingTitleIds.contains(questionTwoId)); - searchBean.setKeywords(Arrays.asList("doctor")); + searchBean.setFullTextSearch(Arrays.asList("doctor")); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); Assert.assertTrue(questionMatchingTitleIds.contains(questionOneId)); - searchBean.setKeywords(null); + searchBean.setFullTextSearch(null); searchBean.setPrivacy(Privacy.PRIVATE.name()); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); @@ -270,7 +270,7 @@ public class QuestionsIndexationServiceTest extends AbstractCoselmarServiceTest questionsIndexationService.indexQuestion(questionOne); // Ok, let's search now ! - searchBean.setKeywords(Arrays.asList("who")); + searchBean.setFullTextSearch(Arrays.asList("who")); searchBean.setPrivacy(Privacy.PUBLIC.name()); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); @@ -314,17 +314,17 @@ public class QuestionsIndexationServiceTest extends AbstractCoselmarServiceTest // Ok, let's search now ! QuestionSearchBean searchBean = new QuestionSearchBean(); - searchBean.setKeywords(Arrays.asList("awesome")); + searchBean.setFullTextSearch(Arrays.asList("awesome")); List<String> questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); Assert.assertEquals(questionOneId, questionMatchingTitleIds.get(0)); - searchBean.setKeywords(Arrays.asList("missing")); + searchBean.setFullTextSearch(Arrays.asList("missing")); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); Assert.assertEquals(questionTwoId, questionMatchingTitleIds.get(0)); - searchBean.setKeywords(Arrays.asList("universe")); + searchBean.setFullTextSearch(Arrays.asList("universe")); List<String> questionMatchingUniverseIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(2, questionMatchingUniverseIds.size()); Assert.assertTrue(questionMatchingUniverseIds.contains(questionOneId)); @@ -334,26 +334,26 @@ public class QuestionsIndexationServiceTest extends AbstractCoselmarServiceTest questionsIndexationService.deleteQuestion(questionOneId); // and let's search same now ! - searchBean.setKeywords(Arrays.asList("awesome")); + searchBean.setFullTextSearch(Arrays.asList("awesome")); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertTrue(questionMatchingTitleIds.isEmpty()); - searchBean.setKeywords(Arrays.asList("missing")); + searchBean.setFullTextSearch(Arrays.asList("missing")); questionMatchingTitleIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingTitleIds.size()); Assert.assertTrue(questionMatchingTitleIds.contains(questionTwoId)); - searchBean.setKeywords(Arrays.asList("universe")); + searchBean.setFullTextSearch(Arrays.asList("universe")); questionMatchingUniverseIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, questionMatchingUniverseIds.size()); Assert.assertTrue(questionMatchingUniverseIds.contains(questionTwoId)); - searchBean.setKeywords(Arrays.asList("can we")); + searchBean.setFullTextSearch(Arrays.asList("can we")); List<String> documentMatchingPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertTrue(documentMatchingPartOfSummaryIds.isEmpty()); - searchBean.setKeywords(Arrays.asList("Something blue")); + searchBean.setFullTextSearch(Arrays.asList("Something blue")); documentMatchingPartOfSummaryIds = questionsIndexationService.searchQuestion(searchBean); Assert.assertEquals(1, documentMatchingPartOfSummaryIds.size()); Assert.assertEquals(questionTwoId, documentMatchingPartOfSummaryIds.get(0)); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index cd2e0ad..5a47ca4 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -192,7 +192,7 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara $scope.advancedSearchDocuments = function() { - documentService.getAdvancedUsers($scope.example, function(documents){ + documentService.getAdvancedDocuments($scope.example, function(documents){ $scope.documents = documents; }); }; @@ -844,7 +844,7 @@ coselmarControllers.directive('identicalCheck', [function () { coselmarControllers.controller("QuestionsCtrl", ['$scope', '$route', '$routeParams', '$location', 'questionsService', 'notify', 'errorService', function($scope, $route, $routeParams, $location, questionsService, notify, errorService){ - $scope.searchOptions = { 'privacy' : '', 'status' : '', 'keywords' : []}; + $scope.searchOptions = { 'privacy' : '', 'status' : '', 'fullTextSearch' : []}; questionsService.getQuestions($scope.searchOptions, function(questions) { // success : just get the questions @@ -1340,7 +1340,7 @@ coselmarControllers.controller('ModalSearchDocumentsCtrl', function ($scope, $mo coselmarControllers.controller('ModalSearchQuestionsCtrl', function ($scope, $modalInstance, currentQuestionId, questionsService, errorService) { $scope.searchKeywords = []; - $scope.searchOptions = { 'type' : 'PERIODICAL_PUBLICATION', 'privacy' : '', 'status' : '', 'keywords' : []}; + $scope.searchOptions = { 'type' : 'PERIODICAL_PUBLICATION', 'privacy' : '', 'status' : '', 'fullTextSearch' : []}; $scope.currentQuestionId = currentQuestionId; questionsService.getQuestions($scope.searchOptions, function(questions) { @@ -1348,7 +1348,7 @@ coselmarControllers.controller('ModalSearchQuestionsCtrl', function ($scope, $mo }, errorService.defaultFailOnCall); $scope.searchQuestions = function(searchKeywords) { - $scope.searchOptions = { 'privacy' : '', 'status' : '', 'keywords' : searchKeywords}; + $scope.searchOptions = { 'privacy' : '', 'status' : '', 'fullTextSearch' : searchKeywords}; questionsService.getQuestions($scope.searchOptions, function(questions) { $scope.questions = questions; }, errorService.defaultFailOnCall); @@ -1446,7 +1446,7 @@ coselmarControllers.controller("ReferentialCtrl", ['$scope', '$routeParams', '$l var remoteSearchInReferential = function() { if ($scope.search.onQuestions && $scope.search.keywords.length > 0) { - var questionSearchOptions = { 'privacy' : '', 'status' : '', 'keywords' : $scope.search.keywords}; + var questionSearchOptions = { 'privacy' : '', 'status' : '', 'fullTextSearch' : $scope.search.keywords}; questionsService.getQuestions(questionSearchOptions, function(questions) { $scope.result.questions = questions; }); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index b145c11..cd741f5 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -138,7 +138,7 @@ function Document(resource, config){ this.getAdvancedDocuments = function(searchExample, successFunction){ // Load documents with search example var docResource = resource(baseURL, {'searchBean' : searchExample}); - userResource.query(successFunction); + docResource.query(successFunction); }; }; \ No newline at end of file diff --git a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html index 410533b..6378b84 100644 --- a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html +++ b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html @@ -65,7 +65,7 @@ <label class="col-md-1 control-label">{{ 'document.metadata.name' | translate }}</label> <div class="col-md-2"> - <input class="form-control" type="search" class="form-control" placeholder="Titre" ng-model="example.title" /> + <input class="form-control" type="search" class="form-control" placeholder="Titre" ng-model="example.name" /> </div> <label class="col-md-1 control-label">{{ 'document.metadata.authors' | translate }}</label> @@ -109,7 +109,7 @@ <label class="col-md-1 control-label">{{ 'document.metadata.depositor' | translate }}</label> <div class="col-md-2"> - <input type="search" class="form-control" placeholder="Prénom Nom" ng-model="example.depositor" ng-list /> + <input type="search" class="form-control" placeholder="Prénom Nom" ng-model="example.ownerName" /> </div> @@ -120,8 +120,8 @@ <label class="col-md-1 control-label">{{ 'document.metadata.licence' | translate }}</label> <div class="col-md-2"> - <input type="text" class="form-control" name="licence" - placeholder="Licence" ng-model="example.licence"/> + <input type="text" class="form-control" name="license" + placeholder="Licence" ng-model="example.license"/> </div> <div class="col-md-3 text-right"> diff --git a/coselmar-ui/src/main/webapp/views/questions/questions.html b/coselmar-ui/src/main/webapp/views/questions/questions.html index cf1fdea..3f580d9 100644 --- a/coselmar-ui/src/main/webapp/views/questions/questions.html +++ b/coselmar-ui/src/main/webapp/views/questions/questions.html @@ -38,7 +38,7 @@ <form class="form-inline pull-right search-zone" role="questionOptions" ng-submit="searchQuestions()"> <div class="form-group"> <span class="fa fa-info-circle" tooltip-placement="bottom" tooltip-html-unsafe="{{ 'common.message.info.searchKeywords' | translate }}"></span> - <input type="search" class="form-control" placeholder="keyword1,keyword2,..." ng-model="searchOptions.keywords" ng-list /> + <input type="search" class="form-control" placeholder="keyword1,keyword2,..." ng-model="searchOptions.fullTextSearch" ng-list /> </div> <div class="form-group"> <button type="submit" class="btn btn-primary glyphicon glyphicon-search"></button> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 baed38f0b722af0a54163c6c9d452e4875f9e04c Author: Yannick Martel <martel@©odelutin.com> Date: Fri Dec 11 11:12:08 2015 +0100 refs-90 #7778 Ajout d'un filtre de recherche sur la date de dépot d'un document --- .../fr/ifremer/coselmar/persistence/DaoUtils.java | 34 ++++++++++++++++++++++ .../persistence/entity/DocumentTopiaDao.java | 23 ++++++++++++++- .../ifremer/coselmar/beans/DocumentSearchBean.java | 19 ++++++++++++ .../coselmar/services/v1/DocumentsWebService.java | 10 +++++++ coselmar-ui/src/main/webapp/i18n/en.js | 3 ++ coselmar-ui/src/main/webapp/i18n/fr.js | 3 ++ .../src/main/webapp/js/coselmar-controllers.js | 8 +++++ .../src/main/webapp/views/documents/toolsPart.html | 29 ++++++++++++++++++ 8 files changed, 128 insertions(+), 1 deletion(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java index b6fa567..cbe02ab 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java @@ -91,11 +91,45 @@ public class DaoUtils { return result; } + public static String getQueryForAttributeGreaterOrEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value, String operator) { + String result = ""; + + if (value != null) { + String alias = StringUtils.isBlank(entityAlias) ? "" : entityAlias + "."; + String queryAttributeName = addQueryAttribute(args, entityAttributeName, value); + result += String.format(" %s %s >= :%s", operator, alias + entityAttributeName, queryAttributeName); + } + + return result; + } + + public static String getQueryForAttributeLesserOrEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value, String operator) { + String result = ""; + + if (value != null) { + String alias = StringUtils.isBlank(entityAlias) ? "" : entityAlias + "."; + String queryAttributeName = addQueryAttribute(args, entityAttributeName, value); + result += String.format(" %s %s <= :%s", operator, alias + entityAttributeName, queryAttributeName); + } + + return result; + } + public static String andAttributeEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { String result = getQueryForAttributeEquals(entityAlias, entityAttributeName, args, value, "AND"); return result; } + public static String andAttributeGreaterOrEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { + String result = getQueryForAttributeGreaterOrEquals(entityAlias, entityAttributeName, args, value, "AND"); + return result; + } + + public static String andAttributeLesserOrEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { + String result = getQueryForAttributeLesserOrEquals(entityAlias, entityAttributeName, args, value, "AND"); + return result; + } + public static String orAttributeEquals(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { String result = getQueryForAttributeEquals(entityAlias, entityAttributeName, args, value, "OR"); return result; diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java index aec17d4..ad68043 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java @@ -171,7 +171,7 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { } - // Now lets start keywords on each text fields on User ! + // Now try to find user with given name if (StringUtils.isNotBlank(searchExample.getOwnerName())) { String activeCondition = DaoUtils.andAttributeEquals("DO", CoselmarUser.PROPERTY_ACTIVE, args, true); @@ -189,6 +189,27 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { hqlBuilder.append(" ) "); // Close this keywords clause } + // Manage date range + if (searchExample.getPublicationBeforeDate() != null) { + String publicationDateConditionBefore = DaoUtils.andAttributeLesserOrEquals("D", Document.PROPERTY_PUBLICATION_DATE, args, searchExample.getPublicationBeforeDate()); + hqlBuilder.append(publicationDateConditionBefore); + } + + if (searchExample.getPublicationAfterDate() != null) { + String publicationDateConditionAfter = DaoUtils.andAttributeGreaterOrEquals("D", Document.PROPERTY_PUBLICATION_DATE, args, searchExample.getPublicationAfterDate()); + hqlBuilder.append(publicationDateConditionAfter); + } + + if (searchExample.getDepositBeforeDate() != null) { + String depositDateConditionBefore = DaoUtils.andAttributeLesserOrEquals("D", Document.PROPERTY_DEPOSIT_DATE, args, searchExample.getDepositBeforeDate()); + hqlBuilder.append(depositDateConditionBefore); + } + + if (searchExample.getDepositAfterDate() != null) { + String depositDateConditionAfter = DaoUtils.andAttributeGreaterOrEquals("D", Document.PROPERTY_DEPOSIT_DATE, args, searchExample.getDepositAfterDate()); + hqlBuilder.append(depositDateConditionAfter); + } + hqlBuilder.append(" ) "); } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.java index 107aea3..1b1b7e4 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchBean.java @@ -39,6 +39,10 @@ public class DocumentSearchBean extends DocumentBean { protected Integer page; protected List<String> fullTextSearch; + protected Date depositAfterDate; + + protected Date depositBeforeDate; + public DocumentSearchBean(String id, String name, String ownerName, String ownerId, String privacy, Date depositDate, Collection<String> keywords, @@ -73,4 +77,19 @@ public class DocumentSearchBean extends DocumentBean { this.fullTextSearch = fullTextSearch; } + public Date getDepositAfterDate() { + return depositAfterDate; + } + + public void setDepositAfterDate(Date depositAfterDate) { + this.depositAfterDate = depositAfterDate; + } + + public Date getDepositBeforeDate() { + return depositBeforeDate; + } + + public void setDepositBeforeDate(Date depositBeforeDate) { + this.depositBeforeDate = depositBeforeDate; + } } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 3eba6e1..8848067 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -64,6 +64,7 @@ import fr.ifremer.coselmar.services.errors.UnauthorizedException; import fr.ifremer.coselmar.services.indexation.DocumentsIndexationService; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.lucene.queryparser.classic.ParseException; @@ -170,6 +171,15 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { searchExample.setOwnerName(searchBean.getOwnerName()); + if (searchBean.getDepositAfterDate() != null) { + Date depositAfterDate = DateUtil.getEndOfDay(DateUtil.getYesterday(searchBean.getDepositAfterDate())); + searchExample.setDepositAfterDate(depositAfterDate); + } + + if (searchBean.getDepositBeforeDate() != null) { + Date depositBeforeDate = DateUtil.getEndOfDay((searchBean.getDepositBeforeDate())); + searchExample.setDepositBeforeDate(depositBeforeDate); + } } diff --git a/coselmar-ui/src/main/webapp/i18n/en.js b/coselmar-ui/src/main/webapp/i18n/en.js index 7480e48..1c8811a 100644 --- a/coselmar-ui/src/main/webapp/i18n/en.js +++ b/coselmar-ui/src/main/webapp/i18n/en.js @@ -100,6 +100,9 @@ var translateEN = { "document.metadata.fileName" : "Document File", "document.metadata.externalLink" : "External Link", +"document.metadata.depositBefore" : "Deposit before", +"document.metadata.depositAfter" : "Deposit after", + "document.message.requiredName" : "Document name is required.", "document.message.requiredType" : "Document type is required.", "document.message.requiredExternalUrlOrFile" : "A File or an external URL is required.", diff --git a/coselmar-ui/src/main/webapp/i18n/fr.js b/coselmar-ui/src/main/webapp/i18n/fr.js index 135a684..412f946 100644 --- a/coselmar-ui/src/main/webapp/i18n/fr.js +++ b/coselmar-ui/src/main/webapp/i18n/fr.js @@ -100,6 +100,9 @@ var translateFR = { "document.metadata.fileName" : "Nom du fichier associé", "document.metadata.externalLink" : "Lien externe", +"document.metadata.depositBefore" : "Déposé avant le", +"document.metadata.depositAfter" : "Déposé après le", + "document.message.requiredName" : "Le nom du document est requis.", "document.message.requiredType" : "Le type du document est requis.", "document.message.requiredExternalUrlOrFile" : "Un fichier ou un lien externe est requis.", diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 5a47ca4..0f40bf1 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -192,6 +192,14 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara $scope.advancedSearchDocuments = function() { + if (angular.isDate($scope.example.depositAfterDate)) { + $scope.example.depositAfterDate = $scope.example.depositAfterDate.getTime(); + } + + if (angular.isDate($scope.example.depositBeforeDate)) { + $scope.example.depositBeforeDate = $scope.example.depositBeforeDate.getTime(); + } + documentService.getAdvancedDocuments($scope.example, function(documents){ $scope.documents = documents; }); diff --git a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html index 6378b84..b65ef3e 100644 --- a/coselmar-ui/src/main/webapp/views/documents/toolsPart.html +++ b/coselmar-ui/src/main/webapp/views/documents/toolsPart.html @@ -129,5 +129,34 @@ </div> </div> + + <div class="form-group row"> + + <label class="col-md-2 control-label">{{ 'document.metadata.depositAfter' | translate }}</label> + <div class="col-md-2"> + <div class="input-group"> + <input type="text" class="form-control" name="depositAfterDate" + placeholder="dd/MM/yyyy" + ng-model="example.depositAfterDate" + datepicker-popup="dd/MM/yyyy" is-open="depositAfterDateOpened" + ng-click="depositAfterDateOpened = true"/> + <span class="input-group-addon"><span class="fa fa-calendar" aria-hidden="true"></span></span> + </div> + </div> + + <label class="col-md-2 control-label">{{ 'document.metadata.depositBefore' | translate }}</label> + <div class="col-md-2"> + <div class="input-group"> + <input type="text" class="form-control" name="depositBeforeDate" + placeholder="dd/MM/yyyy" + ng-model="example.depositBeforeDate" + datepicker-popup="dd/MM/yyyy" is-open="depositBeforeDateOpened" + ng-click="depositBeforeDateOpened = true"/> + <span class="input-group-addon"><span class="fa fa-calendar" aria-hidden="true"></span></span> + </div> + + </div> + + </div> </form> </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm