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=========================================================
20 package org.openecomp.sdc.be.model.utils;
22 import static java.util.Collections.emptyList;
24 import java.util.List;
25 import java.util.Optional;
26 import org.apache.commons.lang3.StringUtils;
27 import org.openecomp.sdc.be.datatypes.elements.Annotation;
28 import org.openecomp.sdc.be.model.Component;
29 import org.openecomp.sdc.be.model.ComponentInstance;
30 import org.openecomp.sdc.be.model.InputDefinition;
32 public class ComponentUtilities {
34 private ComponentUtilities() {
37 public static Optional<String> getComponentInstanceNameByInstanceId(Component component, String id) {
38 return component.getComponentInstanceById(id).flatMap(instance -> component.getComponentInstanceByName(instance.getName()))
39 .map(ComponentInstance::getName);
42 public static List<Annotation> getInputAnnotations(Component component, String inputName) {
43 return getInputByName(component, inputName).map(InputDefinition::getAnnotations).orElse(emptyList());
46 private static Optional<InputDefinition> getInputByName(Component component, String inputName) {
47 return component.safeGetInputs().stream().filter(input -> input.getName().equals(inputName)).findFirst();
50 public static boolean isNotUpdatedCapReqName(String prefix, String currName, String previousName) {
51 return StringUtils.isEmpty(previousName) || StringUtils.isEmpty(currName) || !currName.equals(prefix + previousName);