+ private static Optional<ToscaFunction> handleGetPropertyFunction(Map<String, Object> toscaFunctionPropertyValueMap, String functionType,
+ ToscaFunctionType toscaFunctionType) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(
+ toscaFunctionType == ToscaFunctionType.GET_PROPERTY ? ToscaGetFunctionType.GET_PROPERTY : ToscaGetFunctionType.GET_ATTRIBUTE
+ );
+ final Object functionValueObj = toscaFunctionPropertyValueMap.get(functionType);
+ if (!(functionValueObj instanceof List)) {
+ return Optional.empty();
+ }
+ final List<String> functionParameters;
+ try {
+ functionParameters = (List<String>) functionValueObj;
+ } catch (final ClassCastException ignored) {
+ return Optional.empty();
+ }
+ if (functionParameters.size() < 2) {
+ return Optional.empty();
+ }
+ final String propertySourceType = functionParameters.get(0);
+ final PropertySource propertySource = PropertySource.findType(propertySourceType).orElse(null);
+ if (propertySource == PropertySource.SELF) {
+ toscaGetFunction.setPropertySource(propertySource);
+ } else {
+ toscaGetFunction.setPropertySource(PropertySource.INSTANCE);
+ toscaGetFunction.setSourceName(propertySourceType);
+ }
+ toscaGetFunction.setPropertyPathFromSource(functionParameters.subList(1, functionParameters.size()));
+ final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1);
+ toscaGetFunction.setPropertyName(propertyName);
+ return Optional.of(toscaGetFunction);
+ }
+
+ private static Optional<ToscaFunction> handleGetInputFunction(Map<String, Object> toscaFunctionPropertyValueMap, String functionType) {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
+ toscaGetFunction.setPropertySource(PropertySource.SELF);
+ final Object functionValueObj = toscaFunctionPropertyValueMap.get(functionType);
+ if (!(functionValueObj instanceof List) && !(functionValueObj instanceof String)) {
+ return Optional.empty();
+ }
+ if (functionValueObj instanceof String) {
+ toscaGetFunction.setPropertyPathFromSource(List.of((String) functionValueObj));
+ } else {
+ final List<String> functionParameters;
+ try {
+ functionParameters = (List<String>) functionValueObj;
+ } catch (final ClassCastException ignored) {
+ return Optional.empty();
+ }
+ toscaGetFunction.setPropertyPathFromSource(functionParameters);
+ }
+ final String propertyName = toscaGetFunction.getPropertyPathFromSource().get(toscaGetFunction.getPropertyPathFromSource().size() - 1);
+ toscaGetFunction.setPropertyName(propertyName);
+ return Optional.of(toscaGetFunction);
+ }
+