44d6f507407e63bd7682bdecbd3b66fa4a78e03b
[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.elements.ToscaGetFunctionDataDefinition;
30 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
31 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
32
33 @NoArgsConstructor(access = AccessLevel.PRIVATE)
34 public class ToscaGetFunctionExceptionSupplier {
35
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);
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> targetFunctionTypeNotFound() {
48         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "function type");
49     }
50
51     public static Supplier<ByActionStatusComponentException> targetPropertySourceNotFound(final ToscaGetFunctionType toscaGetFunctionType) {
52         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property source of " + toscaGetFunctionType);
53     }
54
55     public static Supplier<ByActionStatusComponentException> targetSourcePathNotFound(final ToscaGetFunctionType toscaGetFunctionType) {
56         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source path of " + toscaGetFunctionType);
57     }
58
59     public static Supplier<ByActionStatusComponentException> propertyNameNotFound(final PropertySource propertySource) {
60         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property name of source "
61             + propertySource);
62     }
63
64     public static Supplier<ByActionStatusComponentException> propertyIdNotFound(final PropertySource propertySource) {
65         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "property id of source "
66             + propertySource);
67     }
68
69     public static Supplier<ByActionStatusComponentException> sourceNameNotFound(final PropertySource propertySource) {
70         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source name of "
71             + propertySource);
72     }
73
74     public static Supplier<ByActionStatusComponentException> sourceIdNotFound(final PropertySource propertySource) {
75         return () -> new ByActionStatusComponentException(ActionStatus.TOSCA_FUNCTION_MISSING_ATTRIBUTE, "source id of "
76             + propertySource);
77     }
78
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());
84     }
85
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);
90     }
91
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
98         );
99     }
100
101     public static Supplier<ByActionStatusComponentException> couldNotLoadDataTypes(final String model) {
102         return () -> new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
103     }
104
105     public static Supplier<ByActionStatusComponentException> functionNotSupported(final ToscaGetFunctionType functionType) {
106         return () -> new ByActionStatusComponentException(ActionStatus.NOT_SUPPORTED, "Tosca function " + functionType.getFunctionName());
107     }
108
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
115         );
116     }
117
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
124         );
125     }
126
127     public static Supplier<ByActionStatusComponentException> instanceNotFound(final String instanceName) {
128         return () -> new ByActionStatusComponentException(
129             ActionStatus.TOSCA_GET_FUNCTION_INSTANCE_NOT_FOUND,
130             instanceName
131         );
132     }
133
134 }