Backend support for custom functions
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / ToscaCustomFunction.java
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2023 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.datatypes.elements;
23
24 import com.google.gson.Gson;
25 import lombok.Getter;
26 import lombok.Setter;
27
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.stream.Collectors;
32
33 @Getter
34 @Setter
35 public class ToscaCustomFunction implements ToscaFunction, ToscaFunctionParameter {
36
37     private String name;
38     private List<ToscaFunctionParameter> parameters = new ArrayList<>();
39
40     @Override
41     public ToscaFunctionType getType() {
42         return ToscaFunctionType.CUSTOM;
43     }
44
45     @Override
46     public String getValue() {
47         return new Gson().toJson(getJsonObjectValue());
48     }
49
50     @Override
51     public Object getJsonObjectValue() {
52         return Map.of(
53                 "$" + name,
54                 parameters.stream().map(ToscaFunctionParameter::getJsonObjectValue).collect(Collectors.toList())
55         );
56     }
57
58     public void addParameter(final ToscaFunctionParameter functionParameter) {
59         this.parameters.add(functionParameter);
60     }
61
62 }