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(GroupInstanceDataDefinition r) {
48 * 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(GroupInstanceProperty::new).collect(Collectors.toList());
58 return groupInstancesProperties;
62 * Converts received list of GroupInstanceProperties to the list of PropertyDataDefinitions and sets It into the GroupInstanceDataDefinition as
65 * @param groupInstancesProperties
67 public void convertFromGroupInstancesProperties(List<GroupInstanceProperty> groupInstancesProperties) {
68 if (groupInstancesProperties != null && !groupInstancesProperties.isEmpty()) {
69 List<PropertyDataDefinition> propList = groupInstancesProperties.stream().map(PropertyDataDefinition::new).collect(Collectors.toList());
70 super.setProperties(propList);
74 private void removeArtifactsDuplicates() {
75 List<String> artifacts = getArtifacts();
76 Set<String> artifactsSet = new HashSet<>();
77 if (artifacts != null && !artifacts.isEmpty()) {
78 artifactsSet.addAll(artifacts);
80 artifacts.addAll(artifactsSet);
82 List<String> giArtifacts = getGroupInstanceArtifacts();
83 Set<String> giArtifactsSet = new HashSet<>();
84 if (giArtifacts != null && !giArtifacts.isEmpty()) {
85 giArtifactsSet.addAll(giArtifacts);
87 giArtifacts.addAll(giArtifactsSet);
91 private void clearArtifactsUuid() {
92 List<String> artifactsUuid = getArtifactsUuid();
93 if (CollectionUtils.isNotEmpty(artifactsUuid)) {
94 artifactsUuid.clear();
95 } else if (artifactsUuid == null) {
96 setArtifactsUuid(new ArrayList<>());
98 List<String> giartifactsUuid = this.getGroupInstanceArtifactsUuid();
99 if (CollectionUtils.isNotEmpty(giartifactsUuid)) {
100 giartifactsUuid.clear();
101 } else if (giartifactsUuid == null) {
102 setGroupInstanceArtifactsUuid(new ArrayList<>());
107 * Aligns the list of artifacts UUIDs of group instance according to received deployment artifacts
109 * @param deploymentArtifacts
111 public void alignArtifactsUuid(Map<String, ArtifactDefinition> deploymentArtifacts) {
112 List<String> artifactIds = getArtifacts();
113 log.debug("the artifacts Id's are: {}, and the deployment artifacts Id's are: {}", artifactIds, deploymentArtifacts);
114 if (CollectionUtils.isNotEmpty(artifactIds) && deploymentArtifacts != null) {
115 removeArtifactsDuplicates();
116 clearArtifactsUuid();
117 List<String> artifactUuids = getArtifactsUuid();
118 List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
119 for (String artifactId : artifactIds) {
120 String label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
121 ArtifactDefinition artifact = deploymentArtifacts.get(label);
122 log.debug("current artifact id: {}, current artifact definition: {}", artifactId, artifact);
123 ArtifactTypeEnum artifactType = ArtifactTypeEnum.parse(artifact.getArtifactType());
124 if (artifactType != ArtifactTypeEnum.HEAT_ENV) {
125 addArtifactsIdToCollection(artifactUuids, artifact);
127 addArtifactsIdToCollection(giArtifactUuids, artifact);
133 private void addArtifactsIdToCollection(List<String> artifactUuids, ArtifactDefinition artifact) {
134 if (!artifactUuids.contains(artifact.getArtifactUUID()) && StringUtils.isNotEmpty(artifact.getArtifactUUID())) {
135 artifactUuids.add(artifact.getArtifactUUID());