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;
28 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import java.util.stream.Collectors;
33 public class GroupInstance extends GroupInstanceDataDefinition {
35 public GroupInstance() {
39 public GroupInstance(GroupInstanceDataDefinition r) {
43 private static final Logger log = Logger.getLogger(GroupInstance.class);
45 * Converts contained list of PropertyDataDefinitions to list of GroupInstanceProperties
48 public List<GroupInstanceProperty> convertToGroupInstancesProperties() {
49 List<GroupInstanceProperty> groupInstancesProperties = null;
50 List<PropertyDataDefinition> propertiesList = super.getProperties();
51 if(propertiesList != null && !propertiesList .isEmpty()){
52 groupInstancesProperties = propertiesList.stream().map(GroupInstanceProperty::new).collect(Collectors.toList());
54 return groupInstancesProperties;
57 * Converts received list of GroupInstanceProperties to the list of PropertyDataDefinitions and sets It into the GroupInstanceDataDefinition as properties
58 * @param groupInstancesProperties
60 public void convertFromGroupInstancesProperties(List<GroupInstanceProperty> groupInstancesProperties) {
61 if(groupInstancesProperties != null && !groupInstancesProperties .isEmpty()){
62 List<PropertyDataDefinition> propList = groupInstancesProperties.stream().map(PropertyDataDefinition::new).collect(Collectors.toList());
63 super.setProperties(propList);
67 private void removeArtifactsDuplicates() {
68 List<String> artifacts = getArtifacts();
69 Set<String> artifactsSet = new HashSet<>();
71 if (artifacts != null && !artifacts.isEmpty()) {
72 artifactsSet.addAll(artifacts);
74 artifacts.addAll(artifactsSet);
77 List<String> giArtifacts = getGroupInstanceArtifacts();
78 Set<String> giArtifactsSet = new HashSet<>();
80 if (giArtifacts != null && !giArtifacts.isEmpty()) {
81 giArtifactsSet.addAll(giArtifacts);
83 giArtifacts.addAll(giArtifactsSet);
87 private void clearArtifactsUuid() {
88 List<String> artifactsUuid = getArtifactsUuid();
89 if(CollectionUtils.isNotEmpty(artifactsUuid)){
90 artifactsUuid.clear();
91 } else if (artifactsUuid == null){
92 setArtifactsUuid(new ArrayList<>());
95 List<String> giartifactsUuid = this.getGroupInstanceArtifactsUuid();
96 if(CollectionUtils.isNotEmpty(giartifactsUuid)){
97 giartifactsUuid.clear();
98 } else if (giartifactsUuid == null){
99 setGroupInstanceArtifactsUuid(new ArrayList<>());
104 * Aligns the list of artifacts UUIDs of group instance according to received deployment artifacts
105 * @param deploymentArtifacts
107 public void alignArtifactsUuid(Map<String, ArtifactDefinition> deploymentArtifacts) {
108 List<String> artifactIds = getArtifacts();
109 log.debug("the artifacts Id's are: {}, and the deployment artifacts Id's are: {}", artifactIds, deploymentArtifacts);
110 if(CollectionUtils.isNotEmpty(artifactIds) && deploymentArtifacts != null){
111 removeArtifactsDuplicates();
112 clearArtifactsUuid();
113 List<String> artifactUuids = getArtifactsUuid();
114 List<String> giArtifactUuids = getGroupInstanceArtifactsUuid();
115 for(String artifactId : artifactIds){
116 String label = artifactId.substring(artifactId.lastIndexOf('.') + 1);
117 ArtifactDefinition artifact = deploymentArtifacts.get(label);
118 log.debug("current artifact id: {}, current artifact definition: {}", artifactId, artifact);
119 ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
120 if (artifactType != ArtifactTypeEnum.HEAT_ENV){
121 addArtifactsIdToCollection(artifactUuids, artifact);
123 addArtifactsIdToCollection(giArtifactUuids, artifact);
130 private void addArtifactsIdToCollection(List<String> artifactUuids, ArtifactDefinition artifact) {
131 if(!artifactUuids.contains(artifact.getArtifactUUID()) && StringUtils.isNotEmpty(artifact.getArtifactUUID())){
132 artifactUuids.add(artifact.getArtifactUUID());