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>.