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.fasterxml.jackson.annotation.JsonIgnore;
24 import com.google.common.collect.Lists;
25 import com.google.common.collect.Maps;
26 import org.apache.commons.collections.CollectionUtils;
27 import org.apache.commons.collections.MapUtils;
28 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
29 import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner;
31 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
33 import java.util.Collection;
34 import java.util.List;
37 import static java.util.stream.Collectors.*;
39 public class GroupDefinition extends GroupDataDefinition implements PropertiesOwner{
41 private Map<String, List<CapabilityDefinition>> capabilities;
43 public GroupDefinition() {
47 public GroupDefinition(GroupDataDefinition other) {
51 public GroupDefinition(GroupDefinition other) {
53 if(MapUtils.isNotEmpty(other.getCapabilities())) {
54 this.setCapabilities(other.getCapabilities().entrySet()
56 .collect(toMap(Map.Entry::getKey, e -> getCapabilitiesCopyList(e.getValue()))));
60 public Map<String, List<CapabilityDefinition>> getCapabilities() {
61 if(MapUtils.isEmpty(capabilities)) {
62 capabilities = Maps.newHashMap();
67 public void setCapabilities(Map<String, List<CapabilityDefinition>> capabilities) {
68 this.capabilities = capabilities;
71 public List<GroupProperty> convertToGroupProperties() {
72 List<GroupProperty> properties = null;
73 List<PropertyDataDefinition> propList = super.getProperties();
74 if(propList != null && !propList .isEmpty()){
75 properties = propList.stream().map(GroupProperty::new).collect(toList());
80 public <T extends PropertyDataDefinition> void convertFromGroupProperties(List<T> properties) {
81 if(properties != null && !properties .isEmpty()){
82 List<PropertyDataDefinition> propList = properties.stream().map(PropertyDataDefinition::new).collect(toList());
83 super.setProperties(propList);
87 //returns true iff groupName has the same prefix has the resource
88 public boolean isSamePrefix(String resourceName){
89 return getName() != null && getName().toLowerCase().trim().startsWith(resourceName.toLowerCase());
92 public void convertCapabilityDefinitions(Map<String, CapabilityDefinition> capabilities) {
93 if(MapUtils.isNotEmpty(capabilities)){
94 this.capabilities = capabilities.values().stream()
95 .collect(groupingBy(CapabilityDefinition::getType));
100 public String getNormalizedName() {
105 private List<CapabilityDefinition> getCapabilitiesCopyList(List<CapabilityDefinition> capabilities) {
106 return Lists.newArrayList(capabilities.stream().map(CapabilityDefinition::new).collect(toList()));
109 public void updateCapabilitiesProperties(Map<String, Map<String, CapabilityDefinition>> capabilitiesInfo) {
110 if(MapUtils.isNotEmpty(capabilities) && MapUtils.isNotEmpty(capabilitiesInfo)){
111 capabilities.entrySet().forEach(e->updateCapabilitiesProperies(e.getValue(), capabilitiesInfo.get(e.getKey())));
115 private void updateCapabilitiesProperies(List<CapabilityDefinition> capabilities, Map<String, CapabilityDefinition> capabilitiesInfo) {
116 if(CollectionUtils.isNotEmpty(capabilities) && MapUtils.isNotEmpty(capabilitiesInfo)){
117 capabilities.forEach(c->c.updateCapabilityProperties(capabilitiesInfo.get(c.getName())));
121 public void updateEmptyCapabilitiesOwnerFields(){
122 if(MapUtils.isNotEmpty(this.capabilities)){
123 this.capabilities.values().stream()
124 .flatMap(Collection::stream)
125 .forEach(c -> c.updateEmptyCapabilityOwnerFields(getUniqueId(), getName(), CapabilityDataDefinition.OwnerType.GROUP));