@Test @SuppressWarnings("unchecked") public void testTransformRow() { List fields = new ArrayList(); fields.add(AbstractDataImportHandlerTest.createMap("column", "firstName")); fields.add(AbstractDataImportHandlerTest.createMap("column", "lastName")); fields.add(AbstractDataImportHandlerTest.createMap("column", "middleName")); fields.add(AbstractDataImportHandlerTest.createMap("column", "name", TemplateTransformer.TEMPLATE, "${e.lastName}, ${e.firstName} ${e.middleName}")); fields.add(AbstractDataImportHandlerTest.createMap("column", "mrname", TemplateTransformer.TEMPLATE,"Mr ${e.name}")); Map row = AbstractDataImportHandlerTest.createMap( "firstName", "Shalin", "middleName", "Shekhar", "lastName", "Mangar"); VariableResolverImpl resolver = new VariableResolverImpl(); resolver.addNamespace("e", row); Map<String, String> entityAttrs = AbstractDataImportHandlerTest.createMap( "name", "e"); Context context = AbstractDataImportHandlerTest.getContext(null, resolver, null, Context.FULL_DUMP, fields, entityAttrs); new TemplateTransformer().transformRow(row, context); Assert.assertEquals("Mangar, Shalin Shekhar", row.get("name")); Assert.assertEquals("Mr Mangar, Shalin Shekhar", row.get("mrname")); }
@SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolverImpl resolver = (VariableResolverImpl) context .getVariableResolver(); for (Map<String, String> map : context.getAllEntityFields()) { String expr = map.get(TEMPLATE); if (expr == null) continue; String column = map.get(DataImporter.COLUMN); boolean resolvable = true; List<String> variables = TemplateString.getVariables(expr); for (String v : variables) { if (resolver.resolve(v) == null) { LOG.warn("Unable to resolve variable: " + v + " while parsing expression: " + expr); resolvable = false; } } if (!resolvable) continue; row.put(column, resolver.replaceTokens(expr)); } return row; }
TemplateTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolverImpl resolver = (VariableResolverImpl) context .getVariableResolver(); for (Map<String, String> map : context.getAllEntityFields()) { String expr = map.get(TEMPLATE); if (expr == null) continue; String column = map.get(DataImporter.COLUMN); boolean resolvable = true; List<String> variables = TemplateString.getVariables(expr); for (String v : variables) { if (resolver.resolve(v) == null) { LOG.warn("Unable to resolve variable: " + v + " while parsing expression: " + expr); resolvable = false; } } if (!resolvable) continue; row.put(column, resolver.replaceTokens(expr)); } return row; } }
TemplateTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolverImpl resolver = (VariableResolverImpl) context .getVariableResolver(); for (Map<String, String> map : context.getAllEntityFields()) { String expr = map.get(TEMPLATE); if (expr == null) continue; String column = map.get(DataImporter.COLUMN); boolean resolvable = true; List<String> variables = TemplateString.getVariables(expr); for (String v : variables) { if (resolver.resolve(v) == null) { LOG.warn("Unable to resolve variable: " + v + " while parsing expression: " + expr); resolvable = false; } } if (!resolvable) continue; row.put(column, resolver.replaceTokens(expr)); } return row; }  }
TemplateTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolverImpl resolver = (VariableResolverImpl) context .getVariableResolver(); for (Map<String, String> map : context.getAllEntityFields()) { String expr = map.get(TEMPLATE); if (expr == null) continue; String column = map.get(DataImporter.COLUMN); boolean resolvable = true; List<String> variables = TemplateString.getVariables(expr); for (String v : variables) { if (resolver.resolve(v) == null) { LOG.warn("Unable to resolve variable: " + v + " while parsing expression: " + expr); resolvable = false; } } if (!resolvable) continue; row.put(column, resolver.replaceTokens(expr)); } return row; }  @SuppressWarnings("unchecked") Object transformRow(Map<String, Object> row, Context context); }
TemplateTransformer extends Transformer { @SuppressWarnings("unchecked") public Object transformRow(Map<String, Object> row, Context context) { VariableResolverImpl resolver = (VariableResolverImpl) context .getVariableResolver(); for (Map<String, String> map : context.getAllEntityFields()) { String expr = map.get(TEMPLATE); if (expr == null) continue; String column = map.get(DataImporter.COLUMN); boolean resolvable = true; List<String> variables = TemplateString.getVariables(expr); for (String v : variables) { if (resolver.resolve(v) == null) { LOG.warn("Unable to resolve variable: " + v + " while parsing expression: " + expr); resolvable = false; } } if (!resolvable) continue; row.put(column, resolver.replaceTokens(expr)); } return row; }  @SuppressWarnings("unchecked") Object transformRow(Map<String, Object> row, Context context); static final String TEMPLATE; }