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=========================================================
20 package org.openecomp.sdc.be.model;
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.List;
27 import java.util.stream.Collectors;
28 import org.apache.commons.collections.CollectionUtils;
29 import org.apache.commons.lang3.StringUtils;
30 import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
32 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
35 public class GroupInstance extends GroupInstanceDataDefinition {
37 private static final Logger log = Logger.getLogger(GroupInstance.class);
39 public GroupInstance() {
43 public GroupInstance(final GroupInstanceDataDefinition r) {
48 * Converts contained list of PropertyDataDefinitions to list of GroupInstanceProperties
52 public List<GroupInstanceProperty> convertToGroupInstancesProperties() {
53 final List<PropertyDataDefinition> propertiesList = super.getProperties();
54 if (CollectionUtils.isNotEmpty(propertiesList)) {
55 return propertiesList.stream().map(GroupInstanceProperty::new).collect(Collectors.toList());
61 * Converts received list of GroupInstanceProperties to the list of PropertyDataDefinitions and sets It into the GroupInstanceDataDefinition as
64 * @param groupInstancesProperties
66 public void convertFromGroupInstancesProperties(final List<GroupInstanceProperty> groupInstancesProperties) {
67 if (groupInstancesProperties != null && !groupInstancesProperties.isEmpty()) {
68 super.setProperties(groupInstancesProperties.stream().map(PropertyDataDefinition::new).collect(Collectors.toList()));
72 private void removeArtifactsDuplicates() {
73 final List<String> artifacts = getArtifacts();
74 final Set<String> artifactsSet = new HashSet<>();
75 if (artifacts != null && !artifacts.isEmpty()) {
76 artifactsSet.addAll(artifacts);
78 artifacts.addAll(artifactsSet);
80 final List<String> giArtifacts = getGroupInstanceArtifacts();
81 final Set<String> giArtifactsSet = new HashSet<>();
82 if (giArtifacts != null && !giArtifacts.isEmpty()) {
83 giArtifactsSet.addAll(giArtifacts);
85 giArtifacts.addAll(giArtifactsSet);
89 private void clearArtifactsUuid() {
90 final List<String> artifactsUuid = getArtifactsUuid();
91 if (CollectionUtils.isNotEmpty(artifactsUuid)) {
92 artifactsUuid.clear();
93 } else if (artifactsUuid == null) {
94 setArtifactsUuid(new ArrayList<>());
96 final List<String> groupInstanceArtifactsUuid = this.getGroupInstanceArtifactsUuid();
97 if (CollectionUtils.isNotEmpty(groupInstanceArtifactsUuid)) {
98 groupInstanceArtifactsUuid.clear();
99 } else if (groupInstanceArtifactsUuid == null) {
100 setGroupInstanceArtifactsUuid(new ArrayList<>());
105 * Aligns the list of artifacts UUIDs of group instance according to received deployment artifacts
107 * @param deploymentArtifacts
109 public void alignArtifactsUuid(final Map<String, ArtifactDefinition> deploymentArtifacts) {
110 final List<String> artifactIds = getArtifacts();
111 log.debug("the artifacts Id's are: {}, and the deployment artifacts Id's are: {}", artifactIds, deploymentArtifacts);
112 if (CollectionUtils.isNotEmpty(artifactIds) && deploymentArtifacts != null) {
113 removeArtifactsDuplicates();
114 clearArtifactsUuid();
115 final List<String> artifactUuids = getArtifactsUuid();
116 final List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
117 for (final String artifactId : artifactIds) {
118 final var label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
119 final ArtifactDefinition artifact = deploymentArtifacts.get(label);
120 log.debug("current artifact id: {}, current artifact definition: {}", artifactId, artifact);
121 final var artifactType = ArtifactTypeEnum.parse(artifact.getArtifactType());
122 if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
123 addArtifactsIdToCollection(artifactUuids, artifact);
125 addArtifactsIdToCollection(giArtifactUuids, artifact);
131 private void addArtifactsIdToCollection(final List<String> artifactUuids, final ArtifactDefinition artifact) {
132 if (StringUtils.isNotEmpty(artifact.getArtifactUUID()) && !artifactUuids.contains(artifact.getArtifactUUID())) {
133 artifactUuids.add(artifact.getArtifactUUID());