b0fb06974bd57ba48c65b76e548b2a88a2daa94f
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.sdc.tosca.datatypes.model;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Objects;
21 import java.util.Optional;
22 import org.apache.commons.collections4.MapUtils;
23 import org.onap.sdc.tosca.services.DataModelCloneUtil;
24
25 public class InterfaceDefinitionType extends InterfaceDefinition {
26
27     private String type;
28     private Map<String, PropertyDefinition> inputs;
29     private Map<String, OperationDefinitionType> operations;
30
31     public InterfaceDefinitionType() {
32     }
33
34     public InterfaceDefinitionType(Object toscaInterfaceDefinitionType) {
35         InterfaceDefinitionType interfaceDefinitionType = (InterfaceDefinitionType) convertObjToInterfaceDefinition(toscaInterfaceDefinitionType);
36         this.setType(interfaceDefinitionType.getType());
37         this.setInputs(DataModelCloneUtil.cloneStringPropertyDefinitionMap(interfaceDefinitionType.getInputs()));
38         this.setOperations(DataModelCloneUtil.cloneStringOperationDefinitionMap(interfaceDefinitionType.getOperations()));
39     }
40
41     public String getType() {
42         return type;
43     }
44
45     public void setType(String type) {
46         this.type = type;
47     }
48
49     public Map<String, PropertyDefinition> getInputs() {
50         return inputs;
51     }
52
53     public void setInputs(Map<String, PropertyDefinition> inputs) {
54         this.inputs = inputs;
55     }
56
57     public Map<String, OperationDefinitionType> getOperations() {
58         return operations;
59     }
60
61     public void setOperations(Map<String, OperationDefinitionType> operations) {
62         this.operations = operations;
63     }
64
65     @Override
66     public boolean equals(Object o) {
67         if (this == o) {
68             return true;
69         }
70         if (o == null || getClass() != o.getClass()) {
71             return false;
72         }
73         InterfaceDefinitionType that = (InterfaceDefinitionType) o;
74         return Objects.equals(type, that.type) && Objects.equals(inputs, that.inputs) && Objects.equals(operations, that.operations);
75     }
76
77     @Override
78     public int hashCode() {
79         return Objects.hash(type, inputs, operations);
80     }
81
82     @Override
83     public void addOperation(String operationName, OperationDefinition operationDefinition) {
84         addOperation(operationName, (OperationDefinitionType) operationDefinition);
85     }
86
87     private void addOperation(String operationName, OperationDefinitionType operation) {
88         if (MapUtils.isEmpty(this.operations)) {
89             this.operations = new HashMap<>();
90         }
91         this.operations.put(operationName, operation);
92     }
93
94     public Optional<Object> convertInterfaceDefinitionTypeToToscaObj() {
95         return convertInterfaceToToscaInterfaceObj(this);
96     }
97 }