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 java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.HashSet;
26 import java.util.List;
29 import java.util.stream.Collectors;
31 import org.apache.commons.collections.CollectionUtils;
32 import org.apache.commons.lang3.StringUtils;
33 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
35 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
37 public class GroupInstance extends GroupInstanceDataDefinition implements Serializable {
39 private static final long serialVersionUID = -2066335818115254401L;
41 public GroupInstance() {
45 public GroupInstance(GroupInstanceDataDefinition r) {
49 * Converts contained list of PropertyDataDefinitions to list of GroupInstanceProperties
52 public List<GroupInstanceProperty> convertToGroupInstancesProperties() {
53 List<GroupInstanceProperty> groupInstancesProperties = null;
54 List<PropertyDataDefinition> propertiesList = super.getProperties();
55 if(propertiesList != null && !propertiesList .isEmpty()){
56 groupInstancesProperties = propertiesList.stream().map(p -> new GroupInstanceProperty(p)).collect(Collectors.toList());
58 return groupInstancesProperties;
61 * Converts received list of GroupInstanceProperties to the list of PropertyDataDefinitions and sets It into the GroupInstanceDataDefinition as properties
62 * @param groupInstancesProperties
64 public void convertFromGroupInstancesProperties(List<GroupInstanceProperty> groupInstancesProperties) {
65 if(groupInstancesProperties != null && !groupInstancesProperties .isEmpty()){
66 List<PropertyDataDefinition> propList = groupInstancesProperties.stream().map(p -> new PropertyDataDefinition(p)).collect(Collectors.toList());
67 super.setProperties(propList);
71 private void removeArtifactsDuplicates() {
72 List<String> artifacts = getArtifacts();
73 Set<String> artifactsSet = new HashSet<>();
74 artifactsSet.addAll(artifacts);
76 artifacts.addAll(artifactsSet);
78 List<String> giArtifacts = getGroupInstanceArtifacts();
79 Set<String> giArtifactsSet = new HashSet<>();
80 giArtifactsSet.addAll(giArtifacts);
82 giArtifacts.addAll(giArtifactsSet);
85 private void clearArtifactsUuid() {
86 List<String> artifactsUuid = getArtifactsUuid();
87 if(CollectionUtils.isNotEmpty(artifactsUuid)){
88 artifactsUuid.clear();
89 } else if (artifactsUuid == null){
90 setArtifactsUuid(new ArrayList<>());
93 List<String> giartifactsUuid = this.getGroupInstanceArtifactsUuid();
94 if(CollectionUtils.isNotEmpty(giartifactsUuid)){
95 giartifactsUuid.clear();
96 } else if (giartifactsUuid == null){
97 setGroupInstanceArtifactsUuid(new ArrayList<>());
102 * Aligns the list of artifacts UUIDs of group instance according to received deployment artifacts
103 * @param deploymentArtifacts
105 public void alignArtifactsUuid(Map<String, ArtifactDefinition> deploymentArtifacts) {
106 List<String> artifactIds = getArtifacts();
107 if(CollectionUtils.isNotEmpty(artifactIds)){
108 removeArtifactsDuplicates();
109 clearArtifactsUuid();
110 List<String> artifactUuids = getArtifactsUuid();
111 List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
112 for(String artifactId : artifactIds){
113 String label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
114 ArtifactDefinition artifact = deploymentArtifacts.get(label);
115 ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
116 if (artifactType != ArtifactTypeEnum.HEAT_ENV){
117 addArtifactsIdToCollection(artifactUuids, artifact);
119 addArtifactsIdToCollection(giArtifactUuids, artifact);
126 private void addArtifactsIdToCollection(List<String> artifactUuids, ArtifactDefinition artifact) {
127 if(!artifactUuids.contains(artifact.getArtifactUUID()) && StringUtils.isNotEmpty(artifact.getArtifactUUID())){
128 artifactUuids.add(artifact.getArtifactUUID());