java/view-templates/src/main/java/io/opensaber/views/ViewTransformer.java
/**
     * Transforms a single node for given view template
     * 
     * @param viewTemplate
     * @param nodeAttrs
     * @return
     */
Transforms a single node for given view template

@param viewTemplate
@param nodeAttrs
@return
Transforms a single node for given view template @param viewTemplate @param nodeAttrs @return
private JsonNode tranformNode(ViewTemplate viewTemplate, JsonNode nodeAttrs) throws Exception {
        ObjectNode result = JsonNodeFactory.instance.objectNode();
        for (Field field : viewTemplate.getFields()) {
            String functionStr = field.getFunction();
            if (functionStr != null) {
                String fdName = field.getFunctioName();
                FunctionDefinition funcDef = viewTemplate.getFunctionDefinition(fdName);            
                List<Object> actualValues = new ArrayList<>();
                for (String oneArg : field.getArgNames()) {
                	if(nodeAttrs.get(oneArg.substring(1)) != null) {
                        actualValues.add(ValueType.getValue(nodeAttrs.get(oneArg.substring(1))));
                	}
                }
                IEvaluator<Object> evaluator = EvaluatorFactory.getInstance(funcDef, actualValues);
                if (field.getDisplay()) {
                    Object evaluatedValue = evaluator.evaluate();
                    if(evaluatedValue instanceof String){
                        result.put(field.getTitle(), evaluatedValue.toString());
                    } else {
                        result.set(field.getTitle(), JsonNodeFactory.instance.pojoNode(evaluatedValue));
                    }
                }
            } else if (field.getDisplay()) {
                result.set(field.getTitle(), nodeAttrs.get(field.getName()));
            }
        }
        return result;
    }
private JsonNode tranformNode ( ViewTemplate viewTemplate , JsonNode nodeAttrs ) throws Exception { ObjectNode result = JsonNodeFactory . instance . objectNode ( ) ; for ( Field field : viewTemplate . getFields ( ) ) { String functionStr = field . getFunction ( ) ; if ( functionStr != null ) { String fdName = field . getFunctioName ( ) ; FunctionDefinition funcDef = viewTemplate . getFunctionDefinition ( fdName ) ; List < Object > actualValues = new ArrayList < > ( ) ; for ( String oneArg : field . getArgNames ( ) ) { if ( nodeAttrs . get ( oneArg . substring ( 1 ) ) != null ) { actualValues . add ( ValueType . getValue ( nodeAttrs . get ( oneArg . substring ( 1 ) ) ) ) ; } } IEvaluator < Object > evaluator = EvaluatorFactory . getInstance ( funcDef , actualValues ) ; if ( field . getDisplay ( ) ) { Object evaluatedValue = evaluator . evaluate ( ) ; if ( evaluatedValue instanceof String ) { result . put ( field . getTitle ( ) , evaluatedValue . toString ( ) ) ; } else { result . set ( field . getTitle ( ) , JsonNodeFactory . instance . pojoNode ( evaluatedValue ) ) ; } } } else if ( field . getDisplay ( ) ) { result . set ( field . getTitle ( ) , nodeAttrs . get ( field . getName ( ) ) ) ; } } return result ; }
Transforms a single node for given view template
Transforms a single node for given view template
// Cut off the $ // if display is set, show up the field in result    