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=========================================================
21 package org.openecomp.sdc.be.model;
23 import com.google.common.collect.Lists;
24 import lombok.EqualsAndHashCode;
26 import lombok.NoArgsConstructor;
28 import lombok.ToString;
29 import org.apache.commons.collections.CollectionUtils;
30 import org.apache.commons.collections.MapUtils;
31 import org.apache.commons.collections.SetUtils;
32 import org.apache.commons.lang3.StringUtils;
33 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
35 import java.util.ArrayList;
36 import java.util.List;
38 import java.util.stream.Collectors;
41 * Specifies the capabilities that the Node Type exposes.
46 @EqualsAndHashCode(callSuper = true)
48 public class CapabilityDefinition extends CapabilityDataDefinition {
51 * The properties field contains all properties defined for
52 * CapabilityDefinition
54 private List<ComponentInstanceProperty> properties;
56 public CapabilityDefinition(CapabilityDataDefinition cap) {
60 public CapabilityDefinition(CapabilityTypeDefinition other, String ownerName, String name, CapabilityDataDefinition.OwnerType ownerType) {
62 this.setOwnerName(ownerName);
63 this.setOwnerType(ownerType);
65 this.setParentName(name);
66 if (MapUtils.isNotEmpty(other.getProperties())) {
67 this.properties = Lists.newArrayList(other.getProperties().values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()));
71 public CapabilityDefinition(CapabilityDefinition other) {
72 super((CapabilityDefinition)other);
74 if (other.properties != null) {
75 this.properties = new ArrayList<>(other.properties.stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()));
79 public void updateCapabilityProperties(CapabilityDefinition capabilityDefinition) {
80 if(CollectionUtils.isNotEmpty(getProperties()) && capabilityDefinition!= null && CollectionUtils.isNotEmpty(capabilityDefinition.getProperties())){
81 Map<String, ComponentInstanceProperty> propertiesInfo = capabilityDefinition.getProperties()
83 .collect(Collectors.toMap(ComponentInstanceProperty::getName, p->p));
84 getProperties().forEach(p->p.updateCapabilityProperty(propertiesInfo.get(p.getName())));
88 public void updateEmptyCapabilityOwnerFields(String ownerId, String ownerName, OwnerType ownerType) {
89 if (StringUtils.isEmpty(getOwnerId())){
91 if(getPath() == null){
92 setPath(new ArrayList<>());
94 if(!getPath().contains(ownerId)){
95 getPath().add(ownerId);
97 setOwnerName(ownerName);
98 setOwnerTypeIfEmpty(ownerType);
102 private void setOwnerTypeIfEmpty(OwnerType ownerType) {
103 if(getOwnerType() == null){
104 setOwnerType(ownerType);