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