From 97c420bb20fbc56415056f2e6a4fa01074e4fc72 Mon Sep 17 00:00:00 2001
From: anttil <anttil>
Date: Thu, 22 Mar 2012 14:29:28 +0000
Subject: [PATCH] LMS-2830 Date range search possibility in advanced
 sample/data set search in GUI

SVN: 24774
---
 .../search/DetailedSearchCriterionWidget.java | 57 +++++++++++++++++--
 .../search/detailed/IndexFieldNameHelper.java |  8 +++
 .../dto/DataSetAttributeSearchFieldKind.java  | 12 +++-
 .../dto/SampleAttributeSearchFieldKind.java   | 12 +++-
 4 files changed, 81 insertions(+), 8 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java
index 32d128cd6f2..8327883e3f7 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/search/DetailedSearchCriterionWidget.java
@@ -16,6 +16,9 @@
 
 package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.search;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
 import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
@@ -36,6 +39,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericCon
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.DetailedSearchFieldComboModel;
 import ch.systemsx.cisd.openbis.generic.shared.basic.AttributeSearchFieldKindProvider;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.CompareType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
@@ -168,8 +172,8 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel
     {
         DetailedSearchCriterionWidget newCriterion =
                 new DetailedSearchCriterionWidget(parent, getChildId(),
-                        new DetailedSearchFieldsSelectionWidget(nameField, getChildId(), nameField
-                                .getEntityKind()));
+                        new DetailedSearchFieldsSelectionWidget(nameField, getChildId(),
+                                nameField.getEntityKind()));
         parent.addCriterion(newCriterion);
         generatedChildren++;
     }
@@ -204,9 +208,47 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel
 
         final String selectedValue = valueField.getValue();
         final DetailedSearchField selectedFieldName = nameField.tryGetSelectedField();
+
         if (selectedFieldName != null && StringUtils.isBlank(selectedValue) == false)
         {
-            return new DetailedSearchCriterion(selectedFieldName, selectedValue);
+            String aCode = selectedFieldName.getAttributeCode();
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Date date;
+            try
+            {
+                date = sdf.parse(selectedValue);
+            } catch (ParseException ex)
+            {
+                return new DetailedSearchCriterion(selectedFieldName, selectedValue);
+            }
+
+            CompareType compareType;
+            if ("REGISTRATION_DATE_BEFORE".equals(aCode))
+            {
+                compareType = CompareType.LESS_THAN_OR_EQUAL;
+            } else if ("REGISTRATION_DATE".equals(aCode))
+            {
+                compareType = CompareType.EQUALS;
+            } else if ("REGISTRATION_DATE_AFTER".equals(aCode))
+            {
+                compareType = CompareType.MORE_THAN_OR_EQUAL;
+            } else if ("MODIFICATION_DATE_BEFORE".equals(aCode))
+            {
+                compareType = CompareType.LESS_THAN_OR_EQUAL;
+            } else if ("MODIFICATION_DATE".equals(aCode))
+            {
+                compareType = CompareType.EQUALS;
+            } else if ("MODIFICATION_DATE_AFTER".equals(aCode))
+            {
+                compareType = CompareType.MORE_THAN_OR_EQUAL;
+            } else
+            {
+                return new DetailedSearchCriterion(selectedFieldName, selectedValue);
+            }
+
+            return new DetailedSearchCriterion(selectedFieldName, compareType, date);
+
         }
         return null;
 
@@ -221,7 +263,14 @@ public class DetailedSearchCriterionWidget extends HorizontalPanel
             return null;
         }
 
-        return name + " = " + criterion.getValue();
+        if (criterion.getValue() == null && criterion.getDate() != null)
+        {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            return name + " = " + sdf.format(criterion.getDate());
+        } else
+        {
+            return name + " = " + criterion.getValue();
+        }
     }
 
     public List<PropertyType> getAvailablePropertyTypes()
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java
index 25867666570..efe131e367a 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/search/detailed/IndexFieldNameHelper.java
@@ -131,8 +131,12 @@ class IndexFieldNameHelper
             case FILE_TYPE:
                 return SearchFieldConstants.PREFIX_FILE_FORMAT_TYPE + CODE;
             case REGISTRATION_DATE:
+            case REGISTRATION_DATE_BEFORE:
+            case REGISTRATION_DATE_AFTER:
                 return SearchFieldConstants.REGISTRATION_DATE;
             case MODIFICATION_DATE:
+            case MODIFICATION_DATE_BEFORE:
+            case MODIFICATION_DATE_AFTER:
                 return SearchFieldConstants.MODIFICATION_DATE;
         }
         throw new IllegalArgumentException(attributeKind.toString());
@@ -180,8 +184,12 @@ class IndexFieldNameHelper
             case SPACE:
                 return SearchFieldConstants.PREFIX_SPACE + CODE;
             case REGISTRATION_DATE:
+            case REGISTRATION_DATE_BEFORE:
+            case REGISTRATION_DATE_AFTER:
                 return SearchFieldConstants.REGISTRATION_DATE;
             case MODIFICATION_DATE:
+            case MODIFICATION_DATE_BEFORE:
+            case MODIFICATION_DATE_AFTER:
                 return SearchFieldConstants.MODIFICATION_DATE;
         }
         throw new IllegalArgumentException(attributeKind.toString());
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java
index 706b16b6ae3..5cf052034cf 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DataSetAttributeSearchFieldKind.java
@@ -31,9 +31,17 @@ public enum DataSetAttributeSearchFieldKind implements Serializable, IAttributeS
 
     FILE_TYPE("File Type"),
 
-    REGISTRATION_DATE("Registration date"),
+    REGISTRATION_DATE("Registration date equals"),
 
-    MODIFICATION_DATE("Modification date");
+    MODIFICATION_DATE("Modification date equals"),
+
+    REGISTRATION_DATE_BEFORE("Registration date before"),
+
+    MODIFICATION_DATE_BEFORE("Modification date before"),
+
+    REGISTRATION_DATE_AFTER("Registration date after"),
+
+    MODIFICATION_DATE_AFTER("Modification date after");
 
     private final String description;
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java
index 8d5d8320a9b..3fe63044e93 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SampleAttributeSearchFieldKind.java
@@ -31,9 +31,17 @@ public enum SampleAttributeSearchFieldKind implements Serializable, IAttributeSe
 
     SPACE("Space"),
 
-    REGISTRATION_DATE("Registration date"),
+    REGISTRATION_DATE("Registration date equals"),
 
-    MODIFICATION_DATE("Modification date");
+    MODIFICATION_DATE("Modification date equals"),
+
+    REGISTRATION_DATE_BEFORE("Registration date before"),
+
+    MODIFICATION_DATE_BEFORE("Modification date before"),
+
+    REGISTRATION_DATE_AFTER("Registration date after"),
+
+    MODIFICATION_DATE_AFTER("Modification date after");
 
     private final String description;
 
-- 
GitLab