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.ToscaGetFunctionDataDefinition;
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);
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> targetFunctionTypeNotFound() {
48 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "function type");
51 public static Supplier<ByActionStatusComponentException> targetPropertySourceNotFound(final ToscaGetFunctionType toscaGetFunctionType) {
52 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property source of " + toscaGetFunctionType);
55 public static Supplier<ByActionStatusComponentException> targetSourcePathNotFound(final ToscaGetFunctionType toscaGetFunctionType) {
56 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source path of " + toscaGetFunctionType);
59 public static Supplier<ByActionStatusComponentException> propertyNameNotFound(final PropertySource propertySource) {
60 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property name of source "
64 public static Supplier<ByActionStatusComponentException> propertyIdNotFound(final PropertySource propertySource) {
65 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property id of source "
69 public static Supplier<ByActionStatusComponentException> sourceNameNotFound(final PropertySource propertySource) {
70 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source name of "
74 public static Supplier<ByActionStatusComponentException> sourceIdNotFound(final PropertySource propertySource) {
75 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source id of "
79 public static Supplier<ByActionStatusComponentException> propertyNotFoundOnTarget(final List<String> propertyPathFromSource,
80 final PropertySource propertySource,
81 final ToscaGetFunctionType functionType) {
82 return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_GET_FUNCTION_PROPERTY_NOT_FOUND, functionType.getPropertyType(),
83 String.join("->", propertyPathFromSource), propertySource.getName());
86 public static Supplier<ByActionStatusComponentException> propertyDataTypeNotFound(final String propertyName,
87 final String dataType,
88 final ToscaGetFunctionType functionType) {
89 return propertyDataTypeNotFound(List.of(propertyName), dataType, functionType);
92 public static Supplier<ByActionStatusComponentException> propertyDataTypeNotFound(final List<String> propertyPathFromSource,
93 final String dataType,
94 final ToscaGetFunctionType functionType) {
95 return () -> new ByActionStatusComponentException(
96 ActionStatus.TOSCA_GET_FUNCTION_PROPERTY_DATA_TYPE_NOT_FOUND,
97 functionType.getPropertyType(), String.join("->", propertyPathFromSource), dataType
101 public static Supplier<ByActionStatusComponentException> couldNotLoadDataTypes(final String model) {
102 return () -> new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
105 public static Supplier<ByActionStatusComponentException> functionNotSupported(final ToscaGetFunctionType functionType) {
106 return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, "Tosca function " + functionType.getFunctionName());
109 public static Supplier<ByActionStatusComponentException> propertyTypeDiverge(final ToscaGetFunctionType functionType,
110 final String referredPropertyType,
111 final String propertyType) {
112 return () -> new ByActionStatusComponentException(
113 ActionStatus.TOSCA_GET_FUNCTION_TYPE_DIVERGE,
114 functionType.getFunctionName(), referredPropertyType, propertyType
118 public static Supplier<ByActionStatusComponentException> propertySchemaDiverge(final ToscaGetFunctionType functionType,
119 final String referredPropertySchemaType,
120 final String propertySchemaType) {
121 return () -> new ByActionStatusComponentException(
122 ActionStatus.TOSCA_GET_FUNCTION_SCHEMA_DIVERGE,
123 functionType.getFunctionName(), referredPropertySchemaType, propertySchemaType
127 public static Supplier<ByActionStatusComponentException> instanceNotFound(final String instanceName) {
128 return () -> new ByActionStatusComponentException(
129 ActionStatus.TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND,