Ard Schrijvers pushed to branch master at cms-community / hippo-site-toolkit


Commits:
bb37a897 by Ard Schrijvers at 2016-10-13T14:43:42+02:00
HSTTWO-3838 check whether the constrain.dateResolution() is not null

Note to *not* fallback to defaultResolution because defaultResolution can be 
null as well

- - - - -


2 changed files:

- 
content-beans/src/main/java/org/hippoecm/hst/content/beans/query/builder/FieldConstraint.java
- 
content-beans/src/test/java/org/hippoecm/hst/content/beans/query/builderdiffpackage/TestHstQueryBuilder.java


Changes:

=====================================
content-beans/src/main/java/org/hippoecm/hst/content/beans/query/builder/FieldConstraint.java
=====================================
--- 
a/content-beans/src/main/java/org/hippoecm/hst/content/beans/query/builder/FieldConstraint.java
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/beans/query/builder/FieldConstraint.java
@@ -64,25 +64,25 @@ public class FieldConstraint extends Constraint {
                     }
                 }
             } else if (operator == FilterConstraint.Operator.GE) {
-                if (value instanceof Calendar) {
+                if (value instanceof Calendar && constraint.dateResolution() 
!= null) {
                     filter.addGreaterOrEqualThan(builder.fieldName(), 
(Calendar)value, constraint.dateResolution());
                 } else {
                     filter.addGreaterOrEqualThan(builder.fieldName(), value);
                 }
             } else if (operator == FilterConstraint.Operator.GT) {
-                if (value instanceof Calendar) {
+                if (value instanceof Calendar && constraint.dateResolution() 
!= null) {
                     filter.addGreaterThan(builder.fieldName(), 
(Calendar)value, constraint.dateResolution());
                 } else {
                     filter.addGreaterThan(builder.fieldName(), value);
                 }
             } else if (operator == FilterConstraint.Operator.LE) {
-                if (value instanceof Calendar) {
+                if (value instanceof Calendar && constraint.dateResolution() 
!= null) {
                     filter.addLessOrEqualThan(builder.fieldName(), 
(Calendar)value, constraint.dateResolution());
                 } else {
                     filter.addLessOrEqualThan(builder.fieldName(), value);
                 }
             } else if (operator == FilterConstraint.Operator.LT) {
-                if (value instanceof Calendar) {
+                if (value instanceof Calendar && constraint.dateResolution() 
!= null) {
                     filter.addLessThan(builder.fieldName(), (Calendar)value, 
constraint.dateResolution());
                 } else {
                     filter.addLessThan(builder.fieldName(), value);
@@ -94,13 +94,13 @@ public class FieldConstraint extends Constraint {
             } else if (operator == FilterConstraint.Operator.BETWEEN) {
                 Object[] values = (Object[])value;
 
-                if (values[0] instanceof Calendar) {
+                if (values[0] instanceof Calendar && 
constraint.dateResolution() != null) {
                     filter.addBetween(builder.fieldName(), 
(Calendar)values[0], (Calendar)values[1], constraint.dateResolution());
                 } else {
                     filter.addBetween(builder.fieldName(), values[0], 
values[1]);
                 }
             } else if (operator == FilterConstraint.Operator.NOT_EQUAL) {
-                if (value instanceof Calendar) {
+                if (value instanceof Calendar && constraint.dateResolution() 
!= null) {
                     filter.addNotEqualTo(builder.fieldName(), (Calendar)value, 
constraint.dateResolution());
                 } else {
                     if (value instanceof String && 
!constraint.caseSensitive()) {


=====================================
content-beans/src/test/java/org/hippoecm/hst/content/beans/query/builderdiffpackage/TestHstQueryBuilder.java
=====================================
--- 
a/content-beans/src/test/java/org/hippoecm/hst/content/beans/query/builderdiffpackage/TestHstQueryBuilder.java
+++ 
b/content-beans/src/test/java/org/hippoecm/hst/content/beans/query/builderdiffpackage/TestHstQueryBuilder.java
@@ -657,7 +657,8 @@ public class TestHstQueryBuilder extends 
AbstractBeanTestCase {
                                 )
                         )
                 )
-                
.orderByAscending("myhippoproject:title").orderByDescending("myhippoproject:date")
+                .orderByAscending("myhippoproject:title")
+                .orderByDescending("myhippoproject:date")
                 .offset(10).limit(5)
                 .build();
 
@@ -1381,4 +1382,21 @@ public class TestHstQueryBuilder extends 
AbstractBeanTestCase {
         assertHstQueriesEquals(hstQuery, fluentQuery);
         assertHstQueriesEquals(hstQuery, fluentQuery2);
     }
+
+    @Test
+    public void missing_date_resolution_works_correctly() throws Exception {
+        HstQuery hstQuery = queryManager.createQuery(baseContentBean);
+        Calendar cal = Calendar.getInstance();
+        Filter filter = hstQuery.createFilter();
+        filter.addLessThan("myhippoproject:date", cal);
+        hstQuery.setFilter(filter);
+        HstQuery fluentQuery = create(baseContentBean)
+                .where(
+                        constraint("myhippoproject:date").lessThan(cal)
+                )
+                .build();
+
+        assertHstQueriesEquals(hstQuery, fluentQuery);
+
+    }
 }



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/bb37a897783139899eabcb84ed3a95364a7af1b8
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to