2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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;
22 import com.google.common.collect.Lists;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.stream.Collectors;
27 import lombok.EqualsAndHashCode;
29 import lombok.NoArgsConstructor;
31 import lombok.ToString;
32 import org.apache.commons.collections.CollectionUtils;
33 import org.apache.commons.collections.MapUtils;
34 import org.apache.commons.lang3.StringUtils;
35 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
38 * Specifies the capabilities that the Node Type exposes.
43 @EqualsAndHashCode(callSuper = true)
45 public class CapabilityDefinition extends CapabilityDataDefinition {
48 * The properties field contains all properties defined for CapabilityDefinition
50 private List<ComponentInstanceProperty> properties;
52 public CapabilityDefinition(CapabilityDataDefinition cap) {
56 public CapabilityDefinition(CapabilityTypeDefinition other, String ownerName, String name, CapabilityDataDefinition.OwnerType ownerType) {
58 this.setOwnerName(ownerName);
59 this.setOwnerType(ownerType);
61 this.setParentName(name);
62 if (MapUtils.isNotEmpty(other.getProperties())) {
63 this.properties = Lists
64 .newArrayList(other.getProperties().values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()));
68 public CapabilityDefinition(CapabilityDefinition other) {
69 super((CapabilityDefinition) other);
70 if (other.properties != null) {
71 this.properties = new ArrayList<>(other.properties.stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()));
75 public void updateCapabilityProperties(CapabilityDefinition capabilityDefinition) {
76 if (CollectionUtils.isNotEmpty(getProperties()) && capabilityDefinition != null && CollectionUtils
77 .isNotEmpty(capabilityDefinition.getProperties())) {
78 Map<String, ComponentInstanceProperty> propertiesInfo = capabilityDefinition.getProperties().stream()
79 .collect(Collectors.toMap(ComponentInstanceProperty::getName, p -> p));
80 getProperties().forEach(p -> p.updateCapabilityProperty(propertiesInfo.get(p.getName())));
84 public void updateEmptyCapabilityOwnerFields(String ownerId, String ownerName, OwnerType ownerType) {
85 if (StringUtils.isEmpty(getOwnerId())) {
87 if (getPath() == null) {
88 setPath(new ArrayList<>());
90 if (!getPath().contains(ownerId)) {
91 getPath().add(ownerId);
93 setOwnerName(ownerName);
94 setOwnerTypeIfEmpty(ownerType);
98 private void setOwnerTypeIfEmpty(OwnerType ownerType) {
99 if (getOwnerType() == null) {
100 setOwnerType(ownerType);