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 // Base Value is set from properties
68 if(group.convertToGroupInstancesProperties() != null)
69 setProperties(group.convertToGroupInstancesProperties());
70 //converts List of GroupInstanceProperties to Map propertyName : GroupInstanceProperty ()
71 //setProperties(group.getGroupInstancesProperties().stream().collect(Collectors.toMap(p->p.getName(), p->p)));
75 private void setBaseValue(GroupInstance group) {
76 if (group.convertToGroupInstancesProperties() != null) {
77 Optional<GroupInstanceProperty> findBaseProperty = group.convertToGroupInstancesProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
78 if (findBaseProperty.isPresent()) {
79 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
84 private void setBaseValue(GroupDefinition group) {
85 if (group.getProperties() != null) {
86 Optional<GroupProperty> findBaseProperty = group.convertToGroupProperties().stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
87 if (findBaseProperty.isPresent()) {
88 isBase = Boolean.valueOf(findBaseProperty.get().getValue());
96 public List<String> getArtifacts() {
100 public void setArtifacts(List<String> artifacts) {
101 this.artifacts = artifacts;
106 public Map<String, Object> getProperties() {
110 /*public void setProperties(Map<String, Object> properties) {
111 this.properties = properties;
114 public void setProperties(List<GroupInstanceProperty> properties) {
115 this.properties = properties.stream().filter(p -> !p.getName().equals(Constants.IS_BASE)).collect(
116 Collectors.toMap(x -> x.getName(), x -> x.getValue() == null? "":x.getValue() ));
119 public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
120 Float thisCounter = Float.parseFloat(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
121 Float otherCounter = Float.parseFloat(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
122 return thisCounter.compareTo(otherCounter);