Skip to content

Commit

Permalink
Remove overrideFlag from freemarker processing (#2724)
Browse files Browse the repository at this point in the history
* Update FreeMarkerExecutor.java

* Change testflow

* remove unnecessary assert
  • Loading branch information
sprisha authored Apr 1, 2024
1 parent 067d7a7 commit bca1939
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,7 @@ public boolean isEmpty()

public static String processRecursively(String input, Map<String, ?> variableMap, String templateFunctions)
{
boolean overrideTemplateModelFlag = Boolean.valueOf(System.getProperty(overridePropertyForTemplateModel));
if (!overrideTemplateModelFlag)
{
return process(input, new TemplateHashModelOverride(variableMap, templateFunctions), templateFunctions);
}
else
{
return recur(input, variableMap, templateFunctions);
}
return process(input, new TemplateHashModelOverride(variableMap, templateFunctions), templateFunctions);
}

private static String recur(String input, Map<String,?> variableMap, String templateFunctions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public void testFreemarkerStringWithCombinationsAndSpecialCharacters() throws Ex
rootMap.put("C3", "${C4}");
rootMap.put("C4", "C4");
rootMap.put("D", "abcd<@efg");
//should fail in the old flow (since old flow processes placeholder with specialcharacter value twice, causing it to fail
Assert.assertThrows(RuntimeException.class, () -> processRecursivelyWithFlagSwitching(sql, rootMap, "", "this is A1 and B2 and C4 placeholders and abcd<@efg with special characters."));
System.clearProperty(overridePropertyForTemplateModel);
//processing should pass with new flow since it allows placeholder to process only once and avoid this issue.
Assert.assertEquals("this is A1 and B2 and C4 placeholders and abcd<@efg with special characters.", processRecursively(sql, rootMap, ""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,6 @@ public void testFreeMarkerProcessingForCombinationalPlaceholdersWithSpecialChara
//executePlan with freemarker placeholders in sql Query
String expectedResult = "{\"builder\":{\"_type\":\"tdsBuilder\",\"columns\":[{\"name\":\"fullName\",\"type\":\"String\",\"relationalType\":\"VARCHAR(100)\"}]},\"activities\":[{\"_type\":\"relational\",\"sql\":\"select \\\"root\\\".fullName as \\\"fullName\\\" from PERSON as \\\"root\\\" where ((\\\"root\\\".fullName in ('user1','user2','user3') and \\\"root\\\".firmName = 'abcd<@efg') and (\\\"root\\\".birthTime is null))\"}],\"result\":{\"columns\":[\"fullName\"],\"rows\":[]}}";
Assert.assertEquals(expectedResult, RelationalResultToJsonDefaultSerializer.removeComment(executePlan(plan, queryParameters)));

//check if old flow works as expected
System.setProperty(overridePropertyForTemplateModel, "true");
//in old flow, processing "<@" would fail ideally (this was our status quo)
Assert.assertThrows(RuntimeException.class, () -> RelationalResultToJsonDefaultSerializer.removeComment(executePlan(plan, queryParameters)));
System.clearProperty(overridePropertyForTemplateModel);
}

@Test
Expand Down

0 comments on commit bca1939

Please sign in to comment.