-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #159 : Adds dict support for DefaultFilter #344
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gabru-md!
I have a bunch of style comments and some implementation related comments. Let me know if you have any questions. Thanks again!
@@ -15,16 +15,16 @@ | |||
**********************************************************************/ | |||
package com.hubspot.jinjava.lib.filter; | |||
|
|||
import java.math.BigDecimal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you update your import order settings? java imports first is our preference
import com.hubspot.jinjava.interpret.InvalidReason; | ||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
import com.hubspot.jinjava.interpret.TemplateSyntaxException; | ||
import com.hubspot.jinjava.interpret.InvalidInputException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was moved out of alphabetical order
* Created by manishdevgan on 25/06/19. | ||
*/ | ||
public class DefaultFilterTest { | ||
Jinjava jinjava; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our indentation standard is 2 spaces. Could you adjust?
|
||
@Test | ||
public void itSetsDefaultStringValues() { | ||
assertThat(jinjava.render("{% set d=d | default(\"some random value\") %}{{ d }}", new HashMap<>())).isEqualTo("some random value"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you either leave these as long lines or hard-wrap them on a logical boundary, like ,
(preferred)?
@@ -55,6 +68,9 @@ default Object filter(Object var, JinjavaInterpreter interpreter, Object[] args, | |||
List<String> stringArgs = new ArrayList<>(); | |||
|
|||
for (Object arg : allArgs) { | |||
if(arg instanceof PyWrapper) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after if
please
@boulter I've made changes to the files. |
cc : @boulter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some of the issue have been addressed, but there's still a lot of import ordering changes and diffs that are unnecessary. Could you address those? That should dramatically decrease the number of changes here and it make it easier to review.
@@ -25,6 +25,8 @@ | |||
import com.hubspot.jinjava.interpret.InvalidReason; | |||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove extra space here?
@@ -15,11 +15,12 @@ | |||
**********************************************************************/ | |||
package com.hubspot.jinjava.lib.filter; | |||
|
|||
import java.util.HashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still some lingering import reordering...
|
||
if (args.length < 1) { | ||
throw new TemplateSyntaxException(interpreter, getName(), "requires 1 argument (attribute name to use)"); | ||
} | ||
|
||
return interpreter.resolveProperty(var, args[0]); | ||
return interpreter.resolveProperty(var, args[0].toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objects.toString
is safer
@@ -27,10 +32,17 @@ public String getName() { | |||
|
|||
@Override | |||
public Object filter(Object var, JinjavaInterpreter interpreter, | |||
String... args) { | |||
|
|||
Object... args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you join this with the previous line?
|
||
Object... args) { | ||
List<String> stringArgs = new ArrayList<>(); | ||
for(Object arg: args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after for
and before :
please
Object... args) { | ||
List<String> stringArgs = new ArrayList<>(); | ||
for(Object arg: args) { | ||
stringArgs.add(arg == null ? null : Objects.toString(arg)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objects.toString(arg)
will handle nulls for you.
public String getName() { | ||
return "unixtimestamp"; | ||
} | ||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please restore original indentation
@@ -26,7 +26,7 @@ public String getName() { | |||
|
|||
@Override | |||
public Object filter(Object var, JinjavaInterpreter interpreter, | |||
String... args) { | |||
Object... args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can join with previous line
sure! will do the necessary changes |
@boulter I've added changes. please review again 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a bunch of small changes, but there are many more instances that I didn't get to. Can you clean these up first and then I'll take a look when the diffs are smaller? Thanks.
if (arg.length < 1) { | ||
throw new TemplateSyntaxException(interpreter, getName(), "requires 1 number (divisor) argument"); | ||
} | ||
String toMul = arg[0]; | ||
String toMul = (arg[0] == null) ? null : Objects.toString(arg[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objects.toString
will take care of nulls for you.
@@ -26,6 +27,8 @@ | |||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | |||
import com.hubspot.jinjava.interpret.TemplateSyntaxException; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra newlines please
|
||
import com.hubspot.jinjava.doc.annotations.JinjavaDoc; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaParam; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet; | ||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
import com.hubspot.jinjava.util.ForLoop; | ||
import com.hubspot.jinjava.util.ObjectIterator; | ||
import org.apache.commons.lang3.math.NumberUtils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix reordered import
@@ -16,6 +17,7 @@ | |||
import com.hubspot.jinjava.lib.fn.Functions; | |||
import com.hubspot.jinjava.objects.date.PyishDate; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space
@@ -49,5 +49,6 @@ public Object filter(Object var, JinjavaInterpreter interpreter, | |||
return str.equals("1") ? Boolean.TRUE : BooleanUtils.toBoolean(str); | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space
import com.hubspot.jinjava.doc.annotations.JinjavaDoc; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaParam; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet; | ||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
import com.hubspot.jinjava.interpret.TemplateSyntaxException; | ||
import org.apache.commons.lang3.StringUtils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import order
|
||
import com.google.common.collect.Lists; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaDoc; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaParam; | ||
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet; | ||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
import org.apache.commons.lang3.BooleanUtils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import order
@@ -9,6 +9,7 @@ | |||
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet; | |||
import com.hubspot.jinjava.interpret.JinjavaInterpreter; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space
@@ -21,7 +22,12 @@ | |||
}) | |||
public class DifferenceFilter extends AbstractSetFilter { | |||
|
|||
@Override | |||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is off here.
@boulter I'll add changes to this PR in the weekend. |
opening a different PR for the same. |
Fixes #159
Adds a method for processing the dictionary type in DefaultFilter.
Problem : Arguments were being converted to String [] before being processed by the DefaultFilter
Solution : Created a new method for processing the Object [], incase any
arg
is of typePyWrapper
. Implemented the function and created tests for the same.😄