[SDC-29] rebase continue work to align source
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / distribution / engine / VfModuleArtifactPayload.java
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.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Optional;
27 import java.util.stream.Collectors;
28
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;
35
36 public class VfModuleArtifactPayload {
37         
38         private String vfModuleModelName, vfModuleModelInvariantUUID, vfModuleModelVersion, vfModuleModelUUID, vfModuleModelCustomizationUUID, vfModuleModelDescription;
39         private Boolean isBase;
40         private List<String> artifacts;
41         private Map< String, Object> properties;
42         
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();
49
50                 artifacts = group.getArtifactsUuid();
51                 // Base Value is set from properties
52                 setBaseValue(group);
53
54         }
55         
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();
63
64                 artifacts = group.getArtifactsUuid();
65                 artifacts.addAll(group.getGroupInstanceArtifactsUuid());
66                 
67                 // Base Value is set from properties
68                 setBaseValue(group);
69                 
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)));
74
75         }
76
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());
82                         }
83
84                 }
85         }
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());
91                         }
92
93                 }
94         }
95
96
97
98         public List<String> getArtifacts() {
99                 return artifacts;
100         }
101
102         public void setArtifacts(List<String> artifacts) {
103                 this.artifacts = artifacts;
104         }
105         
106         
107
108         public Map<String, Object> getProperties() {
109                 return properties;
110         }
111
112         /*public void setProperties(Map<String, Object> properties) {
113                 this.properties = properties;
114         }*/
115         
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() ));
119         }
120
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);
125         }
126 }