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 org.apache.commons.collections.CollectionUtils;
25 import org.apache.commons.collections.MapUtils;
26 import org.apache.commons.collections.SetUtils;
27 import org.apache.commons.lang3.StringUtils;
28 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
30 import java.util.ArrayList;
31 import java.util.List;
33 import java.util.stream.Collectors;
35 * Specifies the capabilities that the Node Type exposes.
37 public class CapabilityDefinition extends CapabilityDataDefinition {
40 * The properties field contains all properties defined for
41 * CapabilityDefinition
43 private List<ComponentInstanceProperty> properties;
46 public CapabilityDefinition() {
50 public CapabilityDefinition(CapabilityDataDefinition cap) {
54 public CapabilityDefinition(CapabilityTypeDefinition other, String ownerName, String name, CapabilityDataDefinition.OwnerType ownerType) {
56 this.setOwnerName(ownerName);
57 this.setOwnerType(ownerType);
59 this.setParentName(name);
60 if (MapUtils.isNotEmpty(other.getProperties())) {
61 this.properties = Lists.newArrayList(other.getProperties().values().stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()));
65 public CapabilityDefinition(CapabilityDefinition other) {
66 super((CapabilityDefinition)other);
68 if (other.properties != null) {
69 this.properties = new ArrayList<>(other.properties.stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()));
74 public int hashCode() {
76 int result = super.hashCode();
77 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
82 public boolean equals(Object obj) {
85 if (!super.equals(obj))
87 if (getClass() != obj.getClass())
89 CapabilityDefinition other = (CapabilityDefinition) obj;
90 if (properties == null) {
91 if (other.properties != null)
93 } else if (!SetUtils.isEqualSet(properties, other.getProperties()))
99 public String toString() {
100 return "CapabilityDefinition [properties=" + properties + "]";
103 public List<ComponentInstanceProperty> getProperties() {
107 public void setProperties(List<ComponentInstanceProperty> properties) {
108 this.properties = properties;
111 public void updateCapabilityProperties(CapabilityDefinition capabilityDefinition) {
112 if(CollectionUtils.isNotEmpty(getProperties()) && capabilityDefinition!= null && CollectionUtils.isNotEmpty(capabilityDefinition.getProperties())){
113 Map<String, ComponentInstanceProperty> propertiesInfo = capabilityDefinition.getProperties()
115 .collect(Collectors.toMap(ComponentInstanceProperty::getName, p->p));
116 getProperties().forEach(p->p.updateCapabilityProperty(propertiesInfo.get(p.getName())));
120 public void updateEmptyCapabilityOwnerFields(String ownerId, String ownerName, OwnerType ownerType) {
121 if (StringUtils.isEmpty(getOwnerId())){
123 if(getPath() == null){
124 setPath(new ArrayList<>());
126 if(!getPath().contains(ownerId)){
127 getPath().add(ownerId);
129 setOwnerName(ownerName);
130 setOwnerTypeIfEmpty(ownerType);
134 private void setOwnerTypeIfEmpty(OwnerType ownerType) {
135 if(getOwnerType() == null){
136 setOwnerType(ownerType);