Fixes #159 : Adds dict support for DefaultFilter#344
Conversation
| **********************************************************************/ | ||
| package com.hubspot.jinjava.lib.filter; | ||
|
|
||
| import java.math.BigDecimal; |
There was a problem hiding this comment.
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.
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.
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.
Could you either leave these as long lines or hard-wrap them on a logical boundary, like , (preferred)?
| List<String> stringArgs = new ArrayList<>(); | ||
|
|
||
| for (Object arg : allArgs) { | ||
| if(arg instanceof PyWrapper) { |
|
@boulter I've made changes to the files. |
|
cc : @boulter |
boulter
left a comment
There was a problem hiding this comment.
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.
| import com.hubspot.jinjava.interpret.InvalidReason; | ||
| import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
|
|
||
|
|
There was a problem hiding this comment.
can you remove extra space here?
| **********************************************************************/ | ||
| package com.hubspot.jinjava.lib.filter; | ||
|
|
||
| import java.util.HashMap; |
There was a problem hiding this comment.
still some lingering import reordering...
| } | ||
|
|
||
| return interpreter.resolveProperty(var, args[0]); | ||
| return interpreter.resolveProperty(var, args[0].toString()); |
| public Object filter(Object var, JinjavaInterpreter interpreter, | ||
| String... args) { | ||
|
|
||
| Object... args) { |
There was a problem hiding this comment.
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.
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.
Objects.toString(arg) will handle nulls for you.
| public String getName() { | ||
| return "unixtimestamp"; | ||
| } | ||
| @Override |
There was a problem hiding this comment.
please restore original indentation
| @Override | ||
| public Object filter(Object var, JinjavaInterpreter interpreter, | ||
| String... args) { | ||
| Object... args) { |
There was a problem hiding this comment.
can join with previous line
|
sure! will do the necessary changes |
|
@boulter I've added changes. please review again 🙏 |
boulter
left a comment
There was a problem hiding this comment.
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.
| 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.
Objects.toString will take care of nulls for you.
| import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
| import com.hubspot.jinjava.interpret.TemplateSyntaxException; | ||
|
|
||
|
|
There was a problem hiding this comment.
remove extra newlines please
| 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; |
| import com.hubspot.jinjava.lib.fn.Functions; | ||
| import com.hubspot.jinjava.objects.date.PyishDate; | ||
|
|
||
|
|
| return str.equals("1") ? Boolean.TRUE : BooleanUtils.toBoolean(str); | ||
| } | ||
|
|
||
|
|
| 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; |
| 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; |
| import com.hubspot.jinjava.doc.annotations.JinjavaSnippet; | ||
| import com.hubspot.jinjava.interpret.JinjavaInterpreter; | ||
|
|
||
|
|
| public class DifferenceFilter extends AbstractSetFilter { | ||
|
|
||
| @Override | ||
| @Override |
|
@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
argis of typePyWrapper. Implemented the function and created tests for the same.😄