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.datatypes.elements.PropertyDataDefinition;
24 import org.openecomp.sdc.be.model.GroupDefinition;
25 import org.openecomp.sdc.be.model.GroupInstance;
26 import org.openecomp.sdc.be.model.GroupInstanceProperty;
27 import org.openecomp.sdc.be.model.GroupProperty;
28 import org.openecomp.sdc.common.api.Constants;
31 import java.util.stream.Collectors;
33 public class VfModuleArtifactPayload {
35 private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelCustomizationUUID, vfModuleModelDescription;
36 private Boolean isBase;
37 private List<String> artifacts;
38 private Map< String, Object> properties;
40 public VfModuleArtifactPayload(GroupDefinition group) {
41 vfModuleModelName = group.getName();
42 vfModuleModelInvariantUUID = group.getInvariantUUID();
43 vfModuleModelVersion = group.getVersion();
44 vfModuleModelUUID = group.getGroupUUID();
45 vfModuleModelDescription = group.getDescription();
47 artifacts = group.getArtifactsUuid();
48 // Base Value is set from properties
53 public VfModuleArtifactPayload(GroupInstance group) {
54 vfModuleModelName = group.getGroupName();
55 vfModuleModelInvariantUUID = group.getInvariantUUID();
56 vfModuleModelVersion = group.getVersion();
57 vfModuleModelUUID = group.getGroupUUID();
58 vfModuleModelCustomizationUUID = group.getCustomizationUUID();
59 vfModuleModelDescription = group.getDescription();
61 artifacts = new ArrayList<>(group.getArtifactsUuid() != null ? group.getArtifactsUuid() : new LinkedList<>());
62 artifacts.addAll(group.getGroupInstanceArtifactsUuid() != null ? group.getGroupInstanceArtifactsUuid() : new LinkedList<>());
64 // Base Value is set from properties
67 if(group.convertToGroupInstancesProperties() != null)
68 setProperties(group.convertToGroupInstancesProperties());
71 private void setBaseValue(GroupInstance group) {
72 if (group.convertToGroupInstancesProperties() != null) {
73 Optional<GroupInstanceProperty> findBaseProperty = group.convertToGroupInstancesProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
74 if (findBaseProperty.isPresent()) {
75 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
80 private void setBaseValue(GroupDefinition group) {
81 if (group.getProperties() != null) {
82 Optional<GroupProperty> findBaseProperty = group.convertToGroupProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
83 if (findBaseProperty.isPresent()) {
84 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
92 public List<String> getArtifacts() {
96 public void setArtifacts(List<String> artifacts) {
97 this.artifacts = artifacts;
102 public Map<String, Object> getProperties() {
107 public void setProperties(List<GroupInstanceProperty> properties) {
108 this.properties = properties.stream().filter(p -> !p.getName().equals(Constants.IS_BASE)).collect(
109 Collectors.toMap(PropertyDataDefinition::getName, x -> x.getValue() == null? "":x.getValue() ));
112 public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
113 Float thisCounter = Float.parseFloat(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
114 Float otherCounter = Float.parseFloat(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
115 return thisCounter.compareTo(otherCounter);