0af2bb55ed1ae4e22227fdf4606aee74e3dee213
[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 package org.openecomp.sdc.be.components.distribution.engine;
21
22 import java.util.ArrayList;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.stream.Collectors;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
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.common.api.Constants;
32
33 public class VfModuleArtifactPayload {
34
35     private String vfModuleModelName;
36     private List<String> artifacts;
37     private Map<String, Object> properties;
38
39     public VfModuleArtifactPayload(GroupDefinition group) {
40         vfModuleModelName = group.getName();
41         artifacts = group.getArtifactsUuid();
42         // Base Value is set from properties
43     }
44
45     public VfModuleArtifactPayload(GroupInstance group) {
46         vfModuleModelName = group.getGroupName();
47         artifacts = new ArrayList<>(group.getArtifactsUuid() != null ? group.getArtifactsUuid() : new LinkedList<>());
48         artifacts.addAll(group.getGroupInstanceArtifactsUuid() != null ? group.getGroupInstanceArtifactsUuid() : new LinkedList<>());
49         // Base Value is set from properties
50         if (group.convertToGroupInstancesProperties() != null) {
51             setProperties(group.convertToGroupInstancesProperties());
52         }
53     }
54
55     public static int compareByGroupName(VfModuleArtifactPayload art1, VfModuleArtifactPayload art2) {
56         Float thisCounter = Float.parseFloat(art1.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
57         Float otherCounter = Float.parseFloat(art2.vfModuleModelName.split(Constants.MODULE_NAME_DELIMITER)[1].replace(' ', '.'));
58         return thisCounter.compareTo(otherCounter);
59     }
60
61     public List<String> getArtifacts() {
62         return artifacts;
63     }
64
65     public void setArtifacts(List<String> artifacts) {
66         this.artifacts = artifacts;
67     }
68
69     public Map<String, Object> getProperties() {
70         return properties;
71     }
72
73     public void setProperties(List<GroupInstanceProperty> properties) {
74         this.properties = properties.stream().filter(p -> !p.getName().equals(Constants.IS_BASE))
75             .collect(Collectors.toMap(PropertyDataDefinition::getName, x -> x.getValue() == null ? "" : x.getValue()));
76     }
77 }