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.components.distribution.engine;
23 import org.openecomp.sdc.be.model.GroupDefinition;
24 import org.openecomp.sdc.be.model.GroupInstance;
25 import org.openecomp.sdc.be.model.GroupInstanceProperty;
26 import org.openecomp.sdc.be.model.GroupProperty;
27 import org.openecomp.sdc.common.api.Constants;
29 import java.util.ArrayList;
30 import java.util.List;
32 import java.util.Optional;
33 import java.util.stream.Collectors;
35 public class VfModuleArtifactPayload {
37 private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelCustomizationUUID, vfModuleModelDescription;
38 private Boolean isBase;
39 private List<String> artifacts;
40 private Map< String, Object> properties;
42 public VfModuleArtifactPayload(GroupDefinition group) {
43 vfModuleModelName = group.getName();
44 vfModuleModelInvariantUUID = group.getInvariantUUID();
45 vfModuleModelVersion = group.getVersion();
46 vfModuleModelUUID = group.getGroupUUID();
47 vfModuleModelDescription = group.getDescription();
49 artifacts = group.getArtifactsUuid();
50 // Base Value is set from properties
55 public VfModuleArtifactPayload(GroupInstance group) {
56 vfModuleModelName = group.getGroupName();
57 vfModuleModelInvariantUUID = group.getInvariantUUID();
58 vfModuleModelVersion = group.getVersion();
59 vfModuleModelUUID = group.getGroupUUID();
60 vfModuleModelCustomizationUUID = group.getCustomizationUUID();
61 vfModuleModelDescription = group.getDescription();
63 artifacts = new ArrayList<>(group.getArtifactsUuid());
64 artifacts.addAll(group.getGroupInstanceArtifactsUuid());
66 // Base Value is set from properties
69 if(group.convertToGroupInstancesProperties() != null)
70 setProperties(group.convertToGroupInstancesProperties());
73 private void setBaseValue(GroupInstance group) {
74 if (group.convertToGroupInstancesProperties() != null) {
75 Optional<GroupInstanceProperty> findBaseProperty = group.convertToGroupInstancesProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
76 if (findBaseProperty.isPresent()) {
77 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
82 private void setBaseValue(GroupDefinition group) {
83 if (group.getProperties() != null) {
84 Optional<GroupProperty> findBaseProperty = group.convertToGroupProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
85 if (findBaseProperty.isPresent()) {
86 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
94 public List<String> getArtifacts() {
98 public void setArtifacts(List<String> artifacts) {
99 this.artifacts = artifacts;
104 public Map<String, Object> getProperties() {
109 public void setProperties(List<GroupInstanceProperty> properties) {
110 this.properties = properties.stream().filter(p -> !p.getName().equals(Constants.IS_BASE)).collect(
111 Collectors.toMap(x -> x.getName(), x -> x.getValue() == null? "":x.getValue() ));
114 public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
115 Float thisCounter = Float.parseFloat(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
116 Float otherCounter = Float.parseFloat(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
117 return thisCounter.compareTo(otherCounter);