3  *  ============LICENSE_START=======================================================
 
   4  *  Copyright (C) 2022 Nordix Foundation.
 
   5  *  ================================================================================
 
   6  *  Licensed under the Apache License, Version 2.0 (the "License");
 
   7  *  you may not use this file except in compliance with the License.
 
   8  *  You may obtain a copy of the License at
 
  10  *       http://www.apache.org/licenses/LICENSE-2.0
 
  12  *  Unless required by applicable law or agreed to in writing, software
 
  13  *  distributed under the License is distributed on an "AS IS" BASIS,
 
  14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  15  *  See the License for the specific language governing permissions and
 
  16  *  limitations under the License.
 
  18  *  SPDX-License-Identifier: Apache-2.0
 
  19  *  ============LICENSE_END=========================================================
 
  22 package org.openecomp.sdc.be.components.impl.exceptions;
 
  24 import java.util.List;
 
  25 import java.util.function.Supplier;
 
  26 import lombok.AccessLevel;
 
  27 import lombok.NoArgsConstructor;
 
  28 import org.openecomp.sdc.be.dao.api.ActionStatus;
 
  29 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
 
  30 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
 
  32 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 
  33 public class ToscaGetFunctionExceptionSupplier {
 
  35     public static Supplier<ByActionStatusComponentException> targetSourceNotSupported(final ToscaGetFunctionType toscaGetFunctionType,
 
  36                                                                                       final PropertySource propertySource) {
 
  37         final String errorMsg = String.format("%s on %s", toscaGetFunctionType.getFunctionName(), propertySource.getName());
 
  38         return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, errorMsg);
 
  41     public static Supplier<ByActionStatusComponentException> propertyNotFoundOnTarget(final String propertyName,
 
  42                                                                                       final PropertySource propertySource,
 
  43                                                                                       final ToscaGetFunctionType functionType) {
 
  44         return propertyNotFoundOnTarget(List.of(propertyName), propertySource, functionType);
 
  47     public static Supplier<ByActionStatusComponentException> propertyNotFoundOnTarget(final List<String> propertyPathFromSource,
 
  48                                                                                       final PropertySource propertySource,
 
  49                                                                                       final ToscaGetFunctionType functionType) {
 
  50         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_GET_FUNCTION_PROPERTY_NOT_FOUND, functionType.getPropertyType(),
 
  51             String.join("->", propertyPathFromSource), propertySource.getName());
 
  54     public static Supplier<ByActionStatusComponentException> propertyDataTypeNotFound(final String propertyName,
 
  55                                                                                       final String dataType,
 
  56                                                                                       final ToscaGetFunctionType functionType) {
 
  57         return propertyDataTypeNotFound(List.of(propertyName), dataType, functionType);
 
  60     public static Supplier<ByActionStatusComponentException> propertyDataTypeNotFound(final List<String> propertyPathFromSource,
 
  61                                                                                       final String dataType,
 
  62                                                                                       final ToscaGetFunctionType functionType) {
 
  63         return () -> new ByActionStatusComponentException(
 
  64             ActionStatus.TOSCA_GET_FUNCTION_PROPERTY_DATA_TYPE_NOT_FOUND,
 
  65             functionType.getPropertyType(), String.join("->", propertyPathFromSource), dataType
 
  69     public static Supplier<ByActionStatusComponentException> couldNotLoadDataTypes(final String model) {
 
  70         return () -> new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
 
  73     public static Supplier<ByActionStatusComponentException> functionNotSupported(final ToscaGetFunctionType functionType) {
 
  74         return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, "Tosca function " + functionType.getFunctionName());
 
  77     public static Supplier<ByActionStatusComponentException> propertyTypeDiverge(final ToscaGetFunctionType functionType,
 
  78                                                                                  final String referredPropertyType,
 
  79                                                                                  final String propertyType) {
 
  80         return () -> new ByActionStatusComponentException(
 
  81             ActionStatus.TOSCA_GET_FUNCTION_TYPE_DIVERGE,
 
  82             functionType.getFunctionName(), referredPropertyType, propertyType
 
  86     public static Supplier<ByActionStatusComponentException> propertySchemaDiverge(final ToscaGetFunctionType functionType,
 
  87                                                                                    final String referredPropertySchemaType,
 
  88                                                                                    final String propertySchemaType) {
 
  89         return () -> new ByActionStatusComponentException(
 
  90             ActionStatus.TOSCA_GET_FUNCTION_SCHEMA_DIVERGE,
 
  91             functionType.getFunctionName(), referredPropertySchemaType, propertySchemaType