Documentation figure fix
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / utils / InterfaceOperationUtils.java
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.openecomp.sdc.be.components.utils;
17
18 import java.util.Map;
19 import java.util.Optional;
20 import org.apache.commons.collections.MapUtils;
21 import org.openecomp.sdc.be.model.Component;
22 import org.openecomp.sdc.be.model.InterfaceDefinition;
23 import org.openecomp.sdc.be.model.Operation;
24
25 public class InterfaceOperationUtils {
26
27     private InterfaceOperationUtils(){}
28
29     public static final Optional<InterfaceDefinition> getInterfaceDefinitionFromComponentByInterfaceType(Component component, String interfaceType) {
30         if (MapUtils.isEmpty(component.getInterfaces())) {
31             return Optional.empty();
32         }
33         return component.getInterfaces().values().stream().filter(interfaceDefinition -> interfaceDefinition.getType() != null && interfaceDefinition.getType().equals(interfaceType)).findAny();
34     }
35
36     public static final Optional<InterfaceDefinition> getInterfaceDefinitionFromComponentByInterfaceId(Component component, String interfaceId) {
37         if (MapUtils.isEmpty(component.getInterfaces())) {
38             return Optional.empty();
39         }
40         return component.getInterfaces().values().stream().filter(interfaceDefinition -> interfaceDefinition.getUniqueId() != null && interfaceDefinition.getUniqueId().equals(interfaceId)).findAny();
41     }
42
43     public static final Optional<Map.Entry<String, Operation>> getOperationFromInterfaceDefinition(InterfaceDefinition interfaceDefinition, String operationId) {
44         if (MapUtils.isEmpty(interfaceDefinition.getOperationsMap())) {
45             return Optional.empty();
46         }
47         Optional<Map.Entry<String, Operation>> operationMap = interfaceDefinition.getOperationsMap().entrySet().stream().filter(entry -> entry.getValue().getUniqueId().equals(operationId)).findAny();
48         if (operationMap.isPresent()) {
49             return operationMap;
50         }
51         return Optional.empty();
52     }
53
54 }