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 org.apache.commons.collections.CollectionUtils;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
26 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
27 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
30 import java.util.stream.Collectors;
32 public class GroupInstance extends GroupInstanceDataDefinition {
34 public GroupInstance() {
38 public GroupInstance(GroupInstanceDataDefinition r) {
42 * Converts contained list of PropertyDataDefinitions to list of GroupInstanceProperties
45 public List<GroupInstanceProperty> convertToGroupInstancesProperties() {
46 List<GroupInstanceProperty> groupInstancesProperties = null;
47 List<PropertyDataDefinition> propertiesList = super.getProperties();
48 if(propertiesList != null && !propertiesList .isEmpty()){
49 groupInstancesProperties = propertiesList.stream().map(GroupInstanceProperty::new).collect(Collectors.toList());
51 return groupInstancesProperties;
54 * Converts received list of GroupInstanceProperties to the list of PropertyDataDefinitions and sets It into the GroupInstanceDataDefinition as properties
55 * @param groupInstancesProperties
57 public void convertFromGroupInstancesProperties(List<GroupInstanceProperty> groupInstancesProperties) {
58 if(groupInstancesProperties != null && !groupInstancesProperties .isEmpty()){
59 List<PropertyDataDefinition> propList = groupInstancesProperties.stream().map(PropertyDataDefinition::new).collect(Collectors.toList());
60 super.setProperties(propList);
64 private void removeArtifactsDuplicates() {
65 List<String> artifacts = getArtifacts();
66 Set<String> artifactsSet = new HashSet<>();
68 if (artifacts != null && !artifacts.isEmpty()) {
69 artifactsSet.addAll(artifacts);
71 artifacts.addAll(artifactsSet);
74 List<String> giArtifacts = getGroupInstanceArtifacts();
75 Set<String> giArtifactsSet = new HashSet<>();
77 if (giArtifacts != null && !giArtifacts.isEmpty()) {
78 giArtifactsSet.addAll(giArtifacts);
80 giArtifacts.addAll(giArtifactsSet);
84 private void clearArtifactsUuid() {
85 List<String> artifactsUuid = getArtifactsUuid();
86 if(CollectionUtils.isNotEmpty(artifactsUuid)){
87 artifactsUuid.clear();
88 } else if (artifactsUuid == null){
89 setArtifactsUuid(new ArrayList<>());
92 List<String> giartifactsUuid = this.getGroupInstanceArtifactsUuid();
93 if(CollectionUtils.isNotEmpty(giartifactsUuid)){
94 giartifactsUuid.clear();
95 } else if (giartifactsUuid == null){
96 setGroupInstanceArtifactsUuid(new ArrayList<>());
101 * Aligns the list of artifacts UUIDs of group instance according to received deployment artifacts
102 * @param deploymentArtifacts
104 public void alignArtifactsUuid(Map<String, ArtifactDefinition> deploymentArtifacts) {
105 List<String> artifactIds = getArtifacts();
106 if(CollectionUtils.isNotEmpty(artifactIds) && deploymentArtifacts != null){
107 removeArtifactsDuplicates();
108 clearArtifactsUuid();
109 List<String> artifactUuids = getArtifactsUuid();
110 List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
111 for(String artifactId : artifactIds){
112 String label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
113 ArtifactDefinition artifact = deploymentArtifacts.get(label);
114 ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
115 if (artifactType != ArtifactTypeEnum.HEAT_ENV){
116 addArtifactsIdToCollection(artifactUuids, artifact);
118 addArtifactsIdToCollection(giArtifactUuids, artifact);
125 private void addArtifactsIdToCollection(List<String> artifactUuids, ArtifactDefinition artifact) {
126 if(!artifactUuids.contains(artifact.getArtifactUUID()) && StringUtils.isNotEmpty(artifact.getArtifactUUID())){
127 artifactUuids.add(artifact.getArtifactUUID());