2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.utils;
23 import org.apache.commons.lang3.StringUtils;
24 import org.openecomp.sdc.be.datatypes.elements.Annotation;
25 import org.openecomp.sdc.be.model.Component;
26 import org.openecomp.sdc.be.model.ComponentInstance;
27 import org.openecomp.sdc.be.model.InputDefinition;
29 import java.util.List;
30 import java.util.Optional;
32 import static java.util.Collections.emptyList;
34 public class ComponentUtilities {
35 private ComponentUtilities() {
38 public static Optional<String> getComponentInstanceNameByInstanceId(Component component, String id) {
39 return component.getComponentInstanceById(id)
40 .flatMap(instance -> component.getComponentInstanceByName(instance.getName()))
41 .map(ComponentInstance::getName);
44 public static List<Annotation> getInputAnnotations(Component component, String inputName) {
45 return getInputByName(component, inputName)
46 .map(InputDefinition::getAnnotations)
50 private static Optional<InputDefinition> getInputByName(Component component, String inputName) {
51 return component.safeGetInputs().stream()
52 .filter(input -> input.getName().equals(inputName))
56 public static boolean isNotUpdatedCapReqName(String prefix, String currName, String previousName) {
57 return StringUtils.isEmpty(previousName) || !currName.equals(prefix + previousName);