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.elements.ToscaFunctionType;
30 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
31 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
33 @NoArgsConstructor(access = AccessLevel.PRIVATE)
34 public class ToscaGetFunctionExceptionSupplier {
36 public static Supplier<ByActionStatusComponentException> targetSourceNotSupported(final ToscaGetFunctionType toscaGetFunctionType,
37 final PropertySource propertySource) {
38 final String errorMsg = String.format("%s on %s", toscaGetFunctionType.getFunctionName(), propertySource.getName());
39 return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, errorMsg);
42 public static Supplier<ByActionStatusComponentException> propertyNotFoundOnTarget(final String propertyName,
43 final PropertySource propertySource,
44 final ToscaGetFunctionType functionType) {
45 return propertyNotFoundOnTarget(List.of(propertyName), propertySource, functionType);
48 public static Supplier<ByActionStatusComponentException> targetFunctionTypeNotFound() {
49 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "function type");
52 public static Supplier<ByActionStatusComponentException> targetPropertySourceNotFound(final ToscaGetFunctionType toscaGetFunctionType) {
53 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property source of " + toscaGetFunctionType);
56 public static Supplier<ByActionStatusComponentException> targetSourcePathNotFound(final ToscaGetFunctionType toscaGetFunctionType) {
57 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source path of " + toscaGetFunctionType);
60 public static Supplier<ByActionStatusComponentException> propertyNameNotFound(final PropertySource propertySource) {
61 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property name of source "
65 public static Supplier<ByActionStatusComponentException> propertyIdNotFound(final PropertySource propertySource) {
66 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property id of source "
70 public static Supplier<ByActionStatusComponentException> sourceNameNotFound(final PropertySource propertySource) {
71 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source name of "
75 public static Supplier<ByActionStatusComponentException> sourceIdNotFound(final PropertySource propertySource) {
76 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source id of "
80 public static Supplier<ByActionStatusComponentException> propertyNotFoundOnTarget(final List<String> propertyPathFromSource,
81 final PropertySource propertySource,
82 final ToscaGetFunctionType functionType) {
83 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_GET_FUNCTION_PROPERTY_NOT_FOUND, functionType.getPropertyType(),
84 String.join("->", propertyPathFromSource), propertySource.getName());
87 public static Supplier<ByActionStatusComponentException> propertyDataTypeNotFound(final String propertyName,
88 final String dataType,
89 final ToscaGetFunctionType functionType) {
90 return propertyDataTypeNotFound(List.of(propertyName), dataType, functionType);
93 public static Supplier<ByActionStatusComponentException> propertyDataTypeNotFound(final List<String> propertyPathFromSource,
94 final String dataType,
95 final ToscaGetFunctionType functionType) {
96 return () -> new ByActionStatusComponentException(
97 ActionStatus.TOSCA_GET_FUNCTION_PROPERTY_DATA_TYPE_NOT_FOUND,
98 functionType.getPropertyType(), String.join("->", propertyPathFromSource), dataType
102 public static Supplier<ByActionStatusComponentException> couldNotLoadDataTypes(final String model) {
103 return () -> new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
106 public static Supplier<ByActionStatusComponentException> functionNotSupported(final ToscaGetFunctionType functionType) {
107 return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, "Tosca function " + functionType.getFunctionName());
110 public static Supplier<ByActionStatusComponentException> propertyTypeDiverge(final ToscaFunctionType functionType,
111 final String referredPropertyType,
112 final String propertyType) {
113 return () -> new ByActionStatusComponentException(
114 ActionStatus.TOSCA_GET_FUNCTION_TYPE_DIVERGE,
115 functionType.getName(), referredPropertyType, propertyType
119 public static Supplier<ByActionStatusComponentException> propertySchemaDiverge(final ToscaFunctionType functionType,
120 final String referredPropertySchemaType,
121 final String propertySchemaType) {
122 return () -> new ByActionStatusComponentException(
123 ActionStatus.TOSCA_GET_FUNCTION_SCHEMA_DIVERGE,
124 functionType.getName(), referredPropertySchemaType, propertySchemaType
128 public static Supplier<ByActionStatusComponentException> instanceNotFound(final String instanceName) {
129 return () -> new ByActionStatusComponentException(
130 ActionStatus.TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND,