Support of get_property in property assignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / exceptions / ToscaGetFunctionExceptionSupplier.java
1 /*
2  * -
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
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdc.be.components.impl.exceptions;
23
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;
31
32 @NoArgsConstructor(access = AccessLevel.PRIVATE)
33 public class ToscaGetFunctionExceptionSupplier {
34
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);
39     }
40
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);
45     }
46
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());
52     }
53
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);
58     }
59
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
66         );
67     }
68
69     public static Supplier<ByActionStatusComponentException> couldNotLoadDataTypes(final String model) {
70         return () -> new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
71     }
72
73     public static Supplier<ByActionStatusComponentException> functionNotSupported(final ToscaGetFunctionType functionType) {
74         return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, "Tosca function " + functionType.getFunctionName());
75     }
76
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
83         );
84     }
85
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
92         );
93     }
94 }