private void processGetInput(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate template, Map<String, AbstractPropertyValue> properties) { for (Map.Entry<String, AbstractPropertyValue> propEntry : safe(properties).entrySet()) { try { AbstractPropertyValue value = FunctionEvaluator.tryResolveValue(evaluatorContext, template, properties, propEntry.getValue()); if (propEntry.getValue() != value) { propEntry.setValue(value); } } catch (IllegalArgumentException e) { // FIXME we should add an error log rather than throwing the exception here. See internal of FunctionEvaluator.resolveValue and especially // concat processing. throw e; } } } }
private static AbstractPropertyValue concat(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate template, Map<String, AbstractPropertyValue> properties, ConcatPropertyValue concatPropertyValue) { StringBuilder sb = new StringBuilder(); for (AbstractPropertyValue abstractPropertyValue : concatPropertyValue.getParameters()) { AbstractPropertyValue propertyValue = tryResolveValue(evaluatorContext, template, properties, abstractPropertyValue); if (propertyValue == null) { // Ignore this as it may be a null default value } else if (propertyValue instanceof ScalarPropertyValue) { sb.append(((ScalarPropertyValue) propertyValue).getValue()); } else if (propertyValue instanceof ListPropertyValue) { for (Object listValue : ((ListPropertyValue) propertyValue).getValue()) { if (listValue instanceof String) { sb.append(listValue); } else { throw new IllegalArgumentException("Concat can only be resolved for strings or list of strings."); } } } else if (propertyValue instanceof FunctionPropertyValue && ToscaFunctionConstants.GET_INPUT.equals(((FunctionPropertyValue) propertyValue).getFunction())) { // just ignore that as unprocessed inputs are from voluntary callback in the evaluator context for later processing. log.debug("Ignoring contact of an unresolved get_input function."); } else { throw new IllegalArgumentException("Concat can only be resolved for strings or list of strings."); } } return new ScalarPropertyValue(sb.toString()); }
private static AbstractPropertyValue getFromPath(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, Map<String, AbstractPropertyValue> properties, String propertyPath) { if (propertyPath.contains(".")) { String propertyName = propertyPath.split("\\.")[0]; AbstractPropertyValue propertyValue = properties.get(propertyName); if (!(propertyValue instanceof PropertyValue)) { // if the value is not a property value resolve it first propertyValue = tryResolveValue(evaluatorContext, targetTemplate, properties, propertyValue); if (propertyValue == null) { return null; } } // now it is a property value Object value = MapUtil.get(((PropertyValue) propertyValue).getValue(), propertyPath.substring(propertyName.length() + 1)); if (value == null) { return null; } else if (value instanceof String) { return new ScalarPropertyValue((String) value); } else if (value instanceof List) { return new ListPropertyValue((List<Object>) value); } else if (value instanceof Map) { return new ComplexPropertyValue((Map<String, Object>) value); } throw new IllegalArgumentException("The value of a property must be a scalar, a list or a map."); } return safe(properties).get(propertyPath); }
AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, template, properties, function.getElementNameToFetch()); if (propertyValue != null) { return tryResolveValue(evaluatorContext, template, properties, propertyValue); params.addAll(function.getParameters().subList(2, function.getParameters().size())); FunctionPropertyValue newFunc = new FunctionPropertyValue(function.getFunction(), params); return tryResolveValue(evaluatorContext, firstNode, firstNode.getProperties(), newFunc);
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue); return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);