Reformat catalog-model
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / utils / ComponentUtilities.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.model.utils;
21
22 import static java.util.Collections.emptyList;
23
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;
31
32 public class ComponentUtilities {
33
34     private ComponentUtilities() {
35     }
36
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);
40     }
41
42     public static List<Annotation> getInputAnnotations(Component component, String inputName) {
43         return getInputByName(component, inputName).map(InputDefinition::getAnnotations).orElse(emptyList());
44     }
45
46     private static Optional<InputDefinition> getInputByName(Component component, String inputName) {
47         return component.safeGetInputs().stream().filter(input -> input.getName().equals(inputName)).findFirst();
48     }
49
50     public static boolean isNotUpdatedCapReqName(String prefix, String currName, String previousName) {
51         return StringUtils.isEmpty(previousName) || StringUtils.isEmpty(currName) || !currName.equals(prefix + previousName);
52     }
53 }