2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.be.components.utils;
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;
26 public class InterfaceOperationUtils {
28 private InterfaceOperationUtils() {
31 public static Optional<InterfaceDefinition> getInterfaceDefinitionFromComponentByInterfaceType(Component component,
32 String interfaceType) {
33 if (MapUtils.isEmpty(component.getInterfaces())) {
34 return Optional.empty();
36 return component.getInterfaces().values().stream()
37 .filter(interfaceDefinition -> interfaceDefinition.getType() != null && interfaceDefinition
39 .equals(interfaceType))
43 public static Optional<InterfaceDefinition> getInterfaceDefinitionFromComponentByInterfaceId(Component component,
45 if (MapUtils.isEmpty(component.getInterfaces())) {
46 return Optional.empty();
48 return component.getInterfaces().values().stream()
49 .filter(interfaceDefinition -> interfaceDefinition.getUniqueId() != null && interfaceDefinition
55 public static Optional<Map.Entry<String, Operation>> getOperationFromInterfaceDefinition(
56 InterfaceDefinition interfaceDefinition, String operationId) {
57 if (MapUtils.isEmpty(interfaceDefinition.getOperationsMap())) {
58 return Optional.empty();
60 return interfaceDefinition.getOperationsMap().entrySet().stream()
61 .filter(entry -> entry.getValue().getUniqueId().equals(operationId)).findAny();