branch feature/7644-recherche-avancée-documents created (now 9424a8a)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7644-recherche-avancée-documents in repository coselmar. See http://git.codelutin.com/coselmar.git at 9424a8a refs-30 #7778 Revue de la couche DAO pour la recherche de documents This branch includes the following new commits: new 06dc1e7 refs-10 #7778 Prepare la recherche avancée sur les documents new a6df97b refs-20 #7778 Premier jet pour l'ecran de recherche avancée sur les documents et preparation côté service new 9424a8a refs-30 #7778 Revue de la couche DAO pour la recherche de documents The 3 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 9424a8a5d35a41a6f947fd4c8b03042ecd7cf7ef 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 a6df97b2448a0b14bcef22f58cca2daa652f0bcd 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 06dc1e766f160f90d2a8cac798c76b2ebe3da1b0 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 -- 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 feature/7644-recherche-avancée-documents in repository coselmar. See http://git.codelutin.com/coselmar.git commit 06dc1e766f160f90d2a8cac798c76b2ebe3da1b0 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 feature/7644-recherche-avancée-documents in repository coselmar. See http://git.codelutin.com/coselmar.git commit 9424a8a5d35a41a6f947fd4c8b03042ecd7cf7ef 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>.
participants (1)
-
codelutin.com scm