@Test public void invalidTemplate() { final String[] expressions = { "${child.id}" }; assertThrows( InvalidSyntaxException.class, () -> new LogMessage("{}", childRecord, expressions, 1, Optional.empty()).getMessage()); }
public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final Object user = getUser(); if (user != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( user, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } }
LogMessage { public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final Object user = getUser(); if (user != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( user, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } } }
LogMessage { public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final Object user = getUser(); if (user != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( user, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } } LogMessage(String template, int code);  LogMessage(Audit audit, PersistentResource record, Optional<ChangeSpec> changeSpec);  LogMessage(String template,
            PersistentResource record,
            String[] expressions,
            int code,
            Optional<ChangeSpec> changeSpec); }
LogMessage { public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final Object user = getUser(); if (user != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( user, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } } LogMessage(String template, int code);  LogMessage(Audit audit, PersistentResource record, Optional<ChangeSpec> changeSpec);  LogMessage(String template,
            PersistentResource record,
            String[] expressions,
            int code,
            Optional<ChangeSpec> changeSpec); int getOperationCode(); String getMessage(); RequestScope getRequestScope(); Object getUser(); Optional<ChangeSpec> getChangeSpec(); @Override String toString(); }
LogMessage { public String getMessage() { final SimpleContext ctx = new SimpleContext(); final SimpleContext singleElementContext = new SimpleContext(); if (record != null) { ResourceLineage lineage = new ResourceLineage(record.getLineage(), record); for (String name : lineage.getKeys()) { List<PersistentResource> values = lineage.getRecord(name); final ValueExpression expression; final ValueExpression singleElementExpression; if (values.size() == 1) { expression = EXPRESSION_FACTORY.createValueExpression(values.get(0).getObject(), Object.class); singleElementExpression = expression; } else { List<Object> objects = values.stream().map(PersistentResource::getObject) .collect(Collectors.toList()); expression = EXPRESSION_FACTORY.createValueExpression(objects, List.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(values.get(values.size() - 1) .getObject(), Object.class); } ctx.setVariable(name, expression); singleElementContext.setVariable(name, singleElementExpression); } final Object user = getUser(); if (user != null) { final ValueExpression opaqueUserValueExpression = EXPRESSION_FACTORY .createValueExpression( user, Object.class ); ctx.setVariable("opaqueUser", opaqueUserValueExpression); singleElementContext.setVariable("opaqueUser", opaqueUserValueExpression); } } Object[] results = new Object[expressions.length]; for (int idx = 0; idx < results.length; idx++) { String expressionText = expressions[idx]; final ValueExpression expression; final ValueExpression singleElementExpression; try { expression = EXPRESSION_FACTORY.createValueExpression(ctx, expressionText, Object.class); singleElementExpression = EXPRESSION_FACTORY.createValueExpression(singleElementContext, expressionText, Object.class); } catch (ELException e) { throw new InvalidSyntaxException(e); } Object result; try { result = singleElementExpression.getValue(singleElementContext); } catch (PropertyNotFoundException e) { result = expression.getValue(ctx); } results[idx] = result; } try { return MessageFormat.format(template, results); } catch (IllegalArgumentException e) { throw new InvalidSyntaxException(e); } } LogMessage(String template, int code);  LogMessage(Audit audit, PersistentResource record, Optional<ChangeSpec> changeSpec);  LogMessage(String template,
            PersistentResource record,
            String[] expressions,
            int code,
            Optional<ChangeSpec> changeSpec); int getOperationCode(); String getMessage(); RequestScope getRequestScope(); Object getUser(); Optional<ChangeSpec> getChangeSpec(); @Override String toString();  }