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.
16 package org.openecomp.sdc.be.components.utils;
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;
25 public class InterfaceOperationUtils {
27 private InterfaceOperationUtils(){}
29 public static final Optional<InterfaceDefinition> getInterfaceDefinitionFromComponentByInterfaceType(Component component, String interfaceType) {
30 if (MapUtils.isEmpty(component.getInterfaces())) {
31 return Optional.empty();
33 return component.getInterfaces().values().stream().filter(interfaceDefinition -> interfaceDefinition.getType() != null && interfaceDefinition.getType().equals(interfaceType)).findAny();
36 public static final Optional<InterfaceDefinition> getInterfaceDefinitionFromComponentByInterfaceId(Component component, String interfaceId) {
37 if (MapUtils.isEmpty(component.getInterfaces())) {
38 return Optional.empty();
40 return component.getInterfaces().values().stream().filter(interfaceDefinition -> interfaceDefinition.getUniqueId() != null && interfaceDefinition.getUniqueId().equals(interfaceId)).findAny();
43 public static final Optional<Map.Entry<String, Operation>> getOperationFromInterfaceDefinition(InterfaceDefinition interfaceDefinition, String operationId) {
44 if (MapUtils.isEmpty(interfaceDefinition.getOperationsMap())) {
45 return Optional.empty();
47 Optional<Map.Entry<String, Operation>> operationMap = interfaceDefinition.getOperationsMap().entrySet().stream().filter(entry -> entry.getValue().getUniqueId().equals(operationId)).findAny();
48 if (operationMap.isPresent()) {
51 return Optional.empty();