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 java.util.ArrayList;
24 import java.util.List;
26 import java.util.Optional;
27 import java.util.stream.Collectors;
29 import org.apache.commons.collections.CollectionUtils;
30 import org.openecomp.sdc.be.model.GroupDefinition;
31 import org.openecomp.sdc.be.model.GroupInstance;
32 import org.openecomp.sdc.be.model.GroupInstanceProperty;
33 import org.openecomp.sdc.be.model.GroupProperty;
34 import org.openecomp.sdc.common.api.Constants;
36 public class VfModuleArtifactPayload {
38 private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelCustomizationUUID, vfModuleModelDescription;
39 private Boolean isBase;
40 private List<String> artifacts;
41 private Map< String, Object> properties;
43 public VfModuleArtifactPayload(GroupDefinition group) {
44 vfModuleModelName = group.getName();
45 vfModuleModelInvariantUUID = group.getInvariantUUID();
46 vfModuleModelVersion = group.getVersion();
47 vfModuleModelUUID = group.getGroupUUID();
48 vfModuleModelDescription = group.getDescription();
50 artifacts = group.getArtifactsUuid();
51 // Base Value is set from properties
56 public VfModuleArtifactPayload(GroupInstance group) {
57 vfModuleModelName = group.getGroupName();
58 vfModuleModelInvariantUUID = group.getInvariantUUID();
59 vfModuleModelVersion = group.getVersion();
60 vfModuleModelUUID = group.getGroupUUID();
61 vfModuleModelCustomizationUUID = group.getCustomizationUUID();
62 vfModuleModelDescription = group.getDescription();
64 artifacts = group.getArtifactsUuid();
65 artifacts.addAll(group.getGroupInstanceArtifactsUuid());
67 // Base Value is set from properties
70 if(group.convertToGroupInstancesProperties() != null)
71 setProperties(group.convertToGroupInstancesProperties());
72 //converts List of GroupInstanceProperties to Map propertyName : GroupInstanceProperty ()
73 //setProperties(group.getGroupInstancesProperties().stream().collect(Collectors.toMap(p->p.getName(), p->p)));
77 private void setBaseValue(GroupInstance group) {
78 if (group.convertToGroupInstancesProperties() != null) {
79 Optional<GroupInstanceProperty> findBaseProperty = group.convertToGroupInstancesProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
80 if (findBaseProperty.isPresent()) {
81 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
86 private void setBaseValue(GroupDefinition group) {
87 if (group.getProperties() != null) {
88 Optional<GroupProperty> findBaseProperty = group.convertToGroupProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
89 if (findBaseProperty.isPresent()) {
90 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
98 public List<String> getArtifacts() {
102 public void setArtifacts(List<String> artifacts) {
103 this.artifacts = artifacts;
108 public Map<String, Object> getProperties() {
112 /*public void setProperties(Map<String, Object> properties) {
113 this.properties = properties;
116 public void setProperties(List<GroupInstanceProperty> properties) {
117 this.properties = properties.stream().filter(p -> !p.getName().equals(Constants.IS_BASE)).collect(
118 Collectors.toMap(x -> x.getName(), x -> x.getValue() == null? "":x.getValue() ));
121 public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
122 Float thisCounter = Float.parseFloat(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
123 Float otherCounter = Float.parseFloat(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
124 return thisCounter.compareTo(otherCounter);