Skip to content

Fixes #159 : Adds dict support for DefaultFilter#344

Closed
gabru-md wants to merge 5 commits into
HubSpot:masterfrom
gabru-md:patch-dict
Closed

Fixes #159 : Adds dict support for DefaultFilter#344
gabru-md wants to merge 5 commits into
HubSpot:masterfrom
gabru-md:patch-dict

Conversation

@gabru-md

Copy link
Copy Markdown
Contributor

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 type PyWrapper. Implemented the function and created tests for the same.

😄

@gabru-md

Copy link
Copy Markdown
Contributor Author

@boulter boulter left a comment

Copy link
Copy Markdown
Contributor

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!

**********************************************************************/
package com.hubspot.jinjava.lib.filter;

import java.math.BigDecimal;

Copy link
Copy Markdown
Contributor

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;

Copy link
Copy Markdown
Contributor

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;

Copy link
Copy Markdown
Contributor

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");

Copy link
Copy Markdown
Contributor

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)?

List<String> stringArgs = new ArrayList<>();

for (Object arg : allArgs) {
if(arg instanceof PyWrapper) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after if please

Comment thread src/main/java/com/hubspot/jinjava/lib/filter/DefaultFilter.java
@gabru-md

Copy link
Copy Markdown
Contributor Author

@boulter I've made changes to the files.
please review again 😄

@gabru-md

Copy link
Copy Markdown
Contributor Author

cc : @boulter

@boulter boulter left a comment

Copy link
Copy Markdown
Contributor

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.

import com.hubspot.jinjava.interpret.InvalidReason;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;


Copy link
Copy Markdown
Contributor

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?

**********************************************************************/
package com.hubspot.jinjava.lib.filter;

import java.util.HashMap;

Copy link
Copy Markdown
Contributor

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

}

return interpreter.resolveProperty(var, args[0]);
return interpreter.resolveProperty(var, args[0].toString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objects.toString is safer

public Object filter(Object var, JinjavaInterpreter interpreter,
String... args) {

Object... args) {

Copy link
Copy Markdown
Contributor

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) {

Copy link
Copy Markdown
Contributor

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));

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please restore original indentation

@Override
public Object filter(Object var, JinjavaInterpreter interpreter,
String... args) {
Object... args) {

Copy link
Copy Markdown
Contributor

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

@gabru-md

Copy link
Copy Markdown
Contributor Author

sure! will do the necessary changes

@gabru-md

gabru-md commented Jul 1, 2019

Copy link
Copy Markdown
Contributor Author

@boulter I've added changes. please review again 🙏

@boulter boulter left a comment

Copy link
Copy Markdown
Contributor

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.

throw new TemplateSyntaxException(interpreter, getName(), "requires 1 number (divisor) argument");
}
String toMul = arg[0];
String toMul = (arg[0] == null) ? null : Objects.toString(arg[0]);

Copy link
Copy Markdown
Contributor

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.

import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.interpret.TemplateSyntaxException;


Copy link
Copy Markdown
Contributor

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.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.util.ForLoop;
import com.hubspot.jinjava.util.ObjectIterator;
import org.apache.commons.lang3.math.NumberUtils;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix reordered import

import com.hubspot.jinjava.lib.fn.Functions;
import com.hubspot.jinjava.objects.date.PyishDate;


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

return str.equals("1") ? Boolean.TRUE : BooleanUtils.toBoolean(str);
}


Copy link
Copy Markdown
Contributor

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.JinjavaSnippet;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.interpret.TemplateSyntaxException;
import org.apache.commons.lang3.StringUtils;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import order

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import order

import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

public class DifferenceFilter extends AbstractSetFilter {

@Override
@Override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is off here.

@gabru-md

Copy link
Copy Markdown
Contributor Author

@boulter I'll add changes to this PR in the weekend.
I'm a bit busy with some stuff. Writing it down so that this PR doesn't get closed for inactivity.
cheers!

@raomuyang

Copy link
Copy Markdown
Contributor

@boulter I've created a checkstyle configuration to cover some scenarios as much as possible: #353

@gabru-md

Copy link
Copy Markdown
Contributor Author

opening a different PR for the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug dict default

3 participants