d706e40f5c02c75b9f956ff74a7bf8a6159fb5a0
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.distribution.engine;
22
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Optional;
26 import java.util.stream.Collectors;
27
28 import org.openecomp.sdc.be.model.GroupDefinition;
29 import org.openecomp.sdc.be.model.GroupInstance;
30 import org.openecomp.sdc.be.model.GroupInstanceProperty;
31 import org.openecomp.sdc.be.model.GroupProperty;
32 import org.openecomp.sdc.common.api.Constants;
33
34 public class VfModuleArtifactPayload {
35         
36         private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelCustomizationUUID, vfModuleModelDescription;
37         private Boolean isBase;
38         private List<String> artifacts;
39         private Map< String, Object> properties;
40         
41         public VfModuleArtifactPayload(GroupDefinition group) {
42                 vfModuleModelName = group.getName();
43                 vfModuleModelInvariantUUID = group.getInvariantUUID();
44                 vfModuleModelVersion = group.getVersion();
45                 vfModuleModelUUID = group.getGroupUUID();
46                 vfModuleModelDescription = group.getDescription();
47
48                 artifacts = group.getArtifactsUuid();
49                 // Base Value is set from properties
50                 setBaseValue(group);
51
52         }
53         
54         public VfModuleArtifactPayload(GroupInstance group) {
55                 vfModuleModelName = group.getGroupName();
56                 vfModuleModelInvariantUUID = group.getInvariantUUID();
57                 vfModuleModelVersion = group.getVersion();
58                 vfModuleModelUUID = group.getGroupUUID();
59                 vfModuleModelCustomizationUUID = group.getCustomizationUUID();
60                 vfModuleModelDescription = group.getDescription();
61
62                 artifacts = group.getArtifactsUuid();
63                 artifacts.addAll(group.getGroupInstanceArtifactsUuid());
64                 
65                 // Base Value is set from properties
66                 setBaseValue(group);
67                 
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)));
72
73         }
74
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());
80                         }
81
82                 }
83         }
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());
89                         }
90
91                 }
92         }
93
94
95
96         public List<String> getArtifacts() {
97                 return artifacts;
98         }
99
100         public void setArtifacts(List<String> artifacts) {
101                 this.artifacts = artifacts;
102         }
103         
104         
105
106         public Map<String, Object> getProperties() {
107                 return properties;
108         }
109
110         /*public void setProperties(Map<String, Object> properties) {
111                 this.properties = properties;
112         }*/
113         
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() ));
117         }
118
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);
123         }
124 }