Comments (9)
Yep -
is reserved character for minus operation.
from jinjava.
Do you have a unit test that replicates the broken behavior you are seeing?
from jinjava.
No, I don't have. I can share my code, if you need
from jinjava.
Yep we would need to see your template and how you construct your context.
from jinjava.
this is my config file: application.yml
trinodb:
url: jdbc:trino://egap-trino.egdp-analytics.aws.away.black:8443/hive?SSL=true&SSLVerification=NONE
driverClass: io.trino.jdbc.TrinoDriver
catalog: hive
aws:
secretmanager:
storename: affiliate/cofund-reporting/trino-dev
environment: dev
supplyDb: egdp_prod_supply
accountManagementDb: egdp_prod_accountmanagement
#opportunity_view: cpce_affiliate.opportunity_to_sf
view:
opportunity-to-sf: cpce_affiliate
table:
supply-lodging-profile: egdp_prod_supply
sync-price-currency: bexg_prod_sync
booking-coupon: egdp_classic_booking
booking-order-summary: hcom_data_prod_uw2_bix_booking
booking-order: hcom_data_prod_uw2_bix_booking
sync-cards: bexg_prod_sync
this is my java file:
package com.expediagroup.cofundreportapiservice.dao;
import com.expediagroup.cofundreportapiservice.domain.GetDataForPartnerRequest;
import com.expediagroup.cofundreportapiservice.domain.Performance;
import com.expediagroup.cofundreportapiservice.domain.Transaction;
import com.hubspot.jinjava.Jinjava;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@component
public class TrinoCofundReportDao implements CofundReportDao {
private static final Logger LOG = LoggerFactory.getLogger(TrinoCofundReportDao.class);
private String transactionQueryTemplate;
private String performanceQueryTemplate;
private final String summaryWithCancel;
private final String summaryWithoutCancel;
private final String timeFrameStringCardsConsumedTrue;
private final String timeFrameStringHcomConsumedTrue;
private final String timeFrameStringCardsConsumedFalse;
private final String timeFrameStringHcomConsumedFalse;
//private final String opportunityToSf;
@Autowired
private JdbcTemplate trinoJdbcTemplate;
private Jinjava jinJava = new Jinjava();
private TransactionMapper transactionMapper = new TransactionMapper();
private PerformanceMapper performanceMapper = new PerformanceMapper();
@value("${environment}")
private String env;
@Value("${table.supply-lodging-profile}")
private String supply;
@Value("${table.sync-cards}")
private String cards;
@Value("${accountManagementDb}")
private String accountManagementDb;
@Value("${view.opportunity-to-sf}")
private String opportunityView;
@Value("${table.sync-price-currency}")
private String currency;
@Value("${table.booking-coupon}")
private String bookingCoupon;
@Value("${table.booking-order-summary}")
private String bookingOrderSummary;
@Value("${table.booking-order}")
private String bookingOrder;
public TrinoCofundReportDao() {
summaryWithCancel = readClasspathResource("aggregateExcludeCancelTrue.jinja");
summaryWithoutCancel = readClasspathResource("aggregateExcludeCancelFalse.jinja");
timeFrameStringCardsConsumedTrue = readClasspathResource("timeFrame_bex_string_ConsumedTrue.jinja");
timeFrameStringHcomConsumedTrue = readClasspathResource("timeFrame_hcom_string_ConsumedTrue.jinja");
timeFrameStringCardsConsumedFalse = readClasspathResource("timeFrame_bex_string_ConsumedFalse.jinja");
timeFrameStringHcomConsumedFalse = readClasspathResource("timeFrame_hcom_string_ConsumedFalse.jinja");
//opportunityToSf = readClasspathResource("opportunityToSf.jinja");
}
private String readClasspathResource(String fileName) {
try {
return FileCopyUtils.copyToString(new InputStreamReader(new ClassPathResource(fileName).getInputStream()));
} catch (IOException e) {
throw new RuntimeException("Unable to read file " + fileName, e);
}
}
@Override
public List<Performance> getPerformanceMetricsForPartner(GetDataForPartnerRequest request) {
if ("test".equals(env)) {
performanceQueryTemplate = readClasspathResource("performanceQueryTemplateTest.jinja");
} else {
performanceQueryTemplate = readClasspathResource("performanceQueryTemplate.jinja");
}
final String performanceQueryString = getQueryString(request, performanceQueryTemplate);
LOG.info("Now calling getPerformanceMetricsForPartner())");
LOG.info("performanceQueryString.first =" + performanceQueryString.substring(0, 16 * 1024));
LOG.info("performanceQueryString.second =" + performanceQueryString.substring(16 * 1024));
LOG.info("+++Test opportunity table:");
LOG.info(trinoJdbcTemplate.queryForList("select * from " + accountManagementDb + ".retailpartner_eps_opportunity_domain_event_v1 limit 2").toString());
LOG.info("+++Test retail partner table:");
LOG.info(trinoJdbcTemplate.queryForList("select * from " + accountManagementDb + ".retailpartner_eps_opportunity_domain_event_v1 limit 2").toString());
LOG.info("+++Test opportunity view :");
//LOG.info(trinoJdbcTemplate.queryForList("select * from " + opportunityView + " limit 2").toString());
LOG.info("+++Test retail cards table:");
LOG.info(trinoJdbcTemplate.queryForList("select * from bexg_prod_sync.cards limit 2").toString());
LOG.info("+++Test retail hcom order:");
LOG.info(trinoJdbcTemplate.queryForList("select * from hcom_data_prod_uw2_bix_booking.hermes_bkg_order limit 2").toString());
LOG.info("+++Test retail hcom order summary:");
LOG.info(trinoJdbcTemplate.queryForList("select * from hcom_data_prod_uw2_bix_booking.hermes_booking_omniture_order_summary limit 2").toString());
LOG.info("+++Test retail coupon dim table:");
LOG.info(trinoJdbcTemplate.queryForList("select * from egdp_classic_booking.coupn_dim limit 2").toString());
LOG.info("+++Test retail supply table:");
//LOG.info(trinoJdbcTemplate.queryForList("select * from " + supply + ".lodging_profile_eg limit 2").toString());
LOG.info("+++Test retail price currency table:");
LOG.info(trinoJdbcTemplate.queryForList("select * from bexg_prod_sync.price_currn_dim limit 2").toString());
final List<Performance> results = trinoJdbcTemplate.query(performanceQueryString, performanceMapper);
LOG.info("Results of performance report: " + results);
return results;
}
@Override
public List<Transaction> getTransactionsForPartner(GetDataForPartnerRequest request) {
if ("test".equals(env)) {
transactionQueryTemplate = readClasspathResource("transactionQueryTemplateTest.jinja");
} else {
transactionQueryTemplate = readClasspathResource("transactionQueryTemplate.jinja");
}
final String transactionQueryString = getQueryString(request, transactionQueryTemplate);
return trinoJdbcTemplate.query(transactionQueryString, transactionMapper);
}
private String getQueryString(GetDataForPartnerRequest request, String queryTemplate) {
final Map<String, Object> timeFrTemplateValues = new HashMap<>();
final Map<String, Object> templateValues = new HashMap<>();
final String dateFrom = request.getDateFrom().format(DateTimeFormatter.ISO_LOCAL_DATE);
final String dateTo = request.getDateTo().format(DateTimeFormatter.ISO_LOCAL_DATE);
templateValues.put("partner_id", request.getPartnerId());
System.out.println("\n\n\n\\\n\\n\n\ncheckcheckcheck supply "+supply+"\n\\n\n\n\n\n\n\n");
templateValues.put("supply-lodging-profile", supply);
System.out.println("\n\n\n\\\n\\n\n\ncheckcheckcheck opportunityView "+opportunityView+"\n\\n\n\n\n\n\n\n");
templateValues.put("opportunity-to-sf", opportunityView);
System.out.println("\n\n\n\\\n\\n\n\ncheckcheckcheck currency "+currency+"\n\\n\n\n\n\n\n\n");
templateValues.put("sync-price-currency", currency);
System.out.println("\n\n\n\\\n\\n\n\ncheckcheckcheck bookingCoupon "+bookingCoupon+"\n\\n\n\n\n\n\n\n");
templateValues.put("booking-coupon", bookingCoupon);
System.out.println("\n\n\n\\\n\\n\n\ncheckcheckcheck bookingOrderSummary "+bookingOrderSummary+"\n\\n\n\n\n\n\n\n");
templateValues.put("booking-order-summary", bookingOrderSummary);
System.out.println("\n\n\n\\\n\\n\n\ncheckcheckcheck bookingOrder "+bookingOrder+"\n\\n\n\n\n\n\n\n");
templateValues.put("booking-order", bookingOrder);
timeFrTemplateValues.put("date_from", dateFrom);
timeFrTemplateValues.put("date_to", dateTo);
final var timeFrCardsConsumedTrue = jinJava.render(timeFrameStringCardsConsumedTrue, timeFrTemplateValues);
final var timeFrCardsConsumedFalse = jinJava.render(timeFrameStringCardsConsumedFalse, timeFrTemplateValues);
final var timeFrHcomConsumedFalse = jinJava.render(timeFrameStringHcomConsumedFalse, timeFrTemplateValues);
final var timeFrHcomConsumedTrue = jinJava.render(timeFrameStringHcomConsumedTrue, timeFrTemplateValues);
if (request.isConsumed()) {
templateValues.put("timeframe_string_cards", timeFrCardsConsumedTrue);
templateValues.put("timeframe_string_hcom", timeFrHcomConsumedTrue);
} else {
templateValues.put("timeframe_string_cards", timeFrCardsConsumedFalse);
templateValues.put("timeframe_string_hcom", timeFrHcomConsumedFalse);
}
if (request.isExcludeCancellations()) {
templateValues.put("aggregate_section", summaryWithCancel);
} else {
templateValues.put("aggregate_section", summaryWithoutCancel);
}
System.out.println("\n\n\n\\\n\\n\n\nblablablablabla booking-order-summary "+templateValues+"\n\\n\n\n\n\n\n\n");
return jinJava.render(queryTemplate, templateValues);
}
}
Values are fetched successfully form configs. I even printed them right before return "jinJava.render(queryTemplate, templateValues);" line and those were there. but when rendered, they are injected as 0.
from jinjava.
I can confirm this behavior. I am using Java 17, and each and every render returns "0"
from jinjava.
@Indystef are you able to post a concise reproduction example? Preferably a unit test in this repo that demonstrates the behavior
from jinjava.
I figured it out. Just use an expression with a minus sign in it ... that gets interpreted as a numeric operation. For instance this code:
Jinjava jinjava = new Jinjava();
var context = Map.of( "test-expression", "world");
var template = "Hello {{ test-expression }}";
var result = jinjava.render(template, context);
System.out.println(result);
will output "Hello 0"
from jinjava.
from jinjava.
Related Issues (20)
- Can Dict key be an integer? HOT 2
- CVEs in current version: 2.7.0
- time for 2.7.1 / 2.8.0 ?
- Unexpected behavior comparing empty strings to 0
- Is the expression interpolation recursive? HOT 1
- Problem with using the function in nested interpretation HOT 2
- SnakeYAML 1.27 vulnerability in Jinjava 2.7.1 HOT 1
- Add {% hubl %} tag
- Maps in string representation in Сontext
- Support for "with" statement
- Resolve function with map like contructs HOT 1
- Mixing include and extends does not work
- Fix CVEs in version 2.7.1
- Inconsistent implementation with jinja2 HOT 1
- trouble with coercision in test
- Add support for java records HOT 1
- Rendering template with custom function in Scala throws NullPointerException HOT 4
- [question] receiving fixes flow // GHSA-h75v-3vvj-5mfj CVE-2024-34064 HOT 2
- upgrade commons-net to 3.10.0
- Fix eager execution handling of `{% print foo|render %}`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jinjava.